From 0aa3cb430804765e3a8adad0c9881601be0ac049 Mon Sep 17 00:00:00 2001 From: David Sansome Date: Sat, 11 Dec 2010 11:26:47 +0000 Subject: [PATCH] Don't expand items on a double click now that we expand them on single clicks instead --- src/widgets/autoexpandingtreeview.cpp | 15 ++++++++++++++- src/widgets/autoexpandingtreeview.h | 3 +++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/widgets/autoexpandingtreeview.cpp b/src/widgets/autoexpandingtreeview.cpp index deb84545f..0accb7c97 100644 --- a/src/widgets/autoexpandingtreeview.cpp +++ b/src/widgets/autoexpandingtreeview.cpp @@ -24,10 +24,14 @@ const int AutoExpandingTreeView::kRowsToShow = 50; AutoExpandingTreeView::AutoExpandingTreeView(QWidget *parent) : QTreeView(parent), auto_open_(true), - expand_on_reset_(true) + expand_on_reset_(true), + ignore_next_click_(false) { + setExpandsOnDoubleClick(false); + connect(this, SIGNAL(expanded(QModelIndex)), SLOT(ItemExpanded(QModelIndex))); connect(this, SIGNAL(clicked(QModelIndex)), SLOT(ItemClicked(QModelIndex))); + connect(this, SIGNAL(doubleClicked(QModelIndex)), SLOT(ItemDoubleClicked(QModelIndex))); } void AutoExpandingTreeView::reset() { @@ -72,5 +76,14 @@ void AutoExpandingTreeView::ItemExpanded(const QModelIndex& index) { } void AutoExpandingTreeView::ItemClicked(const QModelIndex& index) { + if (ignore_next_click_) { + ignore_next_click_ = false; + return; + } + setExpanded(index, !isExpanded(index)); } + +void AutoExpandingTreeView::ItemDoubleClicked(const QModelIndex& index) { + ignore_next_click_ = true; +} diff --git a/src/widgets/autoexpandingtreeview.h b/src/widgets/autoexpandingtreeview.h index 259e19299..d410d5ae0 100644 --- a/src/widgets/autoexpandingtreeview.h +++ b/src/widgets/autoexpandingtreeview.h @@ -43,6 +43,7 @@ class AutoExpandingTreeView : public QTreeView { private slots: void ItemExpanded(const QModelIndex& index); void ItemClicked(const QModelIndex& index); + void ItemDoubleClicked(const QModelIndex& index); private: bool RecursivelyExpand(const QModelIndex& index, int* count); @@ -50,6 +51,8 @@ class AutoExpandingTreeView : public QTreeView { private: bool auto_open_; bool expand_on_reset_; + + bool ignore_next_click_; }; #endif // AUTOEXPANDINGTREEVIEW_H