From cc64460a80eb00c1d60d00fb6a8f25050570f270 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Mon, 9 Sep 2024 09:54:23 +0200 Subject: [PATCH] QskProgressRingSkinlet::contentsSizeHint with constraints --- examples/iotdashboard/Skin.cpp | 29 ++++++++++++++----------- src/controls/QskProgressRing.cpp | 1 - src/controls/QskProgressRingSkinlet.cpp | 17 +++++++++++++-- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/examples/iotdashboard/Skin.cpp b/examples/iotdashboard/Skin.cpp index 72abc78c..697a0b3b 100644 --- a/examples/iotdashboard/Skin.cpp +++ b/examples/iotdashboard/Skin.cpp @@ -84,9 +84,9 @@ void Skin::initHints() ed.setPadding( MainContentGridBox::Panel, { 19, 0, 27, 24 } ); - // menu bar: - { + // menu bar: + using Q = QskPushButton; using A = QskAspect; @@ -110,24 +110,27 @@ void Skin::initHints() ed.setAlignment( Q::Icon | A::Header, Qt::AlignCenter ); } - // top bar: - ed.setPadding( TopBar::Panel, { 25, 35, 25, 0 } ); + { + // top bar: - ed.setColor( TopBarItem::Item1 | QskAspect::TextColor, 0xffff3122 ); - ed.setColor( TopBarItem::Item2 | QskAspect::TextColor, 0xff6776ff ); - ed.setColor( TopBarItem::Item3 | QskAspect::TextColor, 0xfff99055 ); - ed.setColor( TopBarItem::Item4 | QskAspect::TextColor, 0xff6776ff ); + ed.setPadding( TopBar::Panel, { 25, 35, 25, 0 } ); - ed.setGradient( TopBarItem::Item1, 0xffff5c00, 0xffff3122 ); - ed.setGradient( TopBarItem::Item2, 0xff6776ff, 0xff6100ff ); - ed.setGradient( TopBarItem::Item3, 0xffffce50, 0xffff3122 ); - ed.setGradient( TopBarItem::Item4, 0xff6776ff, 0xff6100ff ); + ed.setColor( TopBarItem::Item1 | QskAspect::TextColor, 0xffff3122 ); + ed.setColor( TopBarItem::Item2 | QskAspect::TextColor, 0xff6776ff ); + ed.setColor( TopBarItem::Item3 | QskAspect::TextColor, 0xfff99055 ); + ed.setColor( TopBarItem::Item4 | QskAspect::TextColor, 0xff6776ff ); + + ed.setGradient( TopBarItem::Item1, 0xffff5c00, 0xffff3122 ); + ed.setGradient( TopBarItem::Item2, 0xff6776ff, 0xff6100ff ); + ed.setGradient( TopBarItem::Item3, 0xffffce50, 0xffff3122 ); + ed.setGradient( TopBarItem::Item4, 0xff6776ff, 0xff6100ff ); + } // the bar gradient is defined through the top bar items above ed.setArcMetrics( QskProgressRing::Groove, 90, -360, 8.53 ); // the span angle will be set in the progress bar, we just give a dummy // value here: - ed.setArcMetrics( QskProgressRing::Fill, 90, -360, 8.53 ); + ed.setArcMetrics( QskProgressRing::Fill, ed.arcMetrics( QskProgressRing::Groove ) ); ed.setFontRole( TimeTitleLabel::Text, { QskFontRole::Caption, QskFontRole::High } ); diff --git a/src/controls/QskProgressRing.cpp b/src/controls/QskProgressRing.cpp index a87cb707..af6c414b 100644 --- a/src/controls/QskProgressRing.cpp +++ b/src/controls/QskProgressRing.cpp @@ -4,7 +4,6 @@ *****************************************************************************/ #include "QskProgressRing.h" - #include "QskIntervalF.h" QSK_SUBCONTROL( QskProgressRing, Groove ) diff --git a/src/controls/QskProgressRingSkinlet.cpp b/src/controls/QskProgressRingSkinlet.cpp index 04f8e427..167cb861 100644 --- a/src/controls/QskProgressRingSkinlet.cpp +++ b/src/controls/QskProgressRingSkinlet.cpp @@ -74,12 +74,25 @@ QSGNode* QskProgressRingSkinlet::updateFillNode( } QSizeF QskProgressRingSkinlet::sizeHint( const QskSkinnable* skinnable, - Qt::SizeHint which, const QSizeF& ) const + Qt::SizeHint which, const QSizeF& constraint ) const { if ( which != Qt::PreferredSize ) return QSizeF(); - return skinnable->strutSizeHint( Q::Fill ); + auto hint = skinnable->strutSizeHint( Q::Fill ); + hint = hint.expandedTo( skinnable->strutSizeHint( Q::Groove ) ); + + if ( !constraint.isEmpty() ) + { + const qreal aspectRatio = hint.isEmpty() ? 1.0 : hint.width() / hint.height(); + + if ( constraint.width() >= 0.0 ) + hint.setHeight( constraint.width() / aspectRatio ); + else + hint.setWidth( constraint.height() * aspectRatio ); + } + + return hint; } QskIntervalF QskProgressRingSkinlet::fillInterval(