macOS: add CheckDelegate
Task-number: QTBUG-115165 Change-Id: Ie873592d74dcda4828ba753391c64929402736f8 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
parent
bd3e1af6cd
commit
b520beaf51
|
@ -9,6 +9,7 @@ set(qml_files
|
|||
"BusyIndicator.qml"
|
||||
"Button.qml"
|
||||
"CheckBox.qml"
|
||||
"CheckDelegate.qml"
|
||||
"ComboBox.qml"
|
||||
"DelayButton.qml"
|
||||
"Dial.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
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -23,7 +23,7 @@ protected:
|
|||
StyleItemGeometry calculateGeometry() override;
|
||||
|
||||
private:
|
||||
void initStyleOption(QStyleOptionButton &styleOption) const;
|
||||
virtual void initStyleOption(QStyleOptionButton &styleOption) const;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
@ -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"
|
|
@ -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
|
|
@ -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
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue