aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/imports/controls/windows/CMakeLists.txt1
-rw-r--r--src/imports/controls/windows/ScrollBar.qml84
-rw-r--r--src/imports/controls/windows/qmldir1
-rw-r--r--src/imports/controls/windows/windows.pri1
-rw-r--r--src/imports/nativestyle/items/qquickstyleitemscrollbar.cpp13
-rw-r--r--src/imports/nativestyle/qstyle/windows/qquickwindowsxpstyle.cpp35
6 files changed, 131 insertions, 4 deletions
diff --git a/src/imports/controls/windows/CMakeLists.txt b/src/imports/controls/windows/CMakeLists.txt
index f1d01946..edd144bb 100644
--- a/src/imports/controls/windows/CMakeLists.txt
+++ b/src/imports/controls/windows/CMakeLists.txt
@@ -51,6 +51,7 @@ set(qml_files
"SpinBox.qml"
"TextArea.qml"
"TextField.qml"
+ "ScrollBar.qml"
"ScrollView.qml"
)
set_source_files_properties(Button.qml PROPERTIES
diff --git a/src/imports/controls/windows/ScrollBar.qml b/src/imports/controls/windows/ScrollBar.qml
new file mode 100644
index 00000000..d3b09418
--- /dev/null
+++ b/src/imports/controls/windows/ScrollBar.qml
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** 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
+import QtQuick.NativeStyle as NativeStyle
+
+NativeStyle.DefaultScrollBar {
+ id: controlRoot
+
+ topPadding: orientation == Qt.Vertical ? 17 : 0
+ bottomPadding: orientation == Qt.Vertical ? 17 : 0
+ leftPadding: orientation == Qt.Horizontal ? 17 : 0
+ rightPadding: orientation == Qt.Horizontal ? 17 : 0
+
+ contentItem: NativeStyle.ScrollBar {
+ control: controlRoot
+ subControl: NativeStyle.ScrollBar.Handle
+ }
+
+ NativeStyle.ScrollBar {
+ // Fade a hovered-looking version of the handle
+ // on top of the default handle when hovering it
+ x: contentItem.x
+ y: contentItem.y
+ z: 1
+ width: contentItem.width
+ height: contentItem.height
+ control: controlRoot
+ subControl: NativeStyle.ScrollBar.Handle
+ overrideState: NativeStyle.StyleItem.AlwaysHovered
+ opacity: controlRoot.hovered || control.pressed ? 1 : 0
+ visible: contentItem instanceof NativeStyle.StyleItem
+ Behavior on opacity { NumberAnimation { duration: contentItem.transitionDuration } }
+ }
+
+ // The groove background should have window color
+ Rectangle {
+ x: background.x
+ y: background.y
+ z: -1
+ width: background.width
+ height: background.height
+ color: controlRoot.palette.window
+ }
+
+ background: NativeStyle.ScrollBar {
+ control: controlRoot
+ subControl: NativeStyle.ScrollBar.Groove
+ overrideState: NativeStyle.ScrollBar.NeverHovered
+ }
+}
diff --git a/src/imports/controls/windows/qmldir b/src/imports/controls/windows/qmldir
index ed9758b3..bc87455d 100644
--- a/src/imports/controls/windows/qmldir
+++ b/src/imports/controls/windows/qmldir
@@ -14,4 +14,5 @@ Frame 6.0 Frame.qml
TextArea 6.0 TextArea.qml
ComboBox 6.0 ComboBox.qml
ProgressBar 6.0 ProgressBar.qml
+ScrollBar 6.0 ScrollBar.qml
ScrollView 6.0 ScrollView.qml
diff --git a/src/imports/controls/windows/windows.pri b/src/imports/controls/windows/windows.pri
index 4c9e51f7..7f13eab0 100644
--- a/src/imports/controls/windows/windows.pri
+++ b/src/imports/controls/windows/windows.pri
@@ -10,4 +10,5 @@ QML_FILES += \
$$PWD/SpinBox.qml \
$$PWD/TextArea.qml \
$$PWD/TextField.qml \
+ $$PWD/ScrollBar.qml \
$$PWD/ScrollView.qml \
diff --git a/src/imports/nativestyle/items/qquickstyleitemscrollbar.cpp b/src/imports/nativestyle/items/qquickstyleitemscrollbar.cpp
index 77185b48..364b9b62 100644
--- a/src/imports/nativestyle/items/qquickstyleitemscrollbar.cpp
+++ b/src/imports/nativestyle/items/qquickstyleitemscrollbar.cpp
@@ -76,9 +76,13 @@ void QQuickStyleItemScrollBar::initStyleOption(QStyleOptionSlider &styleOption)
initStyleOptionBase(styleOption);
auto scrollBar = control<QQuickScrollBar>();
- styleOption.subControls = m_subControl == Groove ? QStyle::SC_ScrollBarGroove : QStyle::SC_ScrollBarSlider;
+ styleOption.subControls = m_subControl == Groove
+ ? QStyle::SC_ScrollBarGroove | QStyle::SC_ScrollBarAddLine | QStyle::SC_ScrollBarSubLine
+ : QStyle::SC_ScrollBarSlider;
styleOption.activeSubControls = QStyle::SC_None;
styleOption.orientation = scrollBar->orientation();
+ if (styleOption.orientation == Qt::Horizontal)
+ styleOption.state |= QStyle::State_Horizontal;
if (scrollBar->isPressed())
styleOption.state |= QStyle::State_Sunken;
@@ -86,10 +90,13 @@ void QQuickStyleItemScrollBar::initStyleOption(QStyleOptionSlider &styleOption)
if (m_overrideState != None) {
// In ScrollBar.qml we fade between two versions of
// the handle, depending on if it's hovered or not
- if (m_overrideState & AlwaysHovered)
+ if (m_overrideState & AlwaysHovered) {
styleOption.state |= QStyle::State_Sunken;
- else if (m_overrideState & NeverHovered)
+ styleOption.activeSubControls = (styleOption.subControls & (QStyle::SC_ScrollBarSlider | QStyle::SC_ScrollBarGroove));
+ } else if (m_overrideState & NeverHovered) {
styleOption.state &= ~QStyle::State_Sunken;
+ styleOption.activeSubControls &= ~(styleOption.subControls & (QStyle::SC_ScrollBarSlider | QStyle::SC_ScrollBarGroove));
+ }
}
// The following values will let the handle fill 100% of the
diff --git a/src/imports/nativestyle/qstyle/windows/qquickwindowsxpstyle.cpp b/src/imports/nativestyle/qstyle/windows/qquickwindowsxpstyle.cpp
index e40cedb0..3dd5149f 100644
--- a/src/imports/nativestyle/qstyle/windows/qquickwindowsxpstyle.cpp
+++ b/src/imports/nativestyle/qstyle/windows/qquickwindowsxpstyle.cpp
@@ -2567,7 +2567,27 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo
d->drawBackground(theme);
}
if (sub & SC_ScrollBarSlider) {
- theme.rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSlider);
+ QRect rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSlider);
+ // The style paint the slider handle so that it is surrounded by transparent areas
+ // on each side. These areas have the same size as the Left/Right (or Top/Left) buttons.
+ // This is probaly done in order for the handle to travel all along the geometry
+ // of the slider, while the handle still not occluding the buttons.
+ // We do not want those transparent areas, so we clip them off here.
+ const QSize handleSize = proxy()->subControlRect(QStyle::CC_ScrollBar, scrollbar, QStyle::SC_ScrollBarAddLine).size();
+
+ if (scrollbar->orientation == Qt::Vertical) {
+ const int handleHeight = handleSize.height();
+ rect.setBottom(rect.bottom() + 2 * handleHeight);
+ p->setClipRect(r.adjusted(0, 0, 0, handleHeight));
+ p->translate(0, -handleHeight);
+ } else {
+ const int handleWidth = handleSize.width();
+ rect.setRight(rect.right() + 2 * handleWidth);
+ p->setClipRect(r.adjusted(0, 0, handleWidth, 0));
+ p->translate(-handleWidth, 0);
+ }
+
+ theme.rect = rect;
if (!(flags & State_Enabled))
stateId = SCRBS_DISABLED;
else if (scrollbar->activeSubControls & SC_ScrollBarSlider && (scrollbar->state & State_Sunken))
@@ -3470,6 +3490,19 @@ QSize QWindowsXPStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt
}
}
break;
+ 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 *>(option)) {
+ const int scrollBarHeight = proxy()->pixelMetric(QStyle::PM_ScrollBarExtent, slider);
+ const int scrollBarSliderMin = proxy()->pixelMetric(QStyle::PM_ScrollBarSliderMin, slider);
+ int &szw = slider->orientation == Qt::Horizontal ? sz.rwidth() : sz.rheight();
+ int &szh = slider->orientation == Qt::Horizontal ? sz.rheight() : sz.rwidth();
+ if (slider->subControls & (SC_ScrollBarSlider | SC_ScrollBarGroove)) {
+ szw = qMax(szw, scrollBarSliderMin + 2 * scrollBarHeight);
+ szh = scrollBarHeight;
+ }
+ }
+ break;
default:
sz = QWindowsStyle::sizeFromContents(ct, option, sz);
break;