aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/controls/universal
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2015-12-11 20:47:39 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2015-12-12 17:47:34 +0000
commitacc5b006938796d53ac8166b79a13de1304b1dd5 (patch)
tree37d940266b5433589aef50261553f7ab72be3155 /src/imports/controls/universal
parent691366a678640448c1dcb04f5297f637919aa220 (diff)
Universal: focus rectangle
Change-Id: I74005dcce5f1f41e9455b882f313952f88c364f9 Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'src/imports/controls/universal')
-rw-r--r--src/imports/controls/universal/ApplicationWindow.qml9
-rw-r--r--src/imports/controls/universal/Button.qml2
-rw-r--r--src/imports/controls/universal/CheckBox.qml2
-rw-r--r--src/imports/controls/universal/RadioButton.qml2
-rw-r--r--src/imports/controls/universal/Slider.qml2
-rw-r--r--src/imports/controls/universal/Switch.qml2
-rw-r--r--src/imports/controls/universal/qquickuniversalfocusrectangle.cpp66
-rw-r--r--src/imports/controls/universal/qquickuniversalfocusrectangle_p.h67
-rw-r--r--src/imports/controls/universal/qtlabsuniversalstyleplugin.cpp2
-rw-r--r--src/imports/controls/universal/universal.pri2
10 files changed, 156 insertions, 0 deletions
diff --git a/src/imports/controls/universal/ApplicationWindow.qml b/src/imports/controls/universal/ApplicationWindow.qml
index 46b8e740..773eec52 100644
--- a/src/imports/controls/universal/ApplicationWindow.qml
+++ b/src/imports/controls/universal/ApplicationWindow.qml
@@ -37,9 +37,18 @@
import QtQuick 2.6
import Qt.labs.templates 1.0 as T
import Qt.labs.controls.universal 1.0
+import Qt.labs.controls.universal.impl 1.0
T.ApplicationWindow {
id: window
color: Universal.altHighColor
+
+ FocusRectangle {
+ parent: window.activeFocusControl
+ width: parent ? parent.width : 0
+ height: parent ? parent.height : 0
+ visible: parent && !!parent.useSystemFocusVisuals
+ && (parent.focusReason === Qt.TabFocusReason || parent.focusReason === Qt.BacktabFocusReason)
+ }
}
diff --git a/src/imports/controls/universal/Button.qml b/src/imports/controls/universal/Button.qml
index 41198f89..6ed57700 100644
--- a/src/imports/controls/universal/Button.qml
+++ b/src/imports/controls/universal/Button.qml
@@ -52,6 +52,8 @@ T.Button {
rightPadding: 8
bottomPadding: 4
+ property bool useSystemFocusVisuals: true
+
//! [label]
label: Text {
x: control.leftPadding
diff --git a/src/imports/controls/universal/CheckBox.qml b/src/imports/controls/universal/CheckBox.qml
index 52523ffd..6bb6bc36 100644
--- a/src/imports/controls/universal/CheckBox.qml
+++ b/src/imports/controls/universal/CheckBox.qml
@@ -53,6 +53,8 @@ T.CheckBox {
padding: 6
spacing: 8
+ property bool useSystemFocusVisuals: true
+
//! [indicator]
indicator: Rectangle {
id: normalRectangle
diff --git a/src/imports/controls/universal/RadioButton.qml b/src/imports/controls/universal/RadioButton.qml
index 02212c4f..a5d7d09e 100644
--- a/src/imports/controls/universal/RadioButton.qml
+++ b/src/imports/controls/universal/RadioButton.qml
@@ -53,6 +53,8 @@ T.RadioButton {
padding: 6
spacing: 8
+ property bool useSystemFocusVisuals: true
+
//! [indicator]
indicator: Rectangle {
id: outerEllipse
diff --git a/src/imports/controls/universal/Slider.qml b/src/imports/controls/universal/Slider.qml
index 6a4107e6..ec1e0ed1 100644
--- a/src/imports/controls/universal/Slider.qml
+++ b/src/imports/controls/universal/Slider.qml
@@ -50,6 +50,8 @@ T.Slider {
padding: 6
+ property bool useSystemFocusVisuals: true
+
//! [handle]
handle: Rectangle {
implicitWidth: horizontal ? 8 : 24
diff --git a/src/imports/controls/universal/Switch.qml b/src/imports/controls/universal/Switch.qml
index 8b7c73f3..ef078a1e 100644
--- a/src/imports/controls/universal/Switch.qml
+++ b/src/imports/controls/universal/Switch.qml
@@ -53,6 +53,8 @@ T.Switch {
padding: 5
spacing: 8
+ property bool useSystemFocusVisuals: true
+
//! [indicator]
indicator: Rectangle {
implicitWidth: 44
diff --git a/src/imports/controls/universal/qquickuniversalfocusrectangle.cpp b/src/imports/controls/universal/qquickuniversalfocusrectangle.cpp
new file mode 100644
index 00000000..5153f96b
--- /dev/null
+++ b/src/imports/controls/universal/qquickuniversalfocusrectangle.cpp
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Labs Controls module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qquickuniversalfocusrectangle_p.h"
+
+#include <QtGui/qpainter.h>
+
+QT_BEGIN_NAMESPACE
+
+QQuickUniversalFocusRectangle::QQuickUniversalFocusRectangle(QQuickItem *parent)
+ : QQuickPaintedItem(parent)
+{
+}
+
+void QQuickUniversalFocusRectangle::paint(QPainter *painter)
+{
+ const QRect bounds = boundingRect().toAlignedRect().adjusted(0, 0, -1, -1);
+
+ QPen pen;
+ pen.setWidth(1);
+ pen.setDashPattern(QVector<qreal>() << 1 << 1);
+
+ pen.setColor(Qt::white);
+ painter->setPen(pen);
+ painter->drawRect(bounds);
+
+ pen.setColor(Qt::black);
+ pen.setDashOffset(1);
+ painter->setPen(pen);
+ painter->drawRect(bounds);
+}
+
+QT_END_NAMESPACE
diff --git a/src/imports/controls/universal/qquickuniversalfocusrectangle_p.h b/src/imports/controls/universal/qquickuniversalfocusrectangle_p.h
new file mode 100644
index 00000000..6b15bc8d
--- /dev/null
+++ b/src/imports/controls/universal/qquickuniversalfocusrectangle_p.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Labs Controls module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUICKUNIVERSALFOCUSRECTANGLE_P_H
+#define QQUICKUNIVERSALFOCUSRECTANGLE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtQuick/qquickpainteditem.h>
+
+QT_BEGIN_NAMESPACE
+
+class QQuickUniversalFocusRectangle : public QQuickPaintedItem
+{
+ Q_OBJECT
+
+public:
+ QQuickUniversalFocusRectangle(QQuickItem *parent = Q_NULLPTR);
+
+ void paint(QPainter *painter) Q_DECL_OVERRIDE;
+};
+
+QT_END_NAMESPACE
+
+#endif // QQUICKUNIVERSALFOCUSRECTANGLE_P_H
diff --git a/src/imports/controls/universal/qtlabsuniversalstyleplugin.cpp b/src/imports/controls/universal/qtlabsuniversalstyleplugin.cpp
index 2cf6fb67..72dca8e8 100644
--- a/src/imports/controls/universal/qtlabsuniversalstyleplugin.cpp
+++ b/src/imports/controls/universal/qtlabsuniversalstyleplugin.cpp
@@ -35,6 +35,7 @@
****************************************************************************/
#include <QtQml/qqmlextensionplugin.h>
+#include "qquickuniversalfocusrectangle_p.h"
#include "qquickuniversalimageprovider_p.h"
#include "qquickuniversalprogressring_p.h"
#include "qquickuniversalprogressstrip_p.h"
@@ -96,6 +97,7 @@ void QtLabsUniversalStylePlugin::initializeEngine(QQmlEngine *engine, const char
engine->addImageProvider(QStringLiteral("universal"), new QQuickUniversalImageProvider);
QByteArray import = QByteArray(uri) + ".impl";
+ qmlRegisterType<QQuickUniversalFocusRectangle>(import, 1, 0, "FocusRectangle");
qmlRegisterType<QQuickUniversalProgressRing>(import, 1, 0, "ProgressRing");
qmlRegisterType<QQuickUniversalProgressRingAnimator>(import, 1, 0, "ProgressRingAnimator");
qmlRegisterType<QQuickUniversalProgressStrip>(import, 1, 0, "ProgressStrip");
diff --git a/src/imports/controls/universal/universal.pri b/src/imports/controls/universal/universal.pri
index 12c939c1..8736d352 100644
--- a/src/imports/controls/universal/universal.pri
+++ b/src/imports/controls/universal/universal.pri
@@ -31,6 +31,7 @@ QML_FILES += \
$$PWD/Tumbler.qml
HEADERS += \
+ $$PWD/qquickuniversalfocusrectangle_p.h \
$$PWD/qquickuniversalimageprovider_p.h \
$$PWD/qquickuniversalprogressring_p.h \
$$PWD/qquickuniversalprogressstrip_p.h \
@@ -38,6 +39,7 @@ HEADERS += \
$$PWD/qquickuniversaltheme_p.h
SOURCES += \
+ $$PWD/qquickuniversalfocusrectangle.cpp \
$$PWD/qquickuniversalimageprovider.cpp \
$$PWD/qquickuniversalprogressring.cpp \
$$PWD/qquickuniversalprogressstrip.cpp \