Skip to content

Commit

Permalink
chore: scrollerbar tweak
Browse files Browse the repository at this point in the history
按设计要求,滚动条需要内外边界,且深色模式的颜色是带透明度的黑
Task: https://pms.uniontech.com/task-view-331783.html
  • Loading branch information
kegechen committed Mar 20, 2024
1 parent 6e1c14b commit dd2b769
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions styleplugins/chameleon/chameleonstyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,41 +864,50 @@ void ChameleonStyle::drawControl(QStyle::ControlElement element, const QStyleOpt
scrollBarRectCenter.setX((scrollBar->rect.x() + scrollBar->rect.width()) / 2);
scrollBarRectCenter.setY(scrollBar->rect.y() + scrollBar->rect.height() / 2);
rect.moveCenter(scrollBarRectCenter);
rect.moveRight(scrollBar->rect.right() - 2);
rect.moveRight(scrollBar->rect.right() - 1);
}

QColor lineColor(opt->palette.color(QPalette::Base));
if (DGuiApplicationHelper::toColorType(lineColor) == DGuiApplicationHelper::LightType) {
// 外侧拓展一个像素的outside border
p->setPen(QPen(QColor(255, 255, 255, 0.1 * 255), Metrics::Painter_PenWidth));
p->setBrush(Qt::NoBrush);
p->drawRoundedRect(rect.adjusted(-1, -1, 1, 1),
realRadius, realRadius);
// 内侧绘制一个像素的inside border
p->setPen(QPen(QColor(0, 0, 0, 0.05 * 255), Metrics::Painter_PenWidth));
p->setPen(QPen(QColor(0, 0, 0, 0.1 * 255), Metrics::Painter_PenWidth));
p->drawRoundedRect(rect.adjusted(1, 1, -1, -1),
realRadius, realRadius);
// normal状态
p->setBrush(QColor(0, 0, 0, 0.3 * 255));
p->setBrush(QColor(0, 0, 0, 0.5 * 255));

if (scrollBar->state & QStyle::State_MouseOver)
// hover 状态
p->setBrush(QColor(0, 0, 0, 0.6 * 255));
p->setBrush(QColor(0, 0, 0, 0.7 * 255));
if (scrollBar->state & QStyle::State_Sunken)
// active状态
p->setBrush(QColor(0, 0, 0, 0.5 * 255));
p->setBrush(QColor(0, 0, 0, 0.6 * 255));
} else {
// 外侧拓展一个像素的outside border
p->setPen(QPen(QColor(0, 0, 0, 0.2 * 255), Metrics::Painter_PenWidth));
p->setPen(QPen(QColor(0, 0, 0, 0.1 * 255), Metrics::Painter_PenWidth));
p->setBrush(Qt::NoBrush);
p->drawRoundedRect(rect.adjusted(-1, -1, 1, 1),
realRadius, realRadius);
// 内侧绘制一个像素的inside border
p->setPen(QPen(QColor(255, 255, 255, 0.05 * 255), Metrics::Painter_PenWidth));
p->setPen(QPen(QColor(255, 255, 255, 0.1 * 255), Metrics::Painter_PenWidth));
p->drawRoundedRect(rect.adjusted(1, 1, -1, -1),
realRadius, realRadius);
// normal状态
p->setBrush(QColor(96, 96, 96, 0.7 * 255));
p->setBrush(QColor(255, 255, 255, 0.2 * 255));

if (scrollBar->state & QStyle::State_MouseOver)
// hover 状态
p->setBrush(QColor(96, 96, 96, 0.8 * 255));
p->setBrush(QColor(255, 255, 255, 0.5 * 255));
if (scrollBar->state & QStyle::State_Sunken)
// active状态
p->setBrush(QColor(112, 112, 112, 0.8 * 255));
p->setBrush(QColor(255, 255, 255, 0.4 * 255));
}

p->setPen(Qt::NoPen);
p->drawRoundedRect(rect, realRadius, realRadius);
p->restore();
}
Expand Down

0 comments on commit dd2b769

Please sign in to comment.