minor improvements of the push button layout
This commit is contained in:
parent
112221f123
commit
061cdb0a07
@ -5,7 +5,7 @@ Qsk.PushButton
|
|||||||
{
|
{
|
||||||
sizePolicy
|
sizePolicy
|
||||||
{
|
{
|
||||||
// long texts, should not have an effect
|
// avoid the effect of long texts
|
||||||
horizontalPolicy: Qsk.SizePolicy.Ignored
|
horizontalPolicy: Qsk.SizePolicy.Ignored
|
||||||
verticalPolicy: Qsk.SizePolicy.Ignored
|
verticalPolicy: Qsk.SizePolicy.Ignored
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "QskGraphic.h"
|
#include "QskGraphic.h"
|
||||||
#include "QskTextOptions.h"
|
#include "QskTextOptions.h"
|
||||||
|
#include "QskFunctions.h"
|
||||||
|
|
||||||
#include <qfontmetrics.h>
|
#include <qfontmetrics.h>
|
||||||
#include <qmath.h>
|
#include <qmath.h>
|
||||||
@ -87,9 +88,13 @@ QRectF QskPushButtonSkinlet::textRect(
|
|||||||
using Q = QskPushButton;
|
using Q = QskPushButton;
|
||||||
|
|
||||||
auto r = button->subControlContentsRect( contentsRect, Q::Panel );
|
auto r = button->subControlContentsRect( contentsRect, Q::Panel );
|
||||||
|
if ( r.isEmpty() || !button->hasGraphic() )
|
||||||
|
return r;
|
||||||
|
|
||||||
if ( button->hasGraphic() )
|
/*
|
||||||
{
|
For horizontal layouts Text depends on Graphic, while
|
||||||
|
for vertical Graphic depends on Text. Confusing ...
|
||||||
|
*/
|
||||||
if ( qskOrientation( button ) == Qt::Horizontal )
|
if ( qskOrientation( button ) == Qt::Horizontal )
|
||||||
{
|
{
|
||||||
const auto graphicsRect = subControlRect( button, contentsRect, Q::Graphic );
|
const auto graphicsRect = subControlRect( button, contentsRect, Q::Graphic );
|
||||||
@ -103,7 +108,6 @@ QRectF QskPushButtonSkinlet::textRect(
|
|||||||
if ( h < r.height() )
|
if ( h < r.height() )
|
||||||
r.setTop( r.bottom() - h );
|
r.setTop( r.bottom() - h );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -114,18 +118,20 @@ QRectF QskPushButtonSkinlet::graphicRect(
|
|||||||
using Q = QskPushButton;
|
using Q = QskPushButton;
|
||||||
|
|
||||||
auto r = button->subControlContentsRect( contentsRect, Q::Panel );
|
auto r = button->subControlContentsRect( contentsRect, Q::Panel );
|
||||||
|
if ( r.isEmpty() || button->text().isEmpty() )
|
||||||
|
return r;
|
||||||
|
|
||||||
const auto orientation = qskOrientation( button );
|
const auto orientation = qskOrientation( button );
|
||||||
|
|
||||||
if ( !button->text().isEmpty() && orientation == Qt::Vertical )
|
if ( orientation == Qt::Vertical )
|
||||||
{
|
{
|
||||||
const auto textRect = subControlRect( button, contentsRect, Q::Text );
|
const auto textRect = subControlRect( button, contentsRect, Q::Text );
|
||||||
qreal h = textRect.height() + button->spacingHint( Q::Panel );
|
const auto h = textRect.height() + button->spacingHint( Q::Panel );
|
||||||
|
|
||||||
|
if ( h > r.height() )
|
||||||
|
return QRectF();
|
||||||
|
|
||||||
if ( h < r.height() )
|
|
||||||
r.setBottom( r.bottom() - h );
|
r.setBottom( r.bottom() - h );
|
||||||
else
|
|
||||||
r.setHeight( 0 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto maxSize = button->graphicSourceSize();
|
const auto maxSize = button->graphicSourceSize();
|
||||||
@ -149,37 +155,20 @@ QRectF QskPushButtonSkinlet::graphicRect(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto sz = button->graphic().defaultSize();
|
r = r.marginsRemoved( button->paddingHint( Q::Graphic ) );
|
||||||
|
|
||||||
if ( !( r.isEmpty() || sz.isEmpty() ) )
|
if ( !r.isEmpty() )
|
||||||
{
|
{
|
||||||
// inner rectangle according to the aspect ratio
|
auto sz = button->graphic().defaultSize();
|
||||||
|
if ( !sz.isEmpty() )
|
||||||
const double scaleFactor =
|
|
||||||
qMin( r.width() / sz.width(), r.height() / sz.height() );
|
|
||||||
|
|
||||||
const int w = qFloor( scaleFactor * sz.width() );
|
|
||||||
const int h = qFloor( scaleFactor * sz.height() );
|
|
||||||
int x, y;
|
|
||||||
|
|
||||||
if ( orientation == Qt::Horizontal )
|
|
||||||
{
|
{
|
||||||
x = r.left();
|
sz.scale( r.size(), Qt::KeepAspectRatio );
|
||||||
y = r.top();
|
|
||||||
|
const auto align = ( orientation == Qt::Horizontal )
|
||||||
|
? ( Qt::AlignLeft | Qt::AlignTop ) : Qt::AlignCenter;
|
||||||
|
|
||||||
|
r = qskAlignedRectF( r, sz.width(), sz.height(), align );
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// early aligning to avoid pointless operations, that finally will
|
|
||||||
// have no effect, when drawing to an integer based paint device
|
|
||||||
|
|
||||||
x = qFloor( r.center().x() - 0.5 * w );
|
|
||||||
y = qFloor( r.center().y() - 0.5 * h );
|
|
||||||
}
|
|
||||||
|
|
||||||
r = QRectF( x, y, w, h );
|
|
||||||
|
|
||||||
const auto padding = button->paddingHint( Q::Graphic );
|
|
||||||
r = r.marginsRemoved( padding );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user