focus handling fixed
This commit is contained in:
parent
bfa8df85d5
commit
d33e1f1a90
@ -42,7 +42,6 @@ class QskSegmentedBar::PrivateData
|
|||||||
|
|
||||||
int selectedIndex = -1;
|
int selectedIndex = -1;
|
||||||
int currentIndex = -1;
|
int currentIndex = -1;
|
||||||
int focusedIndex = -1;
|
|
||||||
|
|
||||||
Qt::Orientation orientation;
|
Qt::Orientation orientation;
|
||||||
bool isPressed = false;
|
bool isPressed = false;
|
||||||
@ -167,10 +166,7 @@ void QskSegmentedBar::mousePressEvent( QMouseEvent* event )
|
|||||||
if( !QGuiApplication::styleHints()->setFocusOnTouchRelease() )
|
if( !QGuiApplication::styleHints()->setFocusOnTouchRelease() )
|
||||||
{
|
{
|
||||||
if( index != m_data->currentIndex )
|
if( index != m_data->currentIndex )
|
||||||
{
|
|
||||||
setCurrentIndex( index );
|
setCurrentIndex( index );
|
||||||
setFocusedIndex( index );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -230,12 +226,11 @@ void QskSegmentedBar::keyPressEvent( QKeyEvent* event )
|
|||||||
else
|
else
|
||||||
forwards = ( event->key() == Qt::Key_Right );
|
forwards = ( event->key() == Qt::Key_Right );
|
||||||
|
|
||||||
const int index = nextIndex( m_data->focusedIndex, forwards );
|
const int index = nextIndex( m_data->selectedIndex, forwards );
|
||||||
|
if ( index != m_data->selectedIndex )
|
||||||
if ( index != m_data->focusedIndex )
|
|
||||||
{
|
{
|
||||||
if ( index >= 0 && index < count() )
|
if ( index >= 0 && index < count() )
|
||||||
setFocusedIndex( index );
|
setSelectedIndex( index );
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -243,11 +238,9 @@ void QskSegmentedBar::keyPressEvent( QKeyEvent* event )
|
|||||||
|
|
||||||
case Qt::Key_Select:
|
case Qt::Key_Select:
|
||||||
case Qt::Key_Space:
|
case Qt::Key_Space:
|
||||||
{
|
|
||||||
setCurrentIndex( m_data->focusedIndex );
|
|
||||||
// stop further processing
|
// stop further processing
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
@ -255,10 +248,10 @@ void QskSegmentedBar::keyPressEvent( QKeyEvent* event )
|
|||||||
|
|
||||||
if( steps != 0 )
|
if( steps != 0 )
|
||||||
{
|
{
|
||||||
const int index = nextIndex( m_data->focusedIndex, steps > 0 );
|
const int index = nextIndex( m_data->currentIndex, steps > 0 );
|
||||||
|
|
||||||
if( index != m_data->focusedIndex )
|
if( index != m_data->currentIndex )
|
||||||
setFocusedIndex( index );
|
setCurrentIndex( index );
|
||||||
|
|
||||||
if( index >= 0 )
|
if( index >= 0 )
|
||||||
return;
|
return;
|
||||||
@ -308,7 +301,7 @@ void QskSegmentedBar::hoverLeaveEvent( QHoverEvent* )
|
|||||||
|
|
||||||
void QskSegmentedBar::focusInEvent( QFocusEvent* event )
|
void QskSegmentedBar::focusInEvent( QFocusEvent* event )
|
||||||
{
|
{
|
||||||
int index = m_data->focusedIndex;
|
int index = m_data->currentIndex;
|
||||||
|
|
||||||
switch( event->reason() )
|
switch( event->reason() )
|
||||||
{
|
{
|
||||||
@ -331,17 +324,15 @@ void QskSegmentedBar::focusInEvent( QFocusEvent* event )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( index != m_data->focusedIndex )
|
if( index != m_data->currentIndex )
|
||||||
setFocusedIndex( index );
|
setCurrentIndex( index );
|
||||||
|
|
||||||
Inherited::focusInEvent( event );
|
Inherited::focusInEvent( event );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskSegmentedBar::focusOutEvent( QFocusEvent* event )
|
void QskSegmentedBar::focusOutEvent( QFocusEvent* event )
|
||||||
{
|
{
|
||||||
setFocusedIndex( -1 );
|
setCurrentIndex( -1 );
|
||||||
update();
|
|
||||||
|
|
||||||
Inherited::focusOutEvent( event );
|
Inherited::focusOutEvent( event );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,6 +367,8 @@ void QskSegmentedBar::setCurrentIndex( int index )
|
|||||||
if( index != m_data->currentIndex )
|
if( index != m_data->currentIndex )
|
||||||
{
|
{
|
||||||
m_data->currentIndex = index;
|
m_data->currentIndex = index;
|
||||||
|
setPositionHint( Segment | Focused, index );
|
||||||
|
|
||||||
Q_EMIT currentIndexChanged( index );
|
Q_EMIT currentIndexChanged( index );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -507,17 +500,4 @@ QRectF QskSegmentedBar::focusIndicatorRect() const
|
|||||||
return Inherited::focusIndicatorRect();
|
return Inherited::focusIndicatorRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskSegmentedBar::setFocusedIndex( int index )
|
|
||||||
{
|
|
||||||
if ( m_data->focusedIndex == index )
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_data->focusedIndex = index;
|
|
||||||
setPositionHint( Segment | Focused, index );
|
|
||||||
|
|
||||||
update();
|
|
||||||
|
|
||||||
Q_EMIT focusIndicatorRectChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "moc_QskSegmentedBar.cpp"
|
#include "moc_QskSegmentedBar.cpp"
|
||||||
|
@ -103,7 +103,6 @@ class QSK_EXPORT QskSegmentedBar : public QskControl
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
int nextIndex( int index, bool forward ) const;
|
int nextIndex( int index, bool forward ) const;
|
||||||
void setFocusedIndex( int );
|
|
||||||
|
|
||||||
class PrivateData;
|
class PrivateData;
|
||||||
std::unique_ptr< PrivateData > m_data;
|
std::unique_ptr< PrivateData > m_data;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user