Better keyboard support in Dictionaries tab:

1. Pressing Down Arrow allows to jump from the Quick Filter to the dictionaries list.
2. Navigating through dictionary list via keyboard (Up/Down) results in dictionary details
   to be shown on the right. Previously, only mouse clicks updated the dictionary info.
This commit is contained in:
Tvangeste 2013-01-07 09:52:36 +01:00
parent c206c7d434
commit 5035f6aa0d
4 changed files with 77 additions and 7 deletions

View file

@ -508,6 +508,11 @@ void DictListWidget::dropEvent( QDropEvent * event )
}
}
void DictListWidget::focusInEvent( QFocusEvent * )
{
emit gotFocus();
}
void DictListWidget::rowsInserted( QModelIndex const & parent, int start, int end )
{
QListView::rowsInserted( parent, start, end );
@ -1046,13 +1051,21 @@ QuickFilterLine::~QuickFilterLine()
void QuickFilterLine::applyTo( QAbstractItemView * source )
{
m_source = source;
m_proxyModel.setSourceModel( source->model() );
source->setModel( &m_proxyModel );
}
QModelIndex QuickFilterLine::mapToSource( QModelIndex const & idx )
{
return m_proxyModel.mapToSource( idx );
if ( &m_proxyModel == idx.model() )
{
return m_proxyModel.mapToSource( idx );
}
else
{
return idx;
}
}
void QuickFilterLine::filterChangedInternal()
@ -1072,3 +1085,19 @@ void QuickFilterLine::focusFilterLine()
setFocus();
selectAll();
}
void QuickFilterLine::keyPressEvent( QKeyEvent * event )
{
switch ( event->key() )
{
case Qt::Key_Down:
if ( m_source )
{
m_source->setCurrentIndex( m_source->model()->index( 0,0 ) );
m_source->setFocus();
}
break;
default:
ExtLineEdit::keyPressEvent( event );
}
}

View file

@ -88,8 +88,12 @@ public:
DictListModel * getModel()
{ return & model; }
signals:
void gotFocus();
protected:
virtual void dropEvent( QDropEvent * event );
virtual void focusInEvent(QFocusEvent *);
// We need these to to handle drag-and-drop focus issues
virtual void rowsInserted( QModelIndex const & parent, int start, int end );
@ -211,9 +215,13 @@ public:
QModelIndex mapToSource( QModelIndex const & idx );
protected:
virtual void keyPressEvent( QKeyEvent * event );
private:
QSortFilterProxyModel m_proxyModel;
QAction m_focusAction;
QAbstractItemView * m_source;
private slots:
void filterChangedInternal();

View file

@ -112,6 +112,17 @@ OrderAndProps::OrderAndProps( QWidget * parent,
ui.dictionaryOrder->setContextMenuPolicy( Qt::CustomContextMenu );
connect( ui.dictionaryOrder, SIGNAL( customContextMenuRequested( QPoint ) ),
this, SLOT( contextMenuRequested( QPoint ) ) );
connect( ui.dictionaryOrder, SIGNAL( gotFocus() ),
this, SLOT( dictListFocused() ) );
connect( ui.inactiveDictionaries, SIGNAL( gotFocus() ),
this, SLOT( inactiveDictListFocused() ) );
connect ( ui.dictionaryOrder->selectionModel(), SIGNAL( selectionChanged ( const QItemSelection & , const QItemSelection & ) ),
this, SLOT( dictionarySelectionChanged( const QItemSelection & ) ) );
connect ( ui.inactiveDictionaries->selectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection & ) ),
this, SLOT( inactiveDictionarySelectionChanged( QItemSelection const & ) ) );
connect (ui.searchLine, SIGNAL( filterChanged( QString const & ) ),
this, SLOT( filterChanged( QString const &) ) );
}
@ -141,14 +152,29 @@ void OrderAndProps::filterChanged( QString const & filterText)
ui.dictionaryOrder->setAcceptDrops(filterText.isEmpty());
}
void OrderAndProps::on_dictionaryOrder_clicked( QModelIndex const & idx )
void OrderAndProps::dictListFocused()
{
describeDictionary( ui.dictionaryOrder, ui.searchLine->mapToSource( idx ) );
describeDictionary( ui.dictionaryOrder, ui.searchLine->mapToSource( ui.dictionaryOrder->currentIndex() ) );
}
void OrderAndProps::on_inactiveDictionaries_clicked( QModelIndex const & idx )
void OrderAndProps::inactiveDictListFocused()
{
describeDictionary( ui.inactiveDictionaries, idx );
describeDictionary( ui.inactiveDictionaries, ui.inactiveDictionaries->currentIndex() );
}
void OrderAndProps::dictionarySelectionChanged( const QItemSelection & current )
{
if ( current.empty() )
return;
describeDictionary( ui.dictionaryOrder, ui.searchLine->mapToSource( current.front().topLeft() ) );
}
void OrderAndProps::inactiveDictionarySelectionChanged( QItemSelection const & current )
{
if ( current.empty() )
return;
describeDictionary( ui.inactiveDictionaries, current.front().topLeft() );
}
void OrderAndProps::disableDictionaryDescription()
@ -175,6 +201,11 @@ void OrderAndProps::describeDictionary( DictListWidget * lst, QModelIndex const
{
sptr< Dictionary::Class > dict = lst->getCurrentDictionaries()[ idx.row() ];
if ( !dict )
{
return;
}
ui.dictionaryInformation->setEnabled( true );
ui.dictionaryName->setText( QString::fromUtf8( dict->getName().c_str() ) );

View file

@ -23,10 +23,12 @@ public:
private slots:
void on_dictionaryOrder_clicked( QModelIndex const & );
void on_inactiveDictionaries_clicked( QModelIndex const & );
void dictionarySelectionChanged( const QItemSelection &current );
void inactiveDictionarySelectionChanged( const QItemSelection &current );
void contextMenuRequested( const QPoint & pos );
void filterChanged( QString const & filterText );
void dictListFocused();
void inactiveDictListFocused();
private: