aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2020-06-08 13:53:00 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2020-06-12 12:59:31 +0000
commit6715627602c049f83ae223ad89a4a0f837ca3c00 (patch)
tree47d6427987aa61e655fa776ec8f9532f46fc70ed
parent6e1fed645d6461f5d1f49f91a8ce32b66638a004 (diff)
NativeStyle: add ScrollBar
Change-Id: Ied2055866a67798ce60105e7251740a3e66b38db Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--examples/quickcontrols2/desktopgallery/CustomScrollBars.qml137
-rw-r--r--examples/quickcontrols2/desktopgallery/ScrollBars.qml99
-rw-r--r--examples/quickcontrols2/desktopgallery/desktopgallery.pro2
-rw-r--r--examples/quickcontrols2/desktopgallery/main.qml2
-rw-r--r--src/imports/controls/macos/ScrollBar.qml43
-rw-r--r--src/imports/controls/macos/macos.pri1
-rw-r--r--src/imports/nativestyle/controls/DefaultScrollBar.qml67
-rw-r--r--src/imports/nativestyle/controls/controls.pri1
-rw-r--r--src/imports/nativestyle/items/items.pri2
-rw-r--r--src/imports/nativestyle/items/qquickstyleitemscrollbar.cpp93
-rw-r--r--src/imports/nativestyle/items/qquickstyleitemscrollbar.h72
-rw-r--r--src/imports/nativestyle/qmldir1
-rw-r--r--src/imports/nativestyle/qstyle/mac/qquickmacstyle_mac.mm32
-rw-r--r--src/imports/nativestyle/qstyle/qquickstyle.h1
14 files changed, 539 insertions, 14 deletions
diff --git a/examples/quickcontrols2/desktopgallery/CustomScrollBars.qml b/examples/quickcontrols2/desktopgallery/CustomScrollBars.qml
new file mode 100644
index 00000000..fcac2eaf
--- /dev/null
+++ b/examples/quickcontrols2/desktopgallery/CustomScrollBars.qml
@@ -0,0 +1,137 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Quick Controls 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$
+**
+****************************************************************************/
+
+import QtQuick 2.15
+import QtQuick.Controls 2.15
+import QtQuick.Layouts 2.15
+
+ControlContainer {
+ id: container
+ title: "ScrollBars"
+
+ Row {
+ spacing: container.rowSpacing
+
+ ScrollBar {
+ height: 200
+ orientation: Qt.Vertical
+ size: 0.2
+ policy: ScrollBar.AlwaysOn
+ background: Rectangle {
+ color: "lightgray"
+ border.color: "gray"
+ border.width: 1
+ }
+ }
+
+ ScrollBar {
+ height: 200
+ orientation: Qt.Vertical
+ size: 0.2
+ policy: ScrollBar.AlwaysOn
+ contentItem: Rectangle {
+ color: "lightgreen"
+ border.color: "green"
+ border.width: 1
+ }
+ }
+
+ ScrollBar {
+ height: 200
+ orientation: Qt.Vertical
+ size: 0.2
+ policy: ScrollBar.AlwaysOn
+ background: Rectangle {
+ color: "lightgray"
+ border.color: "gray"
+ border.width: 1
+ }
+ contentItem: Rectangle {
+ implicitWidth: 15
+ color: "lightgreen"
+ border.color: "green"
+ border.width: 1
+ }
+ }
+
+ Column {
+ spacing: container.rowSpacing
+
+ ScrollBar {
+ width: 300
+ orientation: Qt.Horizontal
+ size: 0.2
+ policy: ScrollBar.AlwaysOn
+ background: Rectangle {
+ color: "lightgray"
+ border.color: "gray"
+ border.width: 1
+ }
+ }
+
+ ScrollBar {
+ width: 300
+ orientation: Qt.Horizontal
+ size: 0.2
+ policy: ScrollBar.AlwaysOn
+ contentItem: Rectangle {
+ color: "lightgray"
+ border.color: "gray"
+ border.width: 1
+ }
+ }
+
+ ScrollBar {
+ width: 300
+ orientation: Qt.Horizontal
+ size: 0.2
+ policy: ScrollBar.AlwaysOn
+ background: Rectangle {
+ color: "lightgray"
+ border.color: "gray"
+ border.width: 1
+ }
+ contentItem: Rectangle {
+ implicitHeight: 15
+ color: "lightgreen"
+ border.color: "green"
+ border.width: 1
+ }
+ }
+ }
+ }
+
+}
diff --git a/examples/quickcontrols2/desktopgallery/ScrollBars.qml b/examples/quickcontrols2/desktopgallery/ScrollBars.qml
new file mode 100644
index 00000000..f7b78f86
--- /dev/null
+++ b/examples/quickcontrols2/desktopgallery/ScrollBars.qml
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Quick Controls 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$
+**
+****************************************************************************/
+
+import QtQuick 2.15
+import QtQuick.Controls 2.15
+import QtQuick.Layouts 2.15
+
+ControlContainer {
+ id: container
+ title: "ScrollBars"
+
+ Row {
+ spacing: container.rowSpacing
+
+ ScrollBar {
+ height: 200
+ orientation: Qt.Vertical
+ size: 0.2
+ policy: ScrollBar.AlwaysOn
+ }
+
+ ScrollBar {
+ height: 150
+ orientation: Qt.Vertical
+ size: 0.2
+ policy: ScrollBar.AlwaysOn
+ property bool qqc2_style_small
+ }
+
+ ScrollBar {
+ height: 100
+ orientation: Qt.Vertical
+ size: 0.2
+ policy: ScrollBar.AlwaysOn
+ property bool qqc2_style_mini
+ }
+
+ Column {
+ spacing: container.rowSpacing
+
+ ScrollBar {
+ width: 300
+ orientation: Qt.Horizontal
+ size: 0.2
+ policy: ScrollBar.AlwaysOn
+ }
+
+ ScrollBar {
+ width: 200
+ orientation: Qt.Horizontal
+ size: 0.2
+ policy: ScrollBar.AlwaysOn
+ property bool qqc2_style_small
+ }
+
+ ScrollBar {
+ width: 100
+ orientation: Qt.Horizontal
+ size: 0.2
+ policy: ScrollBar.AlwaysOn
+ property bool qqc2_style_mini
+ }
+ }
+ }
+
+}
diff --git a/examples/quickcontrols2/desktopgallery/desktopgallery.pro b/examples/quickcontrols2/desktopgallery/desktopgallery.pro
index d0c35910..ab4a07a3 100644
--- a/examples/quickcontrols2/desktopgallery/desktopgallery.pro
+++ b/examples/quickcontrols2/desktopgallery/desktopgallery.pro
@@ -26,6 +26,8 @@ QML_FILES = \
CustomTextAreas.qml \
ComboBoxes.qml \
CustomComboBoxes.qml \
+ ScrollBars.qml \
+ CustomScrollBars.qml \
OTHER_FILES += $$QML_FILES
RESOURCES += $$QML_FILES
diff --git a/examples/quickcontrols2/desktopgallery/main.qml b/examples/quickcontrols2/desktopgallery/main.qml
index 0b512bab..1c973659 100644
--- a/examples/quickcontrols2/desktopgallery/main.qml
+++ b/examples/quickcontrols2/desktopgallery/main.qml
@@ -87,6 +87,7 @@ ApplicationWindow {
TextAreas { }
ComboBoxes { }
Frames { }
+ ScrollBars { }
Sliders { }
SlidersSmall { }
SlidersMini { }
@@ -111,6 +112,7 @@ ApplicationWindow {
CustomTextAreas { }
CustomComboBoxes { }
CustomFrames { }
+ CustomScrollBars { }
CustomSliders { }
}
}
diff --git a/src/imports/controls/macos/ScrollBar.qml b/src/imports/controls/macos/ScrollBar.qml
new file mode 100644
index 00000000..cfd5735e
--- /dev/null
+++ b/src/imports/controls/macos/ScrollBar.qml
@@ -0,0 +1,43 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Quick Controls 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$
+**
+****************************************************************************/
+
+import QtQuick 2.12
+import QtQuick.Controls 2.12
+import QtQuick.Controls.impl 2.12
+import QtQuick.NativeStyle 6.0 as NativeStyle
+
+NativeStyle.DefaultScrollBar {
+}
diff --git a/src/imports/controls/macos/macos.pri b/src/imports/controls/macos/macos.pri
index 18876e4a..e80afb0a 100644
--- a/src/imports/controls/macos/macos.pri
+++ b/src/imports/controls/macos/macos.pri
@@ -9,3 +9,4 @@ QML_FILES += \
$$PWD/Frame.qml \
$$PWD/TextArea.qml \
$$PWD/ComboBox.qml \
+ $$PWD/ScrollBar.qml \
diff --git a/src/imports/nativestyle/controls/DefaultScrollBar.qml b/src/imports/nativestyle/controls/DefaultScrollBar.qml
new file mode 100644
index 00000000..1e563bbc
--- /dev/null
+++ b/src/imports/nativestyle/controls/DefaultScrollBar.qml
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Quick Controls 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$
+**
+****************************************************************************/
+
+import QtQuick 2.12
+import QtQuick.Controls 2.12
+import QtQuick.Controls.impl 2.12
+import QtQuick.Templates 2.12 as T
+import QtQuick.NativeStyle 6.0 as NativeStyle
+
+T.ScrollBar {
+ id: control
+
+ readonly property bool nativeBackground: background instanceof NativeStyle.StyleItem
+
+ implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
+ implicitContentWidth + leftPadding + rightPadding)
+ implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
+ implicitContentHeight + topPadding + bottomPadding)
+
+ font.pixelSize: nativeBackground ? background.styleFont(control).pixelSize : undefined
+
+ visible: policy === T.ScrollBar.AlwaysOn || (active && size < 1.0)
+
+ background: NativeStyle.ScrollBar {
+ control: control
+ subControl: NativeStyle.ScrollBar.Groove
+ }
+
+ contentItem: NativeStyle.ScrollBar {
+ control: control
+ subControl: NativeStyle.ScrollBar.Handle
+ width: control.width
+ }
+}
diff --git a/src/imports/nativestyle/controls/controls.pri b/src/imports/nativestyle/controls/controls.pri
index 3e175c83..b1f5ee0b 100644
--- a/src/imports/nativestyle/controls/controls.pri
+++ b/src/imports/nativestyle/controls/controls.pri
@@ -9,3 +9,4 @@ QML_FILES += \
$$PWD/DefaultFrame.qml \
$$PWD/DefaultTextArea.qml \
$$PWD/DefaultComboBox.qml \
+ $$PWD/DefaultScrollBar.qml \
diff --git a/src/imports/nativestyle/items/items.pri b/src/imports/nativestyle/items/items.pri
index 1bb311fd..bbe6523b 100644
--- a/src/imports/nativestyle/items/items.pri
+++ b/src/imports/nativestyle/items/items.pri
@@ -12,6 +12,7 @@ HEADERS += \
$$PWD/qquickstyleitemframe.h \
$$PWD/qquickstyleitemtextarea.h \
$$PWD/qquickstyleitemcombobox.h \
+ $$PWD/qquickstyleitemscrollbar.h \
SOURCES += \
$$PWD/qquickstyleitem.cpp \
@@ -25,3 +26,4 @@ SOURCES += \
$$PWD/qquickstyleitemframe.cpp \
$$PWD/qquickstyleitemtextarea.cpp \
$$PWD/qquickstyleitemcombobox.cpp \
+ $$PWD/qquickstyleitemscrollbar.cpp \
diff --git a/src/imports/nativestyle/items/qquickstyleitemscrollbar.cpp b/src/imports/nativestyle/items/qquickstyleitemscrollbar.cpp
new file mode 100644
index 00000000..7a462082
--- /dev/null
+++ b/src/imports/nativestyle/items/qquickstyleitemscrollbar.cpp
@@ -0,0 +1,93 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Quick Controls 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$
+**
+****************************************************************************/
+
+#include "qquickstyleitemscrollbar.h"
+
+QFont QQuickStyleItemScrollBar::styleFont(QQuickItem *control)
+{
+ return style()->font(QStyle::CE_ProgressBarLabel, controlSize(control));
+}
+
+void QQuickStyleItemScrollBar::connectToControl()
+{
+ QQuickStyleItem::connectToControl();
+ auto scrollBar = control<QQuickScrollBar>();
+ connect(scrollBar, &QQuickScrollBar::orientationChanged, this, &QQuickStyleItem::markImageDirty);
+ connect(scrollBar, &QQuickScrollBar::pressedChanged, this, &QQuickStyleItem::markImageDirty);
+}
+
+StyleItemGeometry QQuickStyleItemScrollBar::calculateGeometry()
+{
+ QStyleOptionSlider styleOption;
+ initStyleOption(styleOption);
+
+ StyleItemGeometry geometry;
+ geometry.minimumSize = style()->sizeFromContents(QStyle::CT_ScrollBar, &styleOption, QSize(0, 0));
+ geometry.implicitSize = geometry.minimumSize;
+ styleOption.rect = QRect(QPoint(0, 0), geometry.implicitSize);
+ geometry.layoutRect = style()->subElementRect(QStyle::SE_ScrollBarLayoutItem, &styleOption);
+ geometry.ninePatchMargins = style()->ninePatchMargins(QStyle::CC_ScrollBar, &styleOption, geometry.minimumSize);
+
+ return geometry;
+}
+
+void QQuickStyleItemScrollBar::paintEvent(QPainter *painter)
+{
+ QStyleOptionSlider styleOption;
+ initStyleOption(styleOption);
+ style()->drawComplexControl(QStyle::CC_ScrollBar, &styleOption, painter);
+}
+
+void QQuickStyleItemScrollBar::initStyleOption(QStyleOptionSlider &styleOption)
+{
+ initStyleOptionBase(styleOption);
+ auto scrollBar = control<QQuickScrollBar>();
+
+ styleOption.subControls = m_subControl == Groove ? QStyle::SC_ScrollBarGroove : QStyle::SC_ScrollBarSlider;
+ styleOption.activeSubControls = QStyle::SC_None;
+ styleOption.orientation = scrollBar->orientation();
+
+ if (scrollBar->isPressed())
+ styleOption.state |= QStyle::State_Sunken;
+
+ // The following values will let the handle fill 100% of the
+ // groove / imageSize. But when the handle is resized by
+ // QQuickScrollBar, it will end up with the correct size visually.
+ styleOption.pageStep = 1000;
+ styleOption.minimum = 0;
+ styleOption.maximum = 1;
+ styleOption.sliderValue = 0;
+}
diff --git a/src/imports/nativestyle/items/qquickstyleitemscrollbar.h b/src/imports/nativestyle/items/qquickstyleitemscrollbar.h
new file mode 100644
index 00000000..e181d4ec
--- /dev/null
+++ b/src/imports/nativestyle/items/qquickstyleitemscrollbar.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Quick Controls 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 QQUICKSTYLEITEMSCROLLBAR_H
+#define QQUICKSTYLEITEMSCROLLBAR_H
+
+#include "qquickstyleitem.h"
+#include <QtQuickTemplates2/private/qquickscrollbar_p.h>
+
+class QQuickStyleItemScrollBar : public QQuickStyleItem
+{
+ Q_OBJECT
+
+ Q_PROPERTY(SubControl subControl MEMBER m_subControl)
+
+ QML_NAMED_ELEMENT(ScrollBar)
+
+public:
+ enum SubControl {
+ Groove = 1,
+ Handle,
+ };
+ Q_ENUM(SubControl)
+
+ QFont styleFont(QQuickItem *control) override;
+
+protected:
+ void connectToControl() override;
+ void paintEvent(QPainter *painter) override;
+ StyleItemGeometry calculateGeometry() override;
+
+private:
+ void initStyleOption(QStyleOptionSlider &styleOption);
+
+private:
+ SubControl m_subControl = Groove;
+};
+
+#endif // QQUICKSTYLEITEMSCROLLBAR_H
diff --git a/src/imports/nativestyle/qmldir b/src/imports/nativestyle/qmldir
index 903967ce..1e62db50 100644
--- a/src/imports/nativestyle/qmldir
+++ b/src/imports/nativestyle/qmldir
@@ -13,3 +13,4 @@ DefaultTextField 6.0 controls/DefaultTextField.qml
DefaultFrame 6.0 controls/DefaultFrame.qml
DefaultTextArea 6.0 controls/DefaultTextArea.qml
DefaultComboBox 6.0 controls/DefaultComboBox.qml
+DefaultScrollBar 6.0 controls/DefaultScrollBar.qml
diff --git a/src/imports/nativestyle/qstyle/mac/qquickmacstyle_mac.mm b/src/imports/nativestyle/qstyle/mac/qquickmacstyle_mac.mm
index b66a59fd..5101680c 100644
--- a/src/imports/nativestyle/qstyle/mac/qquickmacstyle_mac.mm
+++ b/src/imports/nativestyle/qstyle/mac/qquickmacstyle_mac.mm
@@ -2694,14 +2694,10 @@ int QMacStyle::styleHint(StyleHint sh, const QStyleOption *opt, QStyleHintReturn
ret = false;
break;
case SH_ScrollBar_Transient:
-// if ((qobject_cast<const QScrollBar *>(w) && w->parent() &&
-// qobject_cast<QAbstractScrollArea*>(w->parent()->parent()))
-//#ifndef QT_NO_ACCESSIBILITY
-// || (opt && QStyleHelper::hasAncestor(opt->styleObject, QAccessible::ScrollBar))
-//#endif
-// ) {
- ret = [NSScroller preferredScrollerStyle] == NSScrollerStyleOverlay;
-// }
+ // For the initial version in QQC2, we don't support transient scrollbars. When the
+ // time comes, consider doing all such animations from QML.
+ // ret = [NSScroller preferredScrollerStyle] == NSScrollerStyleOverlay;
+ ret = false;
break;
case SH_TitleBar_ShowToolTipsOnButtons:
// min/max/close buttons on windows don't show tool tips
@@ -4713,6 +4709,10 @@ QRect QMacStyle::subElementRect(SubElement sr, const QStyleOption *opt) const
}
}
break;
+ case SE_ScrollBarLayoutItem:
+ if (const QStyleOptionSlider *sliderOpt = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
+ rect = opt->rect;
+ }
case SE_FrameLayoutItem:
// hack because QStyleOptionFrame doesn't have a frameStyle member
// if (const QFrame *frame = qobject_cast<const QFrame *>(widget)) {
@@ -5069,7 +5069,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
} else {
[scroller drawKnob];
- if (!isTransient && opt->activeSubControls) {
+ if (!isTransient && opt->state & State_Sunken) {
// The knob should appear darker (going from 0.76 down to 0.49).
// But no blending mode can help darken enough in a single pass,
// so we resort to drawing the knob twice with a small help from
@@ -6245,11 +6245,15 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, cons
case CT_ScrollBar :
// Make sure that the scroll bar is large enough to display the thumb indicator.
if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
- const int minimumSize = 24; // Smallest knob size, but Cocoa doesn't seem to care
- if (slider->orientation == Qt::Horizontal)
- sz = sz.expandedTo(QSize(minimumSize, sz.height()));
- else
- sz = sz.expandedTo(QSize(sz.width(), minimumSize));
+ const int minimumWidth = 24;
+ const int absoluteHeight = 14;
+ if (slider->orientation == Qt::Horizontal) {
+ sz = sz.expandedTo(QSize(minimumWidth, sz.height()));
+ sz.setHeight(absoluteHeight);
+ } else {
+ sz = sz.expandedTo(QSize(sz.width(), minimumWidth));
+ sz.setWidth(absoluteHeight);
+ }
}
break;
case CT_ItemViewItem:
diff --git a/src/imports/nativestyle/qstyle/qquickstyle.h b/src/imports/nativestyle/qstyle/qquickstyle.h
index bc0cccf7..8fd3a5ae 100644
--- a/src/imports/nativestyle/qstyle/qquickstyle.h
+++ b/src/imports/nativestyle/qstyle/qquickstyle.h
@@ -296,6 +296,7 @@ public:
SE_PushButtonLayoutItem,
SE_RadioButtonLayoutItem,
SE_SliderLayoutItem,
+ SE_ScrollBarLayoutItem,
SE_SpinBoxLayoutItem,
SE_ToolButtonLayoutItem,