QtPass 1.4.0
Multi-platform GUI for pass, the standard unix password manager.
Loading...
Searching...
No Matches
deselectabletreeview.h
Go to the documentation of this file.
1#ifndef DESELECTABLETREEVIEW_H
2#define DESELECTABLETREEVIEW_H
3
4#include <QCoreApplication>
5#include <QMouseEvent>
6#include <QTime>
7#include <QTreeView>
8
14class DeselectableTreeView : public QTreeView {
15 Q_OBJECT
16
17public:
22 DeselectableTreeView(QWidget *parent) : QTreeView(parent) {}
27
28signals:
33
34private:
35 bool doubleClickHappened = false;
36 bool clickSelected = false;
37
42 virtual void mousePressEvent(QMouseEvent *event) {
43 clickSelected = selectionModel()->isSelected(indexAt(event->pos()));
44 QTreeView::mousePressEvent(event);
45 }
46
51 void mouseReleaseEvent(QMouseEvent *event) {
52 doubleClickHappened = false;
53 // The timer is to distinguish between single and double click
54 QTime dieTime = QTime::currentTime().addMSecs(200);
55 while (QTime::currentTime() < dieTime)
56 QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
57 // could this be done nicer?
58 if (!doubleClickHappened && clickSelected) {
59 QModelIndex item = indexAt(event->pos());
60 bool selected = selectionModel()->isSelected(indexAt(event->pos()));
61 if ((item.row() == -1 && item.column() == -1) || selected) {
62 clearSelection();
63 const QModelIndex index;
64 selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select);
65 emit emptyClicked();
66 } else {
67 QTreeView::mouseReleaseEvent(event);
68 }
69 } else {
70 QTreeView::mouseReleaseEvent(event);
71 }
72 clickSelected = false;
73 }
74
79 void mouseDoubleClickEvent(QMouseEvent *event) {
80 doubleClickHappened = true;
81 QTreeView::mouseDoubleClickEvent(event);
82 }
83};
84
85#endif // DESELECTABLETREEVIEW_H
The DeselectableTreeView class loosly based on http://stackoverflow.com/questions/2761284/ thanks to ...
virtual ~DeselectableTreeView()
~DeselectableTreeView standard destructor
DeselectableTreeView(QWidget *parent)
DeselectableTreeView standard constructor.
void emptyClicked()
emptyClicked event