From 22d009962d0e6b52daa206f5944983394888d986 Mon Sep 17 00:00:00 2001 From: Cranken Date: Sun, 30 Sep 2018 15:02:30 +0200 Subject: [PATCH] Now saves the enable highlight on new message tab setting. --- src/singletons/WindowManager.cpp | 8 ++++++++ src/widgets/helper/NotebookTab.cpp | 25 ++++++++++++++++--------- src/widgets/helper/NotebookTab.hpp | 3 +++ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/singletons/WindowManager.cpp b/src/singletons/WindowManager.cpp index dc6f9c63a..3082d336e 100644 --- a/src/singletons/WindowManager.cpp +++ b/src/singletons/WindowManager.cpp @@ -301,6 +301,10 @@ void WindowManager::initialize(Settings &settings, Paths &paths) window.getNotebook().select(page); } + // highlighting on new messages + bool val = tab_obj.value("highlightsEnabled").toBool(true); + page->getTab()->setHighlightsEnabled(val); + // load splits QJsonObject splitRoot = tab_obj.value("splits2").toObject(); @@ -400,6 +404,10 @@ void WindowManager::save() tab_obj.insert("selected", true); } + // highlighting on new messages + tab_obj.insert("highlightsEnabled", + tab->getTab()->hasHighlightsEnabled()); + // splits QJsonObject splits; diff --git a/src/widgets/helper/NotebookTab.cpp b/src/widgets/helper/NotebookTab.cpp index 603fbf53b..51812e7c7 100644 --- a/src/widgets/helper/NotebookTab.cpp +++ b/src/widgets/helper/NotebookTab.cpp @@ -55,21 +55,17 @@ NotebookTab::NotebookTab(Notebook *notebook) } }); - // QAction *enableHighlightsOnNewMessageAction = - // new QAction("Enable highlights on new message", &this->menu); - // enableHighlightsOnNewMessageAction->setCheckable(true); - this->menu_.addAction("Close", [=]() { this->notebook_->removePage(this->page); }); - auto highlightNewMessagesAction = + highlightNewMessagesAction_ = new QAction("Enable highlights on new messages", &this->menu_); - highlightNewMessagesAction->setCheckable(true); - highlightNewMessagesAction->setChecked(true); + highlightNewMessagesAction_->setCheckable(true); + highlightNewMessagesAction_->setChecked(highlightEnabled_); QObject::connect( - highlightNewMessagesAction, &QAction::triggered, + highlightNewMessagesAction_, &QAction::triggered, [this](bool checked) { this->highlightEnabled_ = checked; }); - this->menu_.addAction(highlightNewMessagesAction); + this->menu_.addAction(highlightNewMessagesAction_); } void NotebookTab::themeChangedEvent() @@ -181,6 +177,17 @@ void NotebookTab::setHighlightState(HighlightState newHighlightStyle) } } +void NotebookTab::setHighlightsEnabled(const bool &newVal) +{ + this->highlightNewMessagesAction_->setChecked(newVal); + this->highlightEnabled_ = newVal; +} + +bool NotebookTab::hasHighlightsEnabled() const +{ + return this->highlightEnabled_; +} + QRect NotebookTab::getDesiredRect() const { return QRect(this->positionAnimationDesiredPoint_, size()); diff --git a/src/widgets/helper/NotebookTab.hpp b/src/widgets/helper/NotebookTab.hpp index 25e0bff47..15baebecc 100644 --- a/src/widgets/helper/NotebookTab.hpp +++ b/src/widgets/helper/NotebookTab.hpp @@ -40,6 +40,8 @@ public: void setSelected(bool value); void setHighlightState(HighlightState style); + void setHighlightsEnabled(const bool &newVal); + bool hasHighlightsEnabled() const; void moveAnimated(QPoint pos, bool animated = true); @@ -83,6 +85,7 @@ private: HighlightState highlightState_ = HighlightState::None; bool highlightEnabled_ = true; + QAction *highlightNewMessagesAction_; QMenu menu_;