summaryrefslogtreecommitdiffstats
path: root/src/dialog.cpp
diff options
context:
space:
mode:
authorChristian Klinger2016-06-01 10:33:41 +0200
committerChristian Klinger2016-06-01 10:33:41 +0200
commitfe2054a73c74b4462c1c528750223b01a6df5f9d (patch)
treec35cede3231fea8133983a1dd20f27c6a73a24c5 /src/dialog.cpp
parentUse foreground instead of background for marking unusable vms (diff)
downloadvmchooser2-fe2054a73c74b4462c1c528750223b01a6df5f9d.tar.gz
vmchooser2-fe2054a73c74b4462c1c528750223b01a6df5f9d.tar.xz
vmchooser2-fe2054a73c74b4462c1c528750223b01a6df5f9d.zip
left/right buttons work globally.
Diffstat (limited to 'src/dialog.cpp')
-rw-r--r--src/dialog.cpp56
1 files changed, 51 insertions, 5 deletions
diff --git a/src/dialog.cpp b/src/dialog.cpp
index 0b7fa48..0a34f6c 100644
--- a/src/dialog.cpp
+++ b/src/dialog.cpp
@@ -20,6 +20,8 @@
#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);
@@ -70,6 +72,8 @@ Dialog::Dialog(int defaultTab, QWidget *parent)
ui->buttonBugReport->setEnabled(false);
QObject::connect(SessionsIconHolder::get(), SIGNAL(iconDownloaded(const QUrl&, const QIcon&)),
this, SLOT(iconDownloaded(const QUrl&, const QIcon&)));
+
+ ui->treeView->installEventFilter(this);
}
Dialog::~Dialog() {
@@ -465,10 +469,14 @@ void Dialog::onTabButtonChanged(int tab) {
// load the new list
setListModel(model_[tab]);
this->activeTab_ = tab;
- ui->treeView->selectionModel()->clear();
- ui->treeView->selectionModel()->clearSelection();
- ui->treeView->selectionModel()->select(ui->treeView->model()->index(0, 0, ui->treeView->rootIndex()), QItemSelectionModel::Select);
- ui->treeView->selectionModel()->setCurrentIndex(ui->treeView->model()->index(0, 0, ui->treeView->rootIndex()), QItemSelectionModel::Select);
+
+ /* 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);
+
}
void Dialog::on_filterEdit_textEdited() {
@@ -658,11 +666,13 @@ 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;
- case Qt::Key_H: this->on_helpNewsButton_clicked(); break;
+ case Qt::Key_H: this->on_helpNewsButton_clicked(); break;
}
+ QDialog::keyPressEvent(event);
}
void Dialog::iconDownloaded(const QUrl& url, const QIcon&) {
@@ -672,3 +682,39 @@ void Dialog::iconDownloaded(const QUrl& url, const QIcon&) {
model_[TAB_ALL_VMS]->updateView();
}
+void Dialog::on_leftButton() {
+ qDebug() << "Left Button";
+ int i = activeTab_;
+ do {
+ i = (i - 1 + TAB_COUNT) % TAB_COUNT;
+ } while (!tabs_[i]->isEnabled());
+ onTabButtonChanged(i);
+}
+
+void Dialog::on_rightButton() {
+ qDebug() << "Right Button";
+ int i = activeTab_;
+ do {
+ i = (i + 1) % TAB_COUNT;
+ } while (!tabs_[i]->isEnabled());
+ onTabButtonChanged(i);
+}
+
+/* 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) {
+ QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
+ if (keyEvent->key() == Qt::Key_Left) {
+ on_leftButton();
+ return true; /* drop this event */
+ } else if (keyEvent->key() == Qt::Key_Right) {
+ on_rightButton();
+ return true;
+ } else if (keyEvent->key() == Qt::Key_Space) {
+ qDebug() << "space button";
+ }
+ }
+ return QDialog::eventFilter(target, event);
+}