aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Arve Sæther <jan-arve.saether@qt.io>2020-08-20 16:48:57 +0200
committerJan Arve Sæther <jan-arve.saether@qt.io>2020-09-09 14:14:34 +0200
commita40192644574daf694f70bbe1661487eb06fef68 (patch)
tree555e6d2d822e5b0bcd7247789a575c819144a8ef
parent2520de0974649b6d720cc75b60024237b1b5ae4f (diff)
Fix ProgressBar on Windows
Also remove the two custom progress bars from the manual test where one has a custom background, and the other has a custom contentItem. If you want to customize a progress bar, you need to provide customizations for both the background and the contentItem. You cannot provide a custom background (or contentItem) alone, since its almost impossible to create a custom background that fits well with the contentItem of all the other possible styles it might be using. Change-Id: I82a87513e73f319bcecbfaed341ac4949f64c3bb Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
-rw-r--r--src/imports/controls/windows/ProgressBar.qml59
-rw-r--r--src/imports/controls/windows/qmldir1
-rw-r--r--src/imports/controls/windows/windows.pri1
-rw-r--r--src/imports/nativestyle/items/qquickstyleitemprogressbar.cpp14
-rw-r--r--src/imports/nativestyle/qstyle/qquickcommonstyle.cpp5
-rw-r--r--tests/manual/nativestyle/CustomProgressBars.qml32
6 files changed, 75 insertions, 37 deletions
diff --git a/src/imports/controls/windows/ProgressBar.qml b/src/imports/controls/windows/ProgressBar.qml
new file mode 100644
index 00000000..62bb63ed
--- /dev/null
+++ b/src/imports/controls/windows/ProgressBar.qml
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** 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.Controls
+import QtQuick.Templates as T
+import QtQuick.NativeStyle as NativeStyle
+
+T.ProgressBar {
+ id: control
+
+ implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
+ implicitContentWidth + leftPadding + rightPadding)
+ implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
+ implicitContentHeight + topPadding + bottomPadding)
+
+ font.pixelSize: nativeIndicator ? indicator.styleFont(control).pixelSize : undefined
+
+ background: NativeStyle.ProgressBar {
+ control: control
+ // Note: Paint both the background and the contents
+ subControl: NativeStyle.ProgressBar.Contents
+ useNinePatchImage: false
+ }
+
+}
diff --git a/src/imports/controls/windows/qmldir b/src/imports/controls/windows/qmldir
index 8daf1cf1..28fd2ce3 100644
--- a/src/imports/controls/windows/qmldir
+++ b/src/imports/controls/windows/qmldir
@@ -13,3 +13,4 @@ TextField 6.0 TextField.qml
Frame 6.0 Frame.qml
TextArea 6.0 TextArea.qml
ComboBox 6.0 ComboBox.qml
+ProgressBar 6.0 ProgressBar.qml
diff --git a/src/imports/controls/windows/windows.pri b/src/imports/controls/windows/windows.pri
index f60f9e03..c04ac6d4 100644
--- a/src/imports/controls/windows/windows.pri
+++ b/src/imports/controls/windows/windows.pri
@@ -4,6 +4,7 @@ QML_FILES += \
$$PWD/ComboBox.qml \
$$PWD/Frame.qml \
$$PWD/GroupBox.qml \
+ $$PWD/ProgressBar.qml \
$$PWD/RadioButton.qml \
$$PWD/Slider.qml \
$$PWD/SpinBox.qml \
diff --git a/src/imports/nativestyle/items/qquickstyleitemprogressbar.cpp b/src/imports/nativestyle/items/qquickstyleitemprogressbar.cpp
index 3429b5ac..8042d35a 100644
--- a/src/imports/nativestyle/items/qquickstyleitemprogressbar.cpp
+++ b/src/imports/nativestyle/items/qquickstyleitemprogressbar.cpp
@@ -57,7 +57,15 @@ StyleItemGeometry QQuickStyleItemProgressBar::calculateGeometry()
StyleItemGeometry geometry;
geometry.minimumSize = style()->sizeFromContents(QStyle::CT_ProgressBar, &styleOption, QSize(0, 0));
- geometry.implicitSize = geometry.minimumSize;
+
+ // From qprogressbar.cpp in qtbase:
+ const int cw = style()->pixelMetric(QStyle::PM_ProgressBarChunkWidth, &styleOption);
+ QFontMetrics fm(control<QQuickProgressBar>()->font());
+ QSize size = QSize(qMax(9, cw) * 7 + fm.horizontalAdvance(QLatin1Char('0')) * 4, fm.height() + 8);
+ if (!(styleOption.state & QStyle::State_Horizontal))
+ size = size.transposed();
+
+ geometry.implicitSize = style()->sizeFromContents(QStyle::CT_ProgressBar, &styleOption, size);
styleOption.rect = QRect(QPoint(0, 0), geometry.implicitSize);
geometry.contentRect = style()->subElementRect(QStyle::SE_ProgressBarContents, &styleOption);
geometry.layoutRect = style()->subElementRect(QStyle::SE_ProgressBarLayoutItem, &styleOption);
@@ -74,6 +82,10 @@ void QQuickStyleItemProgressBar::paintEvent(QPainter *painter)
styleOption.rect = style()->subElementRect(QStyle::SE_ProgressBarGroove, &styleOption);
style()->drawControl(QStyle::CE_ProgressBarGroove, &styleOption, painter);
} else {
+ const QRect r = styleOption.rect;
+ styleOption.rect = style()->subElementRect(QStyle::SE_ProgressBarGroove, &styleOption);
+ style()->drawControl(QStyle::CE_ProgressBarGroove, &styleOption, painter);
+ styleOption.rect = r;
styleOption.rect = style()->subElementRect(QStyle::SE_ProgressBarContents, &styleOption);
style()->drawControl(QStyle::CE_ProgressBarContents, &styleOption, painter);
}
diff --git a/src/imports/nativestyle/qstyle/qquickcommonstyle.cpp b/src/imports/nativestyle/qstyle/qquickcommonstyle.cpp
index fad47783..d7b97f21 100644
--- a/src/imports/nativestyle/qstyle/qquickcommonstyle.cpp
+++ b/src/imports/nativestyle/qstyle/qquickcommonstyle.cpp
@@ -1446,11 +1446,9 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
pbBits.palette = pal2;
int myY = pbBits.rect.y();
int myHeight = pbBits.rect.height();
- pbBits.state = State_None;
- QMatrix4x4 m;
+ pbBits.state = State_Horizontal;
for (int i = 0; i < nu; ++i) {
pbBits.rect.setRect(x0 + x, myY, unit_width, myHeight);
- pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect();
proxy()->drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p);
x += reverse ? -unit_width : unit_width;
}
@@ -1461,7 +1459,6 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
int pixels_left = w - (nu * unit_width);
int offset = reverse ? x0 + x + unit_width-pixels_left : x0 + x;
pbBits.rect.setRect(offset, myY, pixels_left, myHeight);
- pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect();
proxy()->drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p);
}
}
diff --git a/tests/manual/nativestyle/CustomProgressBars.qml b/tests/manual/nativestyle/CustomProgressBars.qml
index c920d243..b7617f92 100644
--- a/tests/manual/nativestyle/CustomProgressBars.qml
+++ b/tests/manual/nativestyle/CustomProgressBars.qml
@@ -59,38 +59,6 @@ ControlContainer {
spacing: container.rowSpacing
ProgressBar {
- id: c1
- width: 100
- from: 0
- to: 10
- value: time
- indeterminate: false
- padding: 5
- background: Rectangle {
- implicitWidth: 100
- implicitHeight: 6
- color: "darkgray"
- }
- }
-
- ProgressBar {
- id: c2
- width: 100
- from: 0
- to: 10
- value: time
- indeterminate: false
- padding: 5
- contentItem: ProgressBarImpl {
- implicitHeight: 6
- implicitWidth: 100
- progress: c2.position
- indeterminate: false
- color: "lightgreen"
- }
- }
-
- ProgressBar {
id: c3
width: 100
from: 0