diff options
author | Dilek Akcay <[email protected]> | 2025-05-16 14:59:24 +0200 |
---|---|---|
committer | Dilek Akcay <[email protected]> | 2025-06-03 15:37:47 +0200 |
commit | e1f8afef69c4f706b1707d58cc164955d8dbf7c5 (patch) | |
tree | 868cac055ba0f4496e41d840aed8cebf67d0ea40 /src | |
parent | f7c43a352703260a6f4c481842678c68696d4ce3 (diff) |
Pick-to: 6.10
Change-Id: I156efd2922c3ad613943ad5fec4eea035b991a6e
Reviewed-by: Richard Moe Gustavsen <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/quickcontrols/macos/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/quickcontrols/macos/SearchField.qml | 65 | ||||
-rw-r--r-- | src/quicknativestyle/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/quicknativestyle/controls/DefaultSearchField.qml | 119 | ||||
-rw-r--r-- | src/quicknativestyle/items/qquickstyleitemsearchfield.cpp | 82 | ||||
-rw-r--r-- | src/quicknativestyle/items/qquickstyleitemsearchfield.h | 44 | ||||
-rw-r--r-- | src/quicknativestyle/qstyle/mac/qquickmacstyle_mac.mm | 159 | ||||
-rw-r--r-- | src/quicknativestyle/qstyle/mac/qquickmacstyle_mac_p_p.h | 1 | ||||
-rw-r--r-- | src/quicknativestyle/qstyle/qquickcommonstyle.cpp | 14 | ||||
-rw-r--r-- | src/quicknativestyle/qstyle/qquickstyle.h | 10 | ||||
-rw-r--r-- | src/quicknativestyle/qstyle/qquickstyleoption.cpp | 16 | ||||
-rw-r--r-- | src/quicknativestyle/qstyle/qquickstyleoption.h | 23 |
12 files changed, 535 insertions, 1 deletions
diff --git a/src/quickcontrols/macos/CMakeLists.txt b/src/quickcontrols/macos/CMakeLists.txt index 4c3ff540a4..1eea4bd646 100644 --- a/src/quickcontrols/macos/CMakeLists.txt +++ b/src/quickcontrols/macos/CMakeLists.txt @@ -32,6 +32,7 @@ set(qml_files "ScrollBar.qml" "ScrollIndicator.qml" "ScrollView.qml" + "SearchField.qml" "SelectionRectangle.qml" "Slider.qml" "SpinBox.qml" diff --git a/src/quickcontrols/macos/SearchField.qml b/src/quickcontrols/macos/SearchField.qml new file mode 100644 index 0000000000..251d48d7e0 --- /dev/null +++ b/src/quickcontrols/macos/SearchField.qml @@ -0,0 +1,65 @@ +// Copyright (C) 2025 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 + +pragma ComponentBehavior: Bound + +import QtQuick +import QtQuick.Templates as T +import QtQuick.NativeStyle as NativeStyle + +NativeStyle.DefaultSearchField { + id: control + + readonly property bool __nativeSearchIndicator: searchIndicator.indicator instanceof NativeStyle.SearchField + readonly property bool __nativeClearIndicator: clearIndicator.indicator instanceof NativeStyle.SearchField + readonly property Item __focusFrameTarget: control + + contentItem: T.TextField { + text: control.text + + color: control.palette.text + selectionColor: control.palette.highlight + selectedTextColor: control.palette.highlightedText + verticalAlignment: Text.AlignVCenter + + readonly property Item __focusFrameControl: control + readonly property bool __ignoreNotCustomizable: true + } + + NativeStyle.SearchField { + id: search + visible: control.__nativeSearchIndicator + control: control + subControl: NativeStyle.SearchField.Search + x: searchIndicator.indicator.x + y: searchIndicator.indicator.y + useNinePatchImage: false + } + + searchIndicator.indicator: Item { + y: control.topPadding + (control.availableHeight - height) / 2 + implicitWidth: search.width + implicitHeight: search.height + + readonly property bool __ignoreNotCustomizable: true + } + + NativeStyle.SearchField { + id: clear + visible: control.__nativeClearIndicator + control: control + subControl: NativeStyle.SearchField.Clear + x: clearIndicator.indicator.x + y: clearIndicator.indicator.y + useNinePatchImage: false + } + + clearIndicator.indicator: Item { + x: control.width - width - 5 + y: control.topPadding + (control.availableHeight - height) / 2 + implicitWidth: clear.width + implicitHeight: clear.height + + readonly property bool __ignoreNotCustomizable: true + } +} diff --git a/src/quicknativestyle/CMakeLists.txt b/src/quicknativestyle/CMakeLists.txt index 598baba146..37bf83c429 100644 --- a/src/quicknativestyle/CMakeLists.txt +++ b/src/quicknativestyle/CMakeLists.txt @@ -20,6 +20,7 @@ set(qml_files "controls/DefaultRadioButton.qml" "controls/DefaultRadioDelegate.qml" "controls/DefaultScrollBar.qml" + "controls/DefaultSearchField.qml" "controls/DefaultSlider.qml" "controls/DefaultSpinBox.qml" "controls/DefaultTextArea.qml" @@ -99,6 +100,7 @@ qt_internal_extend_target(qtquickcontrols2nativestyleplugin CONDITION QT_FEATURE qt_internal_extend_target(qtquickcontrols2nativestyleplugin CONDITION QT_FEATURE_qml_delegate_model SOURCES items/qquickstyleitemcombobox.cpp items/qquickstyleitemcombobox.h + items/qquickstyleitemsearchfield.cpp items/qquickstyleitemsearchfield.h ) qt_internal_extend_target(qtquickcontrols2nativestyleplugin CONDITION MACOS diff --git a/src/quicknativestyle/controls/DefaultSearchField.qml b/src/quicknativestyle/controls/DefaultSearchField.qml new file mode 100644 index 0000000000..9c826db6f3 --- /dev/null +++ b/src/quicknativestyle/controls/DefaultSearchField.qml @@ -0,0 +1,119 @@ +// Copyright (C) 2025 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 + +pragma ComponentBehavior: Bound + +import QtQuick +import QtQuick.Window +import QtQuick.Controls +import QtQuick.Controls.impl +import QtQuick.Templates as T +import QtQuick.NativeStyle as NativeStyle + +T.SearchField { + id: control + + readonly property bool __nativeBackground: background instanceof NativeStyle.StyleItem + readonly property bool __notCustomizable: true + + implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset, + implicitContentWidth + leftPadding + rightPadding, + 90 /* minimum */ ) + implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset, + implicitContentHeight + topPadding + bottomPadding, + searchIndicator.implicitIndicatorHeight + topPadding + bottomPadding, + clearIndicator.implicitIndicatorHeight + topPadding + bottomPadding) + + leftPadding: (__nativeBackground ? background.contentPadding.left : 5) + rightPadding: (__nativeBackground ? background.contentPadding.right : 5) + topPadding: (__nativeBackground ? background.contentPadding.top : 2) + bottomPadding: (__nativeBackground ? background.contentPadding.bottom : 2) + + delegate: ItemDelegate { + width: ListView.view.width + text: model[control.textRole] + palette.text: control.palette.text + palette.highlightedText: control.palette.highlightedText + font.weight: control.currentIndex === index ? Font.DemiBold : Font.Normal + highlighted: control.currentIndex === index + hoverEnabled: control.hoverEnabled + + required property var model + required property int index + } + + contentItem: T.TextField { + topPadding: 6 - control.padding + bottomPadding: 6 - control.padding + + text: control.text + + font: control.font + color: control.palette.text + selectionColor: control.palette.highlight + selectedTextColor: control.palette.highlightedText + verticalAlignment: Text.AlignVCenter + + readonly property bool __ignoreNotCustomizable: true + } + + searchIndicator.indicator: NativeStyle.SearchField { + control: control + subControl: NativeStyle.SearchField.Search + y: control.topPadding + (control.availableHeight - height) / 2 + useNinePatchImage: false + + readonly property bool __ignoreNotCustomizable: true + } + + clearIndicator.indicator: NativeStyle.SearchField { + control: control + subControl: NativeStyle.SearchField.Clear + x: control.width - width - 5 + y: control.topPadding + (control.availableHeight - height) / 2 + useNinePatchImage: false + + readonly property bool __ignoreNotCustomizable: true + } + + background: NativeStyle.SearchField { + control: control + subControl: NativeStyle.SearchField.Frame + contentWidth: contentItem.implicitWidth + contentHeight: contentItem.implicitHeight + + readonly property bool __ignoreNotCustomizable: true + } + + popup: T.Popup { + readonly property var layoutMargins: control.__nativeBackground ? control.background.layoutMargins : null + x: layoutMargins ? layoutMargins.left : 0 + y: control.height - (layoutMargins ? layoutMargins.bottom : 0) + width: control.width - (layoutMargins ? layoutMargins.left + layoutMargins.right : 0) + height: Math.min(contentItem.implicitHeight, control.Window.height - topMargin - bottomMargin) + topMargin: 6 + bottomMargin: 6 + + contentItem: ListView { + clip: true + implicitHeight: contentHeight + model: control.delegateModel + currentIndex: control.currentIndex + highlightMoveDuration: 0 + + Rectangle { + z: 10 + width: parent.width + height: parent.height + color: "transparent" + border.color: control.palette.mid + } + + T.ScrollIndicator.vertical: ScrollIndicator { } + } + + background: Rectangle { + color: control.palette.window + } + } +} diff --git a/src/quicknativestyle/items/qquickstyleitemsearchfield.cpp b/src/quicknativestyle/items/qquickstyleitemsearchfield.cpp new file mode 100644 index 0000000000..2530ffb06a --- /dev/null +++ b/src/quicknativestyle/items/qquickstyleitemsearchfield.cpp @@ -0,0 +1,82 @@ +// Copyright (C) 2025 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 "qquickstyleitemsearchfield.h" +#include <QtQuickTemplates2/private/qquickindicatorbutton_p.h> + +QT_BEGIN_NAMESPACE + +QFont QQuickStyleItemSearchField::styleFont(QQuickItem *control) const +{ + return style()->font(QStyle::CE_PushButtonLabel, controlSize(control)); +} + +void QQuickStyleItemSearchField::connectToControl() const +{ + QQuickStyleItem::connectToControl(); + auto searchField = control<QQuickSearchField>(); + connect(searchField->searchIndicator(), &QQuickIndicatorButton::pressedChanged, this, &QQuickStyleItem::markImageDirty); + connect(searchField->clearIndicator(), &QQuickIndicatorButton::pressedChanged, this, &QQuickStyleItem::markImageDirty); + connect(searchField, &QQuickSearchField::textChanged, this, &QQuickStyleItem::markImageDirty); + +} + +void QQuickStyleItemSearchField::paintEvent(QPainter *painter) const +{ + QStyleOptionSearchField styleOption; + initStyleOption(styleOption); + style()->drawComplexControl(QStyle::CC_SearchField, &styleOption, painter); +} + +StyleItemGeometry QQuickStyleItemSearchField::calculateGeometry() { + QStyleOptionSearchField styleOption; + initStyleOption(styleOption); + StyleItemGeometry geometry; + + geometry.minimumSize = style()->sizeFromContents(QStyle::CT_SearchField, &styleOption, QSize(0, 0)); + + if (styleOption.subControls == QStyle::SC_SearchFieldFrame) { + geometry.implicitSize = style()->sizeFromContents(QStyle::CT_SearchField, &styleOption, contentSize()); + styleOption.rect = QRect(QPoint(0, 0), geometry.implicitSize); + geometry.contentRect = style()->subControlRect(QStyle::CC_SearchField, &styleOption, QStyle::SC_SearchFieldEditField); + geometry.layoutRect = style()->subElementRect(QStyle::SE_SearchFieldLayoutItem, &styleOption); + geometry.ninePatchMargins = style()->ninePatchMargins(QStyle::CC_SearchField, &styleOption, geometry.minimumSize); + geometry.focusFrameRadius = style()->pixelMetric(QStyle::PM_SearchFieldFocusFrameRadius, &styleOption); + } else { + geometry.implicitSize = geometry.minimumSize; + } + + return geometry; +} + +void QQuickStyleItemSearchField::initStyleOption(QStyleOptionSearchField &styleOption) const { + initStyleOptionBase(styleOption); + auto searchField = control<QQuickSearchField>(); + + styleOption.text = searchField->text(); + + switch (m_subControl) { + case Frame: + styleOption.subControls = QStyle::SC_SearchFieldFrame; + styleOption.frame = true; + break; + case Search: + styleOption.subControls = QStyle::SC_SearchFieldSearch; + break; + case Clear: + styleOption.subControls = QStyle::SC_SearchFieldClear; + break; + } + + if (searchField->searchIndicator()->isPressed()) { + styleOption.activeSubControls = QStyle::SC_SearchFieldSearch; + styleOption.state |= QStyle::State_Sunken; + } else if (searchField->clearIndicator()->isPressed()) { + styleOption.activeSubControls = QStyle::SC_SearchFieldClear; + styleOption.state |= QStyle::State_Sunken; + } +} + +QT_END_NAMESPACE + +#include "moc_qquickstyleitemsearchfield.cpp" diff --git a/src/quicknativestyle/items/qquickstyleitemsearchfield.h b/src/quicknativestyle/items/qquickstyleitemsearchfield.h new file mode 100644 index 0000000000..894e255476 --- /dev/null +++ b/src/quicknativestyle/items/qquickstyleitemsearchfield.h @@ -0,0 +1,44 @@ +// Copyright (C) 2025 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 QQUICKSTYLEITEMSEARCHFIELD_H +#define QQUICKSTYLEITEMSEARCHFIELD_H + +#include "qquickstyleitem.h" +#include <QtQuickTemplates2/private/qquicksearchfield_p.h> + +QT_BEGIN_NAMESPACE + +class QQuickStyleItemSearchField : public QQuickStyleItem +{ + Q_OBJECT + + Q_PROPERTY(SubControl subControl MEMBER m_subControl) + + QML_NAMED_ELEMENT(SearchField) + +public: + enum SubControl { + Frame = 1, + Search, + Clear + }; + Q_ENUM(SubControl) + + QFont styleFont(QQuickItem *control) const override; + +protected: + void connectToControl() const override; + void paintEvent(QPainter *painter) const override; + StyleItemGeometry calculateGeometry() override; + +private: + void initStyleOption(QStyleOptionSearchField &styleOption) const; + +private: + SubControl m_subControl = Frame; +}; + +QT_END_NAMESPACE + +#endif // QQUICKSTYLEITEMSEARCHFIELD_H diff --git a/src/quicknativestyle/qstyle/mac/qquickmacstyle_mac.mm b/src/quicknativestyle/qstyle/mac/qquickmacstyle_mac.mm index ffac39c93a..4cc4a09e36 100644 --- a/src/quicknativestyle/qstyle/mac/qquickmacstyle_mac.mm +++ b/src/quicknativestyle/qstyle/mac/qquickmacstyle_mac.mm @@ -1412,6 +1412,9 @@ NSView *QMacStylePrivate::cocoaControl(CocoaControl cocoaControl) const [bv retain]; break; } + case SearchField: + bv = [[NSSearchField alloc] init]; + break; case ComboBox: bv = [[NSComboBox alloc] init]; break; @@ -1980,6 +1983,7 @@ int QMacStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt) const case PM_CheckBoxFocusFrameRadius: ret = LargeSmallMini(opt, 3, 2, 1); break; + case PM_SearchFieldFocusFrameRadius: case PM_ComboBoxFocusFrameRadius: ret = LargeSmallMini(opt, 5, 4, 1); break; @@ -4142,6 +4146,14 @@ QRect QMacStyle::subElementRect(SubElement sr, const QStyleOption *opt) const setLayoutItemMargins(-0, +0, -1, -0, &rect, opt->direction); } break; + case SE_SearchFieldLayoutItem: + if (qstyleoption_cast<const QStyleOptionSearchField *>(opt)) { + rect = LargeSmallMini(opt, + opt->rect.adjusted(4, 6, -4, -7), + opt->rect.adjusted(4, 7, -4, -7), + opt->rect.adjusted(3, 6, -3, -6)); + } + break; case SE_ComboBoxLayoutItem: if (const auto *combo = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) { //#ifndef QT_NO_TOOLBAR @@ -4753,6 +4765,36 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex } } break; + case CC_SearchField: + if (const auto *sf = qstyleoption_cast<const QStyleOptionSearchField *>(opt)) { + const bool isEnabled = sf->state & State_Enabled; + + const auto cs = d->effectiveAquaSizeConstrain(sf); + const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::SearchField, cs); + auto *searchField = static_cast<NSSearchField *>(d->cocoaControl(cw)); + auto *cell = static_cast<NSSearchFieldCell *>(searchField.cell); + + searchField.enabled = isEnabled; + + if (sf->subControls == QStyle::SC_SearchFieldSearch) { + // Draw only the search icon + CGRect rect = [cell searchButtonRectForBounds:searchField.bounds]; + [cell drawWithFrame:rect inView:searchField]; + } else if (sf->subControls == QStyle::SC_SearchFieldClear) { + // Draw only the clear icon + CGRect rect = [cell cancelButtonRectForBounds:searchField.bounds]; + [cell drawWithFrame:rect inView:searchField]; + } else { + // Draw the frame + QRectF frameRect = cw.adjustedControlFrame(sf->rect); + searchField.frame = frameRect.toCGRect(); + [cell setStringValue:sf->text.toNSString()]; + d->drawNSViewInRect(searchField, frameRect, p, ^(CGContextRef, const CGRect &r) { + [cell drawWithFrame:r inView:searchField]; + }); + } + } + break; case CC_TitleBar: if (const auto *titlebar = qstyleoption_cast<const QStyleOptionTitleBar *>(opt)) { const bool isActive = (titlebar->state & State_Active) @@ -5015,6 +5057,37 @@ QStyle::SubControl QMacStyle::hitTestComplexControl(ComplexControl cc, const QSt } } break; + case CC_SearchField: + if (const auto *sf = qstyleoption_cast<const QStyleOptionSearchField *>(opt)) { + if (!sf->rect.contains(pt)) + break; + + const auto cs = d->effectiveAquaSizeConstrain(sf); + const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::SearchField, cs); + auto *searchField = static_cast<NSSearchField *>(d->cocoaControl(cw)); + searchField.frame = cw.adjustedControlFrame(sf->rect).toCGRect(); + + auto *cell = static_cast<NSSearchFieldCell *>(searchField.cell); + const CGRect bounds = searchField.bounds; + + const QRectF cancelRect = QRectF::fromCGRect([cell cancelButtonRectForBounds:bounds]); + const QRectF searchIconRect = QRectF::fromCGRect([cell searchButtonRectForBounds:bounds]); + const QRectF textFieldRect = QRectF::fromCGRect([cell searchTextRectForBounds:bounds]); + + const QPointF localPt = pt - sf->rect.topLeft(); + + if (cancelRect.contains(localPt)) + sc = SC_SearchFieldClear; + else if (searchIconRect.contains(localPt)) + sc = SC_SearchFieldSearch; + else if (textFieldRect.contains(localPt)) + sc = SC_SearchFieldEditField; + else + sc = SC_SearchFieldPopup; + + break; + } + break; default: sc = QCommonStyle::hitTestComplexControl(cc, opt, pt); break; @@ -5359,6 +5432,54 @@ QRect QMacStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *op ret.adjust(-1, 0, 0, 0); } break; + case CC_SearchField: + if (const QStyleOptionSearchField *sf = qstyleoption_cast<const QStyleOptionSearchField *>(opt)) { + const auto cs = d->effectiveAquaSizeConstrain(sf); + const auto cw = QMacStylePrivate::CocoaControl(QMacStylePrivate::SearchField, cs); + + QRectF editRect; + switch (cs) { + case QStyleHelper::SizeLarge: + editRect = sf->rect.adjusted(16, 7, -22, -6); + break; + case QStyleHelper::SizeSmall: + editRect = sf->rect.adjusted(16, 5, -22, -7); + break; + default: + editRect = sf->rect.adjusted(16, 5, -18, -7); + break; + } + + auto *searchField = static_cast<NSSearchField *>(d->cocoaControl(cw)); + auto *cell = static_cast<NSSearchFieldCell *>(searchField.cell); + switch (sc) { + case SC_SearchFieldEditField:{ + ret = editRect.toAlignedRect(); + ret.setX(ret.x() + QMacStylePrivate::PushButtonContentPadding); + break; + } + case SC_SearchFieldClear: { + ret = QRectF::fromCGRect([cell cancelButtonRectForBounds:searchField.bounds]).toAlignedRect(); + break; + } + case SC_SearchFieldSearch: { + ret = QRectF::fromCGRect([cell searchButtonRectForBounds:searchField.bounds]).toAlignedRect(); + break; + } + case SC_SearchFieldPopup: { + const CGRect inner = QMacStylePrivate::comboboxInnerBounds(sf->rect.toCGRect(), cw); + const int searchTop = sf->rect.top(); + ret = QRect(qRound(inner.origin.x), + searchTop, + qRound(inner.origin.x - sf->rect.left() + inner.size.width), + editRect.bottom() - searchTop + 2); + break; + } + default: + break; + } + } + break; default: ret = QCommonStyle::subControlRect(cc, opt, sc); break; @@ -5655,6 +5776,44 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, cons return sz; } break; + case CT_SearchField: + if (const QStyleOptionSearchField *sf = qstyleoption_cast<const QStyleOptionSearchField *>(opt)) { + const QSize clearButton = proxy()->subControlRect(CC_SearchField, sf, SC_SearchFieldClear).size(); + const QSize searchButton = proxy()->subControlRect(CC_SearchField, sf, SC_SearchFieldSearch).size(); + if (sf->subControls == SC_SearchFieldFrame) { + const int controlSize = getControlSize(opt); + int padding; + int iconSpacing; + + if (controlSize == QStyleHelper::SizeLarge) { + padding = 6; + iconSpacing = 6; + sz.setHeight(32); + } else if (controlSize == QStyleHelper::SizeSmall) { + padding = 5; + iconSpacing = 5; + sz.setHeight(28); + } else { + padding = 4; + iconSpacing = 4; + sz.setHeight(22); + } + + // minimum width + if (sz.width() < 60) + sz.setWidth(60); + + const int totalIconsSize = clearButton.width() + searchButton.width() + (padding + iconSpacing) * 2; + sz.rwidth() += totalIconsSize; + + return sz; + } else if (sf->subControls == SC_SearchFieldClear) { + return clearButton; + } else if (sf->subControls == SC_SearchFieldSearch) { + return searchButton; + } + } + break; case CT_Menu: { if (proxy() == this) { sz = csz; diff --git a/src/quicknativestyle/qstyle/mac/qquickmacstyle_mac_p_p.h b/src/quicknativestyle/qstyle/mac/qquickmacstyle_mac_p_p.h index 4540351731..c2e90786f4 100644 --- a/src/quicknativestyle/qstyle/mac/qquickmacstyle_mac_p_p.h +++ b/src/quicknativestyle/qstyle/mac/qquickmacstyle_mac_p_p.h @@ -99,6 +99,7 @@ public: ProgressIndicator_Indeterminate, Scroller_Horizontal, Scroller_Vertical, + SearchField, SegmentedControl_First, // QTabBar buttons focus ring SegmentedControl_Middle, SegmentedControl_Last, diff --git a/src/quicknativestyle/qstyle/qquickcommonstyle.cpp b/src/quicknativestyle/qstyle/qquickcommonstyle.cpp index 01d0746be1..138f2022e5 100644 --- a/src/quicknativestyle/qstyle/qquickcommonstyle.cpp +++ b/src/quicknativestyle/qstyle/qquickcommonstyle.cpp @@ -3683,6 +3683,20 @@ QStyle::SubControl QCommonStyle::hitTestComplexControl(ComplexControl cc, const } } break; + case CC_SearchField: + if (const QStyleOptionSearchField *sf = qstyleoption_cast<const QStyleOptionSearchField *>(opt)) { + QRect r; + uint ctrl = SC_SearchFieldSearch; + while (ctrl <= SC_SearchFieldPopup) { + r = proxy()->subControlRect(cc, sf, QStyle::SubControl(ctrl)); + if (r.isValid() && r.contains(pt)) { + sc = QStyle::SubControl(ctrl); + break; + } + ctrl <<= 1; + } + } + break; case CC_GroupBox: if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(opt)) { QRect r; diff --git a/src/quicknativestyle/qstyle/qquickstyle.h b/src/quicknativestyle/qstyle/qquickstyle.h index 7175972f42..7689e50ee4 100644 --- a/src/quicknativestyle/qstyle/qquickstyle.h +++ b/src/quicknativestyle/qstyle/qquickstyle.h @@ -266,6 +266,7 @@ public: SE_ScrollBarLayoutItem, SE_SpinBoxLayoutItem, SE_ToolButtonLayoutItem, + SE_SearchFieldLayoutItem, SE_FrameLayoutItem, SE_GroupBoxLayoutItem, @@ -302,6 +303,7 @@ public: CC_Dial, CC_GroupBox, CC_MdiControls, + CC_SearchField, // do not add any values below/greater than this CC_CustomBase = 0xf0000000 @@ -330,6 +332,12 @@ public: SC_ComboBoxArrow = 0x00000004, SC_ComboBoxListBoxPopup = 0x00000008, + SC_SearchFieldSearch = 0x00000001, + SC_SearchFieldClear = 0x00000002, + SC_SearchFieldFrame = 0x00000004, + SC_SearchFieldEditField = 0x00000008, + SC_SearchFieldPopup = 0x00000010, + SC_SliderGroove = 0x00000001, SC_SliderHandle = 0x00000002, SC_SliderTickmarks = 0x00000004, @@ -496,6 +504,7 @@ public: PM_ComboBoxFocusFrameRadius, PM_DialFocusFrameRadius, PM_RadioButtonFocusFrameRadius, + PM_SearchFieldFocusFrameRadius, PM_SliderFocusFrameRadius, PM_SpinBoxFocusFrameRadius, PM_TextAreaFocusFrameRadius, @@ -525,6 +534,7 @@ public: CT_LineEdit, CT_SpinBox, CT_SizeGrip, + CT_SearchField, CT_TabWidget, CT_DialogButtons, CT_HeaderSection, diff --git a/src/quicknativestyle/qstyle/qquickstyleoption.cpp b/src/quicknativestyle/qstyle/qquickstyleoption.cpp index 83afa8e399..a021bb7631 100644 --- a/src/quicknativestyle/qstyle/qquickstyleoption.cpp +++ b/src/quicknativestyle/qstyle/qquickstyleoption.cpp @@ -343,6 +343,20 @@ QStyleOptionComboBox::QStyleOptionComboBox(int versionIn) } /*! + Creates a QStyleOptionSearchField, initializing the members variables + to their default values. +*/ +QStyleOptionSearchField::QStyleOptionSearchField() + : QStyleOptionComplex(Version, SO_SearchField), frame(true) +{ +} + +QStyleOptionSearchField::QStyleOptionSearchField(int versionIn) + : QStyleOptionComplex(versionIn, SO_SearchField), frame(true) +{ +} + +/*! Creates a QStyleOptionToolBox, initializing the members variables to their default values. */ @@ -570,6 +584,8 @@ QDebug operator<<(QDebug debug, const QStyleOption::OptionType &optionType) debug << "SO_RubberBand"; break; case QStyleOption::SO_Complex: debug << "SO_Complex"; break; + case QStyleOption::SO_SearchField: + debug << "SO_SearchField"; break; case QStyleOption::SO_Slider: debug << "SO_Slider"; break; case QStyleOption::SO_SpinBox: diff --git a/src/quicknativestyle/qstyle/qquickstyleoption.h b/src/quicknativestyle/qstyle/qquickstyleoption.h index ed430baaca..f5e325f677 100644 --- a/src/quicknativestyle/qstyle/qquickstyleoption.h +++ b/src/quicknativestyle/qstyle/qquickstyleoption.h @@ -34,7 +34,7 @@ public: SO_TabBarBase, SO_RubberBand, SO_ToolBar, SO_GraphicsItem, SO_Complex = 0xf0000, SO_Slider, SO_SpinBox, SO_ToolButton, SO_ComboBox, - SO_TitleBar, SO_GroupBox, SO_SizeGrip, + SO_TitleBar, SO_GroupBox, SO_SizeGrip, SO_SearchField, SO_CustomBase = 0xf00, SO_ComplexCustomBase = 0xf000000 @@ -600,6 +600,27 @@ protected: QStyleOptionComboBox(int version); }; + +class QStyleOptionSearchField : public QStyleOptionComplex +{ +public: + enum StyleOptionType { Type = SO_SearchField }; + enum StyleOptionVersion { Version = 1 }; + + QRect popupRect; + bool frame; + QString text; + QIcon currentIcon; + QSize iconSize; + + QStyleOptionSearchField(); + QStyleOptionSearchField(const QStyleOptionSearchField &other) : QStyleOptionComplex(Version, Type) { *this = other;} + QStyleOptionSearchField &operator=(const QStyleOptionSearchField &) = default; + +protected: + QStyleOptionSearchField(int version); +}; + class QStyleOptionTitleBar : public QStyleOptionComplex { public: |