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 "qquickstyleitemgroupbox.h"
5
6QT_BEGIN_NAMESPACE
7
8QFont QQuickStyleItemGroupBox::styleFont(QQuickItem *control) const
9{
10 return style()->font(element: QStyle::CE_HeaderLabel, state: controlSize(item: control));
11}
12
13StyleItemGeometry QQuickStyleItemGroupBox::calculateGeometry()
14{
15 QStyleOptionGroupBox styleOption;
16 initStyleOption(styleOption);
17
18 StyleItemGeometry geometry;
19 geometry.minimumSize = style()->sizeFromContents(ct: QStyle::CT_GroupBox, opt: &styleOption, contentsSize: QSize(0, 0));
20
21 if (!control<QQuickGroupBox>()->title().isEmpty()) {
22 // We don't draw the title, but we need to take
23 // it into calculation for the control size
24 styleOption.text = QStringLiteral(" ");
25 styleOption.subControls |= QStyle::SC_GroupBoxLabel;
26 }
27
28 geometry.implicitSize = style()->sizeFromContents(ct: QStyle::CT_GroupBox, opt: &styleOption, contentsSize: contentSize());
29 styleOption.rect.setSize(geometry.implicitSize);
30 geometry.contentRect = style()->subControlRect(cc: QStyle::CC_GroupBox, opt: &styleOption, sc: QStyle::SC_GroupBoxContents);
31 geometry.layoutRect = style()->subElementRect(subElement: QStyle::SE_GroupBoxLayoutItem, option: &styleOption);
32 geometry.ninePatchMargins = style()->ninePatchMargins(cc: QStyle::CC_GroupBox, opt: &styleOption, imageSize: geometry.minimumSize);
33
34 const QQuickStyleMargins oldGroupBoxPadding = m_groupBoxPadding;
35 const QRect frame = style()->subControlRect(cc: QStyle::CC_GroupBox, opt: &styleOption, sc: QStyle::SC_GroupBoxFrame);
36 m_groupBoxPadding = QQuickStyleMargins(QRect(QPoint(), geometry.implicitSize), frame);
37 if (m_groupBoxPadding != oldGroupBoxPadding)
38 emit groupBoxPaddingChanged();
39
40 const QPointF oldLabelPos = m_labelPos;
41 m_labelPos = style()->subControlRect(cc: QStyle::CC_GroupBox, opt: &styleOption, sc: QStyle::SC_GroupBoxLabel).topLeft();
42 if (m_labelPos != oldLabelPos)
43 emit labelPosChanged();
44 return geometry;
45}
46
47void QQuickStyleItemGroupBox::paintEvent(QPainter *painter) const
48{
49 QStyleOptionGroupBox styleOption;
50 initStyleOption(styleOption);
51 style()->drawComplexControl(cc: QStyle::CC_GroupBox, opt: &styleOption, p: painter);
52}
53
54void QQuickStyleItemGroupBox::initStyleOption(QStyleOptionGroupBox &styleOption) const
55{
56 initStyleOptionBase(styleOption);
57 styleOption.subControls = QStyle::SC_GroupBoxFrame;
58 styleOption.lineWidth = 1;
59}
60
61QQuickStyleMargins QQuickStyleItemGroupBox::groupBoxPadding() const
62{
63 return m_groupBoxPadding;
64}
65
66QPointF QQuickStyleItemGroupBox::labelPos() const
67{
68 return m_labelPos;
69}
70
71QT_END_NAMESPACE
72
73#include "moc_qquickstyleitemgroupbox.cpp"
74

source code of qtdeclarative/src/quicknativestyle/items/qquickstyleitemgroupbox.cpp