spin box hovering
This commit is contained in:
parent
b7c2b27691
commit
932d34aea8
@ -139,6 +139,8 @@ QskSpinBox::QskSpinBox( qreal min, qreal max, qreal stepSize, QQuickItem* parent
|
|||||||
setBoundaries( min, max );
|
setBoundaries( min, max );
|
||||||
setStepSize( stepSize );
|
setStepSize( stepSize );
|
||||||
|
|
||||||
|
setAcceptHoverEvents( true );
|
||||||
|
|
||||||
setAcceptedMouseButtons( Qt::LeftButton );
|
setAcceptedMouseButtons( Qt::LeftButton );
|
||||||
setFocusPolicy( Qt::StrongFocus );
|
setFocusPolicy( Qt::StrongFocus );
|
||||||
|
|
||||||
@ -302,6 +304,12 @@ void QskSpinBox::mouseUngrabEvent()
|
|||||||
m_data->setAutoRepeat( this, 0.0 );
|
m_data->setAutoRepeat( this, 0.0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QskSpinBox::hoverMoveEvent( QHoverEvent* event )
|
||||||
|
{
|
||||||
|
Inherited::hoverMoveEvent( event );
|
||||||
|
update(); // enter/leaving a subcontrol
|
||||||
|
}
|
||||||
|
|
||||||
void QskSpinBox::keyPressEvent( QKeyEvent* event )
|
void QskSpinBox::keyPressEvent( QKeyEvent* event )
|
||||||
{
|
{
|
||||||
if ( !isReadOnly() && !m_data->repeatTimer.isActive() )
|
if ( !isReadOnly() && !m_data->repeatTimer.isActive() )
|
||||||
|
@ -75,6 +75,8 @@ class QSK_EXPORT QskSpinBox : public QskBoundedValueInput
|
|||||||
void mousePressEvent( QMouseEvent* ) override;
|
void mousePressEvent( QMouseEvent* ) override;
|
||||||
void mouseUngrabEvent() override;
|
void mouseUngrabEvent() override;
|
||||||
|
|
||||||
|
void hoverMoveEvent( QHoverEvent* ) override;
|
||||||
|
|
||||||
void keyPressEvent( QKeyEvent* ) override;
|
void keyPressEvent( QKeyEvent* ) override;
|
||||||
void keyReleaseEvent( QKeyEvent* ) override;
|
void keyReleaseEvent( QKeyEvent* ) override;
|
||||||
|
|
||||||
|
@ -9,6 +9,27 @@
|
|||||||
#include "QskSkinStateChanger.h"
|
#include "QskSkinStateChanger.h"
|
||||||
|
|
||||||
#include <qfontmetrics.h>
|
#include <qfontmetrics.h>
|
||||||
|
#include <qcursor.h>
|
||||||
|
|
||||||
|
static bool qskIsButtonHovered(
|
||||||
|
const QskSpinBox* spinBox, QskAspect::Subcontrol subControl )
|
||||||
|
{
|
||||||
|
if ( spinBox->hasSkinState( QskControl::Hovered ) )
|
||||||
|
{
|
||||||
|
// disable Hovered to avoid recursive calls
|
||||||
|
QskSkinStateChanger stateChanger( spinBox );
|
||||||
|
stateChanger.setStates( spinBox->skinStates() & ~QskControl::Hovered );
|
||||||
|
|
||||||
|
const auto r = spinBox->subControlRect( subControl );
|
||||||
|
if ( !r.isEmpty() )
|
||||||
|
{
|
||||||
|
const auto pos = spinBox->mapFromGlobal( QCursor::pos() );
|
||||||
|
return r.contains( pos );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static inline QskAspect::States qskButtonStates(
|
static inline QskAspect::States qskButtonStates(
|
||||||
const QskSkinnable* skinnable, QskAspect::Subcontrol subControl )
|
const QskSkinnable* skinnable, QskAspect::Subcontrol subControl )
|
||||||
@ -19,17 +40,23 @@ static inline QskAspect::States qskButtonStates(
|
|||||||
|
|
||||||
auto states = spinBox->skinStates();
|
auto states = spinBox->skinStates();
|
||||||
|
|
||||||
if ( spinBox->isEnabled() && !spinBox->isWrapping() )
|
if ( spinBox->isEnabled() )
|
||||||
{
|
{
|
||||||
if ( subControl == Q::DownIndicator || subControl == Q::DownPanel )
|
if ( subControl == Q::DownIndicator || subControl == Q::DownPanel )
|
||||||
{
|
{
|
||||||
if ( spinBox->value() <= spinBox->minimum() )
|
if ( !spinBox->isWrapping() && spinBox->value() <= spinBox->minimum() )
|
||||||
states |= QskControl::Disabled;
|
states |= QskControl::Disabled;
|
||||||
|
|
||||||
|
if ( !qskIsButtonHovered( spinBox, Q::DownPanel ) )
|
||||||
|
states &= ~Q::Hovered;
|
||||||
}
|
}
|
||||||
else if ( subControl == Q::UpIndicator || subControl == Q::UpPanel )
|
else if ( subControl == Q::UpIndicator || subControl == Q::UpPanel )
|
||||||
{
|
{
|
||||||
if ( spinBox->value() >= spinBox->maximum() )
|
if ( !spinBox->isWrapping() && spinBox->value() >= spinBox->maximum() )
|
||||||
states |= QskControl::Disabled;
|
states |= QskControl::Disabled;
|
||||||
|
|
||||||
|
if ( !qskIsButtonHovered( spinBox, Q::UpPanel ) )
|
||||||
|
states &= ~Q::Hovered;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user