| 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 "qquickstyleitemcombobox.h" |
| 5 | |
| 6 | QT_BEGIN_NAMESPACE |
| 7 | |
| 8 | QFont QQuickStyleItemComboBox::styleFont(QQuickItem *control) const |
| 9 | { |
| 10 | return style()->font(element: QStyle::CE_PushButtonLabel, state: controlSize(item: control)); |
| 11 | } |
| 12 | |
| 13 | void QQuickStyleItemComboBox::connectToControl() const |
| 14 | { |
| 15 | QQuickStyleItem::connectToControl(); |
| 16 | auto comboBox = control<QQuickComboBox>(); |
| 17 | connect(sender: comboBox, signal: &QQuickComboBox::downChanged, context: this, slot: &QQuickStyleItem::markImageDirty); |
| 18 | } |
| 19 | |
| 20 | StyleItemGeometry QQuickStyleItemComboBox::calculateGeometry() |
| 21 | { |
| 22 | QStyleOptionComboBox styleOption; |
| 23 | initStyleOption(styleOption); |
| 24 | StyleItemGeometry geometry; |
| 25 | |
| 26 | geometry.minimumSize = style()->sizeFromContents(ct: QStyle::CT_ComboBox, opt: &styleOption, contentsSize: QSize(0, 0)); |
| 27 | geometry.implicitSize = style()->sizeFromContents(ct: QStyle::CT_ComboBox, opt: &styleOption, contentsSize: contentSize()); |
| 28 | styleOption.rect = QRect(QPoint(0, 0), geometry.implicitSize); |
| 29 | geometry.contentRect = style()->subControlRect(cc: QStyle::CC_ComboBox, opt: &styleOption, sc: QStyle::SC_ComboBoxEditField); |
| 30 | geometry.layoutRect = style()->subElementRect(subElement: QStyle::SE_ComboBoxLayoutItem, option: &styleOption); |
| 31 | geometry.ninePatchMargins = style()->ninePatchMargins(cc: QStyle::CC_ComboBox, opt: &styleOption, imageSize: geometry.minimumSize); |
| 32 | geometry.focusFrameRadius = style()->pixelMetric(metric: QStyle::PM_ComboBoxFocusFrameRadius, option: &styleOption); |
| 33 | |
| 34 | return geometry; |
| 35 | } |
| 36 | |
| 37 | void QQuickStyleItemComboBox::paintEvent(QPainter *painter) const |
| 38 | { |
| 39 | QStyleOptionComboBox styleOption; |
| 40 | initStyleOption(styleOption); |
| 41 | style()->drawComplexControl(cc: QStyle::CC_ComboBox, opt: &styleOption, p: painter); |
| 42 | } |
| 43 | |
| 44 | void QQuickStyleItemComboBox::initStyleOption(QStyleOptionComboBox &styleOption) const |
| 45 | { |
| 46 | initStyleOptionBase(styleOption); |
| 47 | auto comboBox = control<QQuickComboBox>(); |
| 48 | |
| 49 | styleOption.subControls = QStyle::SC_ComboBoxArrow | QStyle::SC_ComboBoxFrame | QStyle::SC_ComboBoxEditField; |
| 50 | styleOption.frame = true; |
| 51 | styleOption.state |= QStyle::State_Selected; |
| 52 | styleOption.editable = comboBox->isEditable(); |
| 53 | |
| 54 | if (comboBox->isDown()) |
| 55 | styleOption.state |= QStyle::State_Sunken; |
| 56 | if (!comboBox->isFlat() && !comboBox->isDown()) |
| 57 | styleOption.state |= QStyle::State_Raised; |
| 58 | } |
| 59 | |
| 60 | QT_END_NAMESPACE |
| 61 | |
| 62 | #include "moc_qquickstyleitemcombobox.cpp" |
| 63 | |