aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/nativestyle/items
diff options
context:
space:
mode:
authorJan Arve Sæther <jan-arve.saether@qt.io>2020-09-23 13:13:02 +0200
committerJan Arve Sæther <jan-arve.saether@qt.io>2020-09-29 12:41:00 +0200
commitad25ebd08247579754243b09f8fa60b778d9a3aa (patch)
treee6c300389d0662abecb1e5e53b0ef2bf170fd459 /src/imports/nativestyle/items
parent0ea96f1896a13c8e01b4ee9d45439565e19eb18a (diff)
windows: Add hover animation to Button and CheckBox
Move the hover animation handling API from macOS ScrollBar down to QQuickStyleItem. Change-Id: I36c8b173a15d0f4e10a59b7f3ccfe635e05c73e7 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/imports/nativestyle/items')
-rw-r--r--src/imports/nativestyle/items/qquickstyleitem.cpp9
-rw-r--r--src/imports/nativestyle/items/qquickstyleitem.h18
-rw-r--r--src/imports/nativestyle/items/qquickstyleitemscrollbar.cpp2
-rw-r--r--src/imports/nativestyle/items/qquickstyleitemscrollbar.h17
4 files changed, 27 insertions, 19 deletions
diff --git a/src/imports/nativestyle/items/qquickstyleitem.cpp b/src/imports/nativestyle/items/qquickstyleitem.cpp
index 03659aa2..c45f0c91 100644
--- a/src/imports/nativestyle/items/qquickstyleitem.cpp
+++ b/src/imports/nativestyle/items/qquickstyleitem.cpp
@@ -196,6 +196,15 @@ void QQuickStyleItem::initStyleOptionBase(QStyleOption &styleOption)
styleOption.state |= QStyle::State_KeyboardFocusChange;
}
+ if (m_overrideState != None) {
+ // In Button.qml we fade between two versions of
+ // the handle, depending on if it's hovered or not
+ if (m_overrideState & AlwaysHovered)
+ styleOption.state |= QStyle::State_MouseOver;
+ else if (m_overrideState & NeverHovered)
+ styleOption.state &= ~QStyle::State_MouseOver;
+ }
+
qqc2Debug() << styleOption;
}
diff --git a/src/imports/nativestyle/items/qquickstyleitem.h b/src/imports/nativestyle/items/qquickstyleitem.h
index 3d5bfc31..ff870684 100644
--- a/src/imports/nativestyle/items/qquickstyleitem.h
+++ b/src/imports/nativestyle/items/qquickstyleitem.h
@@ -160,6 +160,9 @@ class QQuickStyleItem : public QQuickItem
Q_PROPERTY(qreal contentHeight READ contentHeight WRITE setContentHeight)
Q_PROPERTY(bool useNinePatchImage MEMBER m_useNinePatchImage)
+ Q_PROPERTY(OverrideState overrideState MEMBER m_overrideState)
+ Q_PROPERTY(int transitionDuration MEMBER m_transitionDuration)
+
// Output
Q_PROPERTY(QQuickStyleMargins contentPadding READ contentPadding() NOTIFY contentPaddingChanged)
Q_PROPERTY(QQuickStyleMargins layoutMargins READ layoutMargins() NOTIFY layoutMarginsChanged)
@@ -176,6 +179,14 @@ public:
};
Q_DECLARE_FLAGS(DirtyFlags, DirtyFlag)
+ enum OverrideState {
+ None = 0,
+ AlwaysHovered,
+ NeverHovered,
+ };
+ Q_ENUM(OverrideState)
+
+
#ifdef QT_DEBUG
enum DebugFlag {
NoDebug = 0x00,
@@ -244,6 +255,7 @@ protected:
#ifdef QT_DEBUG
DebugFlags m_debugFlags = NoDebug;
#endif
+ OverrideState m_overrideState = None;
private:
inline void updateGeometry();
@@ -259,6 +271,12 @@ private:
bool m_useNinePatchImage = true;
bool m_polishing = false;
+#ifdef Q_OS_MACOS
+ int m_transitionDuration = 150;
+#else
+ int m_transitionDuration = 400;
+#endif
+
private:
friend class QtQuickControls2MacOSStylePlugin;
};
diff --git a/src/imports/nativestyle/items/qquickstyleitemscrollbar.cpp b/src/imports/nativestyle/items/qquickstyleitemscrollbar.cpp
index 72f850a8..77185b48 100644
--- a/src/imports/nativestyle/items/qquickstyleitemscrollbar.cpp
+++ b/src/imports/nativestyle/items/qquickstyleitemscrollbar.cpp
@@ -83,7 +83,6 @@ void QQuickStyleItemScrollBar::initStyleOption(QStyleOptionSlider &styleOption)
if (scrollBar->isPressed())
styleOption.state |= QStyle::State_Sunken;
-#ifdef Q_OS_MACOS
if (m_overrideState != None) {
// In ScrollBar.qml we fade between two versions of
// the handle, depending on if it's hovered or not
@@ -92,7 +91,6 @@ void QQuickStyleItemScrollBar::initStyleOption(QStyleOptionSlider &styleOption)
else if (m_overrideState & NeverHovered)
styleOption.state &= ~QStyle::State_Sunken;
}
-#endif
// The following values will let the handle fill 100% of the
// groove / imageSize. But when the handle is resized by
diff --git a/src/imports/nativestyle/items/qquickstyleitemscrollbar.h b/src/imports/nativestyle/items/qquickstyleitemscrollbar.h
index db241ad8..e181d4ec 100644
--- a/src/imports/nativestyle/items/qquickstyleitemscrollbar.h
+++ b/src/imports/nativestyle/items/qquickstyleitemscrollbar.h
@@ -46,10 +46,6 @@ class QQuickStyleItemScrollBar : public QQuickStyleItem
Q_PROPERTY(SubControl subControl MEMBER m_subControl)
-#ifdef Q_OS_MACOS
- Q_PROPERTY(OverrideState overrideState MEMBER m_overrideState)
-#endif
-
QML_NAMED_ELEMENT(ScrollBar)
public:
@@ -59,15 +55,6 @@ public:
};
Q_ENUM(SubControl)
-#ifdef Q_OS_MACOS
- enum OverrideState {
- None = 0,
- AlwaysHovered,
- NeverHovered,
- };
- Q_ENUM(OverrideState)
-#endif
-
QFont styleFont(QQuickItem *control) override;
protected:
@@ -80,10 +67,6 @@ private:
private:
SubControl m_subControl = Groove;
-
-#ifdef Q_OS_MACOS
- OverrideState m_overrideState = None;
-#endif
};
#endif // QQUICKSTYLEITEMSCROLLBAR_H