summaryrefslogtreecommitdiffstats
path: root/src/dialog.cpp
diff options
context:
space:
mode:
authorChristian Klinger2016-06-01 10:53:31 +0200
committerChristian Klinger2016-06-01 10:53:31 +0200
commitced2a07f9f9a9ee31c42779b51019247b8babb2e (patch)
treef05fee4342bb64726533dcf950cf62c7b7e0a797 /src/dialog.cpp
parentforward all other keys to the filterEdit-Box. (diff)
downloadvmchooser2-ced2a07f9f9a9ee31c42779b51019247b8babb2e.tar.gz
vmchooser2-ced2a07f9f9a9ee31c42779b51019247b8babb2e.tar.xz
vmchooser2-ced2a07f9f9a9ee31c42779b51019247b8babb2e.zip
expand/collapse on space.
Diffstat (limited to 'src/dialog.cpp')
-rw-r--r--src/dialog.cpp25
1 files changed, 15 insertions, 10 deletions
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<QKeyEvent *>(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);