diff --git a/styleplugins/chameleon/chameleonstyle.cpp b/styleplugins/chameleon/chameleonstyle.cpp index 497cc874..9719354c 100644 --- a/styleplugins/chameleon/chameleonstyle.cpp +++ b/styleplugins/chameleon/chameleonstyle.cpp @@ -41,6 +41,8 @@ #include #include #include +#include +#include #include #include #include @@ -1422,7 +1424,17 @@ void ChameleonStyle::drawControl(QStyle::ControlElement element, const QStyleOpt frameRadius = qMin(height / 2, 4); } 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(1); + p->setPen(pen); + p->setBrush(Qt::NoBrush); + p->drawRoundedRect(opt->rect.marginsRemoved(QMargins(1, 1, 1, 1)), frameRadius, frameRadius); } return; } @@ -1462,7 +1474,7 @@ 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; @@ -1470,7 +1482,25 @@ void ChameleonStyle::drawControl(QStyle::ControlElement element, const QStyleOpt 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(1); + 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 && @@ -1496,8 +1526,70 @@ void ChameleonStyle::drawControl(QStyle::ControlElement element, const QStyleOpt path2.arcTo(endRect, 90, -180); p->drawPath(path2); } - } else + } else { + QPainterPath clipPath; + clipPath.addRoundedRect(opt->rect, frameRadius, frameRadius); + 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(1); + p->setPen(pen); + p->setBrush(Qt::NoBrush); + p->setClipping(true); + p->drawRoundedRect(rect.marginsRemoved(QMargins(1, 1, 1, 1)), frameRadius, frameRadius); + p->setClipping(false); + } + } + + // 进度条光斑 + int spotWidth = 200; + if (rect.width() >= spotWidth) { + p->setPen(Qt::NoPen); + + QObject *progressbar = opt->styleObject; + if (!progressbar) + progressbar = dynamic_cast(p->device()); + + if (m_progressAni.isEmpty() || !m_progressAni.value(progressbar)) + return; + + QColor shadowColor(0, 0, 0, int(0.15 * 255)); + QColor spotColor(255, 255, 255, int(0.5 * 255)); + QColor highLightColor(getColor(opt, DPalette::Highlight)); + + QPointF pointStart(m_progressAni.value(progressbar)->currentValue().toRect().left(), m_progressAni.value(progressbar)->currentValue().toRect().center().y()); + QPointF pointEnd(m_progressAni.value(progressbar)->currentValue().toRect().right(), m_progressAni.value(progressbar)->currentValue().toRect().center().y()); + QLinearGradient linear(pointStart, pointEnd); + linear.setColorAt(0, highLightColor); + linear.setColorAt(0.35, shadowColor); + linear.setColorAt(0.5, spotColor); + linear.setColorAt(0.65, shadowColor); + linear.setColorAt(1, highLightColor); + linear.setSpread(QGradient::PadSpread); + linear.setInterpolationMode(QLinearGradient::InterpolationMode::ColorInterpolation); + p->setBrush(linear); + + QPainterPath clipPath; + clipPath.addRoundedRect(rect, frameRadius, frameRadius); + p->setClipping(true); + p->drawRect(m_progressAni.value(progressbar)->currentValue().toRect().marginsRemoved(QMargins(1, 1, 1, 1))); + p->setClipping(false); + + if (m_progressAni.value(progressbar)->state() == QVariantAnimation::Running) + return; + + QRect startRect(rect.x() - spotWidth, rect.y(), spotWidth, rect.height()); + m_progressAni.value(progressbar)->setStartValue(startRect); + QRect endRect = startRect; + endRect.moveRight(rect.width() + spotWidth); + m_progressAni.value(progressbar)->setEndValue(endRect); + m_progressAni.value(progressbar)->setDuration(2500); + m_progressAni.value(progressbar)->setEasingCurve(QEasingCurve::InQuad); + m_progressAni.value(progressbar)->start(); } } return; @@ -4357,6 +4449,17 @@ void ChameleonStyle::resetAttribute(QWidget *w, bool polish) scrollbar->setProperty("_d_dtk_scrollbar_visible", true); scrollbar->setAttribute(Qt::WA_OpaquePaintEvent, !polish); } + + if (auto progressBar = qobject_cast(w)) { + m_progressAni.insert(progressBar, new QVariantAnimation(progressBar)); + connect(m_progressAni.value(progressBar), &QVariantAnimation::valueChanged, progressBar, [progressBar](){ + progressBar->update(); + }); + + connect(progressBar, &QObject::destroyed, this, [this]() { + m_progressAni.clear(); + }); + } } static void updateWeekendTextFormat(QCalendarWidget *calendar, QColor) diff --git a/styleplugins/chameleon/chameleonstyle.h b/styleplugins/chameleon/chameleonstyle.h index 67d576f3..45d3f972 100644 --- a/styleplugins/chameleon/chameleonstyle.h +++ b/styleplugins/chameleon/chameleonstyle.h @@ -124,6 +124,7 @@ class ChameleonStyle : public DStyle private: mutable QHash animations; + mutable QHash m_progressAni; }; } // namespace chameleon