aboutsummaryrefslogtreecommitdiffstats
path: root/src/templates/qquickcontrol.cpp
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2015-11-29 23:35:17 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2015-12-12 17:47:21 +0000
commit691366a678640448c1dcb04f5297f637919aa220 (patch)
tree8931979e244b489d4e1bb60d7d79c80e561871e5 /src/templates/qquickcontrol.cpp
parent0cb8763ca7dc3190a797563ff64c35f9208aa9c8 (diff)
Add QQuickControl::focusReason
This allows the Universal style ApplicationWindow to visualize key/tab focus with a focus rectangle, but hide the focus rectangle when the focus moves around for other reasons (mouse, active window, popups...) Change-Id: I5c5b43d7c4c051679e34b806ee43cd80180d7ab8 Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'src/templates/qquickcontrol.cpp')
-rw-r--r--src/templates/qquickcontrol.cpp48
1 files changed, 47 insertions, 1 deletions
diff --git a/src/templates/qquickcontrol.cpp b/src/templates/qquickcontrol.cpp
index b8634874..bcaeed56 100644
--- a/src/templates/qquickcontrol.cpp
+++ b/src/templates/qquickcontrol.cpp
@@ -67,7 +67,7 @@ QT_BEGIN_NAMESPACE
QQuickControlPrivate::QQuickControlPrivate() :
hasTopPadding(false), hasLeftPadding(false), hasRightPadding(false), hasBottomPadding(false),
- padding(0), topPadding(0), leftPadding(0), rightPadding(0), bottomPadding(0), spacing(0),
+ padding(0), topPadding(0), leftPadding(0), rightPadding(0), bottomPadding(0), spacing(0), focusReason(Qt::OtherFocusReason),
background(Q_NULLPTR), contentItem(Q_NULLPTR), accessibleAttached(Q_NULLPTR)
{
#ifndef QT_NO_ACCESSIBILITY
@@ -654,6 +654,40 @@ bool QQuickControl::isMirrored() const
}
/*!
+ \qmlproperty enumeration Qt.labs.controls::Control::focusReason
+
+ This property holds the reason of the last focus change.
+
+ \note This property does not indicate whether the control has \l {Item::activeFocus}
+ {active focus}, but the reason why the control either gained or lost focus.
+
+ \value Qt.MouseFocusReason A mouse action occurred.
+ \value Qt.TabFocusReason The Tab key was pressed.
+ \value Qt.BacktabFocusReason A Backtab occurred. The input for this may include the Shift or Control keys; e.g. Shift+Tab.
+ \value Qt.ActiveWindowFocusReason The window system made this window either active or inactive.
+ \value Qt.PopupFocusReason The application opened/closed a pop-up that grabbed/released the keyboard focus.
+ \value Qt.ShortcutFocusReason The user typed a label's buddy shortcut
+ \value Qt.MenuBarFocusReason The menu bar took focus.
+ \value Qt.OtherFocusReason Another reason, usually application-specific.
+
+ \sa Item::activeFocus
+*/
+Qt::FocusReason QQuickControl::focusReason() const
+{
+ Q_D(const QQuickControl);
+ return d->focusReason;
+}
+
+void QQuickControl::setFocusReason(Qt::FocusReason reason)
+{
+ Q_D(QQuickControl);
+ if (d->focusReason != reason) {
+ d->focusReason = reason;
+ emit focusReasonChanged();
+ }
+}
+
+/*!
\qmlproperty Item Qt.labs.controls::Control::background
This property holds the background item.
@@ -728,6 +762,18 @@ QFont QQuickControl::defaultFont() const
return QQuickControlPrivate::themeFont(QPlatformTheme::SystemFont);
}
+void QQuickControl::focusInEvent(QFocusEvent *event)
+{
+ QQuickItem::focusInEvent(event);
+ setFocusReason(event->reason());
+}
+
+void QQuickControl::focusOutEvent(QFocusEvent *event)
+{
+ QQuickItem::focusOutEvent(event);
+ setFocusReason(event->reason());
+}
+
void QQuickControl::mousePressEvent(QMouseEvent *event)
{
event->accept();