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.cpp227
1 files changed, 122 insertions, 105 deletions
diff --git a/src/quicktemplates2/qquicktextarea.cpp b/src/quicktemplates2/qquicktextarea.cpp
index 5d710d4e..21d74dd8 100644
--- a/src/quicktemplates2/qquicktextarea.cpp
+++ b/src/quicktemplates2/qquicktextarea.cpp
@@ -38,15 +38,14 @@
#include "qquicktextarea_p_p.h"
#include "qquickcontrol_p.h"
#include "qquickcontrol_p_p.h"
+#include "qquickscrollview_p.h"
-#include <QtGui/qguiapplication.h>
#include <QtQml/qqmlinfo.h>
#include <QtQuick/private/qquickitem_p.h>
-#include <QtQuick/private/qquicktext_p.h>
#include <QtQuick/private/qquickclipnode_p.h>
#include <QtQuick/private/qquickflickable_p.h>
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
#include <QtQuick/private/qquickaccessibleattached_p.h>
#endif
@@ -82,14 +81,13 @@ QT_BEGIN_NAMESPACE
\section2 Scrollable TextArea
If you want to make a TextArea scrollable, for example, when it covers
- an entire application page, attach it to a \l Flickable and combine with a
- \l ScrollBar or \l ScrollIndicator.
+ an entire application page, it can be placed inside a \l ScrollView.
- \image qtquickcontrols2-textarea-flickable.png
+ \image qtquickcontrols2-textarea-scrollable.png
- \snippet qtquickcontrols2-textarea-flickable.qml 1
+ \snippet qtquickcontrols2-textarea-scrollable.qml 1
- A TextArea that is attached to a \l Flickable does the following:
+ A TextArea that is placed inside a \l ScrollView does the following:
\list
\li Sets the content size automatically
@@ -133,17 +131,24 @@ QT_BEGIN_NAMESPACE
*/
QQuickTextAreaPrivate::QQuickTextAreaPrivate()
- : hovered(false), explicitHoverEnabled(false), background(nullptr),
- focusReason(Qt::OtherFocusReason), accessibleAttached(nullptr), flickable(nullptr)
+ : QQuickTextEditPrivate(),
+#if QT_CONFIG(quicktemplates2_hover)
+ hovered(false),
+ explicitHoverEnabled(false),
+#endif
+ background(nullptr),
+ focusReason(Qt::OtherFocusReason),
+ accessibleAttached(nullptr),
+ flickable(nullptr)
{
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessible::installActivationObserver(this);
#endif
}
QQuickTextAreaPrivate::~QQuickTextAreaPrivate()
{
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
QAccessible::removeActivationObserver(this);
#endif
}
@@ -170,6 +175,52 @@ void QQuickTextAreaPrivate::resizeBackground()
}
}
+/*!
+ \internal
+
+ Determine which font is implicitly imposed on this control by its ancestors
+ and QGuiApplication::font, resolve this against its own font (attributes from
+ the implicit font are copied over). Then propagate this font to this
+ control's children.
+*/
+void QQuickTextAreaPrivate::resolveFont()
+{
+ Q_Q(QQuickTextArea);
+ inheritFont(QQuickControlPrivate::parentFont(q));
+}
+
+void QQuickTextAreaPrivate::inheritFont(const QFont &f)
+{
+ Q_Q(QQuickTextArea);
+ QFont parentFont = font.resolve(f);
+ parentFont.resolve(font.resolve() | f.resolve());
+
+ const QFont defaultFont = QQuickControlPrivate::themeFont(QPlatformTheme::EditorFont);
+ const QFont resolvedFont = parentFont.resolve(defaultFont);
+
+ const bool changed = resolvedFont != sourceFont;
+ q->QQuickTextEdit::setFont(resolvedFont);
+ if (changed)
+ emit q->fontChanged();
+}
+
+#if QT_CONFIG(quicktemplates2_hover)
+void QQuickTextAreaPrivate::updateHoverEnabled(bool enabled, bool xplicit)
+{
+ Q_Q(QQuickTextArea);
+ if (!xplicit && explicitHoverEnabled)
+ return;
+
+ bool wasEnabled = q->isHoverEnabled();
+ explicitHoverEnabled = xplicit;
+ if (wasEnabled != enabled) {
+ q->setAcceptHoverEvents(enabled);
+ QQuickControlPrivate::updateHoverEnabledRecur(q, enabled);
+ emit q->hoverEnabledChanged();
+ }
+}
+#endif
+
void QQuickTextAreaPrivate::attachFlickable(QQuickFlickable *item)
{
Q_Q(QQuickTextArea);
@@ -305,87 +356,19 @@ void QQuickTextAreaPrivate::implicitHeightChanged()
emit q->implicitHeightChanged3();
}
-QQuickTextArea::QQuickTextArea(QQuickItem *parent) :
- QQuickTextEdit(*(new QQuickTextAreaPrivate), parent)
-{
- Q_D(QQuickTextArea);
- setActiveFocusOnTab(true);
- setAcceptedMouseButtons(Qt::AllButtons);
- d->setImplicitResizeEnabled(false);
- d->pressHandler.control = this;
-#ifndef QT_NO_CURSOR
- setCursor(Qt::IBeamCursor);
-#endif
- QObjectPrivate::connect(this, &QQuickTextEdit::readOnlyChanged,
- d, &QQuickTextAreaPrivate::_q_readOnlyChanged);
-}
-
-QQuickTextArea::~QQuickTextArea()
-{
-}
-
-QQuickTextAreaAttached *QQuickTextArea::qmlAttachedProperties(QObject *object)
-{
- return new QQuickTextAreaAttached(object);
-}
-
-/*!
- \internal
-
- Determine which font is implicitly imposed on this control by its ancestors
- and QGuiApplication::font, resolve this against its own font (attributes from
- the implicit font are copied over). Then propagate this font to this
- control's children.
-*/
-void QQuickTextAreaPrivate::resolveFont()
-{
- Q_Q(QQuickTextArea);
- inheritFont(QQuickControlPrivate::parentFont(q));
-}
-
-void QQuickTextAreaPrivate::inheritFont(const QFont &f)
-{
- Q_Q(QQuickTextArea);
- QFont parentFont = font.resolve(f);
- parentFont.resolve(font.resolve() | f.resolve());
-
- const QFont defaultFont = QQuickControlPrivate::themeFont(QPlatformTheme::EditorFont);
- const QFont resolvedFont = parentFont.resolve(defaultFont);
-
- const bool changed = resolvedFont != sourceFont;
- q->QQuickTextEdit::setFont(resolvedFont);
- if (changed)
- emit q->fontChanged();
-}
-
-void QQuickTextAreaPrivate::updateHoverEnabled(bool enabled, bool xplicit)
-{
- Q_Q(QQuickTextArea);
- if (!xplicit && explicitHoverEnabled)
- return;
-
- bool wasEnabled = q->isHoverEnabled();
- explicitHoverEnabled = xplicit;
- if (wasEnabled != enabled) {
- q->setAcceptHoverEvents(enabled);
- QQuickControlPrivate::updateHoverEnabledRecur(q, enabled);
- emit q->hoverEnabledChanged();
- }
-}
-
-void QQuickTextAreaPrivate::_q_readOnlyChanged(bool isReadOnly)
+void QQuickTextAreaPrivate::readOnlyChanged(bool isReadOnly)
{
Q_UNUSED(isReadOnly);
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
if (accessibleAttached)
accessibleAttached->set_readOnly(isReadOnly);
#endif
-#ifndef QT_NO_CURSOR
+#if QT_CONFIG(cursor)
q_func()->setCursor(isReadOnly ? Qt::ArrowCursor : Qt::IBeamCursor);
#endif
}
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
void QQuickTextAreaPrivate::accessibilityActiveChanged(bool active)
{
if (accessibleAttached || !active)
@@ -408,12 +391,24 @@ QAccessible::Role QQuickTextAreaPrivate::accessibleRole() const
}
#endif
-void QQuickTextAreaPrivate::deleteDelegate(QObject *delegate)
+QQuickTextArea::QQuickTextArea(QQuickItem *parent)
+ : QQuickTextEdit(*(new QQuickTextAreaPrivate), parent)
+{
+ Q_D(QQuickTextArea);
+ setActiveFocusOnTab(true);
+ setAcceptedMouseButtons(Qt::AllButtons);
+ d->setImplicitResizeEnabled(false);
+ d->pressHandler.control = this;
+#if QT_CONFIG(cursor)
+ setCursor(Qt::IBeamCursor);
+#endif
+ QObjectPrivate::connect(this, &QQuickTextEdit::readOnlyChanged,
+ d, &QQuickTextAreaPrivate::readOnlyChanged);
+}
+
+QQuickTextAreaAttached *QQuickTextArea::qmlAttachedProperties(QObject *object)
{
- if (componentComplete)
- delete delegate;
- else if (delegate)
- pendingDeletions.append(delegate);
+ return new QQuickTextAreaAttached(object);
}
QFont QQuickTextArea::font() const
@@ -452,7 +447,7 @@ void QQuickTextArea::setBackground(QQuickItem *background)
if (d->background == background)
return;
- d->deleteDelegate(d->background);
+ QQuickControlPrivate::destroyDelegate(d->background, this);
d->background = background;
if (background) {
background->setParentItem(this);
@@ -483,7 +478,7 @@ void QQuickTextArea::setPlaceholderText(const QString &text)
return;
d->placeholder = text;
-#ifndef QT_NO_ACCESSIBILITY
+#if QT_CONFIG(accessibility)
if (d->accessibleAttached)
d->accessibleAttached->setDescription(text);
#endif
@@ -522,18 +517,26 @@ void QQuickTextArea::setFocusReason(Qt::FocusReason reason)
*/
bool QQuickTextArea::isHovered() const
{
+#if QT_CONFIG(quicktemplates2_hover)
Q_D(const QQuickTextArea);
return d->hovered;
+#else
+ return false;
+#endif
}
void QQuickTextArea::setHovered(bool hovered)
{
+#if QT_CONFIG(quicktemplates2_hover)
Q_D(QQuickTextArea);
if (hovered == d->hovered)
return;
d->hovered = hovered;
emit hoveredChanged();
+#else
+ Q_UNUSED(hovered);
+#endif
}
/*!
@@ -546,27 +549,37 @@ void QQuickTextArea::setHovered(bool hovered)
*/
bool QQuickTextArea::isHoverEnabled() const
{
+#if QT_CONFIG(quicktemplates2_hover)
Q_D(const QQuickTextArea);
return d->hoverEnabled;
+#else
+ return false;
+#endif
}
void QQuickTextArea::setHoverEnabled(bool enabled)
{
+#if QT_CONFIG(quicktemplates2_hover)
Q_D(QQuickTextArea);
if (d->explicitHoverEnabled && enabled == d->hoverEnabled)
return;
d->updateHoverEnabled(enabled, true); // explicit=true
+#else
+ Q_UNUSED(enabled);
+#endif
}
void QQuickTextArea::resetHoverEnabled()
{
+#if QT_CONFIG(quicktemplates2_hover)
Q_D(QQuickTextArea);
if (!d->explicitHoverEnabled)
return;
d->explicitHoverEnabled = false;
d->updateHoverEnabled(QQuickControlPrivate::calcHoverEnabled(d->parentItem), false); // explicit=false
+#endif
}
bool QQuickTextArea::contains(const QPointF &point) const
@@ -588,15 +601,14 @@ void QQuickTextArea::componentComplete()
{
Q_D(QQuickTextArea);
QQuickTextEdit::componentComplete();
+#if QT_CONFIG(quicktemplates2_hover)
if (!d->explicitHoverEnabled)
setAcceptHoverEvents(QQuickControlPrivate::calcHoverEnabled(d->parentItem));
-#ifndef QT_NO_ACCESSIBILITY
+#endif
+#if QT_CONFIG(accessibility)
if (!d->accessibleAttached && QAccessible::isActive())
d->accessibilityActiveChanged(true);
#endif
-
- qDeleteAll(d->pendingDeletions);
- d->pendingDeletions.clear();
}
void QQuickTextArea::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value)
@@ -605,8 +617,16 @@ void QQuickTextArea::itemChange(QQuickItem::ItemChange change, const QQuickItem:
QQuickTextEdit::itemChange(change, value);
if (change == ItemParentHasChanged && value.item) {
d->resolveFont();
+#if QT_CONFIG(quicktemplates2_hover)
if (!d->explicitHoverEnabled)
d->updateHoverEnabled(QQuickControlPrivate::calcHoverEnabled(d->parentItem), false); // explicit=false
+#endif
+ QQuickFlickable *flickable = qobject_cast<QQuickFlickable *>(value.item->parentItem());
+ if (flickable) {
+ QQuickScrollView *scrollView = qobject_cast<QQuickScrollView *>(flickable->parentItem());
+ if (scrollView)
+ d->attachFlickable(flickable);
+ }
}
}
@@ -657,6 +677,7 @@ void QQuickTextArea::focusOutEvent(QFocusEvent *event)
setFocusReason(event->reason());
}
+#if QT_CONFIG(quicktemplates2_hover)
void QQuickTextArea::hoverEnterEvent(QHoverEvent *event)
{
Q_D(QQuickTextArea);
@@ -672,6 +693,7 @@ void QQuickTextArea::hoverLeaveEvent(QHoverEvent *event)
setHovered(false);
event->setAccepted(d->hoverEnabled);
}
+#endif
void QQuickTextArea::mousePressEvent(QMouseEvent *event)
{
@@ -730,11 +752,10 @@ void QQuickTextArea::mouseDoubleClickEvent(QMouseEvent *event)
void QQuickTextArea::timerEvent(QTimerEvent *event)
{
Q_D(QQuickTextArea);
- if (event->timerId() == d->pressHandler.timer.timerId()) {
+ if (event->timerId() == d->pressHandler.timer.timerId())
d->pressHandler.timerEvent(event);
- } else {
+ else
QQuickTextEdit::timerEvent(event);
- }
}
class QQuickTextAreaAttachedPrivate : public QObjectPrivate
@@ -745,12 +766,8 @@ public:
QQuickTextArea *control;
};
-QQuickTextAreaAttached::QQuickTextAreaAttached(QObject *parent) :
- QObject(*(new QQuickTextAreaAttachedPrivate), parent)
-{
-}
-
-QQuickTextAreaAttached::~QQuickTextAreaAttached()
+QQuickTextAreaAttached::QQuickTextAreaAttached(QObject *parent)
+ : QObject(*(new QQuickTextAreaAttachedPrivate), parent)
{
}
@@ -772,7 +789,7 @@ void QQuickTextAreaAttached::setFlickable(QQuickTextArea *control)
Q_D(QQuickTextAreaAttached);
QQuickFlickable *flickable = qobject_cast<QQuickFlickable *>(parent());
if (!flickable) {
- qmlInfo(parent()) << "TextArea must be attached to a Flickable";
+ qmlWarning(parent()) << "TextArea must be attached to a Flickable";
return;
}