From d6b32468667a4890cef6061f08c353a0d0cba43e Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Tue, 26 Apr 2016 15:51:50 +0200 Subject: Move highlighted to subclasses that actually use it Change-Id: I70468b35b2a3a03c6e2d557a67443291697c8b42 Reviewed-by: J-P Nurmi --- src/quicktemplates2/qquickabstractbutton.cpp | 28 +---------- src/quicktemplates2/qquickabstractbutton_p.h | 5 -- src/quicktemplates2/qquickabstractbutton_p_p.h | 1 - src/quicktemplates2/qquickbutton.cpp | 44 +++++++++++++++- src/quicktemplates2/qquickbutton_p.h | 11 ++++ src/quicktemplates2/qquickcheckdelegate.cpp | 4 +- src/quicktemplates2/qquickitemdelegate.cpp | 37 +++++++++++++- src/quicktemplates2/qquickitemdelegate_p.h | 15 +++++- src/quicktemplates2/qquickitemdelegate_p_p.h | 67 +++++++++++++++++++++++++ src/quicktemplates2/qquickmenuitem.cpp | 43 +++++++++++++++- src/quicktemplates2/qquickmenuitem_p.h | 5 ++ src/quicktemplates2/qquickswipedelegate.cpp | 4 +- src/quicktemplates2/qquickswitchdelegate.cpp | 4 +- src/quicktemplates2/quicktemplates2.pri | 1 + tests/auto/controls/data/tst_abstractbutton.qml | 9 ---- tests/auto/controls/data/tst_button.qml | 11 ++++ tests/auto/controls/data/tst_itemdelegate.qml | 11 ++++ tests/auto/controls/data/tst_menuitem.qml | 11 ++++ 18 files changed, 258 insertions(+), 53 deletions(-) create mode 100644 src/quicktemplates2/qquickitemdelegate_p_p.h diff --git a/src/quicktemplates2/qquickabstractbutton.cpp b/src/quicktemplates2/qquickabstractbutton.cpp index 9cfd9b40..68d11bae 100644 --- a/src/quicktemplates2/qquickabstractbutton.cpp +++ b/src/quicktemplates2/qquickabstractbutton.cpp @@ -105,7 +105,7 @@ static const int AUTO_REPEAT_INTERVAL = 100; QQuickAbstractButtonPrivate::QQuickAbstractButtonPrivate() : down(false), explicitDown(false), pressed(false), checked(false), checkable(false), - highlighted(false), autoExclusive(false), autoRepeat(false), wasHeld(false), + autoExclusive(false), autoRepeat(false), wasHeld(false), holdTimer(0), delayTimer(0), repeatTimer(0), repeatButton(Qt::NoButton), indicator(nullptr), group(nullptr) { } @@ -373,32 +373,6 @@ void QQuickAbstractButton::setCheckable(bool checkable) checkableChange(); } -/*! - \qmlproperty bool QtQuick.Controls::AbstractButton::highlighted - - This property holds whether the button is highlighted. - - A button can be highlighted in order to draw the user's attention towards - it. It has no effect on keyboard interaction. - - The default value is \c false. -*/ -bool QQuickAbstractButton::isHighlighted() const -{ - Q_D(const QQuickAbstractButton); - return d->highlighted; -} - -void QQuickAbstractButton::setHighlighted(bool highlighted) -{ - Q_D(QQuickAbstractButton); - if (highlighted == d->highlighted) - return; - - d->highlighted = highlighted; - emit highlightedChanged(); -} - /*! \qmlproperty bool QtQuick.Controls::AbstractButton::autoExclusive diff --git a/src/quicktemplates2/qquickabstractbutton_p.h b/src/quicktemplates2/qquickabstractbutton_p.h index f23d29f3..779739de 100644 --- a/src/quicktemplates2/qquickabstractbutton_p.h +++ b/src/quicktemplates2/qquickabstractbutton_p.h @@ -61,7 +61,6 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickAbstractButton : public QQuickContr Q_PROPERTY(bool down READ isDown WRITE setDown NOTIFY downChanged RESET resetDown FINAL) Q_PROPERTY(bool pressed READ isPressed NOTIFY pressedChanged FINAL) Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY checkedChanged FINAL) - Q_PROPERTY(bool highlighted READ isHighlighted WRITE setHighlighted NOTIFY highlightedChanged FINAL) Q_PROPERTY(bool autoExclusive READ autoExclusive WRITE setAutoExclusive NOTIFY autoExclusiveChanged FINAL) Q_PROPERTY(QQuickItem *indicator READ indicator WRITE setIndicator NOTIFY indicatorChanged FINAL) @@ -85,9 +84,6 @@ public: bool isCheckable() const; void setCheckable(bool checkable); - bool isHighlighted() const; - void setHighlighted(bool highlighted); - bool autoExclusive() const; void setAutoExclusive(bool exclusive); @@ -111,7 +107,6 @@ Q_SIGNALS: void downChanged(); void pressedChanged(); void checkedChanged(); - void highlightedChanged(); void autoExclusiveChanged(); void indicatorChanged(); diff --git a/src/quicktemplates2/qquickabstractbutton_p_p.h b/src/quicktemplates2/qquickabstractbutton_p_p.h index 7aa2c028..e690bbd0 100644 --- a/src/quicktemplates2/qquickabstractbutton_p_p.h +++ b/src/quicktemplates2/qquickabstractbutton_p_p.h @@ -84,7 +84,6 @@ public: bool pressed; bool checked; bool checkable; - bool highlighted; bool autoExclusive; bool autoRepeat; bool wasHeld; diff --git a/src/quicktemplates2/qquickbutton.cpp b/src/quicktemplates2/qquickbutton.cpp index 5f702818..cb5b2963 100644 --- a/src/quicktemplates2/qquickbutton.cpp +++ b/src/quicktemplates2/qquickbutton.cpp @@ -90,7 +90,23 @@ QT_BEGIN_NAMESPACE \sa {Customizing Button}, {Button Controls} */ -QQuickButton::QQuickButton(QQuickItem *parent) : QQuickAbstractButton(parent) +class QQuickButtonPrivate : public QQuickAbstractButtonPrivate +{ + Q_DECLARE_PUBLIC(QQuickButton) + +public: + QQuickButtonPrivate(); + + bool highlighted; +}; + +QQuickButtonPrivate::QQuickButtonPrivate() : + highlighted(false) +{ +} + +QQuickButton::QQuickButton(QQuickItem *parent) : + QQuickAbstractButton(*(new QQuickButtonPrivate), parent) { } @@ -124,4 +140,30 @@ QFont QQuickButton::defaultFont() const return QQuickControlPrivate::themeFont(QPlatformTheme::PushButtonFont); } +/*! + \qmlproperty bool QtQuick.Controls::Button::highlighted + + This property holds whether the button is highlighted. + + A button can be highlighted in order to draw the user's attention towards + it. It has no effect on keyboard interaction. + + The default value is \c false. +*/ +bool QQuickButton::isHighlighted() const +{ + Q_D(const QQuickButton); + return d->highlighted; +} + +void QQuickButton::setHighlighted(bool highlighted) +{ + Q_D(QQuickButton); + if (highlighted == d->highlighted) + return; + + d->highlighted = highlighted; + emit highlightedChanged(); +} + QT_END_NAMESPACE diff --git a/src/quicktemplates2/qquickbutton_p.h b/src/quicktemplates2/qquickbutton_p.h index a98bbe78..36eb4359 100644 --- a/src/quicktemplates2/qquickbutton_p.h +++ b/src/quicktemplates2/qquickbutton_p.h @@ -52,24 +52,35 @@ QT_BEGIN_NAMESPACE +class QQuickButtonPrivate; + class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickButton : public QQuickAbstractButton { Q_OBJECT Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY checkableChanged FINAL) Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat NOTIFY autoRepeatChanged FINAL) + Q_PROPERTY(bool highlighted READ isHighlighted WRITE setHighlighted NOTIFY highlightedChanged FINAL) public: explicit QQuickButton(QQuickItem *parent = nullptr); + bool isHighlighted() const; + void setHighlighted(bool highlighted); + Q_SIGNALS: void checkableChanged(); void autoRepeatChanged(); + void highlightedChanged(); protected: void checkableChange() override; void autoRepeatChange() override; QFont defaultFont() const override; + +private: + Q_DISABLE_COPY(QQuickButton) + Q_DECLARE_PRIVATE(QQuickButton) }; QT_END_NAMESPACE diff --git a/src/quicktemplates2/qquickcheckdelegate.cpp b/src/quicktemplates2/qquickcheckdelegate.cpp index 9d0a0cfb..f21da57c 100644 --- a/src/quicktemplates2/qquickcheckdelegate.cpp +++ b/src/quicktemplates2/qquickcheckdelegate.cpp @@ -35,7 +35,7 @@ ****************************************************************************/ #include "qquickcheckdelegate_p.h" -#include "qquickabstractbutton_p_p.h" +#include "qquickitemdelegate_p_p.h" #include @@ -77,7 +77,7 @@ QT_BEGIN_NAMESPACE \sa {Customizing CheckDelegate}, {Delegate Controls} */ -class QQuickCheckDelegatePrivate : public QQuickAbstractButtonPrivate +class QQuickCheckDelegatePrivate : public QQuickItemDelegatePrivate { Q_DECLARE_PUBLIC(QQuickCheckDelegate) diff --git a/src/quicktemplates2/qquickitemdelegate.cpp b/src/quicktemplates2/qquickitemdelegate.cpp index b2719095..9ff068f1 100644 --- a/src/quicktemplates2/qquickitemdelegate.cpp +++ b/src/quicktemplates2/qquickitemdelegate.cpp @@ -35,6 +35,7 @@ ****************************************************************************/ #include "qquickitemdelegate_p.h" +#include "qquickitemdelegate_p_p.h" #include "qquickcontrol_p_p.h" #include @@ -62,17 +63,49 @@ QT_BEGIN_NAMESPACE \sa {Customizing ItemDelegate}, {Delegate Controls} */ -QQuickItemDelegate::QQuickItemDelegate(QQuickItem *parent) : QQuickAbstractButton(parent) +QQuickItemDelegatePrivate::QQuickItemDelegatePrivate() : + highlighted(false) +{ +} + +QQuickItemDelegate::QQuickItemDelegate(QQuickItem *parent) : + QQuickAbstractButton(*(new QQuickItemDelegatePrivate), parent) { setFocusPolicy(Qt::NoFocus); } -QQuickItemDelegate::QQuickItemDelegate(QQuickAbstractButtonPrivate &dd, QQuickItem *parent) : +QQuickItemDelegate::QQuickItemDelegate(QQuickItemDelegatePrivate &dd, QQuickItem *parent) : QQuickAbstractButton(dd, parent) { setFocusPolicy(Qt::NoFocus); } +/*! + \qmlproperty bool QtQuick.Controls::ItemDelegate::highlighted + + This property holds whether the delegate is highlighted. + + A delegate can be highlighted in order to draw the user's attention towards + it. It has no effect on keyboard interaction. + + The default value is \c false. +*/ +bool QQuickItemDelegate::isHighlighted() const +{ + Q_D(const QQuickItemDelegate); + return d->highlighted; +} + +void QQuickItemDelegate::setHighlighted(bool highlighted) +{ + Q_D(QQuickItemDelegate); + if (highlighted == d->highlighted) + return; + + d->highlighted = highlighted; + emit highlightedChanged(); +} + QFont QQuickItemDelegate::defaultFont() const { return QQuickControlPrivate::themeFont(QPlatformTheme::ItemViewFont); diff --git a/src/quicktemplates2/qquickitemdelegate_p.h b/src/quicktemplates2/qquickitemdelegate_p.h index 205407a0..429b0ca9 100644 --- a/src/quicktemplates2/qquickitemdelegate_p.h +++ b/src/quicktemplates2/qquickitemdelegate_p.h @@ -52,13 +52,22 @@ QT_BEGIN_NAMESPACE +class QQuickItemDelegatePrivate; + class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickItemDelegate : public QQuickAbstractButton { Q_OBJECT + Q_PROPERTY(bool highlighted READ isHighlighted WRITE setHighlighted NOTIFY highlightedChanged FINAL) public: explicit QQuickItemDelegate(QQuickItem *parent = nullptr); + bool isHighlighted() const; + void setHighlighted(bool highlighted); + +Q_SIGNALS: + void highlightedChanged(); + protected: QFont defaultFont() const override; @@ -67,7 +76,11 @@ protected: #endif protected: - QQuickItemDelegate(QQuickAbstractButtonPrivate &dd, QQuickItem *parent); + QQuickItemDelegate(QQuickItemDelegatePrivate &dd, QQuickItem *parent); + +private: + Q_DISABLE_COPY(QQuickItemDelegate) + Q_DECLARE_PRIVATE(QQuickItemDelegate) }; QT_END_NAMESPACE diff --git a/src/quicktemplates2/qquickitemdelegate_p_p.h b/src/quicktemplates2/qquickitemdelegate_p_p.h new file mode 100644 index 00000000..c69f3d46 --- /dev/null +++ b/src/quicktemplates2/qquickitemdelegate_p_p.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Quick Templates 2 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 QQUICKITEMDELEGATE_P_P_H +#define QQUICKITEMDELEGATE_P_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 + +QT_BEGIN_NAMESPACE + +class QQuickItemDelegatePrivate : public QQuickAbstractButtonPrivate +{ + Q_DECLARE_PUBLIC(QQuickItemDelegate) + +public: + QQuickItemDelegatePrivate(); + + bool highlighted; +}; + +QT_END_NAMESPACE + +#endif // QQUICKITEMDELEGATE_P_P_H diff --git a/src/quicktemplates2/qquickmenuitem.cpp b/src/quicktemplates2/qquickmenuitem.cpp index d9740910..7c9ede7d 100644 --- a/src/quicktemplates2/qquickmenuitem.cpp +++ b/src/quicktemplates2/qquickmenuitem.cpp @@ -78,6 +78,21 @@ QT_BEGIN_NAMESPACE \sa {Customizing MenuItem}, {Menu Controls} */ +class QQuickMenuItemPrivate : public QQuickAbstractButtonPrivate +{ + Q_DECLARE_PUBLIC(QQuickMenuItem) + +public: + QQuickMenuItemPrivate(); + + bool highlighted; +}; + +QQuickMenuItemPrivate::QQuickMenuItemPrivate() : + highlighted(false) +{ +} + /*! \qmlsignal void QtQuick.Controls::MenuItem::triggered() @@ -85,7 +100,7 @@ QT_BEGIN_NAMESPACE */ QQuickMenuItem::QQuickMenuItem(QQuickItem *parent) : - QQuickAbstractButton(parent) + QQuickAbstractButton(*(new QQuickMenuItemPrivate), parent) { connect(this, &QQuickAbstractButton::clicked, this, &QQuickMenuItem::triggered); } @@ -106,6 +121,32 @@ QFont QQuickMenuItem::defaultFont() const return QQuickControlPrivate::themeFont(QPlatformTheme::MenuItemFont); } +/*! + \qmlproperty bool QtQuick.Controls::MenuItem::highlighted + + This property holds whether the menu item is highlighted. + + A menu item can be highlighted in order to draw the user's attention + towards it. It has no effect on keyboard interaction. + + The default value is \c false. +*/ +bool QQuickMenuItem::isHighlighted() const +{ + Q_D(const QQuickMenuItem); + return d->highlighted; +} + +void QQuickMenuItem::setHighlighted(bool highlighted) +{ + Q_D(QQuickMenuItem); + if (highlighted == d->highlighted) + return; + + d->highlighted = highlighted; + emit highlightedChanged(); +} + #ifndef QT_NO_ACCESSIBILITY QAccessible::Role QQuickMenuItem::accessibleRole() const { diff --git a/src/quicktemplates2/qquickmenuitem_p.h b/src/quicktemplates2/qquickmenuitem_p.h index b99fdef3..6c717e13 100644 --- a/src/quicktemplates2/qquickmenuitem_p.h +++ b/src/quicktemplates2/qquickmenuitem_p.h @@ -58,13 +58,18 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickMenuItem : public QQuickAbstractBut { Q_OBJECT Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY checkableChanged FINAL) + Q_PROPERTY(bool highlighted READ isHighlighted WRITE setHighlighted NOTIFY highlightedChanged FINAL) public: explicit QQuickMenuItem(QQuickItem *parent = nullptr); + bool isHighlighted() const; + void setHighlighted(bool highlighted); + Q_SIGNALS: void checkableChanged(); void triggered(); + void highlightedChanged(); protected: void checkableChange() override; diff --git a/src/quicktemplates2/qquickswipedelegate.cpp b/src/quicktemplates2/qquickswipedelegate.cpp index 9156d7a3..ed01ea28 100644 --- a/src/quicktemplates2/qquickswipedelegate.cpp +++ b/src/quicktemplates2/qquickswipedelegate.cpp @@ -36,7 +36,7 @@ #include "qquickswipedelegate_p.h" #include "qquickcontrol_p_p.h" -#include "qquickabstractbutton_p_p.h" +#include "qquickitemdelegate_p_p.h" #include "qquickvelocitycalculator_p_p.h" #include @@ -521,7 +521,7 @@ void QQuickSwipeExposure::setActive(bool active) emit activeChanged(); } -class QQuickSwipeDelegatePrivate : public QQuickAbstractButtonPrivate +class QQuickSwipeDelegatePrivate : public QQuickItemDelegatePrivate { Q_DECLARE_PUBLIC(QQuickSwipeDelegate) diff --git a/src/quicktemplates2/qquickswitchdelegate.cpp b/src/quicktemplates2/qquickswitchdelegate.cpp index adaf10c3..190152b8 100644 --- a/src/quicktemplates2/qquickswitchdelegate.cpp +++ b/src/quicktemplates2/qquickswitchdelegate.cpp @@ -36,7 +36,7 @@ #include "qquickswitchdelegate_p.h" -#include "qquickabstractbutton_p_p.h" +#include "qquickitemdelegate_p_p.h" QT_BEGIN_NAMESPACE @@ -69,7 +69,7 @@ QT_BEGIN_NAMESPACE \sa {Customizing SwitchDelegate}, {Delegate Controls} */ -class QQuickSwitchDelegatePrivate : public QQuickAbstractButtonPrivate +class QQuickSwitchDelegatePrivate : public QQuickItemDelegatePrivate { Q_DECLARE_PUBLIC(QQuickSwitchDelegate) diff --git a/src/quicktemplates2/quicktemplates2.pri b/src/quicktemplates2/quicktemplates2.pri index e16d8b69..173112d3 100644 --- a/src/quicktemplates2/quicktemplates2.pri +++ b/src/quicktemplates2/quicktemplates2.pri @@ -20,6 +20,7 @@ HEADERS += \ $$PWD/qquickframe_p_p.h \ $$PWD/qquickgroupbox_p.h \ $$PWD/qquickitemdelegate_p.h \ + $$PWD/qquickitemdelegate_p_p.h \ $$PWD/qquicklabel_p.h \ $$PWD/qquicklabel_p_p.h \ $$PWD/qquickmenu_p.h \ diff --git a/tests/auto/controls/data/tst_abstractbutton.qml b/tests/auto/controls/data/tst_abstractbutton.qml index 96c2ccaa..c94653d9 100644 --- a/tests/auto/controls/data/tst_abstractbutton.qml +++ b/tests/auto/controls/data/tst_abstractbutton.qml @@ -67,13 +67,4 @@ TestCase { control.destroy(); } - - function test_highlighted() { - var control = button.createObject(testCase) - verify(control) - compare(control.highlighted, false) - - control.highlighted = true - compare(control.highlighted, true) - } } diff --git a/tests/auto/controls/data/tst_button.qml b/tests/auto/controls/data/tst_button.qml index ac7915ad..f8717a88 100644 --- a/tests/auto/controls/data/tst_button.qml +++ b/tests/auto/controls/data/tst_button.qml @@ -291,4 +291,15 @@ TestCase { control.destroy() } + + function test_highlighted() { + var control = button.createObject(testCase) + verify(control) + verify(!control.highlighted) + + control.highlighted = true + verify(control.highlighted) + + control.destroy() + } } diff --git a/tests/auto/controls/data/tst_itemdelegate.qml b/tests/auto/controls/data/tst_itemdelegate.qml index 0cd9c27b..37b0db2a 100644 --- a/tests/auto/controls/data/tst_itemdelegate.qml +++ b/tests/auto/controls/data/tst_itemdelegate.qml @@ -61,4 +61,15 @@ TestCase { compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset) control.destroy() } + + function test_highlighted() { + var control = itemDelegate.createObject(testCase) + verify(control) + verify(!control.highlighted) + + control.highlighted = true + verify(control.highlighted) + + control.destroy() + } } diff --git a/tests/auto/controls/data/tst_menuitem.qml b/tests/auto/controls/data/tst_menuitem.qml index 28b1cb8f..be0c0652 100644 --- a/tests/auto/controls/data/tst_menuitem.qml +++ b/tests/auto/controls/data/tst_menuitem.qml @@ -80,4 +80,15 @@ TestCase { control.destroy() } + + function test_highlighted() { + var control = menuItem.createObject(testCase) + verify(control) + verify(!control.highlighted) + + control.highlighted = true + verify(control.highlighted) + + control.destroy() + } } -- cgit v1.2.3