Skip to content

Commit

Permalink
chore: 更新滚动条样式,适配动画
Browse files Browse the repository at this point in the history
更新滚动条样式,适配动画

Log:
  • Loading branch information
Whale107 committed Jul 23, 2024
1 parent d4ae010 commit c561d62
Showing 1 changed file with 50 additions and 3 deletions.
53 changes: 50 additions & 3 deletions styleplugins/chameleon/chameleonstyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1412,11 +1412,25 @@ void ChameleonStyle::drawControl(QStyle::ControlElement element, const QStyleOpt
}
case CE_ProgressBarGroove: { //滑槽显示
if (const QStyleOptionProgressBar *progBar = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
int height = progBar->orientation == Qt::Horizontal ? opt->rect.height() : opt->rect.width();
bool horizontal = progBar->state & State_Horizontal;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
horizontal |= progBar->orientation == Qt::Horizontal;
#endif
int height = horizontal ? opt->rect.height() : opt->rect.width();
int frameRadius = height / 2;

p->setBrush(getColor(opt, DPalette::ObviousBackground, w));
p->setPen(Qt::NoPen);
p->drawRoundedRect(opt->rect, frameRadius, frameRadius);

QPen pen;
pen.setColor(DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType
? QColor(255, 255, 255, 0.15 * 255)
: QColor(0, 0, 0, 0.15 * 255));
pen.setWidth(2);
p->setPen(pen);
p->setBrush(Qt::NoBrush);
p->drawRoundedRect(opt->rect.marginsRemoved(QMargins(1, 1, 1, 1)), frameRadius, frameRadius);
}
return;
}
Expand All @@ -1430,7 +1444,12 @@ void ChameleonStyle::drawControl(QStyle::ControlElement element, const QStyleOpt
int max = progBar->maximum;
int val = progBar->progress;
int drawWidth = 0;
int height = progBar->orientation == Qt::Horizontal ? rect.height() : rect.width();

bool horizontal = progBar->state & State_Horizontal;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
horizontal |= progBar->orientation == Qt::Horizontal;
#endif
int height = horizontal ? rect.height() : rect.width();
int frameRadius = height / 2;

if (horizontal) {
Expand All @@ -1449,15 +1468,33 @@ void ChameleonStyle::drawControl(QStyle::ControlElement element, const QStyleOpt
linear.setColorAt(0, startColor);
linear.setColorAt(1, endColor);
linear.setSpread(QGradient::PadSpread);
p->setBrush(QBrush(linear));
p->setBrush(startColor);

if (progBar->textVisible) {
QPainterPath pathRect;
pathRect.addRect(rect);
QPainterPath pathRoundRect;
pathRoundRect.addRoundedRect(opt->rect, frameRadius, frameRadius);
QPainterPath inter = pathRoundRect.intersected(pathRect);

QPainterPath clipPath;
clipPath.addRoundedRect(rect, frameRadius, frameRadius);
p->setClipPath(clipPath);
p->setClipping(true);
p->drawPath(inter);
p->setClipping(false);

QPen pen;
pen.setColor(DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType
? QColor(255, 255, 255, 0.3 * 255)
: QColor(0, 0, 0, 0.3 * 255));
pen.setWidth(2);
p->setPen(pen);
p->setBrush(Qt::NoBrush);
p->setClipping(true);
p->drawRoundedRect(rect.marginsRemoved(QMargins(1, 1, 1, 1)), frameRadius, frameRadius);
p->setClipping(false);

} else {
//进度条高度 <= 8px && 进度条宽度 <= 8px && value有效
if (rect.height() <= ProgressBar_MinimumStyleHeight &&
Expand Down Expand Up @@ -1489,6 +1526,16 @@ void ChameleonStyle::drawControl(QStyle::ControlElement element, const QStyleOpt
p->setClipPath(clipPath);
p->setClipping(true);
p->drawRoundedRect(rect, frameRadius, frameRadius);
p->setClipping(false);

QPen pen;
pen.setColor(QColor(0, 0, 0, 0.3 * 255));
pen.setWidth(2);
p->setPen(pen);
p->setBrush(Qt::NoBrush);
p->setClipping(true);
p->drawRoundedRect(rect.marginsRemoved(QMargins(1, 1, 1, 1)), frameRadius, frameRadius);
p->setClipping(false);
}
}
}
Expand Down

0 comments on commit c561d62

Please sign in to comment.