From f25f31a83762cbdc71bb38e245153b3f5860ad36 Mon Sep 17 00:00:00 2001 From: Cranken Date: Sat, 29 Sep 2018 22:24:48 +0200 Subject: [PATCH 1/5] Added button on tab to enable/disable highlighting. --- src/widgets/helper/NotebookTab.cpp | 15 ++++++++------- src/widgets/helper/NotebookTab.hpp | 1 + 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/widgets/helper/NotebookTab.cpp b/src/widgets/helper/NotebookTab.cpp index 4225d904b..8dd399c0e 100644 --- a/src/widgets/helper/NotebookTab.cpp +++ b/src/widgets/helper/NotebookTab.cpp @@ -62,12 +62,13 @@ NotebookTab::NotebookTab(Notebook *notebook) this->menu_.addAction("Close", [=]() { this->notebook_->removePage(this->page); }); - // this->menu.addAction(enableHighlightsOnNewMessageAction); - - // QObject::connect(enableHighlightsOnNewMessageAction, - // &QAction::toggled, [this](bool newValue) { - // Log("New value is {}", newValue); // - // }); + auto highlightNewMessagesAction = new QAction("Enable highlights on new messages", &this->menu_); + highlightNewMessagesAction->setCheckable(true); + highlightNewMessagesAction->setChecked(true); + QObject::connect(highlightNewMessagesAction, &QAction::triggered, [this] (bool checked) { + this->highlightEnabled = checked; + }); + this->menu_.addAction(highlightNewMessagesAction); } void NotebookTab::themeChangedEvent() @@ -168,7 +169,7 @@ void NotebookTab::setSelected(bool value) void NotebookTab::setHighlightState(HighlightState newHighlightStyle) { - if (this->isSelected()) { + if (this->isSelected() || !this->highlightEnabled) { return; } if (this->highlightState_ != HighlightState::Highlighted && diff --git a/src/widgets/helper/NotebookTab.hpp b/src/widgets/helper/NotebookTab.hpp index a97e1a23b..59c4b1bcd 100644 --- a/src/widgets/helper/NotebookTab.hpp +++ b/src/widgets/helper/NotebookTab.hpp @@ -82,6 +82,7 @@ private: bool mouseDownX_ = false; HighlightState highlightState_ = HighlightState::None; + bool highlightEnabled = true; QMenu menu_; From 036abd48528fbe4c3cb6f84081c667ffe1d68ab7 Mon Sep 17 00:00:00 2001 From: Cranken Date: Sat, 29 Sep 2018 22:30:31 +0200 Subject: [PATCH 2/5] Don't switch tab if only right mouse is pressed on other tab. --- src/widgets/helper/NotebookTab.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/widgets/helper/NotebookTab.cpp b/src/widgets/helper/NotebookTab.cpp index 8dd399c0e..760799b07 100644 --- a/src/widgets/helper/NotebookTab.cpp +++ b/src/widgets/helper/NotebookTab.cpp @@ -357,12 +357,14 @@ bool NotebookTab::shouldDrawXButton() void NotebookTab::mousePressEvent(QMouseEvent *event) { - this->mouseDown_ = true; - this->mouseDownX_ = this->getXRect().contains(event->pos()); + if (event->button() == Qt::LeftButton) { + this->mouseDown_ = true; + this->mouseDownX_ = this->getXRect().contains(event->pos()); - this->update(); + this->update(); - this->notebook_->select(page); + this->notebook_->select(page); + } if (this->notebook_->getAllowUserTabManagement()) { switch (event->button()) { From 839f78e19bfdd32a8702d0004b4d06653ef0f213 Mon Sep 17 00:00:00 2001 From: Cranken Date: Sat, 29 Sep 2018 22:35:33 +0200 Subject: [PATCH 3/5] Update regardless of button. --- src/widgets/helper/NotebookTab.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/widgets/helper/NotebookTab.cpp b/src/widgets/helper/NotebookTab.cpp index 760799b07..9a5e36362 100644 --- a/src/widgets/helper/NotebookTab.cpp +++ b/src/widgets/helper/NotebookTab.cpp @@ -361,11 +361,11 @@ void NotebookTab::mousePressEvent(QMouseEvent *event) this->mouseDown_ = true; this->mouseDownX_ = this->getXRect().contains(event->pos()); - this->update(); - this->notebook_->select(page); } + this->update(); + if (this->notebook_->getAllowUserTabManagement()) { switch (event->button()) { case Qt::RightButton: { From abb01b54f511bab14dc29e0b1dc258bb7c151e14 Mon Sep 17 00:00:00 2001 From: Cranken Date: Sun, 30 Sep 2018 13:44:41 +0200 Subject: [PATCH 4/5] Fixed clang format. --- src/widgets/helper/NotebookTab.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/widgets/helper/NotebookTab.cpp b/src/widgets/helper/NotebookTab.cpp index 9a5e36362..7d63f36ff 100644 --- a/src/widgets/helper/NotebookTab.cpp +++ b/src/widgets/helper/NotebookTab.cpp @@ -62,12 +62,13 @@ NotebookTab::NotebookTab(Notebook *notebook) this->menu_.addAction("Close", [=]() { this->notebook_->removePage(this->page); }); - auto highlightNewMessagesAction = new QAction("Enable highlights on new messages", &this->menu_); + auto highlightNewMessagesAction = + new QAction("Enable highlights on new messages", &this->menu_); highlightNewMessagesAction->setCheckable(true); highlightNewMessagesAction->setChecked(true); - QObject::connect(highlightNewMessagesAction, &QAction::triggered, [this] (bool checked) { - this->highlightEnabled = checked; - }); + QObject::connect( + highlightNewMessagesAction, &QAction::triggered, + [this](bool checked) { this->highlightEnabled = checked; }); this->menu_.addAction(highlightNewMessagesAction); } From f6e69162630fbefbe582e85854e60a409cbc3ef2 Mon Sep 17 00:00:00 2001 From: Cranken Date: Sun, 30 Sep 2018 14:31:00 +0200 Subject: [PATCH 5/5] Fixed variable naming style. --- src/widgets/helper/NotebookTab.cpp | 4 ++-- src/widgets/helper/NotebookTab.hpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/widgets/helper/NotebookTab.cpp b/src/widgets/helper/NotebookTab.cpp index 7d63f36ff..603fbf53b 100644 --- a/src/widgets/helper/NotebookTab.cpp +++ b/src/widgets/helper/NotebookTab.cpp @@ -68,7 +68,7 @@ NotebookTab::NotebookTab(Notebook *notebook) highlightNewMessagesAction->setChecked(true); QObject::connect( highlightNewMessagesAction, &QAction::triggered, - [this](bool checked) { this->highlightEnabled = checked; }); + [this](bool checked) { this->highlightEnabled_ = checked; }); this->menu_.addAction(highlightNewMessagesAction); } @@ -170,7 +170,7 @@ void NotebookTab::setSelected(bool value) void NotebookTab::setHighlightState(HighlightState newHighlightStyle) { - if (this->isSelected() || !this->highlightEnabled) { + if (this->isSelected() || !this->highlightEnabled_) { return; } if (this->highlightState_ != HighlightState::Highlighted && diff --git a/src/widgets/helper/NotebookTab.hpp b/src/widgets/helper/NotebookTab.hpp index 59c4b1bcd..25e0bff47 100644 --- a/src/widgets/helper/NotebookTab.hpp +++ b/src/widgets/helper/NotebookTab.hpp @@ -82,7 +82,7 @@ private: bool mouseDownX_ = false; HighlightState highlightState_ = HighlightState::None; - bool highlightEnabled = true; + bool highlightEnabled_ = true; QMenu menu_;