Introduce scrollbars to QWindows11Style
Introduces Windows 11 styled scrollbars to QWindows11Style. Change-Id: I720f7d68f94c867a9fdd7142ea60fe46a8b7485c Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>bb10
parent
65d58e6c41
commit
2ec4da62b2
|
|
@ -56,9 +56,107 @@ QWindows11Style::QWindows11Style(QWindows11StylePrivate &dd) : QWindowsVistaStyl
|
|||
*/
|
||||
QWindows11Style::~QWindows11Style() = default;
|
||||
|
||||
/*!
|
||||
\internal
|
||||
see drawPrimitive for comments on the animation support
|
||||
|
||||
*/
|
||||
void QWindows11Style::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
|
||||
QPainter *painter, const QWidget *widget) const
|
||||
{
|
||||
State state = option->state;
|
||||
SubControls sub = option->subControls;
|
||||
State flags = option->state;
|
||||
if (widget && widget->testAttribute(Qt::WA_UnderMouse) && widget->isActiveWindow())
|
||||
flags |= State_MouseOver;
|
||||
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
switch (control) {
|
||||
case QStyle::CC_ScrollBar:
|
||||
if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
|
||||
QRectF rect = scrollbar->rect;
|
||||
QPointF center = rect.center();
|
||||
|
||||
if (scrollbar->orientation == Qt::Vertical && rect.width()>24)
|
||||
rect.marginsRemoved(QMargins(0,2,2,2));
|
||||
else if (scrollbar->orientation == Qt::Horizontal && rect.height()>24)
|
||||
rect.marginsRemoved(QMargins(2,0,2,2));
|
||||
|
||||
if (state & State_MouseOver) {
|
||||
if (scrollbar->orientation == Qt::Vertical && rect.width()>24)
|
||||
rect.setWidth(rect.width()/2);
|
||||
else if (scrollbar->orientation == Qt::Horizontal && rect.height()>24)
|
||||
rect.setHeight(rect.height()/2);
|
||||
rect.moveCenter(center);
|
||||
painter->setBrush(scrollbar->palette.base());
|
||||
painter->setPen(frameColorLight);
|
||||
painter->drawRoundedRect(rect, topLevelRoundingRadius, topLevelRoundingRadius);
|
||||
}
|
||||
if (sub & SC_ScrollBarSlider) {
|
||||
QRectF rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSlider, widget);
|
||||
QPointF center = rect.center();
|
||||
if (flags & State_MouseOver) {
|
||||
if (scrollbar->orientation == Qt::Vertical)
|
||||
rect.setWidth(rect.width()/2);
|
||||
else
|
||||
rect.setHeight(rect.height()/2);
|
||||
}
|
||||
else {
|
||||
if (scrollbar->orientation == Qt::Vertical)
|
||||
rect.setWidth(rect.width()/4);
|
||||
else
|
||||
rect.setHeight(rect.height()/4);
|
||||
|
||||
}
|
||||
rect.moveCenter(center);
|
||||
painter->setBrush(Qt::gray);
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->drawRoundedRect(rect, secondLevelRoundingRadius, secondLevelRoundingRadius);
|
||||
}
|
||||
if (sub & SC_ScrollBarAddLine) {
|
||||
QRectF rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarAddLine, widget);
|
||||
if (flags & State_MouseOver) {
|
||||
painter->setFont(QFont("Segoe Fluent Icons"));
|
||||
painter->setPen(Qt::gray);
|
||||
if (scrollbar->orientation == Qt::Vertical)
|
||||
painter->drawText(rect,"\uEDDC", Qt::AlignVCenter | Qt::AlignHCenter);
|
||||
else
|
||||
painter->drawText(rect,"\uEDDA", Qt::AlignVCenter | Qt::AlignHCenter);
|
||||
}
|
||||
}
|
||||
if (sub & SC_ScrollBarSubLine) {
|
||||
QRectF rect = proxy()->subControlRect(CC_ScrollBar, option, SC_ScrollBarSubLine, widget);
|
||||
if (flags & State_MouseOver) {
|
||||
painter->setPen(Qt::gray);
|
||||
if (scrollbar->orientation == Qt::Vertical)
|
||||
painter->drawText(rect,"\uEDDB", Qt::AlignVCenter | Qt::AlignHCenter);
|
||||
else
|
||||
painter->drawText(rect,"\uEDD9", Qt::AlignVCenter | Qt::AlignHCenter);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
QWindowsVistaStyle::drawComplexControl(control, option, painter, widget);
|
||||
}
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
void QWindows11Style::polish(QWidget* widget)
|
||||
{
|
||||
QWindowsVistaStyle::polish(widget);
|
||||
if (widget->inherits("QScrollBar")) {
|
||||
bool wasCreated = widget->testAttribute(Qt::WA_WState_Created);
|
||||
widget->setAttribute(Qt::WA_OpaquePaintEvent,false);
|
||||
widget->setAttribute(Qt::WA_TranslucentBackground);
|
||||
widget->setWindowFlag(Qt::FramelessWindowHint);
|
||||
widget->setWindowFlag(Qt::NoDropShadowWindowHint);
|
||||
widget->setAttribute(Qt::WA_WState_Created, wasCreated);
|
||||
auto pal = widget->palette();
|
||||
pal.setColor(widget->backgroundRole(), Qt::transparent);
|
||||
widget->setPalette(pal);
|
||||
}
|
||||
if (widget->inherits("QGraphicsView")) {
|
||||
QPalette pal = widget->palette();
|
||||
pal.setColor(QPalette::Base, pal.window().color());
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ public:
|
|||
QWindows11Style();
|
||||
~QWindows11Style() override;
|
||||
|
||||
void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
|
||||
QPainter *painter, const QWidget *widget) const override;
|
||||
void polish(QWidget* widget) override;
|
||||
protected:
|
||||
QWindows11Style(QWindows11StylePrivate &dd);
|
||||
|
|
|
|||
Loading…
Reference in New Issue