diff options
| -rw-r--r-- | src/quickcontrols/macos/ProgressBar.qml | 92 | ||||
| -rw-r--r-- | src/quicknativestyle/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/quicknativestyle/util/qquickstyleconstants.h | 30 | ||||
| -rw-r--r-- | src/quicknativestyle/util/qquickstyleconstants.mm | 40 | ||||
| -rw-r--r-- | tests/baseline/controls/data/progressbar/progressbar.qml | 31 |
5 files changed, 191 insertions, 3 deletions
diff --git a/src/quickcontrols/macos/ProgressBar.qml b/src/quickcontrols/macos/ProgressBar.qml index ad6be98dc6..9a9d7767b7 100644 --- a/src/quickcontrols/macos/ProgressBar.qml +++ b/src/quickcontrols/macos/ProgressBar.qml @@ -1,9 +1,95 @@ -// Copyright (C) 2020 The Qt Company Ltd. +// Copyright (C) 2025 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only import QtQuick +import QtQuick.Controls +import QtQuick.Templates as T import QtQuick.NativeStyle as NativeStyle -NativeStyle.DefaultProgressBar { - id: control +T.ProgressBar { + id: root + + implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, + implicitContentWidth + leftPadding + rightPadding) + implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, + implicitContentHeight + topPadding + bottomPadding) + + readonly property bool __notCustomizable: true + + background: Item { + implicitWidth: 100 + implicitHeight: childrenRect.height + readonly property bool __ignoreNotCustomizable: true + + Loader { + active: NativeStyle.StyleConstants.runningWithLiquidGlass + width: parent.width + height: 8 + sourceComponent: Rectangle { + y: (parent.height - height) / 2 + radius: height / 2 + color: NativeStyle.StyleConstants.tertiarySystemFillColor + border.color: NativeStyle.StyleConstants.secondarySystemFillColor + border.width: 1 + } + } + + Loader { + active: !NativeStyle.StyleConstants.runningWithLiquidGlass + sourceComponent: NativeStyle.ProgressBar { + control: root + useNinePatchImage: false + } + } + } + + contentItem: Loader { + active: NativeStyle.StyleConstants.runningWithLiquidGlass + readonly property bool __ignoreNotCustomizable: true + property real animPos: 0 + + sourceComponent: Item { + // The outer item is resized by the control. + // The inner rectangle is resized according to the progress. + Rectangle { + property real minBlockSize: 10 + property real maxBlockSize: parent.width * 0.5; + property real margin: (maxBlockSize - minBlockSize) / (2 * parent.width); + property real pos: -margin + (animPos * (1 + (margin * 2))); + property real pixelPos: pos * parent.width + property real trackLeft: pixelPos > (maxBlockSize / 2) ? pixelPos - (maxBlockSize / 2) : 0; + property real trackRight: pixelPos > parent.width - (maxBlockSize / 2) + ? parent.width : pixelPos + (maxBlockSize / 2); + + x: root.indeterminate ? trackLeft : 0 + y: (parent.height - height) / 2 + width: root.indeterminate ? trackRight - trackLeft : parent.width * root.position + height: 8 + radius: height / 2 + color: Application.state === Qt.ApplicationActive ? palette.accent : "lightgray" + + SequentialAnimation { + running: root.indeterminate + loops: Animation.Infinite + NumberAnimation { + target: root.contentItem + property: "animPos" + to: 1 + duration: 800 + easing.type: Easing.OutCubic + } + PauseAnimation { duration: 100 } + NumberAnimation { + target: root.contentItem + property: "animPos" + to: 0 + duration: 800 + easing.type: Easing.OutCubic + } + PauseAnimation { duration: 100 } + } + } + } + } + } diff --git a/src/quicknativestyle/CMakeLists.txt b/src/quicknativestyle/CMakeLists.txt index 598baba146..ece4d4589e 100644 --- a/src/quicknativestyle/CMakeLists.txt +++ b/src/quicknativestyle/CMakeLists.txt @@ -107,6 +107,7 @@ qt_internal_extend_target(qtquickcontrols2nativestyleplugin CONDITION MACOS qstyle/mac/qquickmacstyle_mac.mm qstyle/mac/qquickmacstyle_mac_p.h qstyle/mac/qquickmacstyle_mac_p_p.h util/qquickmacfocusframe.h util/qquickmacfocusframe.mm + util/qquickstyleconstants.h util/qquickstyleconstants.mm INCLUDE_DIRECTORIES qstyle/mac LIBRARIES diff --git a/src/quicknativestyle/util/qquickstyleconstants.h b/src/quicknativestyle/util/qquickstyleconstants.h new file mode 100644 index 0000000000..d2c6379512 --- /dev/null +++ b/src/quicknativestyle/util/qquickstyleconstants.h @@ -0,0 +1,30 @@ +// Copyright (C) 2025 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#ifndef QQUICKSTYLECONSTANTS_H +#define QQUICKSTYLECONSTANTS_H + +#include <QtQml/QtQml> + +QT_BEGIN_NAMESPACE + +class QQuickStyleConstants : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool runningWithLiquidGlass READ runningWithLiquidGlass CONSTANT FINAL) + Q_PROPERTY(QColor secondarySystemFillColor READ secondarySystemFillColor CONSTANT FINAL) + Q_PROPERTY(QColor tertiarySystemFillColor READ tertiarySystemFillColor CONSTANT FINAL) + QML_NAMED_ELEMENT(StyleConstants) + QML_SINGLETON + +public: + QQuickStyleConstants(); + + bool runningWithLiquidGlass() const; + QColor secondarySystemFillColor() const; + QColor tertiarySystemFillColor() const; +}; + +QT_END_NAMESPACE + +#endif // QQUICKSTYLECONSTANTS_H diff --git a/src/quicknativestyle/util/qquickstyleconstants.mm b/src/quicknativestyle/util/qquickstyleconstants.mm new file mode 100644 index 0000000000..b99c49b1ad --- /dev/null +++ b/src/quicknativestyle/util/qquickstyleconstants.mm @@ -0,0 +1,40 @@ +// Copyright (C) 2025 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#include "qquickstyleconstants.h" + +#include <QtCore/private/qcore_mac_p.h> +#include <QtGui/private/qcoregraphics_p.h> + +#include <AppKit/AppKit.h> + +QT_BEGIN_NAMESPACE + +using namespace Qt::StringLiterals; + +QQuickStyleConstants::QQuickStyleConstants() +{ +} + +bool QQuickStyleConstants::runningWithLiquidGlass() const +{ + return qt_apple_runningWithLiquidGlass(); +} + +QColor QQuickStyleConstants::secondarySystemFillColor() const +{ + if (@available(macOS 14.0, *)) + return qt_mac_toQBrush([NSColor secondarySystemFillColor]).color(); + return Qt::black; +} + +QColor QQuickStyleConstants::tertiarySystemFillColor() const +{ + if (@available(macOS 14.0, *)) + return qt_mac_toQBrush([NSColor tertiarySystemFillColor]).color(); + return Qt::black; +} + +QT_END_NAMESPACE + +#include "moc_qquickstyleconstants.cpp" diff --git a/tests/baseline/controls/data/progressbar/progressbar.qml b/tests/baseline/controls/data/progressbar/progressbar.qml new file mode 100644 index 0000000000..630a20344a --- /dev/null +++ b/tests/baseline/controls/data/progressbar/progressbar.qml @@ -0,0 +1,31 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts + +ColumnLayout { + spacing: 4 + width: 200 + + ProgressBar { + value: 0 + Layout.alignment: Qt.AlignHCenter + } + + ProgressBar { + value: 1 + Layout.alignment: Qt.AlignHCenter + } + + ProgressBar { + value: 0.5 + Layout.alignment: Qt.AlignHCenter + } + + ProgressBar { + from: 10 + to: 20 + value: 15 + Layout.alignment: Qt.AlignHCenter + } + +} |
