MCPcopy Create free account
hub / github.com/OpenOrienteering/mapper / drawPrimitive

Method drawPrimitive

src/gui/widgets/mapper_proxystyle.cpp:224–304  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

222
223
224void MapperProxyStyle::drawPrimitive(QStyle::PrimitiveElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget) const
225{
226 auto overridden_element = element;
227 switch (element)
228 {
229 case PE_IndicatorButtonDropDown:
230 overridden_element = PE_PanelButtonTool; // Enforce same appearance. Workaround QWindowsStyle quirk.
231 Q_FALLTHROUGH();
232 case PE_PanelButtonCommand:
233 case PE_PanelButtonBevel:
234 case PE_PanelButtonTool:
235 if (int segment = widget ? widget->property("segment").toInt() : 0)
236 {
237 drawSegmentedButton(segment, overridden_element, option, painter, widget);
238 return;
239 }
240 if (touch_mode
241 && element == PE_PanelButtonTool
242 && option
243 && option->state & State_On)
244 {
245 auto const& window_color = option->palette.window().color();
246 auto const fill = QBrush(qGray(window_color.rgb()) > 127 ? window_color.darker(125) : window_color.lighter(125));
247 painter->setPen(Qt::NoPen);
248 painter->setBrush(fill);
249 painter->drawRoundedRect(option->rect, 5.0, 5.0, Qt::AbsoluteSize);
250 return;
251 }
252 break;
253
254 case PE_IndicatorSpinUp:
255 case PE_IndicatorSpinDown:
256 overridden_element = element == PE_IndicatorSpinUp ? PE_IndicatorSpinPlus : PE_IndicatorSpinMinus;
257 Q_FALLTHROUGH();
258 case PE_IndicatorSpinPlus:
259 case PE_IndicatorSpinMinus:
260 if (touch_mode)
261 {
262 if (const QStyleOptionSpinBox* spinbox = qstyleoption_cast<const QStyleOptionSpinBox*>(option))
263 {
264 // Create a small centered square for QCommonStyle to draw '+'/'-'
265 auto copy = *spinbox;
266 auto const outer_size = qMax(copy.rect.width(), copy.rect.height());
267 auto const inner_size = qMin(3 * outer_size / 6, qMin(copy.rect.width(), copy.rect.height()));
268 auto const delta_x = (copy.rect.width() - inner_size) / 2;
269 auto const delta_y = (copy.rect.height() - inner_size) / 2;
270 copy.rect = {copy.rect.x() + delta_x, copy.rect.y() + delta_y, inner_size, inner_size };
271 QProxyStyle::drawPrimitive(overridden_element, &copy, painter, widget);
272 return;
273 }
274 }
275 break;
276
277#ifdef Q_OS_ANDROID
278 case QStyle::PE_IndicatorItemViewItemCheck:
279 if (option->state.testFlag(QStyle::State_NoChange)
280 || !option->state.testFlag(QStyle::State_Enabled))
281 {

Callers 1

makeCheckBoxDecoratorFunction · 0.80

Calls 11

colorMethod · 0.80
windowMethod · 0.80
xMethod · 0.80
yMethod · 0.80
testFlagMethod · 0.80
setOpacityMethod · 0.80
propertyMethod · 0.45
setPenMethod · 0.45
setBrushMethod · 0.45
widthMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected