QWindowStyle: misc cleanup

Misc cleanup in QWindowsStyle:
 - use range-base for loop
 - use std::array instead raw c-array
 - use std::swap instead custom implementation

Change-Id: I479c014d4e19556e1c0a6ce3fbb8ddacd4e179ae
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
This commit is contained in:
Christian Ehrlicher 2023-11-01 10:24:48 +01:00
parent acdef6669f
commit fea9109b3b

View File

@ -117,19 +117,20 @@ bool QWindowsStyle::eventFilter(QObject *o, QEvent *e)
widget = widget->window(); widget = widget->window();
// Alt has been pressed - find all widgets that care // Alt has been pressed - find all widgets that care
QList<QWidget *> l = widget->findChildren<QWidget *>(); const QList<QWidget *> children = widget->findChildren<QWidget *>();
auto ignorable = [](QWidget *w) { auto ignorable = [](QWidget *w) {
return w->isWindow() || !w->isVisible() return w->isWindow() || !w->isVisible()
|| w->style()->styleHint(SH_UnderlineShortcut, nullptr, w); || w->style()->styleHint(SH_UnderlineShortcut, nullptr, w);
}; };
l.removeIf(ignorable);
// Update states before repainting // Update states before repainting
d->seenAlt.append(widget); d->seenAlt.append(widget);
d->alt_down = true; d->alt_down = true;
// Repaint all relevant widgets // Repaint all relevant widgets
for (int pos = 0; pos < l.size(); ++pos) for (QWidget *w : children) {
l.at(pos)->update(); if (!ignorable(w))
w->update();
}
} }
break; break;
case QEvent::KeyRelease: case QEvent::KeyRelease:
@ -139,9 +140,9 @@ bool QWindowsStyle::eventFilter(QObject *o, QEvent *e)
// Update state and repaint the menu bars. // Update state and repaint the menu bars.
d->alt_down = false; d->alt_down = false;
#if QT_CONFIG(menubar) #if QT_CONFIG(menubar)
QList<QMenuBar *> l = widget->findChildren<QMenuBar *>(); const QList<QMenuBar *> menuBars = widget->findChildren<QMenuBar *>();
for (int i = 0; i < l.size(); ++i) for (QWidget *w : menuBars)
l.at(i)->update(); w->update();
#endif #endif
} }
break; break;
@ -808,7 +809,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt,
} }
#endif // QT_CONFIG(itemviews) #endif // QT_CONFIG(itemviews)
if (!(opt->state & State_Off)) { if (!(opt->state & State_Off)) {
QPointF points[6]; std::array<QPointF, 6> points;
qreal scaleh = opt->rect.width() / 12.0; qreal scaleh = opt->rect.width() / 12.0;
qreal scalev = opt->rect.height() / 12.0; qreal scalev = opt->rect.height() / 12.0;
points[0] = { opt->rect.x() + qreal(3.5) * scaleh, opt->rect.y() + qreal(5.5) * scalev }; points[0] = { opt->rect.x() + qreal(3.5) * scaleh, opt->rect.y() + qreal(5.5) * scalev };
@ -819,7 +820,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt,
points[5] = { points[4].x() - 4 * scaleh, points[4].y() + 4 * scalev }; points[5] = { points[4].x() - 4 * scaleh, points[4].y() + 4 * scalev };
p->setPen(QPen(opt->palette.text().color(), 0)); p->setPen(QPen(opt->palette.text().color(), 0));
p->setBrush(opt->palette.text().color()); p->setBrush(opt->palette.text().color());
p->drawPolygon(points, 6); p->drawPolygon(points.data(), static_cast<int>(points.size()));
} }
if (doRestore) if (doRestore)
p->restore(); p->restore();
@ -1571,11 +1572,8 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai
default: default:
break; break;
} }
if (opt->direction == Qt::RightToLeft){ //reverse layout changes the order of Beginning/end if (opt->direction == Qt::RightToLeft) //reverse layout changes the order of Beginning/end
bool tmp = paintLeftBorder; std::swap(paintLeftBorder, paintRightBorder);
paintRightBorder=paintLeftBorder;
paintLeftBorder=tmp;
}
break; break;
case Qt::RightToolBarArea : case Qt::RightToolBarArea :
switch (toolbar->positionOfLine){ switch (toolbar->positionOfLine){