aboutsummaryrefslogtreecommitdiffstats
path: root/src/templates/qquickcontrol.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/templates/qquickcontrol.cpp')
-rw-r--r--src/templates/qquickcontrol.cpp201
1 files changed, 169 insertions, 32 deletions
diff --git a/src/templates/qquickcontrol.cpp b/src/templates/qquickcontrol.cpp
index 0e14bc37..ae6180ad 100644
--- a/src/templates/qquickcontrol.cpp
+++ b/src/templates/qquickcontrol.cpp
@@ -37,6 +37,7 @@
#include "qquickcontrol_p.h"
#include "qquickcontrol_p_p.h"
+#include <QtGui/qstylehints.h>
#include <QtGui/qguiapplication.h>
#include "qquicklabel_p.h"
#include "qquicklabel_p_p.h"
@@ -62,7 +63,7 @@ QT_BEGIN_NAMESPACE
\inherits Item
\instantiates QQuickControl
\inqmlmodule Qt.labs.controls
- \brief A user interface control.
+ \brief The base type of user interface controls.
Control is the base type of user interface controls.
@@ -70,9 +71,10 @@ QT_BEGIN_NAMESPACE
*/
QQuickControlPrivate::QQuickControlPrivate() :
- hasTopPadding(false), hasLeftPadding(false), hasRightPadding(false), hasBottomPadding(false), hasLocale(false),
- padding(0), topPadding(0), leftPadding(0), rightPadding(0), bottomPadding(0), spacing(0), focusReason(Qt::OtherFocusReason),
- background(Q_NULLPTR), contentItem(Q_NULLPTR), accessibleAttached(Q_NULLPTR)
+ hasTopPadding(false), hasLeftPadding(false), hasRightPadding(false), hasBottomPadding(false), hasLocale(false), hovered(false), wheelEnabled(false),
+ padding(0), topPadding(0), leftPadding(0), rightPadding(0), bottomPadding(0), spacing(0),
+ focusPolicy(Qt::NoFocus), focusReason(Qt::OtherFocusReason),
+ background(nullptr), contentItem(nullptr), accessibleAttached(nullptr)
{
#ifndef QT_NO_ACCESSIBILITY
QAccessible::installActivationObserver(this);
@@ -296,7 +298,8 @@ void QQuickControlPrivate::updateFont(const QFont &f)
void QQuickControlPrivate::updateFontRecur(QQuickItem *item, const QFont &f)
{
- foreach (QQuickItem *child, item->childItems()) {
+ const auto childItems = item->childItems();
+ for (QQuickItem *child : childItems) {
if (QQuickControl *control = qobject_cast<QQuickControl *>(child))
QQuickControlPrivate::get(control)->resolveFont();
else if (QQuickLabel *label = qobject_cast<QQuickLabel *>(child))
@@ -710,7 +713,8 @@ void QQuickControlPrivate::updateLocale(const QLocale &l, bool e)
void QQuickControlPrivate::updateLocaleRecur(QQuickItem *item, const QLocale &l)
{
- foreach (QQuickItem *child, item->childItems()) {
+ const auto childItems = item->childItems();
+ for (QQuickItem *child : childItems) {
if (QQuickControl *control = qobject_cast<QQuickControl *>(child))
QQuickControlPrivate::get(control)->updateLocale(l, false);
else
@@ -743,6 +747,37 @@ bool QQuickControl::isMirrored() const
}
/*!
+ \qmlproperty enumeration Qt.labs.controls::Control::focusPolicy
+
+ This property determines the way the control accepts focus.
+
+ \value Qt.TabFocus The control accepts focus by tabbing.
+ \value Qt.ClickFocus The control accepts focus by clicking.
+ \value Qt.StrongFocus The control accepts focus by both tabbing and clicking.
+ \value Qt.WheelFocus The control accepts focus by tabbing, clicking, and using the mouse wheel.
+ \value Qt.NoFocus The control does not accept focus.
+*/
+Qt::FocusPolicy QQuickControl::focusPolicy() const
+{
+ Q_D(const QQuickControl);
+ uint policy = d->focusPolicy;
+ if (activeFocusOnTab())
+ policy |= Qt::TabFocus;
+ return static_cast<Qt::FocusPolicy>(policy);
+}
+
+void QQuickControl::setFocusPolicy(Qt::FocusPolicy policy)
+{
+ Q_D(QQuickControl);
+ if (d->focusPolicy == policy)
+ return;
+
+ d->focusPolicy = policy;
+ setActiveFocusOnTab(policy & Qt::TabFocus);
+ emit focusPolicyChanged();
+}
+
+/*!
\qmlproperty enumeration Qt.labs.controls::Control::focusReason
\readonly
@@ -771,10 +806,79 @@ Qt::FocusReason QQuickControl::focusReason() const
void QQuickControl::setFocusReason(Qt::FocusReason reason)
{
Q_D(QQuickControl);
- if (d->focusReason != reason) {
- d->focusReason = reason;
- emit focusReasonChanged();
- }
+ if (d->focusReason == reason)
+ return;
+
+ d->focusReason = reason;
+ emit focusReasonChanged();
+}
+
+/*!
+ \qmlproperty bool Qt.labs.controls::Control::hovered
+ \readonly
+
+ This property holds whether the control is hovered.
+
+ \sa hoverEnabled
+*/
+bool QQuickControl::isHovered() const
+{
+ Q_D(const QQuickControl);
+ return d->hovered;
+}
+
+void QQuickControl::setHovered(bool hovered)
+{
+ Q_D(QQuickControl);
+ if (hovered == d->hovered)
+ return;
+
+ d->hovered = hovered;
+ emit hoveredChanged();
+}
+
+/*!
+ \qmlproperty bool Qt.labs.controls::Control::hoverEnabled
+
+ This property determines whether the control accepts hover events. The default value is \c false.
+
+ \sa hovered
+*/
+bool QQuickControl::isHoverEnabled() const
+{
+ Q_D(const QQuickControl);
+ return d->hoverEnabled;
+}
+
+void QQuickControl::setHoverEnabled(bool enabled)
+{
+ Q_D(QQuickControl);
+ if (enabled == d->hoverEnabled)
+ return;
+
+ setAcceptHoverEvents(enabled);
+ emit hoverEnabledChanged();
+}
+
+/*!
+ \qmlproperty bool Qt.labs.controls::Control::wheelEnabled
+
+ This property determines whether the control handles wheel events. The default value is \c false.
+*/
+bool QQuickControl::isWheelEnabled() const
+{
+ Q_D(const QQuickControl);
+ return d->wheelEnabled;
+}
+
+void QQuickControl::setWheelEnabled(bool enabled)
+{
+ Q_D(QQuickControl);
+ if (d->wheelEnabled == enabled)
+ return;
+
+ d->wheelEnabled = enabled;
+ emit wheelEnabledChanged();
}
/*!
@@ -795,18 +899,19 @@ QQuickItem *QQuickControl::background() const
void QQuickControl::setBackground(QQuickItem *background)
{
Q_D(QQuickControl);
- if (d->background != background) {
- delete d->background;
- d->background = background;
- if (background) {
- background->setParentItem(this);
- if (qFuzzyIsNull(background->z()))
- background->setZ(-1);
- if (isComponentComplete())
- d->resizeBackground();
- }
- emit backgroundChanged();
+ if (d->background == background)
+ return;
+
+ delete d->background;
+ d->background = background;
+ if (background) {
+ background->setParentItem(this);
+ if (qFuzzyIsNull(background->z()))
+ background->setZ(-1);
+ if (isComponentComplete())
+ d->resizeBackground();
}
+ emit backgroundChanged();
}
/*!
@@ -825,18 +930,19 @@ QQuickItem *QQuickControl::contentItem() const
void QQuickControl::setContentItem(QQuickItem *item)
{
Q_D(QQuickControl);
- if (d->contentItem != item) {
- contentItemChange(item, d->contentItem);
- delete d->contentItem;
- d->contentItem = item;
- if (item) {
- if (!item->parentItem())
- item->setParentItem(this);
- if (isComponentComplete())
- d->resizeContent();
- }
- emit contentItemChanged();
+ if (d->contentItem == item)
+ return;
+
+ contentItemChange(item, d->contentItem);
+ delete d->contentItem;
+ d->contentItem = item;
+ if (item) {
+ if (!item->parentItem())
+ item->setParentItem(this);
+ if (isComponentComplete())
+ d->resizeContent();
}
+ emit contentItemChanged();
}
void QQuickControl::componentComplete()
@@ -869,8 +975,26 @@ void QQuickControl::focusOutEvent(QFocusEvent *event)
setFocusReason(event->reason());
}
+void QQuickControl::hoverEnterEvent(QHoverEvent *event)
+{
+ Q_D(QQuickControl);
+ setHovered(d->hoverEnabled);
+ event->setAccepted(d->hoverEnabled);
+}
+
+void QQuickControl::hoverLeaveEvent(QHoverEvent *event)
+{
+ Q_D(QQuickControl);
+ setHovered(false);
+ event->setAccepted(d->hoverEnabled);
+}
+
void QQuickControl::mousePressEvent(QMouseEvent *event)
{
+ Q_D(QQuickControl);
+ if ((d->focusPolicy & Qt::ClickFocus) == Qt::ClickFocus && !QGuiApplication::styleHints()->setFocusOnTouchRelease())
+ forceActiveFocus(Qt::MouseFocusReason);
+
event->accept();
}
@@ -881,9 +1005,22 @@ void QQuickControl::mouseMoveEvent(QMouseEvent *event)
void QQuickControl::mouseReleaseEvent(QMouseEvent *event)
{
+ Q_D(QQuickControl);
+ if ((d->focusPolicy & Qt::ClickFocus) == Qt::ClickFocus && QGuiApplication::styleHints()->setFocusOnTouchRelease())
+ forceActiveFocus(Qt::MouseFocusReason);
+
event->accept();
}
+void QQuickControl::wheelEvent(QWheelEvent *event)
+{
+ Q_D(QQuickControl);
+ if ((d->focusPolicy & Qt::WheelFocus) == Qt::WheelFocus)
+ forceActiveFocus(Qt::MouseFocusReason);
+
+ event->setAccepted(d->wheelEnabled);
+}
+
void QQuickControl::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
{
Q_D(QQuickControl);