Changeset View
Changeset View
Standalone View
Standalone View
libs/ui/widgets/kis_color_filter_combo.cpp
Show All 16 Lines | |||||
17 | */ | 17 | */ | ||
18 | 18 | | |||
19 | #include "kis_color_filter_combo.h" | 19 | #include "kis_color_filter_combo.h" | ||
20 | 20 | | |||
21 | #include <klocalizedstring.h> | 21 | #include <klocalizedstring.h> | ||
22 | #include <QStylePainter> | 22 | #include <QStylePainter> | ||
23 | #include <QtCore/qmath.h> | 23 | #include <QtCore/qmath.h> | ||
24 | #include <QApplication> | 24 | #include <QApplication> | ||
25 | #include <QProxyStyle> | ||||
25 | #include <QStyleOption> | 26 | #include <QStyleOption> | ||
26 | #include <QSortFilterProxyModel> | 27 | #include <QSortFilterProxyModel> | ||
27 | #include <QStandardItemModel> | 28 | #include <QStandardItemModel> | ||
28 | #include <QListView> | 29 | #include <QListView> | ||
29 | #include <QMouseEvent> | 30 | #include <QMouseEvent> | ||
30 | 31 | | |||
31 | 32 | | |||
32 | 33 | | |||
▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Line(s) | |||||
154 | class FullSizedListView : public QListView | 155 | class FullSizedListView : public QListView | ||
155 | { | 156 | { | ||
156 | public: | 157 | public: | ||
157 | QSize sizeHint() const override { | 158 | QSize sizeHint() const override { | ||
158 | return contentsSize(); | 159 | return contentsSize(); | ||
159 | } | 160 | } | ||
160 | }; | 161 | }; | ||
161 | 162 | | |||
163 | class PopupComboBoxStyle : public QProxyStyle | ||||
164 | { | ||||
165 | public: | ||||
166 | PopupComboBoxStyle(QStyle *baseStyle = nullptr) : QProxyStyle(baseStyle) {} | ||||
167 | | ||||
168 | int styleHint(QStyle::StyleHint hint, const QStyleOption *option, const QWidget *widget, QStyleHintReturn *returnData) const override | ||||
169 | { | ||||
170 | // This flag makes ComboBox popup float ontop of its parent ComboBox, like in Fusion style. | ||||
171 | // Only when this hint is set will Qt respect combobox popup size hints, otherwise the popup | ||||
172 | // can never exceed the width of its parent ComboBox, like in Breeze style. | ||||
173 | if (hint == QStyle::SH_ComboBox_Popup) { | ||||
174 | return true; | ||||
rempt: This looks kind of weird? Returning a true for an int? | |||||
That's what Qt and everyone else does. There's also style hints for "wheel scroll lines" and flags it may return. broulik: That's what Qt and everyone else does. There's also style hints for "wheel scroll lines" and… | |||||
175 | } | ||||
176 | | ||||
177 | return QProxyStyle::styleHint(hint, option, widget, returnData); | ||||
178 | } | ||||
179 | }; | ||||
180 | | ||||
162 | struct KisColorFilterCombo::Private | 181 | struct KisColorFilterCombo::Private | ||
163 | { | 182 | { | ||
164 | LabelFilteringModel *filteringModel; | 183 | LabelFilteringModel *filteringModel; | ||
165 | }; | 184 | }; | ||
166 | 185 | | |||
167 | KisColorFilterCombo::KisColorFilterCombo(QWidget *parent) | 186 | KisColorFilterCombo::KisColorFilterCombo(QWidget *parent) | ||
168 | : QComboBox(parent), | 187 | : QComboBox(parent), | ||
169 | m_d(new Private) | 188 | m_d(new Private) | ||
170 | { | 189 | { | ||
171 | QStandardItemModel *newModel = new QStandardItemModel(this); | 190 | QStandardItemModel *newModel = new QStandardItemModel(this); | ||
172 | setModel(newModel); | 191 | setModel(newModel); | ||
173 | 192 | | |||
193 | PopupComboBoxStyle *proxyStyle = new PopupComboBoxStyle(style()); | ||||
194 | proxyStyle->setParent(this); | ||||
195 | setStyle(proxyStyle); | ||||
196 | | ||||
174 | setView(new FullSizedListView); | 197 | setView(new FullSizedListView); | ||
175 | m_eventFilters.append(new ComboEventFilter(this)); | 198 | m_eventFilters.append(new ComboEventFilter(this)); | ||
176 | m_eventFilters.append(new ComboEventFilter(this)); | 199 | m_eventFilters.append(new ComboEventFilter(this)); | ||
177 | 200 | | |||
178 | view()->installEventFilter(m_eventFilters[0]); | 201 | view()->installEventFilter(m_eventFilters[0]); | ||
179 | view()->viewport()->installEventFilter(m_eventFilters[1]); | 202 | view()->viewport()->installEventFilter(m_eventFilters[1]); | ||
180 | 203 | | |||
181 | KisNodeViewColorScheme scm; | 204 | KisNodeViewColorScheme scm; | ||
▲ Show 20 Lines • Show All 167 Lines • Show Last 20 Lines |
This looks kind of weird? Returning a true for an int?