From ced2a07f9f9a9ee31c42779b51019247b8babb2e Mon Sep 17 00:00:00 2001 From: Christian Klinger Date: Wed, 1 Jun 2016 10:53:31 +0200 Subject: expand/collapse on space. --- src/dialog.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'src/dialog.cpp') diff --git a/src/dialog.cpp b/src/dialog.cpp index 568a6bd..613f1ad 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -20,8 +20,6 @@ #include "vsession.h" #include "choosersettings.h" -#define UNUSED(x) (void)(x) - Dialog::Dialog(int defaultTab, QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) { model_[0] = new SessionTreeModel(parent); @@ -666,7 +664,6 @@ void Dialog::addHelpAfterDownload(QNetworkReply* reply) { } void Dialog::keyPressEvent(QKeyEvent* event) { - qDebug() << "key pressed: " << event; switch(event->key()) { case Qt::Key_Return: this->on_pushButtonStart_clicked(); break; case Qt::Key_Escape: this->on_pushButtonAbort_clicked(); break; @@ -682,8 +679,7 @@ void Dialog::iconDownloaded(const QUrl& url, const QIcon&) { model_[TAB_ALL_VMS]->updateView(); } -void Dialog::on_leftButton() { - qDebug() << "Left Button"; +void Dialog::on_leftKey() { int i = activeTab_; do { i = (i - 1 + TAB_COUNT) % TAB_COUNT; @@ -691,8 +687,7 @@ void Dialog::on_leftButton() { onTabButtonChanged(i); } -void Dialog::on_rightButton() { - qDebug() << "Right Button"; +void Dialog::on_rightKey() { int i = activeTab_; do { i = (i + 1) % TAB_COUNT; @@ -700,6 +695,16 @@ void Dialog::on_rightButton() { onTabButtonChanged(i); } +/* when the user presses the space key, the current selection in the treeview + * should be collapsed/expanded. */ +void Dialog::on_spaceKey() { + QModelIndex index = ui->treeView->selectionModel()->currentIndex(); + if (ui->treeView->isExpanded(index)) { + ui->treeView->collapse(index); + } else { + 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 */ @@ -707,13 +712,13 @@ bool Dialog::eventFilter(QObject* target, QEvent *event) { if (event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast(event); if (keyEvent->key() == Qt::Key_Left) { - on_leftButton(); + on_leftKey(); return true; /* drop this event */ } else if (keyEvent->key() == Qt::Key_Right) { - on_rightButton(); + on_rightKey(); return true; } else if (keyEvent->key() == Qt::Key_Space) { - qDebug() << "space button"; + on_spaceKey(); } else { /* forward to the search box */ ui->filterEdit->event(event); -- cgit v1.2.3-55-g7522