missing Metric bit for spacings added

This commit is contained in:
Uwe Rathmann 2022-06-15 11:38:07 +02:00
parent 9fbcedfc2c
commit 54616a5781

View File

@ -12,6 +12,19 @@
#include <qfontmetrics.h> #include <qfontmetrics.h>
#include <qmath.h> #include <qmath.h>
static inline Qt::Orientation qskOrientation( const QskPushButton* button )
{
// For the moment we only handle the orientation TODO ...
const auto direction = button->flagHint(
QskPushButton::Panel | QskAspect::Direction, Qsk::LeftToRight );
if ( direction == Qsk::LeftToRight || direction == Qsk::RightToLeft )
return Qt::Horizontal;
else
return Qt::Vertical;
}
QskPushButtonSkinlet::QskPushButtonSkinlet( QskSkin* skin ) QskPushButtonSkinlet::QskPushButtonSkinlet( QskSkin* skin )
: Inherited( skin ) : Inherited( skin )
{ {
@ -71,31 +84,26 @@ QSGNode* QskPushButtonSkinlet::updateSubNode(
QRectF QskPushButtonSkinlet::textRect( QRectF QskPushButtonSkinlet::textRect(
const QskPushButton* button, const QRectF& contentsRect ) const const QskPushButton* button, const QRectF& contentsRect ) const
{ {
// buttonShift -> TODO using Q = QskPushButton;
auto r = button->subControlContentsRect( contentsRect, QskPushButton::Panel ); auto r = button->subControlContentsRect( contentsRect, Q::Panel );
if ( button->hasGraphic() ) if ( button->hasGraphic() )
{ {
const auto orientation = button->flagHint( QskPushButton::Panel | QskAspect::Direction, Qsk::LeftToRight ); if ( qskOrientation( button ) == Qt::Horizontal )
{
const auto graphicsRect = subControlRect( button, contentsRect, Q::Graphic );
const auto spacing = button->spacingHint( Q::Panel );
switch( orientation )
{
case Qsk::LeftToRight:
{
const auto graphicsRect = subControlRect( button, contentsRect, QskPushButton::Graphic );
const auto spacing = button->metric( QskPushButton::Panel | QskAspect::Spacing );
r.setX( r.x() + graphicsRect.width() + spacing ); r.setX( r.x() + graphicsRect.width() + spacing );
break;
} }
default: // Qsk::TopToBottom, the other ones are not handled yet else
{ {
qreal h = button->effectiveFontHeight( QskPushButton::Text ); const qreal h = button->effectiveFontHeight( Q::Text );
if ( h < r.height() ) if ( h < r.height() )
r.setTop( r.bottom() - h ); r.setTop( r.bottom() - h );
} }
} }
}
return r; return r;
} }
@ -103,17 +111,16 @@ QRectF QskPushButtonSkinlet::textRect(
QRectF QskPushButtonSkinlet::graphicRect( QRectF QskPushButtonSkinlet::graphicRect(
const QskPushButton* button, const QRectF& contentsRect ) const const QskPushButton* button, const QRectF& contentsRect ) const
{ {
// buttonShift -> TODO using Q = QskPushButton;
auto r = button->subControlContentsRect( contentsRect, QskPushButton::Panel ); auto r = button->subControlContentsRect( contentsRect, Q::Panel );
const auto orientation = button->flagHint( QskPushButton::Panel const auto orientation = qskOrientation( button );
| QskAspect::Direction, Qsk::LeftToRight );
if ( !button->text().isEmpty() && orientation == Qsk::TopToBottom ) if ( !button->text().isEmpty() && orientation == Qt::Vertical )
{ {
const auto textRect = subControlRect( button, contentsRect, QskPushButton::Text ); const auto textRect = subControlRect( button, contentsRect, Q::Text );
qreal h = textRect.height() + button->spacingHint( QskPushButton::Panel ); qreal h = textRect.height() + button->spacingHint( Q::Panel );
if ( h < r.height() ) if ( h < r.height() )
r.setBottom( r.bottom() - h ); r.setBottom( r.bottom() - h );
@ -142,7 +149,7 @@ QRectF QskPushButtonSkinlet::graphicRect(
} }
} }
const QSizeF sz = button->graphic().defaultSize(); const auto sz = button->graphic().defaultSize();
if ( !( r.isEmpty() || sz.isEmpty() ) ) if ( !( r.isEmpty() || sz.isEmpty() ) )
{ {
@ -155,18 +162,12 @@ QRectF QskPushButtonSkinlet::graphicRect(
const int h = qFloor( scaleFactor * sz.height() ); const int h = qFloor( scaleFactor * sz.height() );
int x, y; int x, y;
const auto orientation = button->flagHint( QskPushButton::Panel if ( orientation == Qt::Horizontal )
| QskAspect::Direction, Qsk::LeftToRight );
switch( orientation )
{
case Qsk::LeftToRight:
{ {
x = r.left(); x = r.left();
y = r.top(); y = r.top();
break;
} }
default: // TopToBottom else
{ {
// early aligning to avoid pointless operations, that finally will // early aligning to avoid pointless operations, that finally will
// have no effect, when drawing to an integer based paint device // have no effect, when drawing to an integer based paint device
@ -174,10 +175,10 @@ QRectF QskPushButtonSkinlet::graphicRect(
x = qFloor( r.center().x() - 0.5 * w ); x = qFloor( r.center().x() - 0.5 * w );
y = qFloor( r.center().y() - 0.5 * h ); y = qFloor( r.center().y() - 0.5 * h );
} }
}
r = QRectF( x, y, w, h ); r = QRectF( x, y, w, h );
const auto padding = button->paddingHint( QskPushButton::Graphic );
const auto padding = button->paddingHint( Q::Graphic );
r = r.marginsRemoved( padding ); r = r.marginsRemoved( padding );
} }
@ -187,21 +188,25 @@ QRectF QskPushButtonSkinlet::graphicRect(
QSGNode* QskPushButtonSkinlet::updateTextNode( QSGNode* QskPushButtonSkinlet::updateTextNode(
const QskPushButton* button, QSGNode* node ) const const QskPushButton* button, QSGNode* node ) const
{ {
const auto rect = button->subControlRect( QskPushButton::Text ).toAlignedRect(); using Q = QskPushButton;
const auto textHeight = button->effectiveFontHeight( QskPushButton::Text ); const auto rect = button->subControlRect( Q::Text ).toAlignedRect();
const auto textHeight = button->effectiveFontHeight( Q::Text );
if ( !button->clip() && ( rect.height() < textHeight ) ) if ( !button->clip() && ( rect.height() < textHeight ) )
return nullptr; return nullptr;
const auto alignment = button->alignmentHint( QskPushButton::Text, Qt::AlignCenter ); const auto alignment = button->alignmentHint( Q::Text, Qt::AlignCenter );
return QskSkinlet::updateTextNode( button, node, rect, alignment, return QskSkinlet::updateTextNode( button, node, rect, alignment,
button->text(), button->textOptions(), QskPushButton::Text ); button->text(), button->textOptions(), Q::Text );
} }
QSizeF QskPushButtonSkinlet::sizeHint( const QskSkinnable* skinnable, QSizeF QskPushButtonSkinlet::sizeHint( const QskSkinnable* skinnable,
Qt::SizeHint which, const QSizeF& ) const Qt::SizeHint which, const QSizeF& ) const
{ {
using Q = QskPushButton;
if ( which != Qt::PreferredSize ) if ( which != Qt::PreferredSize )
return QSizeF(); return QSizeF();
@ -249,29 +254,23 @@ QSizeF QskPushButtonSkinlet::sizeHint( const QskSkinnable* skinnable,
} }
} }
const QMarginsF padding = button->paddingHint( QskPushButton::Graphic ); const auto padding = button->paddingHint( Q::Graphic );
const auto orientation = qskOrientation( button );
const auto orientation = button->flagHint( QskPushButton::Panel if( orientation == Qt::Horizontal )
| QskAspect::Direction, Qsk::LeftToRight );
switch( orientation )
{
case Qsk::LeftToRight:
{ {
size.rwidth() += padding.left() + w + padding.right(); size.rwidth() += padding.left() + w + padding.right();
size.rheight() = qMax( size.height(), h ); size.rheight() = qMax( size.height(), h );
break;
} }
default: // TopToBottom else
{ {
size.rheight() += padding.top() + h + padding.bottom(); size.rheight() += padding.top() + h + padding.bottom();
size.rwidth() = qMax( size.width(), w ); size.rwidth() = qMax( size.width(), w );
} }
} }
}
size = size.expandedTo( button->strutSizeHint( QskPushButton::Panel ) ); size = size.expandedTo( button->strutSizeHint( Q::Panel ) );
size = button->outerBoxSize( QskPushButton::Panel, size ); size = button->outerBoxSize( Q::Panel, size );
return size; return size;
} }