tickmarks: support alignment
This commit is contained in:
parent
8a4f644034
commit
caf75721d4
@ -62,6 +62,7 @@ class QskScaleRenderer::PrivateData
|
||||
QskColorFilter colorFilter;
|
||||
|
||||
Qt::Orientation orientation = Qt::Horizontal;
|
||||
Qt::Alignment alignment = Qt::AlignBottom | Qt::AlignRight;
|
||||
};
|
||||
|
||||
QskScaleRenderer::QskScaleRenderer()
|
||||
@ -78,6 +79,11 @@ void QskScaleRenderer::setOrientation( Qt::Orientation orientation )
|
||||
m_data->orientation = orientation;
|
||||
}
|
||||
|
||||
void QskScaleRenderer::setAlignment( Qt::Alignment alignment )
|
||||
{
|
||||
m_data->alignment = alignment;
|
||||
}
|
||||
|
||||
void QskScaleRenderer::setBoundaries( const QskIntervalF& boundaries )
|
||||
{
|
||||
m_data->boundaries = boundaries;
|
||||
@ -169,7 +175,8 @@ QSGNode* QskScaleRenderer::updateTicksNode(
|
||||
ticksNode = new QskTickmarksNode;
|
||||
|
||||
ticksNode->update( m_data->tickColor, rect, m_data->boundaries,
|
||||
m_data->tickmarks, m_data->tickWidth, m_data->orientation );
|
||||
m_data->tickmarks, m_data->tickWidth, m_data->orientation,
|
||||
m_data->alignment );
|
||||
|
||||
return ticksNode;
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ class QSK_EXPORT QskScaleRenderer
|
||||
~QskScaleRenderer();
|
||||
|
||||
void setOrientation( Qt::Orientation );
|
||||
void setAlignment( Qt::Alignment );
|
||||
|
||||
void setBoundaries( const QskIntervalF& );
|
||||
void setTickmarks( const QskScaleTickmarks& );
|
||||
|
@ -12,7 +12,7 @@ QSK_QT_PRIVATE_END
|
||||
static constexpr inline qreal qskTickFactor( QskScaleTickmarks::TickType type )
|
||||
{
|
||||
using TM = QskScaleTickmarks;
|
||||
return type == TM::MinorTick ? 0.7 : ( type == TM::MinorTick ? 0.85 : 1.0 );
|
||||
return type == TM::MinorTick ? 0.7 : ( type == TM::MediumTick ? 0.85 : 1.0 );
|
||||
}
|
||||
|
||||
class QskTickmarksNodePrivate final : public QSGGeometryNodePrivate
|
||||
@ -53,7 +53,7 @@ QskTickmarksNode::~QskTickmarksNode()
|
||||
void QskTickmarksNode::update(
|
||||
const QColor& color, const QRectF& rect,
|
||||
const QskIntervalF& boundaries, const QskScaleTickmarks& tickmarks,
|
||||
int lineWidth, Qt::Orientation orientation )
|
||||
int lineWidth, Qt::Orientation orientation, Qt::Alignment alignment )
|
||||
{
|
||||
Q_D( QskTickmarksNode );
|
||||
|
||||
@ -94,8 +94,27 @@ void QskTickmarksNode::update(
|
||||
{
|
||||
const auto x = rect.x() + ( tick - min ) * ratio;
|
||||
|
||||
vertexData[ 0 ].set( x, rect.bottom() );
|
||||
vertexData[ 1 ].set( x, rect.bottom() - len );
|
||||
qreal y1, y2;
|
||||
|
||||
if( alignment & Qt::AlignTop )
|
||||
{
|
||||
y1 = rect.top() + len;
|
||||
y2 = rect.top();
|
||||
}
|
||||
else if( alignment & Qt::AlignVCenter )
|
||||
{
|
||||
const auto offset = ( rect.height() - len ) / 2;
|
||||
y1 = rect.bottom() - offset;
|
||||
y2 = rect.top() + offset;
|
||||
}
|
||||
else // Bottom (default)
|
||||
{
|
||||
y1 = rect.bottom();
|
||||
y2 = rect.bottom() - len;
|
||||
}
|
||||
|
||||
vertexData[ 0 ].set( x, y1 );
|
||||
vertexData[ 1 ].set( x, y2 );
|
||||
vertexData += 2;
|
||||
}
|
||||
}
|
||||
@ -108,8 +127,27 @@ void QskTickmarksNode::update(
|
||||
{
|
||||
const auto y = rect.bottom() - ( tick - min ) * ratio;
|
||||
|
||||
vertexData[ 0 ].set( rect.right(), y );
|
||||
vertexData[ 1 ].set( rect.right() - len, y );
|
||||
qreal x1, x2;
|
||||
|
||||
if( alignment & Qt::AlignLeft )
|
||||
{
|
||||
x1 = rect.left() + len;
|
||||
x2 = rect.left();
|
||||
}
|
||||
else if( alignment & Qt::AlignHCenter )
|
||||
{
|
||||
const auto offset = ( rect.width() - len ) / 2;
|
||||
x1 = rect.right() - offset;
|
||||
x2 = rect.left() + offset;
|
||||
}
|
||||
else // Right (default)
|
||||
{
|
||||
x1 = rect.right();
|
||||
x2 = rect.right() - len;
|
||||
}
|
||||
|
||||
vertexData[ 0 ].set( x1, y );
|
||||
vertexData[ 1 ].set( x2, y );
|
||||
vertexData += 2;
|
||||
}
|
||||
}
|
||||
|
@ -24,8 +24,9 @@ class QSK_EXPORT QskTickmarksNode : public QSGGeometryNode
|
||||
QskTickmarksNode();
|
||||
~QskTickmarksNode() override;
|
||||
|
||||
void update( const QColor&, const QRectF&, const QskIntervalF&,
|
||||
const QskScaleTickmarks&, int tickLineWidth, Qt::Orientation );
|
||||
void update(const QColor&, const QRectF&, const QskIntervalF&,
|
||||
const QskScaleTickmarks&, int tickLineWidth, Qt::Orientation,
|
||||
Qt::Alignment );
|
||||
|
||||
private:
|
||||
Q_DECLARE_PRIVATE( QskTickmarksNode )
|
||||
|
Loading…
x
Reference in New Issue
Block a user