Fix alighnment if sizes of symbol and button differ
This commit is contained in:
parent
6beabfcbb1
commit
72190aee91
@ -54,6 +54,7 @@
|
|||||||
|
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
|
#include <qnamespace.h>
|
||||||
|
|
||||||
static const int qskDuration = 150;
|
static const int qskDuration = 150;
|
||||||
|
|
||||||
@ -479,10 +480,11 @@ void Editor::setupRadioBox()
|
|||||||
setStrutSize( Q::Symbol, { 10_dp, 10_dp });
|
setStrutSize( Q::Symbol, { 10_dp, 10_dp });
|
||||||
setStrutSize( Q::Ripple, { 40_dp, 40_dp });
|
setStrutSize( Q::Ripple, { 40_dp, 40_dp });
|
||||||
|
|
||||||
setMargin( Q::Button, QskMargins( 10_dp, 0, 10, 0));
|
setAlignment( Q::Symbol, Qt::AlignCenter );
|
||||||
setMargin( Q::Text, QskMargins( 10_dp, 0, 0, 0 ));
|
|
||||||
setAlignment( Q::Text, Qt::AlignBottom );
|
setAlignment( Q::Text, Qt::AlignBottom );
|
||||||
|
|
||||||
|
setMargin( Q::Text, QskMargins( 10_dp, 0, 10_dp, 0));
|
||||||
|
|
||||||
setBoxShape(Q::Button, 20_dp);
|
setBoxShape(Q::Button, 20_dp);
|
||||||
setBoxShape(Q::Ripple, 40_dp);
|
setBoxShape(Q::Ripple, 40_dp);
|
||||||
setBoxBorderMetrics( Q::Button, 2_dp );
|
setBoxBorderMetrics( Q::Button, 2_dp );
|
||||||
@ -501,7 +503,6 @@ void Editor::setupRadioBox()
|
|||||||
setBoxBorderColors( Q::Button | Q::Disabled | Q::Selected, m_pal.onSurface38 );
|
setBoxBorderColors( Q::Button | Q::Disabled | Q::Selected, m_pal.onSurface38 );
|
||||||
setColor( Q::Text | Q::Disabled, m_pal.onSurface38 );
|
setColor( Q::Text | Q::Disabled, m_pal.onSurface38 );
|
||||||
setColor( Q::Symbol | Q::Disabled, m_pal.onSurface38 );
|
setColor( Q::Symbol | Q::Disabled, m_pal.onSurface38 );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::setupFocusIndicator()
|
void Editor::setupFocusIndicator()
|
||||||
|
@ -639,6 +639,7 @@ void Editor::setupRadioBox()
|
|||||||
|
|
||||||
setMargin( Q::Text, QskMargins( qskDpiScaled( 10 ), 0, qskDpiScaled( 10 ), 0 ));
|
setMargin( Q::Text, QskMargins( qskDpiScaled( 10 ), 0, qskDpiScaled( 10 ), 0 ));
|
||||||
|
|
||||||
|
setAlignment( Q::Symbol, Qt::AlignCenter );
|
||||||
setAlignment( Q::Text, Qt::AlignBottom );
|
setAlignment( Q::Text, Qt::AlignBottom );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "QskGraphic.h"
|
#include "QskGraphic.h"
|
||||||
#include "QskFunctions.h"
|
#include "QskFunctions.h"
|
||||||
#include "QskSkin.h"
|
#include "QskSkin.h"
|
||||||
|
#include <qnamespace.h>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -48,7 +49,7 @@ QRectF QskRadioBoxSkinlet::subControlRect( const QskSkinnable* skinnable,
|
|||||||
auto radio = static_cast<const QskRadioBox*>( skinnable );
|
auto radio = static_cast<const QskRadioBox*>( skinnable );
|
||||||
|
|
||||||
if( subcontrol == Q::Ripple ) {
|
if( subcontrol == Q::Ripple ) {
|
||||||
return buttonRect(radio, Q::Ripple, contentsRect, radio->positionHint(Q::Ripple));
|
return rippleRect(radio, contentsRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
return contentsRect;
|
return contentsRect;
|
||||||
@ -69,15 +70,15 @@ QSizeF QskRadioBoxSkinlet::sizeHint( const QskSkinnable* skinnable,
|
|||||||
maxTextWidth = std::max( maxTextWidth, qskHorizontalAdvance( font, item ) );
|
maxTextWidth = std::max( maxTextWidth, qskHorizontalAdvance( font, item ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
auto radioWidth = radio->strutSizeHint(Q::Button).width();
|
auto buttonWidth = radio->strutSizeHint(Q::Button).width();
|
||||||
auto symbolWidth = radio->strutSizeHint(Q::Symbol).width();
|
auto symbolWidth = radio->strutSizeHint(Q::Symbol).width();
|
||||||
|
|
||||||
maxTextWidth += textMargins.left() + textMargins.right();
|
maxTextWidth += textMargins.left() + textMargins.right();
|
||||||
radioWidth += buttonMargins.left() + buttonMargins.right();
|
buttonWidth += buttonMargins.left() + buttonMargins.right();
|
||||||
symbolWidth += symbolMargins.left() + symbolMargins.right();
|
symbolWidth += symbolMargins.left() + symbolMargins.right();
|
||||||
|
|
||||||
auto spacing = radio->spacingHint(Q::Panel);
|
auto spacing = radio->spacingHint(Q::Panel);
|
||||||
return QSizeF( maxTextWidth + qMax(radioWidth, symbolWidth),
|
return QSizeF( maxTextWidth + qMax(buttonWidth, symbolWidth),
|
||||||
( lineHeight( radio ) + spacing ) * radio->items().size()
|
( lineHeight( radio ) + spacing ) * radio->items().size()
|
||||||
- spacing );
|
- spacing );
|
||||||
}
|
}
|
||||||
@ -123,13 +124,40 @@ qreal QskRadioBoxSkinlet::lineHeight(const QskRadioBox* target) const {
|
|||||||
return qMax( strutHight, fontHeight );
|
return qMax( strutHight, fontHeight );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int QskRadioBoxSkinlet::sampleCount( const QskSkinnable* skinnable,
|
int QskRadioBoxSkinlet::sampleCount( const QskSkinnable* skinnable,
|
||||||
QskAspect::Subcontrol ) const {
|
QskAspect::Subcontrol ) const {
|
||||||
const auto radio = static_cast< const QskRadioBox* >( skinnable );
|
const auto radio = static_cast< const QskRadioBox* >( skinnable );
|
||||||
return radio->items().count();
|
return radio->items().count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QSizeF QskRadioBoxSkinlet::buttonSymbolSize( const QskRadioBox* radio ) const {
|
||||||
|
auto buttonStrut = radio->strutSizeHint( Q::Button );
|
||||||
|
auto symbolStrut = radio->strutSizeHint( Q::Symbol );
|
||||||
|
|
||||||
|
buttonStrut = buttonStrut.grownBy( radio->marginHint( Q::Button ) );
|
||||||
|
symbolStrut = symbolStrut.grownBy( radio->marginHint( Q::Symbol ) );
|
||||||
|
|
||||||
|
return QSizeF(
|
||||||
|
qMax( buttonStrut.width(), symbolStrut.width() ),
|
||||||
|
qMax( buttonStrut.height(), symbolStrut.height() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
QRectF QskRadioBoxSkinlet::rippleRect( const QskRadioBox* radio,
|
||||||
|
const QRectF& rect ) const {
|
||||||
|
auto ripplePosition = radio->positionHint( Q::Ripple );
|
||||||
|
|
||||||
|
if( ripplePosition < 0 ) {
|
||||||
|
return QRectF();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto button = buttonRect( radio, Q::Button, rect, ripplePosition );
|
||||||
|
auto rippleSize = radio->strutSizeHint( Q::Ripple );
|
||||||
|
button.moveLeft( button.x() - ( rippleSize.width() - button.width() ) / 2 );
|
||||||
|
button.moveTop( button.y() - ( rippleSize.height() - button.height() ) / 2 );
|
||||||
|
button.setSize( rippleSize );
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
QRectF QskRadioBoxSkinlet::buttonRect( const QskRadioBox* radio,
|
QRectF QskRadioBoxSkinlet::buttonRect( const QskRadioBox* radio,
|
||||||
const QskAspect::Subcontrol target,
|
const QskAspect::Subcontrol target,
|
||||||
const QRectF& rect, double index ) const {
|
const QRectF& rect, double index ) const {
|
||||||
@ -138,19 +166,38 @@ QRectF QskRadioBoxSkinlet::buttonRect( const QskRadioBox* radio,
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto result = rect;
|
auto result = rect;
|
||||||
result.setSize( radio->strutSizeHint( target ) );
|
result.setSize( radio->strutSizeHint( target ));
|
||||||
|
|
||||||
auto spacing = radio->spacingHint(Q::Panel);
|
auto spacing = radio->spacingHint(Q::Panel);
|
||||||
result.moveTop( ( lineHeight( radio ) + spacing ) * index
|
result.moveTop( ( lineHeight( radio ) + spacing ) * index );
|
||||||
+ (lineHeight(radio) - result.size().height()) / 2);
|
|
||||||
|
|
||||||
auto maxWidth = qMax(radio->strutSizeHint( Q::Button ).width(),
|
auto margins = radio->marginHint( target );
|
||||||
radio->strutSizeHint( Q::Symbol ).width());
|
auto withMargins = result.size().grownBy( margins );
|
||||||
|
|
||||||
|
auto maxSize = buttonSymbolSize( radio );
|
||||||
|
auto alignment = radio->alignmentHint( target );
|
||||||
|
|
||||||
|
// Vertical positioning
|
||||||
|
auto alignHeight = maxSize.height() - withMargins.height();
|
||||||
|
if( alignment.testFlag( Qt::AlignVCenter )) {
|
||||||
|
result.moveTop( result.top() + alignHeight / 2);
|
||||||
|
} else if( alignment.testFlag( Qt::AlignBottom ) ) {
|
||||||
|
result.moveTop( result.top() + alignHeight );
|
||||||
|
}
|
||||||
|
result.moveTop( result.top() + margins.top());
|
||||||
|
|
||||||
|
// Horizontal positioning
|
||||||
|
auto alignWidth = 0;
|
||||||
|
if( alignment.testFlag( Qt::AlignHCenter ) ) {
|
||||||
|
alignWidth = (maxSize.width() - withMargins.width()) / 2;
|
||||||
|
} else if ( alignment.testFlag( Qt::AlignRight )) {
|
||||||
|
alignWidth = maxSize.width() - withMargins.width();
|
||||||
|
}
|
||||||
|
|
||||||
if( radio->layoutMirroring() ) {
|
if( radio->layoutMirroring() ) {
|
||||||
result.moveRight( rect.width() - (maxWidth - result.width())/2);
|
result.moveRight( rect.width() - (alignWidth + margins.right() ));
|
||||||
} else {
|
} else {
|
||||||
result.moveLeft((maxWidth - result.width()) / 2);
|
result.moveLeft( margins.left() + alignWidth );
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -175,16 +222,17 @@ QRectF QskRadioBoxSkinlet::textRect( const QskRadioBox* radio,
|
|||||||
+ textMargins.top());
|
+ textMargins.top());
|
||||||
|
|
||||||
result.setHeight( lh );
|
result.setHeight( lh );
|
||||||
result.setWidth( qskHorizontalAdvance( font, radio->items()[index] ) );
|
result.setWidth( qskHorizontalAdvance( font, text ) );
|
||||||
|
|
||||||
auto buttonWidth = buttonRect( radio, Q::Button, rect, index ).width();
|
auto button = buttonRect( radio, Q::Button, rect, index );
|
||||||
auto buttonsMargins = radio->marginHint( Q::Button );
|
auto buttonsMargins = radio->marginHint( Q::Button );
|
||||||
|
auto buttonWidth = button.marginsAdded( buttonsMargins ).width();
|
||||||
|
|
||||||
if( radio->layoutMirroring() ) {
|
if( radio->layoutMirroring() ) {
|
||||||
result.moveLeft( rect.width() - textMargins.right()
|
result.moveLeft( rect.width() - textMargins.right()
|
||||||
- result.width() - buttonWidth - buttonsMargins.left());
|
- result.width() - buttonWidth);
|
||||||
} else {
|
} else {
|
||||||
result.moveLeft( buttonWidth + textMargins.left()
|
result.moveLeft( buttonWidth + textMargins.left() );
|
||||||
+ radio->marginHint( Q::Button ).right());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -37,8 +37,11 @@ class QSK_EXPORT QskRadioBoxSkinlet : public QskSkinlet
|
|||||||
QRectF sampleRect( const QskSkinnable*,
|
QRectF sampleRect( const QskSkinnable*,
|
||||||
const QRectF&, QskAspect::Subcontrol, int index ) const override;
|
const QRectF&, QskAspect::Subcontrol, int index ) const override;
|
||||||
|
|
||||||
|
QSizeF buttonSymbolSize( const QskRadioBox* radio ) const;
|
||||||
QRectF textRect( const QskRadioBox*, const QRectF&, int ) const;
|
QRectF textRect( const QskRadioBox*, const QRectF&, int ) const;
|
||||||
QRectF buttonRect( const QskRadioBox*, const QskAspect::Subcontrol target, const QRectF&, double ) const;
|
QRectF buttonRect( const QskRadioBox*, const QskAspect::Subcontrol target, const QRectF&, double ) const;
|
||||||
|
QRectF rippleRect( const QskRadioBox*, const QRectF& ) const;
|
||||||
|
|
||||||
|
|
||||||
QskAspect::States sampleStates( const QskSkinnable*,
|
QskAspect::States sampleStates( const QskSkinnable*,
|
||||||
QskAspect::Subcontrol, int index ) const override;
|
QskAspect::Subcontrol, int index ) const override;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user