6#include <QtCore/qpropertyanimation.h>
7#include <QtGui/qpainter.h>
8#include <QtGui/qpainterpath.h>
9#include <QtQml/qqmlinfo.h>
67 return m_outlineColor;
81 return m_outlineColor;
95 return m_focusAnimationProgress;
103 m_focusAnimationProgress = progress;
109 return m_placeholderTextWidth;
123 return m_placeholderTextHAlign;
137 return m_controlHasActiveFocus;
146 if (m_controlHasActiveFocus)
147 controlGotActiveFocus();
149 controlLostActiveFocus();
155 return m_controlHasText;
166 maybeSetFocusAnimationProgress();
173 return m_placeholderHasText;
182 maybeSetFocusAnimationProgress();
189 return m_horizontalPadding;
213 if (
w <= 0 ||
h <= 0)
217 const qreal penWidth = m_filled ? 1 : (m_controlHasActiveFocus ? 2 : 1);
221 const qreal cornerRadius = 4;
224 const qreal gapPadding = 4;
229 const qreal halfPlaceholderWidth = m_placeholderTextWidth / 2;
232 switch (m_placeholderTextHAlign) {
234 gapCenterX =
width() / 2;
237 gapCenterX =
width() - halfPlaceholderWidth - m_horizontalPadding;
240 gapCenterX = m_horizontalPadding + halfPlaceholderWidth;
249 if (m_filled || m_focusAnimationProgress == 0) {
250 startPos =
QPointF(cornerRadius, 0);
257 startPos =
QPointF(gapCenterX - (m_focusAnimationProgress * halfPlaceholderWidth) - gapPadding - penWidth, 0);
259 path.moveTo(startPos);
260 path.arcTo(0, 0, cornerRadius * 2, cornerRadius * 2, 90, 90);
266 path.lineTo(0,
h - cornerRadius * 2);
267 path.arcTo(0,
h - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 180, 90);
274 path.lineTo(
w - cornerRadius * 2,
h);
275 path.arcTo(
w - cornerRadius * 2,
h - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 270, 90);
279 path.lineTo(
w, cornerRadius);
280 path.arcTo(
w - (cornerRadius * 2), 0, cornerRadius * 2, cornerRadius * 2, 0, 90);
282 if (m_filled ||
qFuzzyIsNull(m_focusAnimationProgress)) {
284 path.lineTo(startPos.
x(), startPos.
y());
286 path.lineTo(gapCenterX + (m_focusAnimationProgress * halfPlaceholderWidth) + gapPadding, startPos.
y());
294 auto control = textControl();
295 const bool focused = control && control->hasActiveFocus();
299 pen.
setColor(m_filled ? m_fillColor : (focused ? m_focusedOutlineColor : m_outlineColor));
324 const int lineLength = m_focusAnimationProgress *
w;
325 const int horizontalCenter =
w / 2;
326 pen.
setColor(m_focusedOutlineColor);
330 horizontalCenter + (lineLength / 2) + pen.
width() / 2,
h);
335bool QQuickMaterialTextContainer::shouldAnimateOutline()
const
337 return !m_controlHasText && m_placeholderHasText;
345QQuickItem *QQuickMaterialTextContainer::textControl()
const
350void QQuickMaterialTextContainer::controlGotActiveFocus()
352 const bool shouldAnimate = m_filled ? !m_controlHasText : shouldAnimateOutline();
353 if (!shouldAnimate) {
355 if (m_filled && m_controlHasText) {
358 m_focusAnimationProgress = 1;
364 startFocusAnimation();
367void QQuickMaterialTextContainer::controlLostActiveFocus()
371 if (m_filled || !shouldAnimateOutline()) {
375 m_focusAnimationProgress = 0;
387void QQuickMaterialTextContainer::startFocusAnimation()
398void QQuickMaterialTextContainer::maybeSetFocusAnimationProgress()
403 if (m_controlHasText && m_placeholderHasText) {
406 }
else if (!m_controlHasText && !m_controlHasActiveFocus) {
417 qmlWarning(
this) <<
"Expected parent item by component completion!";
419 maybeSetFocusAnimationProgress();
void start(QAbstractAnimation::DeletionPolicy policy=KeepWhenStopped)
Starts the animation.
The QColor class provides colors based on RGB, HSV or CMYK values.
The QPainter class performs low-level painting on widgets and other paint devices.
void drawPath(const QPainterPath &path)
Draws the given painter path using the current pen for outline and the current brush for filling.
void setPen(const QColor &color)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void drawLine(const QLineF &line)
Draws a line defined by line.
void setBrush(const QBrush &brush)
Sets the painter's brush to the given brush.
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint.
void setWidth(int width)
Sets the pen width to the given width in pixels with integer precision.
void setWidthF(qreal width)
Sets the pen width to the given width in pixels with floating point precision.
int width() const
Returns the pen width with integer precision.
void setColor(const QColor &color)
Sets the color of this pen's brush to the given color.
\inmodule QtCore\reentrant
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
virtual void componentComplete()=0
Invoked after the root component that caused this instantiation has completed construction.
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
qreal width
This property holds the width of this item.
QQuickItem * parentItem() const
QQuickItem * parent
\qmlproperty Item QtQuick::Item::parent This property holds the visual parent of the item.
qreal height
This property holds the height of this item.
void update()
Schedules a call to updatePaintNode() for this item.
void setFocusedOutlineColor(const QColor &focusedOutlineColor)
void componentComplete() override
\reimp Derived classes should call the base class method before adding their own actions to perform a...
void setOutlineColor(const QColor &outlineColor)
void setControlHasActiveFocus(bool controlHasActiveFocus)
void setControlHasText(bool controlHasText)
qreal focusAnimationProgress
bool controlHasActiveFocus
PlaceHolderHAlignment placeholderTextHAlign
void placeholderHasTextChanged()
void setHorizontalPadding(int horizontalPadding)
void setFilled(bool filled)
void setPlaceholderTextHAlign(PlaceHolderHAlignment placeHolderTextHAlign)
void controlHasTextChanged()
void setPlaceholderTextWidth(qreal placeholderTextWidth)
void setFillColor(const QColor &fillColor)
void setPlaceholderHasText(bool placeholderHasText)
void paint(QPainter *painter) override
This function, which is usually called by the QML Scene Graph, paints the contents of an item in loca...
QColor focusedOutlineColor
void horizontalPaddingChanged()
void controlHasActiveFocusChanged()
qreal placeholderTextWidth
void setFocusAnimationProgress(qreal progress)
QQuickMaterialTextContainer(QQuickItem *parent=nullptr)
The QQuickPaintedItem class provides a way to use the QPainter API in the QML Scene Graph.
void setStartValue(const QVariant &value)
void setDuration(int msecs)
void setEndValue(const QVariant &value)
Combined button and popup list for selecting options.
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
bool qFuzzyIsNull(qfloat16 f) noexcept
GLfloat GLfloat GLfloat w
[0]
GLfloat GLfloat GLfloat GLfloat h
GLsizei const GLchar *const * path
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
QQuickItem * qobject_cast< QQuickItem * >(QObject *o)