aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquicktextarea.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quicktemplates2/qquicktextarea.cpp')
-rw-r--r--src/quicktemplates2/qquicktextarea.cpp306
1 files changed, 287 insertions, 19 deletions
diff --git a/src/quicktemplates2/qquicktextarea.cpp b/src/quicktemplates2/qquicktextarea.cpp
index db6d9283..ee7d0ae3 100644
--- a/src/quicktemplates2/qquicktextarea.cpp
+++ b/src/quicktemplates2/qquicktextarea.cpp
@@ -145,28 +145,76 @@ QQuickTextAreaPrivate::~QQuickTextAreaPrivate()
#endif
}
-void QQuickTextAreaPrivate::resizeBackground()
+void QQuickTextAreaPrivate::setTopInset(qreal value, bool reset)
{
Q_Q(QQuickTextArea);
- if (background) {
- QQuickItemPrivate *p = QQuickItemPrivate::get(background);
- if (!p->widthValid && qFuzzyIsNull(background->x())) {
- if (flickable)
- background->setWidth(flickable->width());
- else
- background->setWidth(q->width());
- p->widthValid = false;
- }
- if (!p->heightValid && qFuzzyIsNull(background->y())) {
- if (flickable)
- background->setHeight(flickable->height());
- else
- background->setHeight(q->height());
- p->heightValid = false;
- }
+ const QMarginsF oldInset = getInset();
+ extra.value().topInset = value;
+ extra.value().hasTopInset = !reset;
+ if (!qFuzzyCompare(oldInset.top(), value)) {
+ emit q->topInsetChanged();
+ q->insetChange(getInset(), oldInset);
+ }
+}
+
+void QQuickTextAreaPrivate::setLeftInset(qreal value, bool reset)
+{
+ Q_Q(QQuickTextArea);
+ const QMarginsF oldInset = getInset();
+ extra.value().leftInset = value;
+ extra.value().hasLeftInset = !reset;
+ if (!qFuzzyCompare(oldInset.left(), value)) {
+ emit q->leftInsetChanged();
+ q->insetChange(getInset(), oldInset);
+ }
+}
+
+void QQuickTextAreaPrivate::setRightInset(qreal value, bool reset)
+{
+ Q_Q(QQuickTextArea);
+ const QMarginsF oldInset = getInset();
+ extra.value().rightInset = value;
+ extra.value().hasRightInset = !reset;
+ if (!qFuzzyCompare(oldInset.right(), value)) {
+ emit q->rightInsetChanged();
+ q->insetChange(getInset(), oldInset);
+ }
+}
+
+void QQuickTextAreaPrivate::setBottomInset(qreal value, bool reset)
+{
+ Q_Q(QQuickTextArea);
+ const QMarginsF oldInset = getInset();
+ extra.value().bottomInset = value;
+ extra.value().hasBottomInset = !reset;
+ if (!qFuzzyCompare(oldInset.bottom(), value)) {
+ emit q->bottomInsetChanged();
+ q->insetChange(getInset(), oldInset);
}
}
+void QQuickTextAreaPrivate::resizeBackground()
+{
+ if (!background)
+ return;
+
+ resizingBackground = true;
+
+ QQuickItemPrivate *p = QQuickItemPrivate::get(background);
+ if (((!p->widthValid || !extra.isAllocated() || !extra->hasBackgroundWidth) && qFuzzyIsNull(background->x()))
+ || (extra.isAllocated() && (extra->hasLeftInset || extra->hasRightInset))) {
+ background->setX(getLeftInset());
+ background->setWidth(width - getLeftInset() - getRightInset());
+ }
+ if (((!p->heightValid || !extra.isAllocated() || !extra->hasBackgroundHeight) && qFuzzyIsNull(background->y()))
+ || (extra.isAllocated() && (extra->hasTopInset || extra->hasBottomInset))) {
+ background->setY(getTopInset());
+ background->setHeight(height - getTopInset() - getBottomInset());
+ }
+
+ resizingBackground = false;
+}
+
/*!
\internal
@@ -186,7 +234,7 @@ void QQuickTextAreaPrivate::inheritFont(const QFont &font)
QFont parentFont = extra.isAllocated() ? extra->requestedFont.resolve(font) : font;
parentFont.resolve(extra.isAllocated() ? extra->requestedFont.resolve() | font.resolve() : font.resolve());
- const QFont defaultFont = QQuickControlPrivate::themeFont(QPlatformTheme::EditorFont);
+ const QFont defaultFont = QQuickTheme::font(QQuickTheme::TextArea);
const QFont resolvedFont = parentFont.resolve(defaultFont);
setFont_helper(resolvedFont);
@@ -228,7 +276,7 @@ void QQuickTextAreaPrivate::inheritPalette(const QPalette &palette)
QPalette parentPalette = extra.isAllocated() ? extra->requestedPalette.resolve(palette) : palette;
parentPalette.resolve(extra.isAllocated() ? extra->requestedPalette.resolve() | palette.resolve() : palette.resolve());
- const QPalette defaultPalette = QQuickControlPrivate::themePalette(QPlatformTheme::TextEditPalette);
+ const QPalette defaultPalette = QQuickTheme::palette(QQuickTheme::TextArea);
const QPalette resolvedPalette = parentPalette.resolve(defaultPalette);
setPalette_helper(resolvedPalette);
@@ -450,6 +498,30 @@ void QQuickTextAreaPrivate::executeBackground(bool complete)
quickCompleteDeferred(q, backgroundName(), background);
}
+void QQuickTextAreaPrivate::itemImplicitWidthChanged(QQuickItem *item)
+{
+ Q_Q(QQuickTextArea);
+ if (item == background)
+ emit q->implicitBackgroundWidthChanged();
+}
+
+void QQuickTextAreaPrivate::itemImplicitHeightChanged(QQuickItem *item)
+{
+ Q_Q(QQuickTextArea);
+ if (item == background)
+ emit q->implicitBackgroundHeightChanged();
+}
+
+void QQuickTextAreaPrivate::itemDestroyed(QQuickItem *item)
+{
+ Q_Q(QQuickTextArea);
+ if (item == background) {
+ background = nullptr;
+ emit q->implicitBackgroundWidthChanged();
+ emit q->implicitBackgroundHeightChanged();
+ }
+}
+
QQuickTextArea::QQuickTextArea(QQuickItem *parent)
: QQuickTextEdit(*(new QQuickTextAreaPrivate), parent)
{
@@ -470,6 +542,7 @@ QQuickTextArea::~QQuickTextArea()
Q_D(QQuickTextArea);
if (d->flickable)
d->detachFlickable();
+ QQuickControlPrivate::removeImplicitSizeListener(d->background, d, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
}
QQuickTextAreaAttached *QQuickTextArea::qmlAttachedProperties(QObject *object)
@@ -518,8 +591,18 @@ void QQuickTextArea::setBackground(QQuickItem *background)
if (!d->background.isExecuting())
d->cancelBackground();
+ const qreal oldImplicitBackgroundWidth = implicitBackgroundWidth();
+ const qreal oldImplicitBackgroundHeight = implicitBackgroundHeight();
+
+ if (d->extra.isAllocated()) {
+ d->extra.value().hasBackgroundWidth = false;
+ d->extra.value().hasBackgroundHeight = false;
+ }
+
+ QQuickControlPrivate::removeImplicitSizeListener(d->background, d, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
delete d->background;
d->background = background;
+
if (background) {
if (d->flickable)
background->setParentItem(d->flickable);
@@ -527,9 +610,20 @@ void QQuickTextArea::setBackground(QQuickItem *background)
background->setParentItem(this);
if (qFuzzyIsNull(background->z()))
background->setZ(-1);
+ QQuickItemPrivate *p = QQuickItemPrivate::get(background);
+ if (p->widthValid || p->heightValid) {
+ d->extra.value().hasBackgroundWidth = p->widthValid;
+ d->extra.value().hasBackgroundHeight = p->heightValid;
+ }
if (isComponentComplete())
d->resizeBackground();
+ QQuickControlPrivate::addImplicitSizeListener(background, d, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry);
}
+
+ if (!qFuzzyCompare(oldImplicitBackgroundWidth, implicitBackgroundWidth()))
+ emit implicitBackgroundWidthChanged();
+ if (!qFuzzyCompare(oldImplicitBackgroundHeight, implicitBackgroundHeight()))
+ emit implicitBackgroundHeightChanged();
if (!d->background.isExecuting())
emit backgroundChanged();
}
@@ -561,6 +655,30 @@ void QQuickTextArea::setPlaceholderText(const QString &text)
}
/*!
+ \qmlproperty color QtQuick.Controls::TextArea::placeholderTextColor
+ \since QtQuick.Controls 2.5 (Qt 5.12)
+
+ This property holds the color of placeholderText.
+
+ \sa placeholderText
+*/
+QColor QQuickTextArea::placeholderTextColor() const
+{
+ Q_D(const QQuickTextArea);
+ return d->placeholderColor;
+}
+
+void QQuickTextArea::setPlaceholderTextColor(const QColor &color)
+{
+ Q_D(QQuickTextArea);
+ if (d->placeholderColor == color)
+ return;
+
+ d->placeholderColor = color;
+ emit placeholderTextColorChanged();
+}
+
+/*!
\qmlproperty enumeration QtQuick.Controls::TextArea::focusReason
\include qquickcontrol-focusreason.qdocinc
@@ -697,6 +815,148 @@ void QQuickTextArea::resetPalette()
setPalette(QPalette());
}
+/*!
+ \since QtQuick.Controls 2.5 (Qt 5.12)
+ \qmlproperty real QtQuick.Controls::TextArea::implicitBackgroundWidth
+ \readonly
+
+ This property holds the implicit background width.
+
+ The value is equal to \c {background ? background.implicitWidth : 0}.
+
+ \sa implicitBackgroundHeight
+*/
+qreal QQuickTextArea::implicitBackgroundWidth() const
+{
+ Q_D(const QQuickTextArea);
+ if (!d->background)
+ return 0;
+ return d->background->implicitWidth();
+}
+
+/*!
+ \since QtQuick.Controls 2.5 (Qt 5.12)
+ \qmlproperty real QtQuick.Controls::TextArea::implicitBackgroundHeight
+ \readonly
+
+ This property holds the implicit background height.
+
+ The value is equal to \c {background ? background.implicitHeight : 0}.
+
+ \sa implicitBackgroundWidth
+*/
+qreal QQuickTextArea::implicitBackgroundHeight() const
+{
+ Q_D(const QQuickTextArea);
+ if (!d->background)
+ return 0;
+ return d->background->implicitHeight();
+}
+
+/*!
+ \since QtQuick.Controls 2.5 (Qt 5.12)
+ \qmlproperty real QtQuick.Controls::TextArea::topInset
+
+ This property holds the top inset for the background.
+
+ \sa {Control Layout}, bottomInset
+*/
+qreal QQuickTextArea::topInset() const
+{
+ Q_D(const QQuickTextArea);
+ return d->getTopInset();
+}
+
+void QQuickTextArea::setTopInset(qreal inset)
+{
+ Q_D(QQuickTextArea);
+ d->setTopInset(inset);
+}
+
+void QQuickTextArea::resetTopInset()
+{
+ Q_D(QQuickTextArea);
+ d->setTopInset(0, true);
+}
+
+/*!
+ \since QtQuick.Controls 2.5 (Qt 5.12)
+ \qmlproperty real QtQuick.Controls::TextArea::leftInset
+
+ This property holds the left inset for the background.
+
+ \sa {Control Layout}, rightInset
+*/
+qreal QQuickTextArea::leftInset() const
+{
+ Q_D(const QQuickTextArea);
+ return d->getLeftInset();
+}
+
+void QQuickTextArea::setLeftInset(qreal inset)
+{
+ Q_D(QQuickTextArea);
+ d->setLeftInset(inset);
+}
+
+void QQuickTextArea::resetLeftInset()
+{
+ Q_D(QQuickTextArea);
+ d->setLeftInset(0, true);
+}
+
+/*!
+ \since QtQuick.Controls 2.5 (Qt 5.12)
+ \qmlproperty real QtQuick.Controls::TextArea::rightInset
+
+ This property holds the right inset for the background.
+
+ \sa {Control Layout}, leftInset
+*/
+qreal QQuickTextArea::rightInset() const
+{
+ Q_D(const QQuickTextArea);
+ return d->getRightInset();
+}
+
+void QQuickTextArea::setRightInset(qreal inset)
+{
+ Q_D(QQuickTextArea);
+ d->setRightInset(inset);
+}
+
+void QQuickTextArea::resetRightInset()
+{
+ Q_D(QQuickTextArea);
+ d->setRightInset(0, true);
+}
+
+/*!
+ \since QtQuick.Controls 2.5 (Qt 5.12)
+ \qmlproperty real QtQuick.Controls::TextArea::bottomInset
+
+ This property holds the bottom inset for the background.
+
+ \sa {Control Layout}, topInset
+*/
+qreal QQuickTextArea::bottomInset() const
+{
+ Q_D(const QQuickTextArea);
+ return d->getBottomInset();
+}
+
+void QQuickTextArea::setBottomInset(qreal inset)
+{
+ Q_D(QQuickTextArea);
+ d->setBottomInset(inset);
+}
+
+void QQuickTextArea::resetBottomInset()
+{
+ Q_D(QQuickTextArea);
+ d->setBottomInset(0, true);
+}
+
void QQuickTextArea::classBegin()
{
Q_D(QQuickTextArea);
@@ -760,6 +1020,14 @@ void QQuickTextArea::geometryChanged(const QRectF &newGeometry, const QRectF &ol
d->resizeBackground();
}
+void QQuickTextArea::insetChange(const QMarginsF &newInset, const QMarginsF &oldInset)
+{
+ Q_D(QQuickTextArea);
+ Q_UNUSED(newInset);
+ Q_UNUSED(oldInset);
+ d->resizeBackground();
+}
+
QSGNode *QQuickTextArea::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data)
{
Q_D(QQuickTextArea);