1 | // Copyright (C) 2020 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qquickstyleitemradiobutton.h" |
5 | |
6 | QT_BEGIN_NAMESPACE |
7 | |
8 | QFont QQuickStyleItemRadioButton::styleFont(QQuickItem *control) const |
9 | { |
10 | return style()->font(element: QStyle::CE_RadioButtonLabel, state: controlSize(item: control)); |
11 | } |
12 | |
13 | void QQuickStyleItemRadioButton::connectToControl() const |
14 | { |
15 | QQuickStyleItem::connectToControl(); |
16 | auto checkbox = control<QQuickRadioButton>(); |
17 | connect(sender: checkbox, signal: &QQuickRadioButton::downChanged, context: this, slot: &QQuickStyleItem::markImageDirty); |
18 | connect(sender: checkbox, signal: &QQuickRadioButton::checkedChanged, context: this, slot: &QQuickStyleItem::markImageDirty); |
19 | } |
20 | |
21 | StyleItemGeometry QQuickStyleItemRadioButton::calculateGeometry() |
22 | { |
23 | QStyleOptionButton styleOption; |
24 | initStyleOption(styleOption); |
25 | StyleItemGeometry geometry; |
26 | |
27 | geometry.minimumSize = style()->sizeFromContents(ct: QStyle::CT_RadioButton, opt: &styleOption, contentsSize: QSize(0, 0)); |
28 | geometry.implicitSize = geometry.minimumSize; |
29 | styleOption.rect = QRect(QPoint(0, 0), geometry.implicitSize); |
30 | geometry.contentRect = style()->subElementRect(subElement: QStyle::SE_RadioButtonContents, option: &styleOption); |
31 | geometry.layoutRect = style()->subElementRect(subElement: QStyle::SE_RadioButtonLayoutItem, option: &styleOption); |
32 | geometry.ninePatchMargins = style()->ninePatchMargins(ce: QStyle::CE_RadioButton, opt: &styleOption, imageSize: geometry.minimumSize); |
33 | geometry.focusFrameRadius = style()->pixelMetric(metric: QStyle::PM_RadioButtonFocusFrameRadius, option: &styleOption); |
34 | |
35 | return geometry; |
36 | } |
37 | |
38 | void QQuickStyleItemRadioButton::paintEvent(QPainter *painter) const |
39 | { |
40 | QStyleOptionButton styleOption; |
41 | initStyleOption(styleOption); |
42 | style()->drawControl(element: QStyle::CE_RadioButton, opt: &styleOption, p: painter); |
43 | } |
44 | |
45 | void QQuickStyleItemRadioButton::initStyleOption(QStyleOptionButton &styleOption) const |
46 | { |
47 | initStyleOptionBase(styleOption); |
48 | auto checkbox = control<QQuickRadioButton>(); |
49 | |
50 | styleOption.state |= checkbox->isDown() ? QStyle::State_Sunken : QStyle::State_Raised; |
51 | styleOption.state |= checkbox->isChecked() ? QStyle::State_On : QStyle::State_Off; |
52 | } |
53 | |
54 | QT_END_NAMESPACE |
55 | |
56 | #include "moc_qquickstyleitemradiobutton.cpp" |
57 | |