using StrutSize instead og Minimum/Maximum metric hints
This commit is contained in:
parent
6c0f0810f1
commit
58de684902
|
@ -73,14 +73,12 @@ namespace
|
|||
setGradient( Q::NeedleHead, color2 );
|
||||
setBoxBorderColors( Q::NeedleHead, color4 );
|
||||
|
||||
setMetric( Q::Needle | MinimumWidth, 4 );
|
||||
setMetric( Q::Needle | Size, 4 );
|
||||
setMetric( Q::Needle | Margin, 15 );
|
||||
setColor( Q::Needle, color4 );
|
||||
|
||||
// margins between numbers and ticks:
|
||||
setMargin( Q::Labels, 3 );
|
||||
setMetric( Q::Labels | MinimumWidth, 3 );
|
||||
setMetric( Q::Labels | Size, 25 ); // ticks size
|
||||
setSpacing( Q::Labels, 3 );
|
||||
setStrutSize( Q::Labels, 3, 25 );
|
||||
setColor( Q::Labels, color4 );
|
||||
setFontRole( Q::Labels, QskSkin::SmallFont );
|
||||
}
|
||||
|
@ -124,14 +122,12 @@ namespace
|
|||
QskGradient( QskGradient::Diagonal, color2, color1 ) );
|
||||
// setBoxBorderColors( Q::NeedleHead, color4 );
|
||||
|
||||
setMetric( Q::Needle | MinimumWidth, 2 );
|
||||
setMetric( Q::Needle | Size, 2 );
|
||||
setMetric( Q::Needle | Margin, 10 );
|
||||
setColor( Q::Needle, color2 );
|
||||
|
||||
// margins between numbers and ticks:
|
||||
setMargin( Q::Labels, 4 );
|
||||
setMetric( Q::Labels | MinimumWidth, 2 );
|
||||
setMetric( Q::Labels | Size, 15 ); // ticks size
|
||||
setSpacing( Q::Labels, 4 );
|
||||
setStrutSize( Q::Labels, 2, 15 );
|
||||
setColor( Q::Labels, color4 );
|
||||
setFontRole( Q::Labels, QskSkin::SmallFont );
|
||||
}
|
||||
|
|
|
@ -134,7 +134,7 @@ QSGNode* SpeedometerSkinlet::updateLabelsNode(
|
|||
ticksNode = new TicksNode();
|
||||
}
|
||||
|
||||
QColor color = speedometer->color( Q::Labels );
|
||||
const auto color = speedometer->color( Q::Labels );
|
||||
ticksNode->setColor( color );
|
||||
|
||||
const auto startAngle = speedometer->minimum();
|
||||
|
@ -156,27 +156,28 @@ QSGNode* SpeedometerSkinlet::updateLabelsNode(
|
|||
QPointF center = QPointF( panelRect.x() + panelRect.width() / 2,
|
||||
panelRect.y() + panelRect.height() / 2 );
|
||||
|
||||
auto radius = static_cast< float >( panelRect.width() / 2 );
|
||||
const auto radius = static_cast< float >( panelRect.width() / 2 );
|
||||
|
||||
const auto numbersMargins = speedometer->marginHint( Q::Labels );
|
||||
const auto spacing = speedometer->spacingHint( Q::Labels );
|
||||
QFontMetricsF fontMetrics( speedometer->effectiveFont( Q::Labels ) );
|
||||
|
||||
auto angle = startAngle;
|
||||
qreal length = speedometer->metric( Q::Labels | Size );
|
||||
const auto labels = speedometer->labels();
|
||||
|
||||
const auto tickSize = speedometer->strutSizeHint( Q::Labels );
|
||||
const auto needleRadius = radius - tickSize.height();
|
||||
|
||||
// Create a series of tickmarks from minimum to maximum
|
||||
for ( int i = 0; i < labelsCount; ++i, angle += step )
|
||||
{
|
||||
qreal cosine = qCos( qDegreesToRadians( angle ) );
|
||||
qreal sine = qSin( qDegreesToRadians( angle ) );
|
||||
const qreal cos = qFastCos( qDegreesToRadians( angle ) );
|
||||
const qreal sin = qFastSin( qDegreesToRadians( angle ) );
|
||||
|
||||
auto xStart = center.x() + radius * cosine;
|
||||
auto yStart = center.y() + radius * sine;
|
||||
const auto xStart = center.x() + radius * cos;
|
||||
const auto yStart = center.y() + radius * sin;
|
||||
|
||||
// ### skin hint for each of highlighted / normal marks
|
||||
auto xEnd = center.x() + ( radius - length ) * cosine;
|
||||
auto yEnd = center.y() + ( radius - length ) * sine;
|
||||
const auto xEnd = center.x() + needleRadius * cos;
|
||||
const auto yEnd = center.y() + needleRadius * sin;
|
||||
|
||||
vertexData[ 0 ].set( xStart, yStart );
|
||||
vertexData[ 1 ].set( xEnd, yEnd );
|
||||
|
@ -188,13 +189,13 @@ QSGNode* SpeedometerSkinlet::updateLabelsNode(
|
|||
{
|
||||
const QString& text = labels.at( i );
|
||||
|
||||
auto w = qskHorizontalAdvance( fontMetrics, text );
|
||||
auto h = fontMetrics.height();
|
||||
auto adjustX = ( -0.5 * cosine - 0.5 ) * w;
|
||||
auto adjustY = ( -0.5 * sine - 0.5 ) * h;
|
||||
const auto w = qskHorizontalAdvance( fontMetrics, text );
|
||||
const auto h = fontMetrics.height();
|
||||
const auto adjustX = ( -0.5 * cos - 0.5 ) * w;
|
||||
const auto adjustY = ( -0.5 * sin - 0.5 ) * h;
|
||||
|
||||
auto numbersX = xEnd + ( -1 * numbersMargins.left() * cosine ) + adjustX;
|
||||
auto numbersY = yEnd + ( -1 * numbersMargins.top() * sine ) + adjustY;
|
||||
const auto numbersX = xEnd - ( spacing * cos ) + adjustX;
|
||||
const auto numbersY = yEnd - ( spacing * sin ) + adjustY;
|
||||
|
||||
QRectF numbersRect( numbersX, numbersY, w, h );
|
||||
|
||||
|
@ -221,8 +222,7 @@ QSGNode* SpeedometerSkinlet::updateLabelsNode(
|
|||
}
|
||||
}
|
||||
|
||||
auto lineWidth = speedometer->metric( Q::Labels | MinimumWidth );
|
||||
geometry->setLineWidth( lineWidth );
|
||||
geometry->setLineWidth( tickSize.width() );
|
||||
geometry->markVertexDataDirty();
|
||||
|
||||
ticksNode->markDirty( QSGNode::DirtyGeometry );
|
||||
|
@ -259,35 +259,34 @@ QSGNode* SpeedometerSkinlet::updateNeedleNode(
|
|||
|
||||
panelRect = panelRect.marginsRemoved( margins );
|
||||
|
||||
auto radius = speedometer->metric( Q::NeedleHead | Size );
|
||||
QPointF center = QPointF( panelRect.x() + panelRect.width() / 2,
|
||||
panelRect.y() + panelRect.height() / 2 );
|
||||
const auto radius = speedometer->metric( Q::NeedleHead | Size );
|
||||
const QPointF center = panelRect.center();
|
||||
|
||||
const auto borderMetrics = speedometer->boxBorderMetricsHint( Q::NeedleHead );
|
||||
const auto borderColors = speedometer->boxBorderColorsHint( Q::NeedleHead );
|
||||
const auto gradient = speedometer->gradientHint( Q::NeedleHead );
|
||||
|
||||
QskBoxShapeMetrics shapeMetrics( radius, radius, radius, radius );
|
||||
QskBoxBorderMetrics borderMetrics = speedometer->boxBorderMetricsHint( Q::NeedleHead );
|
||||
QskBoxBorderColors borderColors = speedometer->boxBorderColorsHint( Q::NeedleHead );
|
||||
QskGradient gradient = speedometer->gradientHint( Q::NeedleHead );
|
||||
QRectF centerNodeRect( center.x() - radius, center.y() - radius, 2 * radius, 2 * radius );
|
||||
boxNode->setBoxData( centerNodeRect, shapeMetrics, borderMetrics, borderColors, gradient );
|
||||
boxNode->setBoxData( centerNodeRect, radius, borderMetrics, borderColors, gradient );
|
||||
|
||||
QColor color = speedometer->color( Q::Needle );
|
||||
needleNode->setColor( color );
|
||||
|
||||
auto panelRadius = static_cast< float >( panelRect.width() / 2 );
|
||||
|
||||
auto needleWidth = speedometer->metric( Q::Needle | MinimumWidth );
|
||||
auto needleMargin = speedometer->metric( Q::Needle | Margin );
|
||||
const auto needleWidth = speedometer->metric( Q::Needle | Size );
|
||||
const auto needleMargin = speedometer->metric( Q::Needle | Margin );
|
||||
|
||||
float xStart = center.x();
|
||||
float yStart = center.y();
|
||||
const float xStart = center.x();
|
||||
const float yStart = center.y();
|
||||
|
||||
float angle = speedometer->value();
|
||||
qreal cosine = qCos( qDegreesToRadians( angle ) );
|
||||
qreal sine = qSin( qDegreesToRadians( angle ) );
|
||||
const float angle = speedometer->value();
|
||||
const qreal cosine = qCos( qDegreesToRadians( angle ) );
|
||||
const qreal sine = qSin( qDegreesToRadians( angle ) );
|
||||
|
||||
float needleRadius = panelRadius - needleMargin;
|
||||
float xEnd = center.x() + needleRadius * cosine;
|
||||
float yEnd = center.y() + needleRadius * sine;
|
||||
const float needleRadius = panelRadius - needleMargin;
|
||||
const float xEnd = center.x() + needleRadius * cosine;
|
||||
const float yEnd = center.y() + needleRadius * sine;
|
||||
|
||||
auto geometry = needleNode->geometry();
|
||||
geometry->allocate( 2 );
|
||||
|
|
|
@ -135,14 +135,10 @@ class MySkin : public QskSkin
|
|||
setBoxBorderColors( Q::Cursor, QColor( foregroundColor ).darker( 120 ) );
|
||||
setBoxBorderMetrics( Q::Cursor, 1 );
|
||||
|
||||
for( auto subControl : { Q::Panel, Q::Cursor } )
|
||||
{
|
||||
setMetric( subControl | MinimumWidth, width );
|
||||
setMetric( subControl | MinimumHeight, height );
|
||||
//setPadding( subControl, +2 );
|
||||
setStrutSize( Q::Panel, width, height );
|
||||
|
||||
setBoxShape( subControl, radius );
|
||||
}
|
||||
setBoxShape( Q::Panel, radius );
|
||||
setBoxShape( Q::Cursor, radius );
|
||||
|
||||
setPadding( Q::CheckedPanel, 10 );
|
||||
setPadding( Q::UncheckedPanel, 10 );
|
||||
|
|
|
@ -200,8 +200,7 @@ QSizeF MyToggleButton::contentsSizeHint(
|
|||
}
|
||||
else
|
||||
{
|
||||
hint.rwidth() = metric( Panel | QskAspect::MinimumWidth );
|
||||
hint.rheight() = metric( Panel | QskAspect::MinimumHeight );
|
||||
hint = strutSizeHint( Panel );
|
||||
}
|
||||
|
||||
return hint;
|
||||
|
|
|
@ -321,9 +321,7 @@ void QskMaterialSkin::initPushButtonHints()
|
|||
|
||||
const auto& pal = m_data->palette;
|
||||
|
||||
setMetric( Q::Panel | MinimumWidth, qskDpiScaled( 75.0 ) );
|
||||
setMetric( Q::Panel | MinimumHeight, qskDpiScaled( 23.0 ) );
|
||||
|
||||
setStrutSize( Q::Panel, qskDpiScaled( 75.0 ), qskDpiScaled( 23.0 ) );
|
||||
setSpacing( Q::Panel, 4 );
|
||||
|
||||
const QskMargins margin( 4, 3 );
|
||||
|
@ -382,9 +380,8 @@ void QskMaterialSkin::initDialogButtonHints()
|
|||
|
||||
const auto& pal = m_data->palette;
|
||||
|
||||
setMetric( Q::Panel | MinimumWidth, 30 );
|
||||
setMetric( Q::Panel | MinimumHeight, 16 );
|
||||
setMetric( Q::Panel | Spacing, 4 );
|
||||
setStrutSize( Q::Panel, 30, 16 );
|
||||
setSpacing( Q::Panel, 4 );
|
||||
|
||||
setMargin( Q::Panel, QskMargins( 4, 3 ) );
|
||||
setPadding( Q::Panel, QskMargins( 10, 6 ) );
|
||||
|
@ -515,8 +512,7 @@ void QskMaterialSkin::initTabButtonHints()
|
|||
|
||||
const auto& pal = m_data->palette;
|
||||
|
||||
setMetric( Q::Panel | MinimumWidth, 30 );
|
||||
setMetric( Q::Panel | MinimumHeight, 16 );
|
||||
setStrutSize( Q::Panel, 30, 16 );
|
||||
|
||||
for ( const auto placement : { Left, Right, Top, Bottom } )
|
||||
{
|
||||
|
@ -662,8 +658,9 @@ void QskMaterialSkin::initScrollViewHints()
|
|||
setPadding( subControl, 0 );
|
||||
}
|
||||
|
||||
setMetric( Q::HorizontalScrollHandle | MinimumWidth, qskDpiScaled( 40.0 ) );
|
||||
setMetric( Q::VerticalScrollHandle | MinimumHeight, qskDpiScaled( 40.0 ) );
|
||||
const auto handleExtent = qskDpiScaled( 40.0 );
|
||||
setStrutSize( Q::HorizontalScrollHandle, handleExtent, 0.0 );
|
||||
setStrutSize( Q::VerticalScrollHandle, 0.0, handleExtent );
|
||||
|
||||
for ( auto subControl : { Q::HorizontalScrollHandle, Q::VerticalScrollHandle } )
|
||||
{
|
||||
|
@ -689,7 +686,6 @@ void QskMaterialSkin::initScrollViewHints()
|
|||
|
||||
void QskMaterialSkin::initListViewHints()
|
||||
{
|
||||
using namespace QskAspect;
|
||||
using Q = QskListView;
|
||||
|
||||
const auto& pal = m_data->palette;
|
||||
|
|
|
@ -418,8 +418,7 @@ void QskSquiekSkin::initPushButtonHints()
|
|||
|
||||
// Panel
|
||||
|
||||
setMetric( Q::Panel | MinimumWidth, qskDpiScaled( 75.0 ) );
|
||||
setMetric( Q::Panel | MinimumHeight, qskDpiScaled( 23.0 ) );
|
||||
setStrutSize( Q::Panel, qskDpiScaled( 75.0 ), qskDpiScaled( 23.0 ) );
|
||||
|
||||
setMargin( Q::Panel, 0 );
|
||||
setPadding( Q::Panel, 10 );
|
||||
|
@ -459,8 +458,7 @@ void QskSquiekSkin::initDialogButtonHints()
|
|||
const auto& pal = m_data->palette;
|
||||
|
||||
// panel
|
||||
setMetric( Q::Panel | MinimumWidth, qskDpiScaled( 75.0 ) );
|
||||
setMetric( Q::Panel | MinimumHeight, qskDpiScaled( 23.0 ) );
|
||||
setStrutSize( Q::Panel, qskDpiScaled( 75.0 ), qskDpiScaled( 23.0 ) );
|
||||
|
||||
setPadding( Q::Panel, 10 );
|
||||
setMetric( Q::Panel | Spacing, 4 );
|
||||
|
@ -498,8 +496,7 @@ void QskSquiekSkin::initTabButtonHints()
|
|||
|
||||
const auto& pal = m_data->palette;
|
||||
|
||||
setMetric( Q::Panel | MinimumWidth, 30 );
|
||||
setMetric( Q::Panel | MinimumHeight, 16 );
|
||||
setStrutSize( Q::Panel, 30, 16 );
|
||||
|
||||
for ( auto placement : { Top, Bottom } )
|
||||
{
|
||||
|
@ -719,7 +716,8 @@ void QskSquiekSkin::initInputPredictionBar()
|
|||
|
||||
setButton( Q::ButtonPanel, Flat );
|
||||
setButton( Q::ButtonPanel | QskPushButton::Pressed, Sunken );
|
||||
setMetric( Q::ButtonPanel | MinimumWidth, qskDpiScaled( 30.0 ) );
|
||||
|
||||
setStrutSize( Q::ButtonPanel, qskDpiScaled( 30.0 ), qskDpiScaled( 10.0 ) );
|
||||
|
||||
setColor( Q::ButtonText, pal.themeForeground );
|
||||
setColor( Q::ButtonText | QskPushButton::Disabled, pal.darker200 );
|
||||
|
@ -779,15 +777,16 @@ void QskSquiekSkin::initScrollViewHints()
|
|||
|
||||
setButton( subControl, Raised, bw );
|
||||
|
||||
// placement ???
|
||||
const auto extent = qskDpiScaled( 40.0 );
|
||||
|
||||
if ( subControl == Q::HorizontalScrollHandle )
|
||||
{
|
||||
setMetric( subControl | MinimumWidth, qskDpiScaled( 40.0 ) );
|
||||
setStrutSize( subControl, extent, 0.0 );
|
||||
setButton( subControl | Q::HorizontalHandlePressed, Sunken, bw );
|
||||
}
|
||||
else
|
||||
{
|
||||
setMetric( subControl | MinimumHeight, qskDpiScaled( 40.0 ) );
|
||||
setStrutSize( subControl, 0.0, extent );
|
||||
setButton( subControl | Q::VerticalHandlePressed, Sunken, bw );
|
||||
}
|
||||
|
||||
|
@ -841,8 +840,8 @@ void QskSquiekSkin::initSubWindowHints()
|
|||
|
||||
setGradient( Q::TitleBar | Q::Focused, pal.highlighted );
|
||||
setGradient( Q::TitleBar, pal.contrasted );
|
||||
setMetric( Q::TitleBar | Spacing, 5 );
|
||||
setMetric( Q::TitleBar | MinimumHeight, 20 );
|
||||
setSpacing( Q::TitleBar, 5 );
|
||||
setStrutSize( Q::TitleBar, 0, 20 );
|
||||
setBoxShape( Q::TitleBar, radius, radius, 0, 0, Qt::AbsoluteSize );
|
||||
|
||||
// TitleBarText
|
||||
|
|
|
@ -69,12 +69,10 @@ QSK_NAMESPACE( QskAspect )
|
|||
{
|
||||
NoMetricPrimitive,
|
||||
|
||||
StrutSize,
|
||||
|
||||
Size,
|
||||
Position,
|
||||
MinimumWidth,
|
||||
MinimumHeight,
|
||||
MaximumWidth,
|
||||
MaximumHeight,
|
||||
|
||||
Margin,
|
||||
Padding,
|
||||
|
|
|
@ -97,11 +97,7 @@ QSizeF QskBox::contentsSizeHint(
|
|||
Qt::SizeHint which, const QSizeF& constraint ) const
|
||||
{
|
||||
if ( m_hasPanel && which == Qt::PreferredSize )
|
||||
{
|
||||
return QSizeF(
|
||||
metric( Panel | QskAspect::MinimumWidth ),
|
||||
metric( Panel | QskAspect::MinimumHeight ) );
|
||||
}
|
||||
return strutSizeHint( Panel );
|
||||
|
||||
return Inherited::contentsSizeHint( which, constraint );
|
||||
}
|
||||
|
|
|
@ -103,11 +103,9 @@ QSizeF QskPageIndicator::contentsSizeHint(
|
|||
if ( which != Qt::PreferredSize )
|
||||
return QSizeF();
|
||||
|
||||
using namespace QskAspect;
|
||||
|
||||
const qreal sizeBullet = metric( Bullet | Size );
|
||||
const qreal sizeCurrent = metric( Highlighted | Size );
|
||||
const qreal spacing = metric( Panel | Spacing );
|
||||
const qreal sizeBullet = metric( Bullet | QskAspect::Size );
|
||||
const qreal sizeCurrent = metric( Highlighted | QskAspect::Size );
|
||||
const qreal spacing = spacingHint( Panel );
|
||||
|
||||
const int n = m_data->count;
|
||||
|
||||
|
@ -139,11 +137,8 @@ QSizeF QskPageIndicator::contentsSizeHint(
|
|||
w = qMax( sizeCurrent, sizeBullet );
|
||||
}
|
||||
|
||||
const QSizeF minSize(
|
||||
metric( Panel | MinimumWidth ),
|
||||
metric( Panel | MinimumHeight ) );
|
||||
|
||||
return outerBoxSize( Panel, QSizeF( w, h ) ).expandedTo( minSize );
|
||||
const auto hint = outerBoxSize( Panel, QSizeF( w, h ) );
|
||||
return hint.expandedTo( strutSizeHint( Panel ) );
|
||||
}
|
||||
|
||||
#include "moc_QskPageIndicator.cpp"
|
||||
|
|
|
@ -290,10 +290,7 @@ QSizeF QskPushButton::contentsSizeHint( Qt::SizeHint which, const QSizeF& ) cons
|
|||
size.rwidth() = qMax( size.width(), w );
|
||||
}
|
||||
|
||||
const QSizeF minSize( metric( Panel | QskAspect::MinimumWidth ),
|
||||
metric( Panel | QskAspect::MinimumHeight ) );
|
||||
|
||||
size = size.expandedTo( minSize );
|
||||
size = size.expandedTo( strutSizeHint( Panel ) );
|
||||
size = outerBoxSize( Panel, size );
|
||||
|
||||
return size;
|
||||
|
|
|
@ -229,9 +229,9 @@ QRectF QskScrollViewSkinlet::scrollHandleRect( const QskScrollView* scrollView,
|
|||
if ( !( orientation & scrollOrientations ) )
|
||||
return QRectF();
|
||||
|
||||
const QPointF pos = scrollView->scrollPos();
|
||||
const auto pos = scrollView->scrollPos();
|
||||
|
||||
const QRectF vRect = subControlRect(
|
||||
const auto vRect = subControlRect(
|
||||
scrollView, contentsRect, QskScrollView::Viewport );
|
||||
|
||||
QRectF handleRect;
|
||||
|
@ -248,11 +248,10 @@ QRectF QskScrollViewSkinlet::scrollHandleRect( const QskScrollView* scrollView,
|
|||
const qreal y1 = pos.y() / h;
|
||||
const qreal y2 = ( pos.y() + vRect.height() ) / h;
|
||||
|
||||
const qreal minHandleLength =
|
||||
scrollView->metric( Q::VerticalScrollHandle | MinimumHeight );
|
||||
const auto strut = scrollView->strutSizeHint( Q::VerticalScrollHandle );
|
||||
|
||||
qreal top, bottom;
|
||||
qskAlignedHandle( y1, y2, sbRect.height(), minHandleLength, top, bottom );
|
||||
qskAlignedHandle( y1, y2, sbRect.height(), strut.height(), top, bottom );
|
||||
|
||||
handleRect = sbRect;
|
||||
handleRect.setTop( sbRect.y() + top );
|
||||
|
@ -271,11 +270,10 @@ QRectF QskScrollViewSkinlet::scrollHandleRect( const QskScrollView* scrollView,
|
|||
const qreal x1 = pos.x() / w;
|
||||
const qreal x2 = ( pos.x() + vRect.width() ) / w;
|
||||
|
||||
const qreal minHandleLength =
|
||||
scrollView->metric( Q::HorizontalScrollHandle | MinimumWidth );
|
||||
const auto strut = scrollView->strutSizeHint( Q::HorizontalScrollHandle );
|
||||
|
||||
qreal left, right;
|
||||
qskAlignedHandle( x1, x2, sbRect.width(), minHandleLength, left, right );
|
||||
qskAlignedHandle( x1, x2, sbRect.width(), strut.width(), left, right );
|
||||
|
||||
handleRect = sbRect;
|
||||
handleRect.setLeft( sbRect.x() + left );
|
||||
|
|
|
@ -195,6 +195,21 @@ qreal QskSkin::metric( QskAspect::Aspect aspect ) const
|
|||
return m_data->hintTable.metric( aspect );
|
||||
}
|
||||
|
||||
void QskSkin::setStrutSize( QskAspect::Aspect aspect, qreal width, qreal height )
|
||||
{
|
||||
setStrutSize( aspect, QSizeF( width, height ) );
|
||||
}
|
||||
|
||||
void QskSkin::setStrutSize( QskAspect::Aspect aspect, const QSizeF& strut )
|
||||
{
|
||||
m_data->hintTable.setStrutSize( aspect, strut );
|
||||
}
|
||||
|
||||
QSizeF QskSkin::strutSize( QskAspect::Aspect aspect ) const
|
||||
{
|
||||
return m_data->hintTable.strutSize( aspect );
|
||||
}
|
||||
|
||||
void QskSkin::setMargin( QskAspect::Aspect aspect, const QskMargins& margins )
|
||||
{
|
||||
m_data->hintTable.setMargin( aspect, margins );
|
||||
|
|
|
@ -70,6 +70,10 @@ class QSK_EXPORT QskSkin : public QObject
|
|||
void setMetric( QskAspect::Aspect, qreal metric );
|
||||
qreal metric( QskAspect::Aspect ) const;
|
||||
|
||||
void setStrutSize( QskAspect::Aspect, const QSizeF& );
|
||||
void setStrutSize( QskAspect::Aspect, qreal width, qreal height );
|
||||
QSizeF strutSize( QskAspect::Aspect ) const;
|
||||
|
||||
void setMargin( QskAspect::Aspect, const QskMargins& );
|
||||
QskMargins margin( QskAspect::Aspect ) const;
|
||||
|
||||
|
|
|
@ -39,6 +39,9 @@ class QSK_EXPORT QskSkinHintTable
|
|||
void setMetric( QskAspect::Aspect, qreal metric );
|
||||
qreal metric( QskAspect::Aspect ) const;
|
||||
|
||||
void setStrutSize( QskAspect::Aspect, const QSizeF& );
|
||||
QSizeF strutSize( QskAspect::Aspect ) const;
|
||||
|
||||
void setMargin( QskAspect::Aspect, const QskMargins& );
|
||||
QskMargins margin( QskAspect::Aspect ) const;
|
||||
|
||||
|
@ -175,6 +178,19 @@ inline qreal QskSkinHintTable::metric( QskAspect::Aspect aspect ) const
|
|||
return hint( aspect | QskAspect::Metric ).toReal();
|
||||
}
|
||||
|
||||
inline void QskSkinHintTable::setStrutSize(
|
||||
QskAspect::Aspect aspect, const QSizeF& size )
|
||||
{
|
||||
const auto aspectStrut = aspect | QskAspect::Metric | QskAspect::StrutSize;
|
||||
setHint( aspectStrut, QVariant::fromValue( size ) );
|
||||
}
|
||||
|
||||
inline QSizeF QskSkinHintTable::strutSize( QskAspect::Aspect aspect ) const
|
||||
{
|
||||
const auto aspectStrut = aspect | QskAspect::Metric | QskAspect::StrutSize;
|
||||
return hint( aspectStrut ).value< QSizeF >();
|
||||
}
|
||||
|
||||
inline void QskSkinHintTable::setMargin(
|
||||
QskAspect::Aspect aspect, const QskMargins& margins )
|
||||
{
|
||||
|
|
|
@ -246,6 +246,24 @@ qreal QskSkinnable::metric( QskAspect::Aspect aspect, QskSkinHintStatus* status
|
|||
return effectiveHint( aspect | QskAspect::Metric, status ).toReal();
|
||||
}
|
||||
|
||||
void QskSkinnable::setStrutSizeHint(
|
||||
QskAspect::Aspect aspect, qreal width, qreal height )
|
||||
{
|
||||
setStrutSizeHint( aspect, QSizeF( width, height ) );
|
||||
}
|
||||
|
||||
void QskSkinnable::setStrutSizeHint( const QskAspect::Aspect aspect, const QSizeF& strut )
|
||||
{
|
||||
m_data->hintTable.setStrutSize( aspect, strut );
|
||||
}
|
||||
|
||||
QSizeF QskSkinnable::strutSizeHint(
|
||||
const QskAspect::Aspect aspect, QskSkinHintStatus* status ) const
|
||||
{
|
||||
const auto asp = aspect | QskAspect::Metric | QskAspect::StrutSize;
|
||||
return effectiveHint( asp, status ).value< QSizeF >();
|
||||
}
|
||||
|
||||
void QskSkinnable::setMarginHint( QskAspect::Aspect aspect, qreal margins )
|
||||
{
|
||||
m_data->hintTable.setMargin( aspect, QskMargins( margins ) );
|
||||
|
|
|
@ -91,6 +91,10 @@ class QSK_EXPORT QskSkinnable
|
|||
int flagHint( QskAspect::Aspect ) const;
|
||||
template< typename T > T flagHint( QskAspect::Aspect, T = T() ) const;
|
||||
|
||||
QSizeF strutSizeHint( QskAspect::Aspect, QskSkinHintStatus* = nullptr ) const;
|
||||
void setStrutSizeHint( QskAspect::Aspect, const QSizeF& );
|
||||
void setStrutSizeHint( QskAspect::Aspect, qreal width, qreal height );
|
||||
|
||||
void setMarginHint( QskAspect::Aspect, qreal );
|
||||
void setMarginHint( QskAspect::Aspect, const QMarginsF& );
|
||||
bool resetMarginHint( QskAspect::Aspect );
|
||||
|
|
|
@ -23,7 +23,9 @@ QskSliderSkinlet::QskSliderSkinlet( QskSkin* skin )
|
|||
setNodeRoles( { PanelRole, GrooveRole, FillRole, HandleRole } );
|
||||
}
|
||||
|
||||
QskSliderSkinlet::~QskSliderSkinlet() = default;
|
||||
QskSliderSkinlet::~QskSliderSkinlet()
|
||||
{
|
||||
}
|
||||
|
||||
QRectF QskSliderSkinlet::subControlRect( const QskSkinnable* skinnable,
|
||||
const QRectF& contentsRect, QskAspect::Subcontrol subControl ) const
|
||||
|
@ -92,32 +94,12 @@ QSGNode* QskSliderSkinlet::updateSubNode(
|
|||
QRectF QskSliderSkinlet::panelRect(
|
||||
const QskSlider* slider, const QRectF& contentsRect ) const
|
||||
{
|
||||
using namespace QskAspect;
|
||||
|
||||
const auto subControl = QskSlider::Panel;
|
||||
|
||||
qreal size = slider->metric( subControl | Size ); // 0: no hint
|
||||
|
||||
{
|
||||
/*
|
||||
We use MinimumHeight/MaximumHeight/Size for the "thickness" of
|
||||
to slider even if "Height" is not the expected value for
|
||||
vertical sliders. Maybe we should have the orientation as an aspect bit ?
|
||||
*/
|
||||
|
||||
const qreal minSize = slider->metric( subControl | MinimumHeight );
|
||||
const qreal maxSize = slider->metric( subControl | MaximumHeight );
|
||||
|
||||
size = qMax( size, minSize );
|
||||
if ( maxSize > minSize )
|
||||
size = qMin( size, maxSize );
|
||||
}
|
||||
|
||||
QRectF r = contentsRect;
|
||||
auto r = contentsRect;
|
||||
|
||||
const qreal size = slider->metric( QskSlider::Panel | QskAspect::Size ); // 0: no hint
|
||||
if ( size > 0 && size < r.height() )
|
||||
{
|
||||
const auto alignment = slider->alignmentHint( subControl );
|
||||
const auto alignment = slider->alignmentHint( QskSlider::Panel );
|
||||
|
||||
if ( slider->orientation() == Qt::Horizontal )
|
||||
r = qskAlignedRectF( r, r.width(), size, alignment & Qt::AlignVertical_Mask );
|
||||
|
@ -173,13 +155,15 @@ QRectF QskSliderSkinlet::scaleRect(
|
|||
QRectF QskSliderSkinlet::fillRect(
|
||||
const QskSlider* slider, const QRectF& contentsRect ) const
|
||||
{
|
||||
auto r = subControlRect( slider, contentsRect, QskSlider::Panel );
|
||||
r = r.marginsRemoved( qskPadding( slider, QskSlider::Panel ) );
|
||||
using Q = QskSlider;
|
||||
|
||||
qreal pos = slider->metric( QskSlider::Handle | QskAspect::Position );
|
||||
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, QskSlider::Fill );
|
||||
auto fillRect = innerRect( slider, contentsRect, Q::Fill );
|
||||
if ( slider->orientation() == Qt::Horizontal )
|
||||
{
|
||||
fillRect.setLeft( r.left() );
|
||||
|
@ -197,7 +181,6 @@ QRectF QskSliderSkinlet::fillRect(
|
|||
QRectF QskSliderSkinlet::handleRect(
|
||||
const QskSlider* slider, const QRectF& contentsRect ) const
|
||||
{
|
||||
using namespace QskAspect;
|
||||
using Q = QskSlider;
|
||||
|
||||
auto r = subControlRect( slider, contentsRect, Q::Panel );
|
||||
|
@ -210,7 +193,7 @@ QRectF QskSliderSkinlet::handleRect(
|
|||
{
|
||||
QskSkinHintStatus status;
|
||||
|
||||
extent = slider->metric( Q::Handle | Size, &status );
|
||||
extent = slider->metric( Q::Handle | QskAspect::Size, &status );
|
||||
if ( !status.isValid() )
|
||||
extent = isHorizontal ? r.height() : r.width();
|
||||
}
|
||||
|
@ -222,7 +205,7 @@ QRectF QskSliderSkinlet::handleRect(
|
|||
slider->marginHint( Q::Handle) );
|
||||
}
|
||||
|
||||
qreal pos = slider->metric( Q::Handle | Position );
|
||||
qreal pos = slider->metric( Q::Handle | QskAspect::Position );
|
||||
pos = qBound( 0.0, pos, 1.0 );
|
||||
|
||||
if ( slider->orientation() == Qt::Horizontal )
|
||||
|
|
|
@ -111,9 +111,9 @@ qreal QskSubWindowSkinlet::titleBarHeight( const QskSubWindow* subWindow ) const
|
|||
const QFontMetricsF fm( subWindow->effectiveFont( Q::TitleBarText ) );
|
||||
|
||||
const qreal height = fm.height() + margins.top() + margins.bottom();
|
||||
const qreal minHeight = subWindow->metric( Q::TitleBar | QskAspect::MinimumHeight );
|
||||
const auto strutSize = subWindow->strutSizeHint( Q::TitleBar );
|
||||
|
||||
return qMax( height, minHeight );
|
||||
return qMax( height, strutSize.height() );
|
||||
}
|
||||
|
||||
QRectF QskSubWindowSkinlet::symbolRect(
|
||||
|
|
|
@ -93,14 +93,12 @@ QSizeF QskTabButton::contentsSizeHint(
|
|||
if ( which != Qt::PreferredSize )
|
||||
return QSizeF();
|
||||
|
||||
QSizeF size( metric( Panel | QskAspect::MinimumWidth ),
|
||||
metric( Panel | QskAspect::MinimumHeight ) );
|
||||
auto size = strutSizeHint( Panel );
|
||||
|
||||
if ( !m_data->text.isEmpty() )
|
||||
{
|
||||
const QFontMetricsF fm( effectiveFont( Text ) );
|
||||
const auto textSize = fm.size( Qt::TextShowMnemonic, m_data->text );
|
||||
size += textSize;
|
||||
size += fm.size( Qt::TextShowMnemonic, m_data->text );
|
||||
}
|
||||
|
||||
return size;
|
||||
|
|
|
@ -463,10 +463,8 @@ QSizeF QskTextInput::contentsSizeHint( Qt::SizeHint which, const QSizeF& ) const
|
|||
const qreal w = input->implicitWidth();
|
||||
const qreal h = input->implicitHeight();
|
||||
|
||||
const QSizeF minSize( metric( Panel | QskAspect::MinimumWidth ),
|
||||
metric( Panel | QskAspect::MinimumHeight ) );
|
||||
|
||||
return outerBoxSize( Panel, QSizeF( w, h ) ).expandedTo( minSize );
|
||||
const auto hint = outerBoxSize( Panel, QSizeF( w, h ) );
|
||||
return hint.expandedTo( strutSizeHint( Panel ) );
|
||||
}
|
||||
|
||||
void QskTextInput::updateLayout()
|
||||
|
|
|
@ -37,10 +37,7 @@ namespace
|
|||
|
||||
auto size = QFontMetricsF( font() ).size( Qt::TextSingleLine, text() );
|
||||
|
||||
const QSizeF minSize( metric( Panel | QskAspect::MinimumWidth ),
|
||||
metric( Panel | QskAspect::MinimumHeight ) );
|
||||
|
||||
size = size.expandedTo( minSize );
|
||||
size = size.expandedTo( strutSizeHint( Panel ) );
|
||||
size = outerBoxSize( Panel, size );
|
||||
|
||||
return size;
|
||||
|
|
Loading…
Reference in New Issue