6#include "QskPushButton.h"
7#include "QskAnimationHint.h"
9#include "QskBoxShapeMetrics.h"
10#include "QskGraphic.h"
11#include "QskGraphicProvider.h"
12#include "QskSkinManager.h"
14#include "QskSkinlet.h"
15#include "QskTextOptions.h"
23class QskPushButton::PrivateData
26 PrivateData(
const QString& txt )
28 , isCheckable( false )
29 , isIconSourceDirty( false )
30 , emphasis( NoEmphasis )
36 if ( isIconSourceDirty )
38 if ( !iconSource.isEmpty() )
39 icon = button->loadIcon( iconSource );
41 isIconSourceDirty =
false;
51 bool isIconSourceDirty : 1;
55QskPushButton::QskPushButton( QQuickItem* parent )
60QskPushButton::QskPushButton(
const QString& text, QQuickItem* parent )
62 , m_data( new PrivateData( text ) )
64 initSizePolicy( QskSizePolicy::Minimum, QskSizePolicy::Fixed );
67QskPushButton::~QskPushButton()
71void QskPushButton::setCheckable(
bool on )
73 if ( on != m_data->isCheckable )
75 m_data->isCheckable = on;
76 Q_EMIT checkableChanged( on );
80bool QskPushButton::isCheckable()
const
82 return m_data->isCheckable;
85void QskPushButton::setEmphasis( Emphasis emphasis )
87 if ( emphasis != m_data->emphasis )
89 m_data->emphasis = emphasis;
94 Q_EMIT emphasisChanged( emphasis );
98QskPushButton::Emphasis QskPushButton::emphasis()
const
100 return static_cast< Emphasis
>( m_data->emphasis );
106 Q_EMIT shapeChanged();
109void QskPushButton::resetShape()
112 Q_EMIT shapeChanged();
120void QskPushButton::setText(
const QString& text )
122 if ( text != m_data->text )
129 Q_EMIT textChanged();
133QString QskPushButton::text()
const
138void QskPushButton::setTextOptions(
const QskTextOptions& textOptions )
140 if ( setTextOptionsHint( Text, textOptions ) )
141 Q_EMIT textOptionsChanged();
146 return textOptionsHint( Text );
149void QskPushButton::resetTextOptions()
151 if ( resetTextOptionsHint( Text ) )
152 Q_EMIT textOptionsChanged();
155QFont QskPushButton::font()
const
160void QskPushButton::resetIconStrutSize()
163 Q_EMIT iconStrutSizeChanged();
166void QskPushButton::setIconStrutSize(
const QSizeF& size )
169 if ( newSize.width() < 0.0 )
170 newSize.setWidth( -1.0 );
172 if ( newSize.height() < 0.0 )
173 newSize.setHeight( -1.0 );
176 Q_EMIT iconStrutSizeChanged();
179QSizeF QskPushButton::iconStrutSize()
const
184void QskPushButton::setIconSource(
const QUrl& url )
186 if ( m_data->iconSource == url )
189 m_data->iconSource = url;
190 m_data->icon.reset();
192 m_data->isIconSourceDirty =
true;
198 Q_EMIT iconSourceChanged();
201void QskPushButton::setIconSource(
const QString& source )
203 setIconSource( QUrl( source ) );
206QUrl QskPushButton::iconSource()
const
208 return m_data->iconSource;
211void QskPushButton::setIcon(
const QskGraphic& icon )
213 if ( icon != m_data->icon )
217 if ( !m_data->iconSource.isEmpty() )
219 m_data->iconSource = QString();
220 m_data->isIconSourceDirty =
false;
222 Q_EMIT iconSourceChanged();
225 Q_EMIT iconChanged();
235 m_data->ensureIcon(
this );
239bool QskPushButton::hasIcon()
const
241 return !( icon().isEmpty() && iconSource().isEmpty() );
244void QskPushButton::updateResources()
246 m_data->ensureIcon(
this );
251 switch( m_data->emphasis )
253 case VeryLowEmphasis:
254 return QskAspect::Tiny;
257 return QskAspect::Small;
260 return QskAspect::Large;
262 case VeryHighEmphasis:
263 return QskAspect::Huge;
277 switch ( event->type() )
279 case QEvent::StyleChange:
281 if ( !m_data->iconSource.isEmpty() &&
282 qskSkinManager->skin()->hasGraphicProvider() )
285 m_data->isIconSourceDirty =
true;
289 case QEvent::LocaleChange:
291 if ( !m_data->text.isEmpty() )
306void QskPushButton::mousePressEvent( QMouseEvent* event )
308 Inherited::mousePressEvent( event );
316 setPositionHint( Splash, qskMousePosition( event ).x() );
317 startTransition( Splash | A::Metric | A::Size, hint, 0.0, 1.0 );
321QskGraphic QskPushButton::loadIcon(
const QUrl& url )
const
323 return Qsk::loadGraphic( url );
326#include "moc_QskPushButton.cpp"
Lookup key for a QskSkinHintTable.
Variation
Some sort of variation.
QRectF subControlContentsRect(QskAspect::Subcontrol) const
A paint device for scalable graphics.
virtual void changeEvent(QEvent *)
bool setStrutSizeHint(QskAspect, const QSizeF &)
Sets a metric hint.
QFont effectiveFont(QskAspect) const
QSizeF strutSizeHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a strut size hint.
QskBoxShapeMetrics boxShapeHint(QskAspect, QskSkinHintStatus *=nullptr) const
Retrieves a shape hint.
QskAnimationHint animationHint(QskAspect, QskSkinHintStatus *=nullptr) const
bool setBoxShapeHint(QskAspect, const QskBoxShapeMetrics &)
Sets a shape hint.
bool resetStrutSizeHint(QskAspect)
Removes a strut size hint from the local table.
bool resetBoxShapeHint(QskAspect)
Removes a shape hint from the local table.