summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Klinger2016-06-10 12:12:14 +0200
committerChristian Klinger2016-06-10 12:12:14 +0200
commit011d0933fa5a811da37fca99a81c31e103dcc35d (patch)
tree3a13a50e41a885d7ed22f701c1a7b330231129f2
parentcatch ALL keyboard events. (diff)
downloadvmchooser2-011d0933fa5a811da37fca99a81c31e103dcc35d.tar.gz
vmchooser2-011d0933fa5a811da37fca99a81c31e103dcc35d.tar.xz
vmchooser2-011d0933fa5a811da37fca99a81c31e103dcc35d.zip
improve keyboard behaviour.
-rw-r--r--src/dialog.cpp65
-rw-r--r--src/dialog.h2
-rw-r--r--src/main.cpp2
-rw-r--r--src/ui/dialog.ui21
-rw-r--r--src/vmtree.cpp16
-rw-r--r--src/vmtree.h18
6 files changed, 89 insertions, 35 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;
}
diff --git a/src/dialog.h b/src/dialog.h
index d99c00b..a170d31 100644
--- a/src/dialog.h
+++ b/src/dialog.h
@@ -12,6 +12,7 @@
#include "sessiontreemodel.h"
#include "sessionsiconholder.h"
+
namespace Ui {
class Dialog;
}
@@ -59,6 +60,7 @@ class Dialog : public QDialog {
void configClearButton();
void setListModel(SessionTreeModel *model);
void keyPressEvent(QKeyEvent * e);
+ void selectFirstElement();
private slots:
void on_pushButtonStart_clicked();
diff --git a/src/main.cpp b/src/main.cpp
index 0b515cd..7dfdfc7 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -271,8 +271,6 @@ int main(int argc, char *argv[]) {
w.setTheme();
- a.installEventFilter(&w);
-
w.setWindowFlags(Qt::FramelessWindowHint);
if (cmdOptions.contains("pvs")) {
pvsEnabled = true;
diff --git a/src/ui/dialog.ui b/src/ui/dialog.ui
index 1dd6625..ca93287 100644
--- a/src/ui/dialog.ui
+++ b/src/ui/dialog.ui
@@ -132,8 +132,8 @@ margin-bottom:0px;}</string>
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
-&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'DejaVuSans'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
-&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Loading...&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
+&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'DejaVuSans'; font-size:9pt;&quot;&gt;Loading...&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
@@ -164,8 +164,8 @@ p, li { white-space: pre-wrap; }
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
-&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'DejaVuSans'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
-&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Loading...&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
+&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'DejaVuSans'; font-size:9pt;&quot;&gt;Loading...&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
@@ -266,7 +266,7 @@ p, li { white-space: pre-wrap; }
</layout>
</item>
<item>
- <widget class="QTreeView" name="treeView">
+ <widget class="VmTree" name="treeView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
@@ -492,8 +492,8 @@ border:1px solid #999;
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
-&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'DejaVuSans'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
-&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Click on an item on the left side for more information&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
+&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'DejaVuSans'; font-size:9pt;&quot;&gt;Click on an item on the left side for more information&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
@@ -597,6 +597,13 @@ p, li { white-space: pre-wrap; }
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
+ <customwidgets>
+ <customwidget>
+ <class>VmTree</class>
+ <extends>QTreeView</extends>
+ <header>../src/vmtree.h</header>
+ </customwidget>
+ </customwidgets>
<resources>
<include location="../images.qrc"/>
</resources>
diff --git a/src/vmtree.cpp b/src/vmtree.cpp
new file mode 100644
index 0000000..e430c39
--- /dev/null
+++ b/src/vmtree.cpp
@@ -0,0 +1,16 @@
+#include "vmtree.h"
+
+#include <QDebug>
+#include <QAbstractItemView>
+#include <QEvent>
+#include <QKeyEvent>
+
+void VmTree::cursorDown() {
+ QKeyEvent* e = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, Qt::NoModifier);
+ event(e);
+}
+
+void VmTree::cursorUp() {
+ QKeyEvent* e = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier);
+ event(e);
+}
diff --git a/src/vmtree.h b/src/vmtree.h
new file mode 100644
index 0000000..a80248d
--- /dev/null
+++ b/src/vmtree.h
@@ -0,0 +1,18 @@
+#ifndef VMTREE_H
+
+#include <QObject>
+#include <QTreeView>
+
+#define VMTREE_H
+
+class VmTree : public QTreeView {
+ Q_OBJECT
+
+ public:
+ VmTree(QWidget* parent = 0) : QTreeView(parent) {};
+
+ void cursorDown();
+ void cursorUp();
+};
+
+#endif