6#include "QskTextLabel.h"
8#include "QskTextOptions.h"
9#include "QskFontRole.h"
14class QskTextLabel::PrivateData
17 PrivateData(
const QString& txt, QskTextOptions::TextFormat textFormat )
19 , effectiveTextFormat( textFormat )
26 mutable QskTextOptions::TextFormat effectiveTextFormat;
31QskTextLabel::QskTextLabel( QQuickItem* parent )
36QskTextLabel::QskTextLabel(
const QString& text, QQuickItem* parent )
38 , m_data( new PrivateData( text, textOptions().format() ) )
40 initSizePolicy( QskSizePolicy::Minimum, QskSizePolicy::Fixed );
43QskTextLabel::~QskTextLabel()
47void QskTextLabel::setPanel(
bool on )
49 if ( on == m_data->hasPanel )
52 m_data->hasPanel = on;
57 Q_EMIT panelChanged( on );
60bool QskTextLabel::hasPanel()
const
62 return m_data->hasPanel;
65void QskTextLabel::setText(
const QString& text )
67 if ( text == m_data->text )
71 m_data->effectiveTextFormat = textOptions().format();
76 Q_EMIT textChanged( text );
79QString QskTextLabel::text()
const
84void QskTextLabel::setTextOptions(
const QskTextOptions& textOptions )
86 if ( setTextOptionsHint( Text, textOptions ) )
91 const QskSizePolicy::Policy policy = ( options.wrapMode() == QTextOption::NoWrap )
97 m_data->effectiveTextFormat = textOptions.format();
98 Q_EMIT textOptionsChanged( textOptions );
104 return textOptionsHint( Text );
107void QskTextLabel::resetTextOptions()
109 if ( resetTextOptionsHint( Text ) )
110 Q_EMIT textOptionsChanged( textOptions() );
113void QskTextLabel::setTextFormat( QskTextOptions::TextFormat format )
115 auto options = textOptions();
116 options.setFormat( format );
118 setTextOptions( options );
121QskTextOptions::TextFormat QskTextLabel::textFormat()
const
123 return textOptions().format();
126QskTextOptions::TextFormat QskTextLabel::effectiveTextFormat()
const
128 const auto options = textOptions();
130 if ( options.format() != QskTextOptions::AutoText )
131 return options.format();
133 if ( m_data->effectiveTextFormat == QskTextOptions::AutoText )
134 m_data->effectiveTextFormat = options.effectiveFormat( m_data->text );
136 return m_data->effectiveTextFormat;
139void QskTextLabel::setWrapMode( QskTextOptions::WrapMode wrapMode )
141 auto options = textOptions();
142 options.setWrapMode( wrapMode );
144 setTextOptions( options );
147QskTextOptions::WrapMode QskTextLabel::wrapMode()
const
149 return textOptions().wrapMode();
152void QskTextLabel::setElideMode( Qt::TextElideMode elideMode )
154 auto options = textOptions();
155 options.setElideMode( elideMode );
157 setTextOptions( options );
160Qt::TextElideMode QskTextLabel::elideMode()
const
162 return textOptions().elideMode();
165void QskTextLabel::setFontRole(
const QskFontRole& role )
168 Q_EMIT fontRoleChanged( role );
171void QskTextLabel::resetFontRole()
182void QskTextLabel::setTextColor(
const QColor& color )
185 Q_EMIT textColorChanged(
color );
188void QskTextLabel::resetTextColor()
191 Q_EMIT textColorChanged(
color( Text ) );
194QColor QskTextLabel::textColor()
const
196 return color( Text );
199void QskTextLabel::setAlignment( Qt::Alignment alignment )
202 Q_EMIT alignmentChanged( alignment );
205void QskTextLabel::resetAlignment()
208 Q_EMIT alignmentChanged( alignment() );
211Qt::Alignment QskTextLabel::alignment()
const
216QFont QskTextLabel::font()
const
223 switch ( event->type() )
225 case QEvent::LocaleChange:
227 if ( !m_data->text.isEmpty() )
242#include "moc_QskTextLabel.cpp"
void setSizePolicy(QskSizePolicy)
virtual void changeEvent(QEvent *)
bool resetColor(QskAspect)
Removes a color hint from the local table.
bool setAlignmentHint(QskAspect, Qt::Alignment)
Sets an alignment hint.
bool resetFontRoleHint(QskAspect)
Removes a font role hint from the local table.
bool setColor(QskAspect, Qt::GlobalColor)
Sets a color hint.
QFont effectiveFont(QskAspect) const
bool setFontRoleHint(QskAspect, const QskFontRole &)
Sets a font role hint.
QskFontRole fontRoleHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a font role hint.
bool resetAlignmentHint(QskAspect)
Removes an alignment hint from the local table.
QColor color(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a color hint.
Qt::Alignment alignmentHint(QskAspect, Qt::Alignment=Qt::Alignment()) const
Retrieves an alignment hint.
void changeEvent(QEvent *) override