diff --git a/examples/gallery/slider/CustomSlider.cpp b/examples/gallery/slider/CustomSlider.cpp index 9edd79b8..503e6b9b 100644 --- a/examples/gallery/slider/CustomSlider.cpp +++ b/examples/gallery/slider/CustomSlider.cpp @@ -24,7 +24,7 @@ CustomSlider::CustomSlider( QQuickItem* parentItem ) setGradientHint( Fill, Grey700 ); setColor( Scale, qRgb( 178, 178, 178 ) ); // for the ticks - setMetric( Handle | QskAspect::Size, 80 ); + setStrutSizeHint( Handle, 80, 80 ); setColor( Handle, Grey800 ); for ( auto state : { Pressed, Focused | Hovered, Hovered, Focused } ) diff --git a/examples/gallery/slider/CustomSliderSkinlet.cpp b/examples/gallery/slider/CustomSliderSkinlet.cpp index fbd0e355..fcf2df22 100644 --- a/examples/gallery/slider/CustomSliderSkinlet.cpp +++ b/examples/gallery/slider/CustomSliderSkinlet.cpp @@ -222,9 +222,13 @@ QRectF CustomSliderSkinlet::handleRect( handleRect.moveCenter( QPointF( fillRect.right(), handleRect.center().y() ) ); if ( handleRect.left() < contentsRect.left() ) + { handleRect.moveLeft( contentsRect.left() ); + } else if ( handleRect.right() > contentsRect.right() ) + { handleRect.moveRight( contentsRect.right() ); + } return handleRect; } @@ -327,21 +331,21 @@ QSGNode* CustomSliderSkinlet::updateDecorationNode( QSGNode* CustomSliderSkinlet::updateHandleNode( const QskSlider* slider, QSGNode* node ) const { - const QRectF handleRect = subControlRect( - slider, slider->contentsRect(), QskSlider::Handle ); + const auto cr = slider->contentsRect(); + + const auto handleRect = subControlRect( slider, cr, QskSlider::Handle ); if ( handleRect.isEmpty() ) return nullptr; - const QRectF fillRect = subControlRect( - slider, slider->contentsRect(), QskSlider::Fill ); + const auto fillRect = subControlRect( slider, cr, QskSlider::Fill ); auto handleNode = static_cast< HandleNode* >( node ); if ( handleNode == nullptr ) handleNode = new HandleNode(); - handleNode->update( handleRect, fillRect.right(), - slider->color( QskSlider::Handle ) ); + const auto handleColor = slider->color( QskSlider::Handle ); + handleNode->update( handleRect, fillRect.right(), handleColor ); // finally the value label auto labelNode = static_cast< QskTextNode* >( handleNode->firstChild() ); @@ -359,7 +363,7 @@ QSGNode* CustomSliderSkinlet::updateHandleNode( auto textRect = handleRect; textRect.setTop( textRect.bottom() - 0.5 * ( textRect.height() - qskPeak + h ) ); - const QString text = QString::number( slider->value(), 'f', 0 ); + const auto text = QString::number( slider->value(), 'f', 0 ); labelNode->setTextData( slider, text, textRect, font, QskTextOptions(), QskTextColors( Qt::white ), Qt::AlignHCenter, Qsk::Normal ); diff --git a/skins/material/QskMaterialSkin.cpp b/skins/material/QskMaterialSkin.cpp index b3b7ce15..e9164789 100644 --- a/skins/material/QskMaterialSkin.cpp +++ b/skins/material/QskMaterialSkin.cpp @@ -293,7 +293,8 @@ void QskMaterialSkin::initPageIndicatorHints() for ( auto subControl : { Q::Bullet, Q::Highlighted } ) { - setMetric( subControl | Size, qskDpiScaled( 10 ) ); + const auto extent = qskDpiScaled( 10 ); + setStrutSize( subControl, extent, extent ); // circles, without border setBoxShape( subControl, 100, Qt::RelativeSize ); @@ -441,17 +442,17 @@ void QskMaterialSkin::initSliderHints() const auto& pal = m_data->palette; - const qreal dim = 30; + const qreal extent = 30; // Panel - setMetric( Q::Panel | Size, dim ); + setMetric( Q::Panel | Size, extent ); setBoxShape( Q::Panel, 0 ); setBoxBorderMetrics( Q::Panel, 0 ); setGradient( Q::Panel, QskGradient() ); - setPadding( Q::Panel | Horizontal, QskMargins( 0.5 * dim, 0 ) ); - setPadding( Q::Panel | Vertical, QskMargins( 0, 0.5 * dim ) ); + setPadding( Q::Panel | Horizontal, QskMargins( 0.5 * extent, 0 ) ); + setPadding( Q::Panel | Vertical, QskMargins( 0, 0.5 * extent ) ); // Groove, Fill @@ -475,8 +476,9 @@ void QskMaterialSkin::initSliderHints() setBoxBorderMetrics( Q::Handle, 4 ); // handle expanding, when being pressed - setMetric( Q::Handle | Size, 0.6 * dim ); - setMetric( Q::Handle | Size | Q::Pressed, dim ); + QSize extentSize( extent, extent ); + setStrutSize( Q::Handle, 0.6 * extentSize ); + setStrutSize( Q::Handle | Q::Pressed, extentSize ); setGradient( Q::Handle | Q::Disabled, Grey ); setBoxBorderColors( Q::Handle | Q::Disabled, Grey ); diff --git a/skins/squiek/QskSquiekSkin.cpp b/skins/squiek/QskSquiekSkin.cpp index abdd2360..e3347e81 100644 --- a/skins/squiek/QskSquiekSkin.cpp +++ b/skins/squiek/QskSquiekSkin.cpp @@ -391,16 +391,16 @@ void QskSquiekSkin::initPageIndicatorHints() for ( auto subControl : { Q::Bullet, Q::Highlighted } ) { - setMetric( subControl | Size, qskDpiScaled( 12 ) ); + const auto extent = qskDpiScaled( 12 ); + setStrutSize( subControl, extent, extent ); - setBoxBorderMetrics( subControl, QskBoxBorderMetrics( 50, Qt::RelativeSize ) ); + setBoxBorderMetrics( subControl, 50, Qt::RelativeSize ); setBoxShape( subControl, 100, Qt::RelativeSize ); - - setGradient( subControl, - ( subControl == Q::Bullet ) ? pal.darker150 : pal.lighter150 ); - } + setGradient( Q::Bullet, pal.darker150 ); + setGradient( Q::Highlighted, pal.lighter150 ); + // no visible background panel setBoxBorderMetrics( Q::Panel, 0 ); setBoxShape( Q::Panel, 2 ); @@ -604,7 +604,7 @@ void QskSquiekSkin::initSliderHints() const auto& pal = m_data->palette; - const qreal dim = 40; + const qreal extent = 40; // Panel @@ -612,14 +612,14 @@ void QskSquiekSkin::initSliderHints() { const auto aspect = Q::Panel | placement; - setMetric( aspect | Size, dim ); + setMetric( aspect | Size, extent ); setBoxBorderMetrics( aspect, 0 ); setBoxShape( aspect, 0 ); setGradient( aspect, QskGradient() ); } - setPadding( Q::Panel | Horizontal, QskMargins( 0.5 * dim, 0 ) ); - setPadding( Q::Panel | Vertical, QskMargins( 0, 0.5 * dim ) ); + setPadding( Q::Panel | Horizontal, QskMargins( 0.5 * extent, 0 ) ); + setPadding( Q::Panel | Vertical, QskMargins( 0, 0.5 * extent ) ); // Groove, Fill @@ -629,17 +629,15 @@ void QskSquiekSkin::initSliderHints() { const auto aspect = subControl | placement; - setMetric( aspect | Size, 0.3 * dim ); + setMetric( aspect | Size, 0.3 * extent ); setPadding( aspect, 0 ); setBoxBorderMetrics( aspect, 0 ); - setBoxShape( aspect, 0.1 * dim ); - - if ( subControl == Q::Groove ) - setGradient( aspect, pal.darker200 ); - else - setGradient( aspect, QskGradient() ); // no filling + setBoxShape( aspect, 0.1 * extent ); } + + setGradient( Q::Groove | placement, pal.darker200 ); + setGradient( Q::Fill | placement, QskGradient() ); // no filling } // Handle @@ -651,7 +649,9 @@ void QskSquiekSkin::initSliderHints() setButton( aspect, Raised, 1 ); setBoxShape( aspect, 20.0, Qt::RelativeSize ); setButton( aspect | Q::Pressed, Sunken, 1 ); - setMetric( Q::Handle | Size, 0.75 * dim ); + + const qreal sz = 0.75 * extent; + setStrutSize( aspect, sz, sz ); } setAnimation( Q::Handle | Color, qskDuration ); @@ -669,10 +669,10 @@ void QskSquiekSkin::initTabBarHints() const qreal vb = 1.0; // borderWidth of the view const qreal pw = 1.0; // extra space for the negative padding of the buttons - setPadding( Q::Panel | Top, QskMargins( pw, 0.0, pw, vb ) ); - setPadding( Q::Panel | Bottom, QskMargins( pw, vb, pw, 0.0 ) ); - setPadding( Q::Panel | Left, QskMargins( 0.0, pw, vb, pw ) ); - setPadding( Q::Panel | Right, QskMargins( vb, pw, 0.0, pw ) ); + setPadding( Q::Panel | Top, pw, 0.0, pw, vb ); + setPadding( Q::Panel | Bottom, pw, vb, pw, 0.0 ); + setPadding( Q::Panel | Left, 0.0, pw, vb, pw ); + setPadding( Q::Panel | Right, vb, pw, 0.0, pw ); // when flicking setAnimation( Q::Panel | Metric, QskAnimationHint( 200, QEasingCurve::OutCubic ) ); @@ -706,7 +706,6 @@ void QskSquiekSkin::initInputPanelHints() void QskSquiekSkin::initInputPredictionBar() { - using namespace QskAspect; using Q = QskInputPredictionBar; const auto& pal = m_data->palette; diff --git a/src/controls/QskPageIndicator.cpp b/src/controls/QskPageIndicator.cpp index 762a21b0..8d335533 100644 --- a/src/controls/QskPageIndicator.cpp +++ b/src/controls/QskPageIndicator.cpp @@ -66,7 +66,7 @@ void QskPageIndicator::setOrientation( Qt::Orientation orientation ) resetImplicitSize(); update(); - Q_EMIT orientationChanged(); + Q_EMIT orientationChanged( orientation ); } } @@ -79,7 +79,7 @@ void QskPageIndicator::setCount( int count ) resetImplicitSize(); update(); - Q_EMIT countChanged(); + Q_EMIT countChanged( count ); } } @@ -93,7 +93,7 @@ void QskPageIndicator::setCurrentIndex( qreal index ) m_data->currentIndex = index; update(); - Q_EMIT currentIndexChanged(); + Q_EMIT currentIndexChanged( index ); } } @@ -103,8 +103,9 @@ QSizeF QskPageIndicator::contentsSizeHint( if ( which != Qt::PreferredSize ) return QSizeF(); - const qreal sizeBullet = metric( Bullet | QskAspect::Size ); - const qreal sizeCurrent = metric( Highlighted | QskAspect::Size ); + const auto bulletSize = strutSizeHint( Bullet ); + const auto maxSize = bulletSize.expandedTo( strutSizeHint( Highlighted ) ); + const qreal spacing = spacingHint( Panel ); const int n = m_data->count; @@ -116,25 +117,25 @@ QSizeF QskPageIndicator::contentsSizeHint( { if ( n > 0 ) { - w += qMax( sizeCurrent, sizeBullet ); + w += maxSize.width(); if ( n > 1 ) - w += ( n - 1 ) * ( sizeBullet + spacing ); + w += ( n - 1 ) * ( bulletSize.width() + spacing ); } - h = qMax( sizeCurrent, sizeBullet ); + h = maxSize.height(); } else { if ( n > 0 ) { - h += qMax( sizeCurrent, sizeBullet ); + h += maxSize.height(); if ( n > 1 ) - h += ( n - 1 ) * ( sizeBullet + spacing ); + h += ( n - 1 ) * ( bulletSize.height() + spacing ); } - w = qMax( sizeCurrent, sizeBullet ); + w = maxSize.width(); } const auto hint = outerBoxSize( Panel, QSizeF( w, h ) ); diff --git a/src/controls/QskPageIndicator.h b/src/controls/QskPageIndicator.h index 690afb5c..63028864 100644 --- a/src/controls/QskPageIndicator.h +++ b/src/controls/QskPageIndicator.h @@ -41,9 +41,9 @@ class QSK_EXPORT QskPageIndicator : public QskControl void setOrientation( Qt::Orientation ); Q_SIGNALS: - void countChanged(); - void currentIndexChanged(); - void orientationChanged(); + void countChanged( int ); + void currentIndexChanged( qreal ); + void orientationChanged( Qt::Orientation ); public Q_SLOTS: void setCount( int count ); diff --git a/src/controls/QskPageIndicatorSkinlet.cpp b/src/controls/QskPageIndicatorSkinlet.cpp index 48eeee63..6829f26d 100644 --- a/src/controls/QskPageIndicatorSkinlet.cpp +++ b/src/controls/QskPageIndicatorSkinlet.cpp @@ -56,15 +56,17 @@ QRectF QskPageIndicatorSkinlet::bulletRect( { using Q = QskPageIndicator; - const qreal szNormal = indicator->metric( Q::Bullet | QskAspect::Size ); - const qreal szHighlighted = indicator->metric( Q::Highlighted | QskAspect::Size ); + const qreal szNormal = indicator->strutSizeHint( Q::Bullet ).width(); + const qreal szHighlighted = indicator->strutSizeHint( Q::Highlighted ).width(); + + const auto currentIndex = indicator->currentIndex(); // scale bullet size if we are in between a transition: - qreal indexDiff = qAbs( indicator->currentIndex() - index ); + qreal indexDiff = qAbs( currentIndex - index ); if ( indexDiff > ( indicator->count() - 1 ) ) - indexDiff = ( indicator->count() - indicator->currentIndex() ); // wrapping + indexDiff = ( indicator->count() - currentIndex ); // wrapping - const qreal sz = ( indexDiff < 1 ) ? + const qreal sz0 = ( indexDiff < 1 ) ? ( 1 - indexDiff ) * szHighlighted + indexDiff * szNormal : szNormal; const qreal spacing = indicator->spacingHint( Q::Panel ); @@ -85,44 +87,48 @@ QRectF QskPageIndicatorSkinlet::bulletRect( QRectF r( 0, 0, w, h ); r.moveCenter( rect.center() ); - const qreal s = ( index > indicator->currentIndex() ) ? szHighlighted : szNormal; - qreal s2; - if ( indexDiff < 1 && index >= indicator->currentIndex() ) + { - // scrolling from or to this bullet: - s2 = szNormal + qAbs( szHighlighted - szNormal ) * indexDiff; - } - else if ( ( indicator->currentIndex() > ( indicator->count() - 1 ) && - index > ( indicator->currentIndex() - indicator->count() + 1 ) ) ) - { - // wrapping case: - qreal wrappingDiff = indexDiff; - while ( wrappingDiff > 1 ) - wrappingDiff -= 1; - s2 = szNormal + qAbs( szHighlighted - szNormal ) * wrappingDiff; - } - else - { - s2 = s; + const qreal s = ( index > currentIndex ) ? szHighlighted : szNormal; + if ( indexDiff < 1 && index >= currentIndex ) + { + // scrolling from or to this bullet: + s2 = szNormal + qAbs( szHighlighted - szNormal ) * indexDiff; + } + else if ( ( currentIndex > ( indicator->count() - 1 ) && + index > ( currentIndex - indicator->count() + 1 ) ) ) + { + // wrapping case: + qreal wrappingDiff = indexDiff; + while ( wrappingDiff > 1 ) + wrappingDiff -= 1; + + s2 = szNormal + qAbs( szHighlighted - szNormal ) * wrappingDiff; + } + else + { + s2 = s; + } } - qreal x = r.left() + s2 + spacing + ( index - 1 ) * ( szNormal + spacing ); + const qreal x = r.left() + s2 + spacing + ( index - 1 ) * ( szNormal + spacing ); + + qreal adjust = ( currentIndex == index ) + ? ( szNormal - szHighlighted ) : ( szHighlighted - szNormal ); + adjust = 0.5 * qMax( 0.0, adjust ); - qreal yAdjust; - if ( indicator->currentIndex() == index ) - { - yAdjust = qMax( 0.0, szNormal - szHighlighted ) / 2; - } - else - { - yAdjust = qMax( 0.0, szHighlighted - szNormal ) / 2; - } if ( indexDiff < 1 ) - yAdjust *= indexDiff; - const qreal y = ( horizontal ? r.top() : r.left() ) + yAdjust; + adjust *= indexDiff; - return horizontal ? QRectF( x, y, sz, sz ) : QRectF( y, x, sz, sz ); + QRectF bulletRect( 0.0, 0.0, sz0, sz0 ); + + if ( horizontal ) + bulletRect.moveTo( x, r.top() + adjust ); + else + bulletRect.moveTo( r.left() + adjust, x ); + + return bulletRect; } QSGNode* QskPageIndicatorSkinlet::updateBulletsNode( diff --git a/src/controls/QskSlider.cpp b/src/controls/QskSlider.cpp index 417d1e70..178da73c 100644 --- a/src/controls/QskSlider.cpp +++ b/src/controls/QskSlider.cpp @@ -123,9 +123,9 @@ QSizeF QskSlider::contentsSizeHint( if ( which != Qt::PreferredSize ) return QSizeF(); - const qreal dim = metric( QskSlider::Panel | QskAspect::Size ); + const qreal extent = metric( QskSlider::Panel | QskAspect::Size ); return ( m_data->orientation == Qt::Horizontal ) - ? QSizeF( 4 * dim, dim ) : QSizeF( dim, 4 * dim ); + ? QSizeF( 4 * extent, extent ) : QSizeF( extent, 4 * extent ); } QSizeF QskSlider::handleSize() const diff --git a/src/controls/QskSliderSkinlet.cpp b/src/controls/QskSliderSkinlet.cpp index fb3812e1..f6907e04 100644 --- a/src/controls/QskSliderSkinlet.cpp +++ b/src/controls/QskSliderSkinlet.cpp @@ -10,11 +10,19 @@ #include "QskBoxBorderMetrics.h" #include "QskFunctions.h" -static inline QMarginsF qskPadding( - const QskSlider* slider, QskAspect::Subcontrol subControl ) +static inline QRectF qskInnerPanelRect( + const QskSlider* slider, const QRectF& contentsRect ) { - return slider->paddingHint( subControl ) + - slider->boxBorderMetricsHint( subControl ).widths(); + using Q = QskSlider; + + // QskSkinnable::innerBox ??? + auto padding = slider->paddingHint( Q::Panel ); + padding += slider->boxBorderMetricsHint( Q::Panel ).widths(); + + auto r = slider->subControlRect( contentsRect, Q::Panel ); + r = r.marginsRemoved( padding ); + + return r; } QskSliderSkinlet::QskSliderSkinlet( QskSkin* skin ) @@ -113,8 +121,7 @@ QRectF QskSliderSkinlet::panelRect( QRectF QskSliderSkinlet::innerRect( const QskSlider* slider, const QRectF& contentsRect, QskAspect::Subcontrol subControl ) const { - QRectF r = subControlRect( slider, contentsRect, QskSlider::Panel ); - r = r.marginsRemoved( qskPadding( slider, QskSlider::Panel ) ); + auto r = qskInnerPanelRect( slider, contentsRect ); QskSkinHintStatus status; @@ -155,15 +162,10 @@ QRectF QskSliderSkinlet::scaleRect( QRectF QskSliderSkinlet::fillRect( const QskSlider* slider, const QRectF& contentsRect ) const { - using Q = QskSlider; + const auto r = qskInnerPanelRect( slider, contentsRect ); + const auto pos = qBound( 0.0, slider->handlePosition(), 1.0 ); - auto r = subControlRect( slider, contentsRect, Q::Panel ); - r = r.marginsRemoved( qskPadding( slider, Q::Panel ) ); - - qreal pos = slider->metric( Q::Handle | QskAspect::Position ); - pos = qBound( 0.0, pos, 1.0 ); - - auto fillRect = innerRect( slider, contentsRect, Q::Fill ); + auto fillRect = innerRect( slider, contentsRect, QskSlider::Fill ); if ( slider->orientation() == Qt::Horizontal ) { fillRect.setLeft( r.left() ); @@ -183,42 +185,38 @@ QRectF QskSliderSkinlet::handleRect( { using Q = QskSlider; - auto r = subControlRect( slider, contentsRect, Q::Panel ); - r = r.marginsRemoved( qskPadding( slider, Q::Panel ) ); + auto handleSize = slider->strutSizeHint( Q::Handle ); + const auto pos = qBound( 0.0, slider->handlePosition(), 1.0 ); - const bool isHorizontal = slider->orientation() == Qt::Horizontal; - - qreal extent; - - { - QskSkinHintStatus status; - - extent = slider->metric( Q::Handle | QskAspect::Size, &status ); - if ( !status.isValid() ) - extent = isHorizontal ? r.height() : r.width(); - } - - QRectF handleRect( 0, 0, extent, extent ); - if ( extent > 0 ) - { - handleRect = handleRect.marginsRemoved( - slider->marginHint( Q::Handle) ); - } - - qreal pos = slider->metric( Q::Handle | QskAspect::Position ); - pos = qBound( 0.0, pos, 1.0 ); + const auto r = qskInnerPanelRect( slider, contentsRect ); + auto center = r.center(); if ( slider->orientation() == Qt::Horizontal ) { - pos = r.left() + pos * r.width(); - handleRect.moveCenter( QPointF( pos, r.center().y() ) ); + if ( handleSize.height() < 0.0 ) + handleSize.setHeight( r.height() ); + + if ( handleSize.width() < 0.0 ) + handleSize.setWidth( handleSize.height() ); + + center.setX( r.left() + pos * r.width() ); } else { - pos = r.bottom() - pos * r.height(); - handleRect.moveCenter( QPointF( r.center().x(), pos ) ); + if ( handleSize.width() < 0.0 ) + handleSize.setWidth( r.width() ); + + if ( handleSize.height() < 0.0 ) + handleSize.setHeight( handleSize.width() ); + + center.setY( r.bottom() - pos * r.height() ); } + QRectF handleRect( 0, 0, handleSize.width(), handleSize.height() ); + handleRect.moveCenter( center ); + + handleRect = handleRect.marginsRemoved( slider->marginHint( Q::Handle ) ); + return handleRect; }