From ab4a3b5ddbb13308a2c1586778632bcb8af1d7fa Mon Sep 17 00:00:00 2001 From: Anne Jan Brouwer Date: Tue, 22 Nov 2016 23:31:21 +0100 Subject: [PATCH] Only deselect on mouseReleaseEvent if the mousePressEvent was on a selected item, fixes #233 --- deselectabletreeview.h | 24 +++++++++++++++++++----- mainwindow.cpp | 1 - 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/deselectabletreeview.h b/deselectabletreeview.h index d64f1526f..079019b06 100644 --- a/deselectabletreeview.h +++ b/deselectabletreeview.h @@ -32,29 +32,43 @@ class DeselectableTreeView : public QTreeView { void emptyClicked(); private: - bool DoubleClickHappened; + bool doubleClickHappened = false; + bool clickSelected = false; + + /** + * @brief mousePressEvent registers if the field was pre-selected + * @param event + */ + virtual void mousePressEvent(QMouseEvent *event) { + clickSelected = selectionModel()->isSelected(indexAt(event->pos())); + QTreeView::mousePressEvent(event); + } /** * @brief mouseReleaseEvent now deselects on click on empty space * @param event */ void mouseReleaseEvent(QMouseEvent *event) { - DoubleClickHappened = false; + doubleClickHappened = false; // The timer is to distinguish between single and double click QTime dieTime= QTime::currentTime().addMSecs(200); while (QTime::currentTime() < dieTime) QCoreApplication::processEvents(QEventLoop::AllEvents, 100); - if (!DoubleClickHappened){ + if (!doubleClickHappened && clickSelected){ QModelIndex item = indexAt(event->pos()); bool selected = selectionModel()->isSelected(indexAt(event->pos())); - QTreeView::mouseReleaseEvent(event); if ((item.row() == -1 && item.column() == -1) || selected) { clearSelection(); const QModelIndex index; selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select); emit emptyClicked(); + } else { + QTreeView::mouseReleaseEvent(event); } + } else { + QTreeView::mouseReleaseEvent(event); } + clickSelected = false; } @@ -63,7 +77,7 @@ class DeselectableTreeView : public QTreeView { * @param event */ void mouseDoubleClickEvent(QMouseEvent *event){ - DoubleClickHappened = true; + doubleClickHappened = true; QTreeView::mouseDoubleClickEvent(event); } diff --git a/mainwindow.cpp b/mainwindow.cpp index 8fa4b3410..fdcddea0c 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1856,7 +1856,6 @@ void MainWindow::copyTextToClipboard(const QString &text) { clippedText = text; ui->statusBar->showMessage(tr("Copied to clipboard"), 2000); if (QtPassSettings::isUseAutoclear()) { - qDebug() << QtPassSettings::getAutoclearSeconds(); QTimer::singleShot(1000 * QtPassSettings::getAutoclearSeconds(), this, SLOT(clearClipboard())); }