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_controlHasActiveFocus;
132 if (m_controlHasActiveFocus)
133 controlGotActiveFocus();
135 controlLostActiveFocus();
141 return m_controlHasText;
152 maybeSetFocusAnimationProgress();
159 return m_placeholderHasText;
168 maybeSetFocusAnimationProgress();
175 return m_horizontalPadding;
199 if (
w <= 0 ||
h <= 0)
203 const qreal penWidth = m_filled ? 1 : (m_controlHasActiveFocus ? 2 : 1);
207 const qreal cornerRadius = 4;
210 const qreal gapPadding = 4;
216 if (m_filled || m_focusAnimationProgress == 0) {
217 startPos =
QPointF(cornerRadius, 0);
223 const qreal halfPlaceholderWidth = m_placeholderTextWidth / 2;
227 const qreal gapCenterX = m_horizontalPadding + halfPlaceholderWidth;
233 startPos =
QPointF(gapCenterX - (m_focusAnimationProgress * halfPlaceholderWidth) - gapPadding - penWidth, 0);
235 path.moveTo(startPos);
236 path.arcTo(0, 0, cornerRadius * 2, cornerRadius * 2, 90, 90);
242 path.lineTo(0,
h - cornerRadius * 2);
243 path.arcTo(0,
h - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 180, 90);
250 path.lineTo(
w - cornerRadius * 2,
h);
251 path.arcTo(
w - cornerRadius * 2,
h - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 270, 90);
255 path.lineTo(
w, cornerRadius);
256 path.arcTo(
w - (cornerRadius * 2), 0, cornerRadius * 2, cornerRadius * 2, 0, 90);
258 if (m_filled ||
qFuzzyIsNull(m_focusAnimationProgress)) {
260 path.lineTo(startPos.
x(), startPos.
y());
263 const qreal halfPlaceholderWidth = (m_placeholderTextWidth) / 2;
264 const qreal gapCenterX = m_horizontalPadding + halfPlaceholderWidth;
267 path.lineTo(gapCenterX + (m_focusAnimationProgress * halfPlaceholderWidth) + gapPadding, startPos.
y());
275 auto control = textControl();
276 const bool focused = control && control->hasActiveFocus();
280 pen.
setColor(m_filled ? m_fillColor : (focused ? m_focusedOutlineColor : m_outlineColor));
305 const int lineLength = m_focusAnimationProgress *
w;
306 const int horizontalCenter =
w / 2;
307 pen.
setColor(m_focusedOutlineColor);
311 horizontalCenter + (lineLength / 2) + pen.
width() / 2,
h);
316bool QQuickMaterialTextContainer::shouldAnimateOutline()
const
318 return !m_controlHasText && m_placeholderHasText;
326QQuickItem *QQuickMaterialTextContainer::textControl()
const
331void QQuickMaterialTextContainer::controlGotActiveFocus()
333 const bool shouldAnimate = m_filled ? !m_controlHasText : shouldAnimateOutline();
334 if (!shouldAnimate) {
336 if (m_filled && m_controlHasText) {
339 m_focusAnimationProgress = 1;
345 startFocusAnimation();
348void QQuickMaterialTextContainer::controlLostActiveFocus()
352 if (m_filled || !shouldAnimateOutline()) {
356 m_focusAnimationProgress = 0;
368void QQuickMaterialTextContainer::startFocusAnimation()
379void QQuickMaterialTextContainer::maybeSetFocusAnimationProgress()
384 if (m_controlHasText && m_placeholderHasText) {
387 }
else if (!m_controlHasText && !m_controlHasActiveFocus) {
398 qmlWarning(
this) <<
"Expected parent item by component completion!";
400 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
void placeholderHasTextChanged()
void setHorizontalPadding(int horizontalPadding)
void setFilled(bool filled)
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)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent