From 5035f6aa0d9014aaa081845708f1c0a2b7c2a11d Mon Sep 17 00:00:00 2001 From: Tvangeste Date: Mon, 7 Jan 2013 09:52:36 +0100 Subject: [PATCH] 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. --- groups_widgets.cc | 31 ++++++++++++++++++++++++++++++- groups_widgets.hh | 8 ++++++++ orderandprops.cc | 39 +++++++++++++++++++++++++++++++++++---- orderandprops.hh | 6 ++++-- 4 files changed, 77 insertions(+), 7 deletions(-) diff --git a/groups_widgets.cc b/groups_widgets.cc index b491917b..6491c3c5 100644 --- a/groups_widgets.cc +++ b/groups_widgets.cc @@ -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 ); + } +} diff --git a/groups_widgets.hh b/groups_widgets.hh index c74890c6..ce442fa2 100644 --- a/groups_widgets.hh +++ b/groups_widgets.hh @@ -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(); diff --git a/orderandprops.cc b/orderandprops.cc index 6cac76aa..af8f0631 100644 --- a/orderandprops.cc +++ b/orderandprops.cc @@ -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() ) ); diff --git a/orderandprops.hh b/orderandprops.hh index bf02dac9..45fa98a5 100644 --- a/orderandprops.hh +++ b/orderandprops.hh @@ -23,10 +23,12 @@ public: private slots: - void on_dictionaryOrder_clicked( QModelIndex const & ); - void on_inactiveDictionaries_clicked( QModelIndex const & ); + void dictionarySelectionChanged( const QItemSelection ¤t ); + void inactiveDictionarySelectionChanged( const QItemSelection ¤t ); void contextMenuRequested( const QPoint & pos ); void filterChanged( QString const & filterText ); + void dictListFocused(); + void inactiveDictListFocused(); private: