6#include "QskAbstractButton.h"
11#include <qbasictimer.h>
18 const auto parentItem = button->parentItem();
19 if ( parentItem ==
nullptr )
22 const auto siblings = parentItem->childItems();
23 for (
auto sibling : siblings )
25 if (
auto btn = qobject_cast< QskAbstractButton* >( sibling ) )
27 if ( btn != button && btn->exclusive() && btn->isChecked() )
35class QskAbstractButton::PrivateData
39 : autoRepeatDelay( 300 )
40 , autoRepeatInterval( 100 )
46 QBasicTimer repeatTimer;
49 int autoRepeatInterval;
55QskAbstractButton::QskAbstractButton( QQuickItem* parent )
57 , m_data( new PrivateData() )
59 setFocusPolicy( Qt::StrongFocus );
60 setAcceptedMouseButtons( Qt::LeftButton );
61 setAcceptHoverEvents(
true );
64QskAbstractButton::~QskAbstractButton()
68void QskAbstractButton::click()
74void QskAbstractButton::releaseButton()
85 setCheckedState( !hasSkinState( Checked ) );
92void QskAbstractButton::setCheckedState(
bool on )
97void QskAbstractButton::toggle()
99 setChecked( !isChecked() );
102bool QskAbstractButton::isPressed()
const
104 return hasSkinState( Pressed );
107void QskAbstractButton::setPressed(
bool on )
109 if ( on == isPressed() )
113 Q_EMIT pressedChanged( on );
120 if ( m_data->autoRepeat )
124 m_data->repeatTimer.start( m_data->autoRepeatDelay,
this );
128 m_data->repeatTimer.stop();
133bool QskAbstractButton::isCheckable()
const
138void QskAbstractButton::setChecked(
bool on )
140 if ( on == isChecked() )
143 if ( m_data->exclusive && !on )
149 auto checkedButton = qskCheckedSibling(
this );
155 checkedButton->setSkinStateFlag( Checked,
false );
159 Q_EMIT checkedChanged( on );
160 Q_EMIT toggled( on );
164 Q_EMIT checkedButton->checkedChanged(
false );
165 Q_EMIT checkedButton->toggled(
false );
169bool QskAbstractButton::isChecked()
const
171 return hasSkinState( Checked );
174void QskAbstractButton::setAutoRepeat(
bool on )
176 if ( on != m_data->autoRepeat )
178 m_data->autoRepeat = on;
180 if ( m_data->autoRepeat && isPressed() )
181 m_data->repeatTimer.start( m_data->autoRepeatDelay,
this );
183 m_data->repeatTimer.stop();
185 Q_EMIT autoRepeatChanged( on );
189bool QskAbstractButton::autoRepeat()
const
191 return m_data->autoRepeat;
194void QskAbstractButton::setAutoRepeatDelay(
int ms )
196 if ( ms != m_data->autoRepeatDelay )
198 m_data->autoRepeatDelay = ms;
199 Q_EMIT autoRepeatDelayChanged();
203int QskAbstractButton::autoRepeatDelay()
const
205 return m_data->autoRepeatDelay;
208void QskAbstractButton::setAutoRepeatInterval(
int ms )
210 if ( ms != m_data->autoRepeatInterval )
212 m_data->autoRepeatInterval = ms;
213 Q_EMIT autoRepeatIntervalChanged();
217int QskAbstractButton::autoRepeatInterval()
const
219 return m_data->autoRepeatInterval;
222void QskAbstractButton::setExclusive(
bool on )
224 if ( on != m_data->exclusive )
226 m_data->exclusive = on;
227 Q_EMIT exclusiveChanged( on );
231bool QskAbstractButton::exclusive()
const
233 return m_data->exclusive;
236bool QskAbstractButton::event( QEvent* event )
238 const auto eventType =
static_cast< int >(
event->type() );
241 case QEvent::Shortcut:
247 case QskEvent::WindowChange:
249 if ( qskIsItemComplete(
this ) && isPressed() )
262 return Inherited::event( event );
265void QskAbstractButton::keyPressEvent( QKeyEvent* event )
267 if ( qskIsButtonPressKey( event ) )
269 if ( !event->isAutoRepeat() )
276 Inherited::keyPressEvent( event );
279void QskAbstractButton::keyReleaseEvent( QKeyEvent* event )
281 if ( qskIsButtonPressKey( event ) )
287 Inherited::keyReleaseEvent( event );
290void QskAbstractButton::mouseMoveEvent( QMouseEvent* event )
294 if ( !contains( event->pos() ) )
302void QskAbstractButton::mousePressEvent( QMouseEvent* )
308void QskAbstractButton::mouseReleaseEvent( QMouseEvent* )
313void QskAbstractButton::mouseUngrabEvent()
322void QskAbstractButton::focusInEvent( QFocusEvent* event )
324 Inherited::focusInEvent( event );
327void QskAbstractButton::focusOutEvent( QFocusEvent* event )
335 Inherited::focusOutEvent( event );
338void QskAbstractButton::timerEvent( QTimerEvent* event )
340 if ( event->timerId() == m_data->repeatTimer.timerId() )
348 m_data->repeatTimer.start( m_data->autoRepeatInterval,
this );
352 m_data->repeatTimer.stop();
358 Inherited::timerEvent( event );
361#include "moc_QskAbstractButton.cpp"
Lookup key for a QskSkinHintTable.
void setSkinStateFlag(QskAspect::State, bool on=true)