6#include <QtCore/qpropertyanimation.h>
7#include <QtCore/qparallelanimationgroup.h>
8#include <QtGui/qpainter.h>
9#include <QtGui/qpainterpath.h>
10#include <QtQml/qqmlinfo.h>
11#include <QtQuickTemplates2/private/qquicktheme_p.h>
12#include <QtQuickTemplates2/private/qquicktextarea_p.h>
13#include <QtQuickTemplates2/private/qquicktextfield_p.h>
53 return m_controlHasActiveFocus;
62 if (m_controlHasActiveFocus)
63 controlGotActiveFocus();
65 controlLostActiveFocus();
71 return m_controlHasText;
80 maybeSetFocusAnimationProgress();
90bool QQuickMaterialPlaceholderText::shouldFloat()
const
92 const bool controlHasActiveFocusOrText = m_controlHasActiveFocus || m_controlHasText;
94 ? controlHasActiveFocusOrText
98bool QQuickMaterialPlaceholderText::shouldAnimate()
const
105void QQuickMaterialPlaceholderText::updateY()
107 setY(shouldFloat() ? floatingTargetY() : normalTargetY());
112 if (
const auto textArea = qobject_cast<QQuickTextArea *>(textControl))
113 return textArea->topInset();
115 if (
const auto textField = qobject_cast<QQuickTextField *>(textControl))
116 return textField->topInset();
121qreal QQuickMaterialPlaceholderText::normalTargetY()
const
123 auto *textArea = qobject_cast<QQuickTextArea *>(
textControl());
124 if (textArea && m_controlHeight >= textArea->implicitHeight()) {
132 return ((m_controlImplicitBackgroundHeight - m_largestHeight) / 2.0)
137 return (m_controlHeight -
height()) / 2.0;
140qreal QQuickMaterialPlaceholderText::floatingTargetY()
const
145 return m_verticalPadding;
159 return m_largestHeight;
164 return m_controlImplicitBackgroundHeight;
189 return m_controlHeight;
203 return m_verticalPadding;
215void QQuickMaterialPlaceholderText::controlGotActiveFocus()
217 if (m_focusOutAnimation)
218 m_focusOutAnimation->
stop();
221 if (shouldAnimate()) {
232 scaleAnimation->setDuration(300);
233 scaleAnimation->setStartValue(1);
244void QQuickMaterialPlaceholderText::controlLostActiveFocus()
247 if (shouldAnimate()) {
258 scaleAnimation->setDuration(300);
260 scaleAnimation->setEndValue(1);
270void QQuickMaterialPlaceholderText::maybeSetFocusAnimationProgress()
283 qmlWarning(
this) <<
"Expected parent item by component completion!";
286 if (m_largestHeight > 0) {
289 qmlWarning(
this) <<
"Expected implicitHeight of placeholder text" <<
text()
290 <<
"to be greater than 0 by component completion!";
293 maybeSetFocusAnimationProgress();
void stop()
Stops the animation.
void start(QAbstractAnimation::DeletionPolicy policy=KeepWhenStopped)
Starts the animation.
void addAnimation(QAbstractAnimation *animation)
Adds animation to this group.
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
QQuickItem * parentItem() const
void setTransformOrigin(TransformOrigin)
void update()
Schedules a call to updatePaintNode() for this item.
void setFilled(bool filled)
void setControlHasText(bool controlHasText)
void verticalPaddingChanged()
void controlImplicitBackgroundHeightChanged()
void setControlImplicitBackgroundHeight(qreal controlImplicitBackgroundHeight)
void controlHasTextChanged()
void setVerticalPadding(qreal verticalPadding)
void setControlHeight(qreal controlHeight)
void controlHasActiveFocusChanged()
void componentComplete() override
\reimp Derived classes should call the base class method before adding their own actions to perform a...
QQuickMaterialPlaceholderText(QQuickItem *parent=nullptr)
void largestHeightChanged()
qreal controlImplicitBackgroundHeight
bool controlHasActiveFocus
void setControlHasActiveFocus(bool controlHasActiveFocus)
QQuickItem * textControl() const
void componentComplete() override
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
void setStartValue(const QVariant &value)
void setEasingCurve(const QEasingCurve &easing)
void setDuration(int msecs)
void setEndValue(const QVariant &value)
Combined button and popup list for selecting options.
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
GLint GLsizei GLsizei height
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
static QT_BEGIN_NAMESPACE const qreal floatingScale
qreal controlTopInset(QQuickItem *textControl)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent