diff options
author | Mitch Curtis <[email protected]> | 2023-10-26 13:29:48 +0800 |
---|---|---|
committer | Mitch Curtis <[email protected]> | 2023-11-01 21:45:06 +0800 |
commit | b520beaf514aeeedc73b49c56ba55ad9b8e22afc (patch) | |
tree | d6107957b97d2f714b860bae6d9f00870fda8547 | |
parent | bd3e1af6cd6c77b19fcae128cb0016e5dd6fd3d0 (diff) |
macOS: add CheckDelegate
Task-number: QTBUG-115165
Change-Id: Ie873592d74dcda4828ba753391c64929402736f8
Reviewed-by: Richard Moe Gustavsen <[email protected]>
8 files changed, 130 insertions, 4 deletions
diff --git a/src/quickcontrols/macos/CMakeLists.txt b/src/quickcontrols/macos/CMakeLists.txt index 952442c21b..35eb951a10 100644 --- a/src/quickcontrols/macos/CMakeLists.txt +++ b/src/quickcontrols/macos/CMakeLists.txt @@ -9,6 +9,7 @@ set(qml_files "BusyIndicator.qml" "Button.qml" "CheckBox.qml" + "CheckDelegate.qml" "ComboBox.qml" "DelayButton.qml" "Dial.qml" diff --git a/src/quickcontrols/macos/CheckDelegate.qml b/src/quickcontrols/macos/CheckDelegate.qml new file mode 100644 index 0000000000..ddcc6dabb4 --- /dev/null +++ b/src/quickcontrols/macos/CheckDelegate.qml @@ -0,0 +1,61 @@ +// Copyright (C) 2023 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.Templates as T +import QtQuick.Controls +import QtQuick.Controls.impl +import QtQuick.NativeStyle as NativeStyle + +T.CheckDelegate { + id: control + + readonly property bool __nativeIndicator: indicator instanceof NativeStyle.StyleItem + readonly property bool __notCustomizable: true + readonly property Item __focusFrameTarget: indicator + readonly property Item __focusFrameStyleItem: indicator + + implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, + implicitContentWidth + leftPadding + rightPadding) + implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, + implicitContentHeight + topPadding + bottomPadding, + implicitIndicatorHeight + topPadding + bottomPadding) + + spacing: 6 + padding: 6 + + contentItem: IconLabel { + text: control.text + font: control.font + icon: control.icon + color: control.palette.windowText + spacing: control.spacing + mirrored: control.mirrored + display: control.display + alignment: control.display === IconLabel.IconOnly || control.display === IconLabel.TextUnderIcon ? Qt.AlignCenter : Qt.AlignLeft + leftPadding: control.mirrored ? control.indicator.width + control.spacing : 0 + rightPadding: !control.mirrored ? control.indicator.width + control.spacing : 0 + + readonly property bool __ignoreNotCustomizable: true + } + + indicator: NativeStyle.CheckDelegate { + x: control.text ? (control.mirrored ? control.leftPadding : control.width - width - control.rightPadding) : control.leftPadding + (control.availableWidth - width) / 2 + y: control.topPadding + (control.availableHeight - height) / 2 + contentWidth: control.implicitContentWidth + contentHeight: control.implicitContentHeight + useNinePatchImage: false + control: control + + readonly property bool __ignoreNotCustomizable: true + } + + background: Rectangle { + implicitWidth: 100 + implicitHeight: 20 + color: Qt.darker(control.highlighted + ? control.palette.highlight : control.palette.button, control.down ? 1.05 : 1) + + readonly property bool __ignoreNotCustomizable: true + } +} diff --git a/src/quicknativestyle/CMakeLists.txt b/src/quicknativestyle/CMakeLists.txt index 50a29abf35..321af84760 100644 --- a/src/quicknativestyle/CMakeLists.txt +++ b/src/quicknativestyle/CMakeLists.txt @@ -48,6 +48,7 @@ qt_internal_add_qml_module(qtquickcontrols2nativestyleplugin items/qquickstyleitembutton.cpp items/qquickstyleitembutton.h items/qquickstyleitemcheckbox.cpp items/qquickstyleitemcheckbox.h items/qquickstyleitemdelaybutton.cpp items/qquickstyleitemdelaybutton.h + items/qquickstyleitemcheckdelegate.cpp items/qquickstyleitemcheckdelegate.h items/qquickstyleitemdial.cpp items/qquickstyleitemdial.h items/qquickstyleitemframe.cpp items/qquickstyleitemframe.h items/qquickstyleitemgroupbox.cpp items/qquickstyleitemgroupbox.h diff --git a/src/quicknativestyle/items/qquickstyleitemcheckbox.h b/src/quicknativestyle/items/qquickstyleitemcheckbox.h index 92cda579ef..f50c621d12 100644 --- a/src/quicknativestyle/items/qquickstyleitemcheckbox.h +++ b/src/quicknativestyle/items/qquickstyleitemcheckbox.h @@ -23,7 +23,7 @@ protected: StyleItemGeometry calculateGeometry() override; private: - void initStyleOption(QStyleOptionButton &styleOption) const; + virtual void initStyleOption(QStyleOptionButton &styleOption) const; }; QT_END_NAMESPACE diff --git a/src/quicknativestyle/items/qquickstyleitemcheckdelegate.cpp b/src/quicknativestyle/items/qquickstyleitemcheckdelegate.cpp new file mode 100644 index 0000000000..22576c50d2 --- /dev/null +++ b/src/quicknativestyle/items/qquickstyleitemcheckdelegate.cpp @@ -0,0 +1,32 @@ +// Copyright (C) 2023 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 "qquickstyleitemcheckdelegate.h" + +#include <QtQuickTemplates2/private/qquickcheckdelegate_p.h> + +QT_BEGIN_NAMESPACE + +void QQuickStyleItemCheckDelegate::connectToControl() const +{ + QQuickStyleItem::connectToControl(); + auto checkDelegate = control<QQuickCheckDelegate>(); + connect(checkDelegate, &QQuickCheckDelegate::downChanged, this, &QQuickStyleItem::markImageDirty); + connect(checkDelegate, &QQuickCheckDelegate::checkStateChanged, this, &QQuickStyleItem::markImageDirty); +} + +void QQuickStyleItemCheckDelegate::initStyleOption(QStyleOptionButton &styleOption) const +{ + initStyleOptionBase(styleOption); + auto checkDelegate = control<QQuickCheckDelegate>(); + + styleOption.state |= checkDelegate->isDown() ? QStyle::State_Sunken : QStyle::State_Raised; + if (checkDelegate->isTristate() && checkDelegate->checkState() == Qt::PartiallyChecked) + styleOption.state |= QStyle::State_NoChange; + else + styleOption.state |= checkDelegate->isChecked() ? QStyle::State_On : QStyle::State_Off; +} + +QT_END_NAMESPACE + +#include "moc_qquickstyleitemcheckdelegate.cpp" diff --git a/src/quicknativestyle/items/qquickstyleitemcheckdelegate.h b/src/quicknativestyle/items/qquickstyleitemcheckdelegate.h new file mode 100644 index 0000000000..27ff42de25 --- /dev/null +++ b/src/quicknativestyle/items/qquickstyleitemcheckdelegate.h @@ -0,0 +1,25 @@ +// Copyright (C) 2023 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 QQUICKSTYLEITEMCHECKDELEGATE_H +#define QQUICKSTYLEITEMCHECKDELEGATE_H + +#include "qquickstyleitemcheckbox.h" + +QT_BEGIN_NAMESPACE + +class QQuickStyleItemCheckDelegate : public QQuickStyleItemCheckBox +{ + Q_OBJECT + QML_NAMED_ELEMENT(CheckDelegate) + +protected: + void connectToControl() const override; + +private: + void initStyleOption(QStyleOptionButton &styleOption) const override; +}; + +QT_END_NAMESPACE + +#endif // QQUICKSTYLEITEMCHECKDELEGATE_H diff --git a/tests/auto/quickcontrols/customization/tst_customization.cpp b/tests/auto/quickcontrols/customization/tst_customization.cpp index b80dc7229e..24dea69fff 100644 --- a/tests/auto/quickcontrols/customization/tst_customization.cpp +++ b/tests/auto/quickcontrols/customization/tst_customization.cpp @@ -365,9 +365,9 @@ void tst_customization::override_data() { "macOS", { - "Button", "CheckBox", "ComboBox", "DelayButton", "Dial", "Frame", "GroupBox", - "ProgressBar", "RadioButton", "SelectionRectangle", "RangeSlider", "Slider", - "SpinBox", "TextArea", "TextField", "TreeViewDelegate" + "Button", "CheckBox", "CheckDelegate", "ComboBox", "DelayButton", "Dial", "Frame", + "GroupBox", "ProgressBar", "RadioButton", "SelectionRectangle", "RangeSlider", + "Slider", "SpinBox", "TextArea", "TextField", "TreeViewDelegate" // TODO: ScrollView, ScrollBar } }, diff --git a/tests/manual/quickcontrols/testbench/controls/CheckDelegate.qml b/tests/manual/quickcontrols/testbench/controls/CheckDelegate.qml index d64339501f..1353ce4cf8 100644 --- a/tests/manual/quickcontrols/testbench/controls/CheckDelegate.qml +++ b/tests/manual/quickcontrols/testbench/controls/CheckDelegate.qml @@ -15,6 +15,9 @@ QtObject { ["partially-checked"], ["partially-checked", "disabled"], ["partially-checked", "pressed"], + ["highlighted"], + ["highlighted", "pressed"], + ["mirrored"] ] property Component component: CheckDelegate { @@ -23,7 +26,10 @@ QtObject { checkState: is("checked") ? Qt.Checked : is("partially-checked") ? Qt.PartiallyChecked : Qt.Unchecked // Only set it if it's pressed, or the non-pressed examples will have no press effects down: is("pressed") ? true : undefined + highlighted: is("highlighted") focusPolicy: Qt.StrongFocus + + LayoutMirroring.enabled: is("mirrored") } property Component exampleComponent: ListView { |