diff options
author | Christian Klinger | 2016-06-10 12:12:14 +0200 |
---|---|---|
committer | Christian Klinger | 2016-06-10 12:12:14 +0200 |
commit | 011d0933fa5a811da37fca99a81c31e103dcc35d (patch) | |
tree | 3a13a50e41a885d7ed22f701c1a7b330231129f2 /src/dialog.cpp | |
parent | catch ALL keyboard events. (diff) | |
download | vmchooser2-011d0933fa5a811da37fca99a81c31e103dcc35d.tar.gz vmchooser2-011d0933fa5a811da37fca99a81c31e103dcc35d.tar.xz vmchooser2-011d0933fa5a811da37fca99a81c31e103dcc35d.zip |
improve keyboard behaviour.
Diffstat (limited to 'src/dialog.cpp')
-rw-r--r-- | src/dialog.cpp | 65 |
1 files changed, 39 insertions, 26 deletions
diff --git a/src/dialog.cpp b/src/dialog.cpp index f42ad65..cd2b9b6 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -48,6 +48,10 @@ Dialog::Dialog(int defaultTab, QWidget *parent) connect(centerTimer_, SIGNAL(timeout()), this, SLOT(onCenterTimer())); centerTimer_->start(1000); + ui->treeView->setFocusProxy(ui->filterEdit); + // ui->filterEdit->installEventFilter(this); + qApp->installEventFilter(this); + ui->helpBox->hide(); ui->newsBox->hide(); @@ -71,8 +75,6 @@ Dialog::Dialog(int defaultTab, QWidget *parent) QObject::connect(SessionsIconHolder::get(), SIGNAL(iconDownloaded(const QUrl&, const QIcon&)), this, SLOT(iconDownloaded(const QUrl&, const QIcon&))); - // ui->treeView->installEventFilter(this); - // this->installEventFilter(this); } Dialog::~Dialog() { @@ -451,8 +453,8 @@ void Dialog::onTabButtonChanged(int tab) { } // give focus to treeView - if (!ui->filterEdit->hasFocus()) { - ui->filterEdit->setFocus(); + if (!ui->treeView->hasFocus()) { + ui->treeView->setFocus(); } // Update pressed status of buttons @@ -470,11 +472,7 @@ void Dialog::onTabButtonChanged(int tab) { this->activeTab_ = tab; /* get the first element ad select it */ - QModelIndex root(ui->treeView->rootIndex()); - QModelIndex section(model_[tab]->index(0, 0, root)); - QModelIndex element(model_[tab]->index(0, 0, section)); - ui->treeView->selectionModel()->setCurrentIndex(element, QItemSelectionModel::Select); - ui->treeView->setFocus(Qt::OtherFocusReason); + selectFirstElement(); } @@ -706,26 +704,41 @@ void Dialog::on_spaceKey() { ui->treeView->expand(index); } } -/* install this event filter to the treeView to receive Left/Right button - * presses. (Usually treeView consumes left/right to use them as collapse/expand - * shortcuts */ -bool Dialog::eventFilter(QObject* target, QEvent *event) { - if (event->type() == QEvent::KeyPress) { - qDebug() << "keyboard event"; + +void Dialog::selectFirstElement() { + QModelIndex root(ui->treeView->rootIndex()); + QModelIndex section(model_[activeTab_]->index(0, 0, root)); + QModelIndex newIndex = QModelIndex(model_[activeTab_]->index(0, 0, section)); + + ui->treeView->selectionModel()->setCurrentIndex(newIndex, QItemSelectionModel::Select); + ui->treeView->setFocus(); +} + +/* install this filter to the filterEdit to listen for arrow keys */ +bool Dialog::eventFilter(QObject*, QEvent *event) { + if (event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); - qDebug() << keyEvent; + bool fortv = false; + if (keyEvent->key() == Qt::Key_Right) { + on_rightKey(); + fortv = true; + } if (keyEvent->key() == Qt::Key_Left) { on_leftKey(); - return true; /* drop this event */ - } else if (keyEvent->key() == Qt::Key_Right) { - on_rightKey(); + fortv = true; + } + if (keyEvent->key() == Qt::Key_Up) { + ui->treeView->cursorUp(); + fortv = true; + } + if (keyEvent->key() == Qt::Key_Down) { + ui->treeView->cursorDown(); + fortv = true; + } + if (fortv) { + ui->treeView->setFocus(); return true; - } else if (keyEvent->key() == Qt::Key_Space) { - on_spaceKey(); - } else { - /* forward to the search box */ - ui->filterEdit->event(event); } - } - return QDialog::eventFilter(target, event); + } + return false; } |