From 02f0a5e0541a806e5f75d601f638162472154272 Mon Sep 17 00:00:00 2001 From: apa420 Date: Thu, 2 Aug 2018 00:14:29 +0200 Subject: [PATCH] Added functionality of highlighitng whispers #640 --- src/common/SignalVectorModel.hpp | 4 +- src/controllers/highlights/HighlightModel.cpp | 45 ++++++++++++++----- src/controllers/highlights/HighlightModel.hpp | 2 +- .../taggedusers/TaggedUsersModel.cpp | 12 ++--- src/providers/twitch/TwitchMessageBuilder.cpp | 20 +++++++-- src/singletons/Settings.hpp | 14 ++++-- src/widgets/helper/NotebookTab.cpp | 8 ++-- .../settingspages/HighlightingPage.cpp | 2 +- 8 files changed, 75 insertions(+), 32 deletions(-) diff --git a/src/common/SignalVectorModel.hpp b/src/common/SignalVectorModel.hpp index cab31c063..88bf93c33 100644 --- a/src/common/SignalVectorModel.hpp +++ b/src/common/SignalVectorModel.hpp @@ -118,7 +118,7 @@ public: rowItem.items[column]->setData(value, role); if (rowItem.isCustomRow) { - this->customRowSetData(rowItem.items, column, value, role); + this->customRowSetData(rowItem.items, column, value, role, row); } else { int vecRow = this->getVectorIndexFromModelIndex(row); this->vector_->removeItem(vecRow, this); @@ -217,7 +217,7 @@ protected: } virtual void customRowSetData(const std::vector &row, int column, - const QVariant &value, int role) + const QVariant &value, int role, int rowIndex) { } diff --git a/src/controllers/highlights/HighlightModel.cpp b/src/controllers/highlights/HighlightModel.cpp index fcc36c3b3..4c1588953 100644 --- a/src/controllers/highlights/HighlightModel.cpp +++ b/src/controllers/highlights/HighlightModel.cpp @@ -34,32 +34,55 @@ void HighlightModel::getRowFromItem(const HighlightPhrase &item, std::vector row = this->createRow(); - setBoolItem(row[0], getApp()->settings->enableHighlightsSelf.getValue(), true, false); - row[0]->setData("Your username (automatic)", Qt::DisplayRole); - setBoolItem(row[1], getApp()->settings->enableHighlightTaskbar.getValue(), true, false); - setBoolItem(row[2], getApp()->settings->enableHighlightSound.getValue(), true, false); - row[3]->setFlags(0); - this->insertCustomRow(row, 0); + std::vector usernameRow = this->createRow(); + setBoolItem(usernameRow[0], getApp()->settings->enableSelfHighlight.getValue(), true, false); + usernameRow[0]->setData("Your username (automatic)", Qt::DisplayRole); + setBoolItem(usernameRow[1], getApp()->settings->enableSelfHighlightTaskbar.getValue(), true, + false); + setBoolItem(usernameRow[2], getApp()->settings->enableSelfHighlightSound.getValue(), true, + false); + usernameRow[3]->setFlags(0); + this->insertCustomRow(usernameRow, 0); + std::vector whisperRow = this->createRow(); + setBoolItem(whisperRow[0], getApp()->settings->enableWhisperHighlight.getValue(), true, false); + whisperRow[0]->setData("Whispers", Qt::DisplayRole); + setBoolItem(whisperRow[1], getApp()->settings->enableWhisperHighlightTaskbar.getValue(), true, + false); + setBoolItem(whisperRow[2], getApp()->settings->enableWhisperHighlightSound.getValue(), true, + false); + whisperRow[3]->setFlags(0); + this->insertCustomRow(whisperRow, 1); } void HighlightModel::customRowSetData(const std::vector &row, int column, - const QVariant &value, int role) + const QVariant &value, int role, int rowIndex) { switch (column) { case 0: { if (role == Qt::CheckStateRole) { - getApp()->settings->enableHighlightsSelf.setValue(value.toBool()); + if (rowIndex == 0) { + getApp()->settings->enableSelfHighlight.setValue(value.toBool()); + } else if (rowIndex == 1) { + getApp()->settings->enableWhisperHighlight.setValue(value.toBool()); + } } } break; case 1: { if (role == Qt::CheckStateRole) { - getApp()->settings->enableHighlightTaskbar.setValue(value.toBool()); + if (rowIndex == 0) { + getApp()->settings->enableSelfHighlightTaskbar.setValue(value.toBool()); + } else if (rowIndex == 1) { + getApp()->settings->enableWhisperHighlightTaskbar.setValue(value.toBool()); + } } } break; case 2: { if (role == Qt::CheckStateRole) { - getApp()->settings->enableHighlightSound.setValue(value.toBool()); + if (rowIndex == 0) { + getApp()->settings->enableSelfHighlightSound.setValue(value.toBool()); + } else if (rowIndex == 1) { + getApp()->settings->enableWhisperHighlightSound.setValue(value.toBool()); + } } } break; case 3: { diff --git a/src/controllers/highlights/HighlightModel.hpp b/src/controllers/highlights/HighlightModel.hpp index 7f50287ed..737ac5c8e 100644 --- a/src/controllers/highlights/HighlightModel.hpp +++ b/src/controllers/highlights/HighlightModel.hpp @@ -25,7 +25,7 @@ protected: virtual void afterInit() override; virtual void customRowSetData(const std::vector &row, int column, - const QVariant &value, int role) override; + const QVariant &value, int role, int rowIndex) override; friend class HighlightController; }; diff --git a/src/controllers/taggedusers/TaggedUsersModel.cpp b/src/controllers/taggedusers/TaggedUsersModel.cpp index b3ef872f9..2bfd83962 100644 --- a/src/controllers/taggedusers/TaggedUsersModel.cpp +++ b/src/controllers/taggedusers/TaggedUsersModel.cpp @@ -27,10 +27,10 @@ void TaggedUsersModel::getRowFromItem(const TaggedUser &item, std::vector row = this->createRow(); - // setBoolItem(row[0], getApp()->settings->enableHighlightsSelf.getValue(), true, + // setBoolItem(row[0], getApp()->settings->enableSelfHighlight.getValue(), true, // false); row[0]->setData("Your username (automatic)", Qt::DisplayRole); - // setBoolItem(row[1], getApp()->settings->enableHighlightTaskbar.getValue(), true, - // false); setBoolItem(row[2], getApp()->settings->enableHighlightSound.getValue(), + // setBoolItem(row[1], getApp()->settings->enableSelfHighlightTaskbar.getValue(), true, + // false); setBoolItem(row[2], getApp()->settings->enableSelfHighlightSound.getValue(), // true, false); row[3]->setFlags(0); this->insertCustomRow(row, 0); } @@ -40,17 +40,17 @@ void TaggedUsersModel::afterInit() // switch (column) { // case 0: { // if (role == Qt::CheckStateRole) { -// getApp()->settings->enableHighlightsSelf.setValue(value.toBool()); +// getApp()->settings->enableSelfHighlight.setValue(value.toBool()); // } // } break; // case 1: { // if (role == Qt::CheckStateRole) { -// getApp()->settings->enableHighlightTaskbar.setValue(value.toBool()); +// getApp()->settings->enableSelfHighlightTaskbar.setValue(value.toBool()); // } // } break; // case 2: { // if (role == Qt::CheckStateRole) { -// getApp()->settings->enableHighlightSound.setValue(value.toBool()); +// getApp()->settings->enableSelfHighlightSound.setValue(value.toBool()); // } // } break; // case 3: { diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index 4b75ecd5d..dd01bc8c6 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -456,9 +456,9 @@ void TwitchMessageBuilder::parseHighlights(bool isPastMsg) std::vector activeHighlights = app->highlights->phrases.getVector(); std::vector userHighlights = app->highlights->highlightedUsers.getVector(); - if (app->settings->enableHighlightsSelf && currentUsername.size() > 0) { - HighlightPhrase selfHighlight(currentUsername, app->settings->enableHighlightTaskbar, - app->settings->enableHighlightSound, false); + if (app->settings->enableSelfHighlight && currentUsername.size() > 0) { + HighlightPhrase selfHighlight(currentUsername, app->settings->enableSelfHighlightTaskbar, + app->settings->enableSelfHighlightSound, false); activeHighlights.emplace_back(std::move(selfHighlight)); } @@ -510,6 +510,20 @@ void TwitchMessageBuilder::parseHighlights(bool isPastMsg) } } } + if (app->settings->enableWhisperHighlight) { + if (this->args.isReceivedWhisper) { + Log("Highlight because it's a whisper", this->args.isReceivedWhisper); + doHighlight = true; + + if (getSettings()->enableWhisperHighlightTaskbar) { + doAlert = true; + } + + if (getSettings()->enableWhisperHighlightSound) { + playSound = true; + } + } + } this->setHighlight(doHighlight); diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index 1eda0e815..72dcfce3f 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -91,11 +91,17 @@ public: QStringSetting timeoutAction = {"/moderation/timeoutAction", "Disable"}; /// Highlighting - // BoolSetting enableHighlights = {"/highlighting/enabled", true}; - BoolSetting enableHighlightsSelf = {"/highlighting/nameIsHighlightKeyword", true}; - BoolSetting enableHighlightSound = {"/highlighting/enableSound", true}; - BoolSetting enableHighlightTaskbar = {"/highlighting/enableTaskbarFlashing", true}; + // BoolSetting enableSelfHighlights = {"/highlighting/enabled", true}; BoolSetting customHighlightSound = {"/highlighting/useCustomSound", false}; + BoolSetting enableSelfHighlight = {"/highlighting/selfHighlight/nameIsHighlightKeyword", true}; + BoolSetting enableSelfHighlightSound = {"/highlighting/selfHighlight/enableSound", true}; + BoolSetting enableSelfHighlightTaskbar = {"/highlighting/selfHighlight/enableTaskbarFlashing", + true}; + BoolSetting enableWhisperHighlight = {"/highlighting/whisperHighlight/whispersHighlighted", + true}; + BoolSetting enableWhisperHighlightSound = {"/highlighting/whisperHighlight/enableSound", false}; + BoolSetting enableWhisperHighlightTaskbar = { + "/highlighting/whisperHighlight/enableTaskbarFlashing", false}; /// Logging BoolSetting enableLogging = {"/logging/enabled", false}; diff --git a/src/widgets/helper/NotebookTab.cpp b/src/widgets/helper/NotebookTab.cpp index 46bf3993e..554fce352 100644 --- a/src/widgets/helper/NotebookTab.cpp +++ b/src/widgets/helper/NotebookTab.cpp @@ -50,15 +50,15 @@ NotebookTab::NotebookTab(Notebook *notebook) } }); - // QAction *enableHighlightsOnNewMessageAction = + // QAction *enableSelfHighlightsOnNewMessageAction = // new QAction("Enable highlights on new message", &this->menu); - // enableHighlightsOnNewMessageAction->setCheckable(true); + // enableSelfHighlightsOnNewMessageAction->setCheckable(true); this->menu_.addAction("Close", [=]() { this->notebook_->removePage(this->page); }); - // this->menu.addAction(enableHighlightsOnNewMessageAction); + // this->menu.addAction(enableSelfHighlightsOnNewMessageAction); - // QObject::connect(enableHighlightsOnNewMessageAction, &QAction::toggled, [this](bool + // QObject::connect(enableSelfHighlightsOnNewMessageAction, &QAction::toggled, [this](bool // newValue) { // Log("New value is {}", newValue); // // }); diff --git a/src/widgets/settingspages/HighlightingPage.cpp b/src/widgets/settingspages/HighlightingPage.cpp index 45a0876f3..f54267ea2 100644 --- a/src/widgets/settingspages/HighlightingPage.cpp +++ b/src/widgets/settingspages/HighlightingPage.cpp @@ -37,7 +37,7 @@ HighlightingPage::HighlightingPage() auto layout = layoutCreator.emplace().withoutMargin(); { // GENERAL - // layout.append(this->createCheckBox(ENABLE_HIGHLIGHTS, app->settings->enableHighlights)); + // layout.append(this->createCheckBox(ENABLE_HIGHLIGHTS, app->settings->enableSelfHighlights)); // TABS auto tabs = layout.emplace();