Add animation support for the Ripple, remove focusedItem
This commit is contained in:
parent
bfc172c04f
commit
f5c7f7f2b4
@ -4,6 +4,7 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#include "QskMaterial3Skin.h"
|
#include "QskMaterial3Skin.h"
|
||||||
|
#include "QskTextOptions.h"
|
||||||
|
|
||||||
#include <QskSkinHintTableEditor.h>
|
#include <QskSkinHintTableEditor.h>
|
||||||
|
|
||||||
@ -471,10 +472,9 @@ void Editor::setupRadioBox()
|
|||||||
using Q = QskRadioBox;
|
using Q = QskRadioBox;
|
||||||
using A = QskAspect;
|
using A = QskAspect;
|
||||||
|
|
||||||
setStrutSize( Q::Text, {100, 20 });
|
|
||||||
setStrutSize( Q::Button, {20, 20 });
|
setStrutSize( Q::Button, {20, 20 });
|
||||||
setStrutSize( Q::Symbol, {10, 10 });
|
setStrutSize( Q::Symbol, {10, 10 });
|
||||||
setStrutSize( Q::Ripple | Q::Focused, { 40, 40 });
|
setStrutSize( Q::Ripple, { 40, 40 });
|
||||||
|
|
||||||
setSpacing(Q::Panel, 10);
|
setSpacing(Q::Panel, 10);
|
||||||
|
|
||||||
@ -487,17 +487,16 @@ void Editor::setupRadioBox()
|
|||||||
|
|
||||||
setBoxShape(Q::Ripple, 40);
|
setBoxShape(Q::Ripple, 40);
|
||||||
|
|
||||||
|
|
||||||
setColor( Q::Symbol, m_pal.primary );
|
setColor( Q::Symbol, m_pal.primary );
|
||||||
setColor( Q::Ripple | Q::Focused,
|
setColor( Q::Ripple, stateLayerColor( m_pal.onSurface, m_pal.focusOpacity ) );
|
||||||
stateLayerColor( m_pal.onSurface, m_pal.focusOpacity ) );
|
setColor( Q::Ripple | Q::Selected, stateLayerColor( m_pal.primary, m_pal.focusOpacity ) );
|
||||||
setColor( Q::Ripple | Q::Selected | Q::Focused,
|
|
||||||
// stateLayerColor( m_pal.primary, m_pal.focusOpacity ) );
|
|
||||||
Qt::red);
|
|
||||||
|
|
||||||
setMargin( Q::Text, QskMargins(10, 0,0,0));
|
setMargin( Q::Text, QskMargins(10, 0,0,0));
|
||||||
|
|
||||||
setAlignment( Q::Text, Qt::AlignBottom );
|
setAlignment( Q::Text, Qt::AlignBottom );
|
||||||
setAnimation(Q::Ripple | A::Metric, 1000);
|
|
||||||
|
setAnimation( Q::Ripple | A::Metric | A::Position, qskDuration );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::setupFocusIndicator()
|
void Editor::setupFocusIndicator()
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include "QskRadioBox.h"
|
#include "QskRadioBox.h"
|
||||||
#include "QskEvent.h"
|
#include "QskEvent.h"
|
||||||
|
#include "QskAnimationHint.h"
|
||||||
|
|
||||||
#include <qnamespace.h>
|
#include <qnamespace.h>
|
||||||
|
|
||||||
QSK_SUBCONTROL( QskRadioBox, Panel )
|
QSK_SUBCONTROL( QskRadioBox, Panel )
|
||||||
@ -17,7 +19,6 @@ public:
|
|||||||
QStringList items;
|
QStringList items;
|
||||||
int selectedIndex = -1;
|
int selectedIndex = -1;
|
||||||
int pressedIndex = -1;
|
int pressedIndex = -1;
|
||||||
int focusedIndex = -1;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QskRadioBox::QskRadioBox( QQuickItem* parent ) :
|
QskRadioBox::QskRadioBox( QQuickItem* parent ) :
|
||||||
@ -35,6 +36,8 @@ QskRadioBox::QskRadioBox( QQuickItem* parent ) :
|
|||||||
setFocusPolicy( Qt::NoFocus );
|
setFocusPolicy( Qt::NoFocus );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setPositionHint( Ripple, -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
QskRadioBox::QskRadioBox( const QStringList& list, QQuickItem* parent ) :
|
QskRadioBox::QskRadioBox( const QStringList& list, QQuickItem* parent ) :
|
||||||
@ -62,10 +65,6 @@ const QStringList& QskRadioBox::items() const {
|
|||||||
return m_data->items;
|
return m_data->items;
|
||||||
}
|
}
|
||||||
|
|
||||||
int QskRadioBox::focusedIndex() const {
|
|
||||||
return m_data->focusedIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
int QskRadioBox::pressedIndex() const {
|
int QskRadioBox::pressedIndex() const {
|
||||||
return m_data->pressedIndex;
|
return m_data->pressedIndex;
|
||||||
}
|
}
|
||||||
@ -102,48 +101,53 @@ void QskRadioBox::keyPressEvent( QKeyEvent* event )
|
|||||||
case Qt::Key_Up:
|
case Qt::Key_Up:
|
||||||
case Qt::Key_Left:
|
case Qt::Key_Left:
|
||||||
m_data->selectedIndex = qMax(m_data->selectedIndex - 1, 0);
|
m_data->selectedIndex = qMax(m_data->selectedIndex - 1, 0);
|
||||||
m_data->focusedIndex = m_data->selectedIndex;
|
setPositionHint( Ripple, m_data->selectedIndex );
|
||||||
setSkinStateFlag( QskRadioBox::Selected );
|
|
||||||
event->setAccepted( true );
|
event->setAccepted( true );
|
||||||
update();
|
update();
|
||||||
return;
|
return;
|
||||||
case Qt::Key_Down:
|
case Qt::Key_Down:
|
||||||
case Qt::Key_Right:
|
case Qt::Key_Right:
|
||||||
m_data->selectedIndex = qMin(m_data->selectedIndex + 1, items().size() - 1);
|
m_data->selectedIndex = qMin(m_data->selectedIndex + 1, items().size() - 1);
|
||||||
m_data->focusedIndex = m_data->selectedIndex;
|
setPositionHint( Ripple, m_data->selectedIndex );
|
||||||
setSkinStateFlag( QskRadioBox::Selected );
|
|
||||||
event->setAccepted( true );
|
event->setAccepted( true );
|
||||||
update();
|
update();
|
||||||
return;
|
return;
|
||||||
case Qt::Key_Select:
|
case Qt::Key_Select:
|
||||||
case Qt::Key_Return:
|
case Qt::Key_Return:
|
||||||
case Qt::Key_Space:
|
case Qt::Key_Space:
|
||||||
m_data->selectedIndex = m_data->focusedIndex;
|
m_data->selectedIndex = positionHint( Ripple );
|
||||||
setSkinStateFlag( QskRadioBox::Selected );
|
|
||||||
setSkinStateFlag( QskRadioBox::Pressed );
|
|
||||||
event->setAccepted( true );
|
event->setAccepted( true );
|
||||||
update();
|
update();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto nextTabIndex = m_data->focusedIndex;
|
auto currentTabIndex = positionHint( Ripple );
|
||||||
nextTabIndex += qskFocusChainIncrement( event );
|
auto nextTabIndex = currentTabIndex + qskFocusChainIncrement( event );
|
||||||
if( nextTabIndex >= items().size()
|
if( nextTabIndex >= items().size()
|
||||||
|| nextTabIndex < 0 ) {
|
|| nextTabIndex < 0 ) {
|
||||||
Inherited::keyPressEvent( event );
|
Inherited::keyPressEvent( event );
|
||||||
} else {
|
setPositionHint(Ripple, -1);
|
||||||
m_data->focusedIndex = nextTabIndex;
|
|
||||||
setSkinStateFlag( QskRadioBox::Focused );
|
|
||||||
event->setAccepted( true );
|
|
||||||
update();
|
update();
|
||||||
|
} else {
|
||||||
|
event->setAccepted( true );
|
||||||
|
setPositionHint( Ripple, (float) nextTabIndex );
|
||||||
|
|
||||||
|
const auto aspect = Ripple | QskAspect::Metric | QskAspect::Position;
|
||||||
|
auto hint = animationHint(aspect | skinStates());
|
||||||
|
if( hint.isValid()) {
|
||||||
|
startTransition( aspect,
|
||||||
|
hint,
|
||||||
|
(float) currentTabIndex, (float) nextTabIndex );
|
||||||
|
}
|
||||||
|
|
||||||
|
update();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskRadioBox::keyReleaseEvent( QKeyEvent* e )
|
void QskRadioBox::keyReleaseEvent( QKeyEvent* e )
|
||||||
{
|
{
|
||||||
setSkinStateFlag( QskRadioBox::Pressed, false );
|
|
||||||
e->setAccepted( true );
|
e->setAccepted( true );
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskRadioBox::mousePressEvent( QMouseEvent* e )
|
void QskRadioBox::mousePressEvent( QMouseEvent* e )
|
||||||
@ -153,9 +157,7 @@ void QskRadioBox::mousePressEvent( QMouseEvent* e )
|
|||||||
m_data->pressedIndex = indexAtPosition;
|
m_data->pressedIndex = indexAtPosition;
|
||||||
m_data->selectedIndex = -1;
|
m_data->selectedIndex = -1;
|
||||||
|
|
||||||
m_data->focusedIndex = indexAtPosition;
|
setPositionHint( Ripple, indexAtPosition );
|
||||||
|
|
||||||
setSkinStateFlag( QskRadioBox::Pressed );
|
|
||||||
|
|
||||||
e->setAccepted( true );
|
e->setAccepted( true );
|
||||||
update();
|
update();
|
||||||
@ -163,8 +165,6 @@ void QskRadioBox::mousePressEvent( QMouseEvent* e )
|
|||||||
|
|
||||||
void QskRadioBox::mouseReleaseEvent( QMouseEvent* e )
|
void QskRadioBox::mouseReleaseEvent( QMouseEvent* e )
|
||||||
{
|
{
|
||||||
setSkinStateFlag( QskRadioBox::Pressed, false );
|
|
||||||
|
|
||||||
auto index = indexAt( e->localPos() );
|
auto index = indexAt( e->localPos() );
|
||||||
if( index == m_data->pressedIndex ) {
|
if( index == m_data->pressedIndex ) {
|
||||||
setSelectedIndex( index );
|
setSelectedIndex( index );
|
||||||
@ -176,19 +176,19 @@ void QskRadioBox::mouseReleaseEvent( QMouseEvent* e )
|
|||||||
|
|
||||||
void QskRadioBox::focusInEvent( QFocusEvent* e ) {
|
void QskRadioBox::focusInEvent( QFocusEvent* e ) {
|
||||||
if( e->reason() == Qt::TabFocusReason ) {
|
if( e->reason() == Qt::TabFocusReason ) {
|
||||||
m_data->focusedIndex = 0;
|
setPositionHint( Ripple, 0 );
|
||||||
} else if( e->reason() == Qt::BacktabFocusReason ) {
|
} else if( e->reason() == Qt::BacktabFocusReason ) {
|
||||||
m_data->focusedIndex = items().size() - 1;
|
setPositionHint( Ripple, items().size() - 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
setSkinStateFlag( Focused );
|
update();
|
||||||
Inherited::focusInEvent( e );
|
Inherited::focusInEvent( e );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskRadioBox::focusOutEvent( QFocusEvent* e ) {
|
void QskRadioBox::focusOutEvent( QFocusEvent* e ) {
|
||||||
m_data->focusedIndex = -1;
|
setPositionHint(Ripple, -1);
|
||||||
setSkinStateFlag( Focused, false );
|
|
||||||
update();
|
update();
|
||||||
|
|
||||||
Inherited::focusOutEvent( e );
|
Inherited::focusOutEvent( e );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,6 @@ class QSK_EXPORT QskRadioBox : public QskControl
|
|||||||
|
|
||||||
const QStringList& items() const;
|
const QStringList& items() const;
|
||||||
int selectedIndex() const;
|
int selectedIndex() const;
|
||||||
int focusedIndex() const;
|
|
||||||
int pressedIndex() const;
|
int pressedIndex() const;
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "QskAspect.h"
|
#include "QskAspect.h"
|
||||||
#include "QskRadioBox.h"
|
#include "QskRadioBox.h"
|
||||||
|
|
||||||
|
#include "QskSkinStateChanger.h"
|
||||||
#include "QskStandardSymbol.h"
|
#include "QskStandardSymbol.h"
|
||||||
#include "QskColorFilter.h"
|
#include "QskColorFilter.h"
|
||||||
#include "QskGraphic.h"
|
#include "QskGraphic.h"
|
||||||
@ -23,13 +24,31 @@ QskRadioBoxSkinlet::~QskRadioBoxSkinlet()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QskAspect::States statesForIndex(const QskRadioBox* radio, int index) {
|
||||||
|
auto states = radio->skinStates();
|
||||||
|
|
||||||
|
if( radio->selectedIndex() == index ) {
|
||||||
|
states |= Q::Selected;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( radio->pressedIndex() == index ) {
|
||||||
|
states |= Q::Pressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( radio->positionHint( Q::Ripple ) == index ) {
|
||||||
|
states |= Q::Focused;
|
||||||
|
}
|
||||||
|
|
||||||
|
return states;
|
||||||
|
}
|
||||||
|
|
||||||
QRectF QskRadioBoxSkinlet::subControlRect( const QskSkinnable* skinnable,
|
QRectF QskRadioBoxSkinlet::subControlRect( const QskSkinnable* skinnable,
|
||||||
const QRectF& contentsRect, QskAspect::Subcontrol subcontrol) const
|
const QRectF& contentsRect, QskAspect::Subcontrol subcontrol) const
|
||||||
{
|
{
|
||||||
auto radio = static_cast<const QskRadioBox*>( skinnable );
|
auto radio = static_cast<const QskRadioBox*>( skinnable );
|
||||||
|
|
||||||
if( subcontrol == Q::Ripple ) {
|
if( subcontrol == Q::Ripple ) {
|
||||||
return buttonRect(radio, Q::Ripple, contentsRect, radio->focusedIndex());
|
return buttonRect(radio, Q::Ripple, contentsRect, radio->positionHint(Q::Ripple));
|
||||||
}
|
}
|
||||||
|
|
||||||
return contentsRect;
|
return contentsRect;
|
||||||
@ -83,7 +102,12 @@ QSGNode* QskRadioBoxSkinlet::updateSubNode( const QskSkinnable* skinnable,
|
|||||||
return updateSeriesNode( radio, Q::Text, node );
|
return updateSeriesNode( radio, Q::Text, node );
|
||||||
|
|
||||||
case RippleRole:
|
case RippleRole:
|
||||||
|
{
|
||||||
|
QskSkinStateChanger cleaner( radio );
|
||||||
|
cleaner.setStates( statesForIndex( radio, radio->positionHint( Q::Ripple ) ) );
|
||||||
|
|
||||||
return updateBoxNode( radio, node, Q::Ripple );
|
return updateBoxNode( radio, node, Q::Ripple );
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return Inherited::updateSubNode( skinnable, nodeRole, node );
|
return Inherited::updateSubNode( skinnable, nodeRole, node );
|
||||||
@ -108,10 +132,11 @@ int QskRadioBoxSkinlet::sampleCount( const QskSkinnable* skinnable,
|
|||||||
|
|
||||||
QRectF QskRadioBoxSkinlet::buttonRect( const QskRadioBox* radio,
|
QRectF QskRadioBoxSkinlet::buttonRect( const QskRadioBox* radio,
|
||||||
const QskAspect::Subcontrol target,
|
const QskAspect::Subcontrol target,
|
||||||
const QRectF& rect, int index ) const {
|
const QRectF& rect, double index ) const {
|
||||||
if( index < 0 ) {
|
if( index < 0 ) {
|
||||||
return QRectF();
|
return QRectF();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto result = rect;
|
auto result = rect;
|
||||||
result.setSize( radio->strutSizeHint( target ) );
|
result.setSize( radio->strutSizeHint( target ) );
|
||||||
|
|
||||||
@ -169,19 +194,7 @@ QskAspect::States QskRadioBoxSkinlet::sampleStates( const QskSkinnable* skinnabl
|
|||||||
auto radio = static_cast<const QskRadioBox*>( skinnable );
|
auto radio = static_cast<const QskRadioBox*>( skinnable );
|
||||||
auto states = Inherited::sampleStates( skinnable, subControl, index );
|
auto states = Inherited::sampleStates( skinnable, subControl, index );
|
||||||
|
|
||||||
if( radio->selectedIndex() == index ) {
|
return states | statesForIndex( radio, index );
|
||||||
states |= Q::Selected;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( radio->pressedIndex() == index ) {
|
|
||||||
states |= Q::Pressed;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( radio->focusedIndex() == index ) {
|
|
||||||
states |= Q::Focused;
|
|
||||||
}
|
|
||||||
|
|
||||||
return states;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QSGNode* QskRadioBoxSkinlet::updateSampleNode( const QskSkinnable* skinnable,
|
QSGNode* QskRadioBoxSkinlet::updateSampleNode( const QskSkinnable* skinnable,
|
||||||
|
@ -38,7 +38,7 @@ class QSK_EXPORT QskRadioBoxSkinlet : public QskSkinlet
|
|||||||
const QRectF&, QskAspect::Subcontrol, int index ) const override;
|
const QRectF&, QskAspect::Subcontrol, int index ) const override;
|
||||||
|
|
||||||
QRectF textRect( const QskRadioBox*, const QRectF&, int ) const;
|
QRectF textRect( const QskRadioBox*, const QRectF&, int ) const;
|
||||||
QRectF buttonRect( const QskRadioBox*, const QskAspect::Subcontrol target, const QRectF&, int ) const;
|
QRectF buttonRect( const QskRadioBox*, const QskAspect::Subcontrol target, const QRectF&, double ) const;
|
||||||
|
|
||||||
QskAspect::States sampleStates( const QskSkinnable*,
|
QskAspect::States sampleStates( const QskSkinnable*,
|
||||||
QskAspect::Subcontrol, int index ) const override;
|
QskAspect::Subcontrol, int index ) const override;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user