From d56c99b3e76ecc14d489379b44add21bba5f65c8 Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Fri, 2 Jun 2023 15:14:13 +0200 Subject: [PATCH] windows style: Style progress bar ... and allow for the case where the bar is bigger than the groove. --- skins/windows/QskWindowsSkin.cpp | 10 ++++++++ src/controls/QskProgressBar.cpp | 4 +++- src/controls/QskProgressBarSkinlet.cpp | 32 ++++++++++++++++++-------- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/skins/windows/QskWindowsSkin.cpp b/skins/windows/QskWindowsSkin.cpp index a171fe79..73ead1f2 100644 --- a/skins/windows/QskWindowsSkin.cpp +++ b/skins/windows/QskWindowsSkin.cpp @@ -276,6 +276,16 @@ void Editor::setupPopup() void Editor::setupProgressBar() { + using Q = QskProgressBar; + using A = QskAspect; + + setMetric( Q::Groove | A::Size, 1 ); + setBoxShape( Q::Groove, 100, Qt::RelativeSize ); + setGradient( Q::Groove, theme.palette.strokeColor.controlStrongStroke.defaultColor ); + + setMetric( Q::Bar| A::Size, 3 ); + setBoxShape( Q::Bar, 100, Qt::RelativeSize ); + setGradient( Q::Bar, theme.palette.fillColor.accent.defaultColor ); } void Editor::setupPushButton() diff --git a/src/controls/QskProgressBar.cpp b/src/controls/QskProgressBar.cpp index d24dbc5b..7a496b2d 100644 --- a/src/controls/QskProgressBar.cpp +++ b/src/controls/QskProgressBar.cpp @@ -192,7 +192,9 @@ void QskProgressBar::resetExtent() qreal QskProgressBar::extent() const { - return metric( Groove | QskAspect::Size ); + auto grooveSize = metric( Groove | QskAspect::Size ); + auto barSize = metric( Bar | QskAspect::Size ); + return qMax( grooveSize, barSize ); } void QskProgressBar::setOrigin( qreal origin ) diff --git a/src/controls/QskProgressBarSkinlet.cpp b/src/controls/QskProgressBarSkinlet.cpp index 391a382f..91de022a 100644 --- a/src/controls/QskProgressBarSkinlet.cpp +++ b/src/controls/QskProgressBarSkinlet.cpp @@ -62,28 +62,29 @@ QRectF QskProgressBarSkinlet::subControlRect( const QskSkinnable* skinnable, const QRectF& contentsRect, QskAspect::Subcontrol subControl ) const { - const auto bar = static_cast< const QskProgressBar* >( skinnable ); + using Q = QskProgressBar; + const auto bar = static_cast< const Q* >( skinnable ); - if( subControl == QskProgressBar::Groove ) + if( subControl == Q::Groove ) { - const auto extent = bar->extent(); + const auto grooveSize = bar->metric( Q::Groove | QskAspect::Size ); auto rect = contentsRect; if ( bar->orientation() == Qt::Horizontal ) { - rect.setY( rect.y() + 0.5 * ( rect.height() - extent ) ); - rect.setHeight( extent ); + rect.setY( rect.y() + 0.5 * ( rect.height() - grooveSize ) ); + rect.setHeight( grooveSize ); } else { - rect.setX( rect.x() + 0.5 * ( rect.width() - extent ) ); - rect.setWidth( extent ); + rect.setX( rect.x() + 0.5 * ( rect.width() - grooveSize ) ); + rect.setWidth( grooveSize ); } return rect; } - if( subControl == QskProgressBar::Bar ) + if( subControl == Q::Bar ) { return barRect( bar ); } @@ -154,10 +155,23 @@ QSGNode* QskProgressBarSkinlet::updateBarNode( QRectF QskProgressBarSkinlet::barRect( const QskProgressBar* bar ) const { - const auto subControl = QskProgressBar::Groove; + using Q = QskProgressBar; + const auto subControl = Q::Groove; + const auto barSize = bar->metric( Q::Bar | QskAspect::Size ); auto rect = bar->subControlRect( subControl ); + if ( bar->orientation() == Qt::Horizontal ) + { + rect.setY( rect.y() + 0.5 * ( rect.height() - barSize ) ); + rect.setHeight( barSize ); + } + else + { + rect.setX( rect.x() + 0.5 * ( rect.width() - barSize ) ); + rect.setWidth( barSize ); + } + const auto borderMetrics = bar->boxBorderMetricsHint( subControl ); auto m = bar->paddingHint( subControl );