From 7c3cd930f3086a08016daf31263223e0a1b205b4 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 11 Jun 2017 20:53:43 +0200 Subject: [PATCH] make a few settings into pajlada::Settings::Settings Add setting to hide badges Give focus to text input if you click anywhere in a chat widget --- src/messages/messagebuilder.cpp | 5 ++-- src/messages/messageref.cpp | 5 ++-- src/settingsmanager.cpp | 43 ++++++++++++++++++++------------- src/settingsmanager.hpp | 10 +++++--- src/widgets/chatwidget.cpp | 5 ++++ src/widgets/chatwidget.hpp | 2 ++ src/widgets/chatwidgetinput.hpp | 4 ++- src/widgets/chatwidgetview.cpp | 2 ++ src/widgets/chatwidgetview.hpp | 2 +- src/widgets/settingsdialog.cpp | 18 ++++++++++++++ src/widgets/settingsdialog.hpp | 2 ++ 11 files changed, 71 insertions(+), 27 deletions(-) diff --git a/src/messages/messagebuilder.cpp b/src/messages/messagebuilder.cpp index 5858be799..d39c8e58f 100644 --- a/src/messages/messagebuilder.cpp +++ b/src/messages/messagebuilder.cpp @@ -50,5 +50,6 @@ QString MessageBuilder::matchLink(const QString &string) // TODO: Implement this xD return QString(); } -} -} + +} // namespace messages +} // namespace chatterino diff --git a/src/messages/messageref.cpp b/src/messages/messageref.cpp index e6cb18037..402f82be2 100644 --- a/src/messages/messageref.cpp +++ b/src/messages/messageref.cpp @@ -84,7 +84,7 @@ bool MessageRef::layout(int width, bool enableEmoteMargins) } if (newWordTypes) { - _currentWordTypes = SettingsManager::getInstance().getWordTypeMask(); + _currentWordTypes = settings.getWordTypeMask(); } // layout @@ -102,11 +102,12 @@ bool MessageRef::layout(int width, bool enableEmoteMargins) _wordParts.clear(); - uint32_t flags = SettingsManager::getInstance().getWordTypeMask(); + uint32_t flags = settings.getWordTypeMask(); for (auto it = _message->getWords().begin(); it != _message->getWords().end(); ++it) { Word &word = *it; + // Check if given word is supposed to be rendered by comparing it to the current setting if ((word.getType() & flags) == Word::None) { continue; } diff --git a/src/settingsmanager.cpp b/src/settingsmanager.cpp index 32b3d951a..517f79bc0 100644 --- a/src/settingsmanager.cpp +++ b/src/settingsmanager.cpp @@ -17,8 +17,9 @@ SettingsManager::SettingsManager() , emoteScale(_settingsItems, "emoteScale", 1.0) , mouseScrollMultiplier(_settingsItems, "mouseScrollMultiplier", 1.0) , scaleEmotesByLineHeight(_settingsItems, "scaleEmotesByLineHeight", false) - , showTimestamps(_settingsItems, "showTimestamps", true) - , showTimestampSeconds(_settingsItems, "showTimestampSeconds", false) + , showTimestamps("/appearance/messages/showTimestamps", true) + , showTimestampSeconds("/appearance/messages/showTimestampSeconds", true) + , showBadges("/appearance/messages/showBadges", true) , showLastMessageIndicator(_settingsItems, "showLastMessageIndicator", false) , allowDouplicateMessages(_settingsItems, "allowDouplicateMessages", true) , linksDoubleClickOnly(_settingsItems, "linksDoubleClickOnly", false) @@ -47,6 +48,7 @@ SettingsManager::SettingsManager() this->showTimestamps.valueChanged.connect([this](const auto &) { this->updateWordTypeMask(); }); this->showTimestampSeconds.valueChanged.connect( [this](const auto &) { this->updateWordTypeMask(); }); + this->showBadges.valueChanged.connect([this](const auto &) { this->updateWordTypeMask(); }); this->enableBttvEmotes.valueChanged.connect( [this](const auto &) { this->updateWordTypeMask(); }); this->enableEmojis.valueChanged.connect([this](const auto &) { this->updateWordTypeMask(); }); @@ -87,29 +89,36 @@ QSettings &SettingsManager::getQSettings() void SettingsManager::updateWordTypeMask() { - uint32_t mask = Word::Text; + uint32_t newMaskUint = Word::Text; - if (showTimestamps.get()) { - mask |= showTimestampSeconds.get() ? Word::TimestampWithSeconds : Word::TimestampNoSeconds; + if (this->showTimestamps) { + if (this->showTimestampSeconds) { + newMaskUint |= Word::TimestampWithSeconds; + } else { + newMaskUint |= Word::TimestampNoSeconds; + } } - mask |= enableTwitchEmotes.get() ? Word::TwitchEmoteImage : Word::TwitchEmoteText; - mask |= enableFfzEmotes.get() ? Word::FfzEmoteImage : Word::FfzEmoteText; - mask |= enableBttvEmotes.get() ? Word::BttvEmoteImage : Word::BttvEmoteText; - mask |= + newMaskUint |= enableTwitchEmotes.get() ? Word::TwitchEmoteImage : Word::TwitchEmoteText; + newMaskUint |= enableFfzEmotes.get() ? Word::FfzEmoteImage : Word::FfzEmoteText; + newMaskUint |= enableBttvEmotes.get() ? Word::BttvEmoteImage : Word::BttvEmoteText; + newMaskUint |= (enableBttvEmotes.get() && enableGifs.get()) ? Word::BttvEmoteImage : Word::BttvEmoteText; - mask |= enableEmojis.get() ? Word::EmojiImage : Word::EmojiText; + newMaskUint |= enableEmojis.get() ? Word::EmojiImage : Word::EmojiText; - mask |= Word::BitsAmount; - mask |= enableGifs.get() ? Word::BitsAnimated : Word::BitsStatic; + newMaskUint |= Word::BitsAmount; + newMaskUint |= enableGifs.get() ? Word::BitsAnimated : Word::BitsStatic; - mask |= Word::Badges; - mask |= Word::Username; + if (this->showBadges) { + newMaskUint |= Word::Badges; + } - Word::Type _mask = (Word::Type)mask; + newMaskUint |= Word::Username; - if (mask != _mask) { - _wordTypeMask = _mask; + Word::Type newMask = static_cast(newMaskUint); + + if (newMask != _wordTypeMask) { + _wordTypeMask = newMask; emit wordTypeMaskChanged(); } diff --git a/src/settingsmanager.hpp b/src/settingsmanager.hpp index 9c4365392..509f636e3 100644 --- a/src/settingsmanager.hpp +++ b/src/settingsmanager.hpp @@ -5,6 +5,7 @@ #include "settingssnapshot.hpp" #include +#include namespace chatterino { @@ -36,6 +37,11 @@ private: void updateWordTypeMask(); public: + // new pajlada settings BBaper + pajlada::Settings::Setting showTimestamps; + pajlada::Settings::Setting showTimestampSeconds; + pajlada::Settings::Setting showBadges; + // Settings Setting theme; Setting themeHue; @@ -43,8 +49,6 @@ public: Setting emoteScale; Setting mouseScrollMultiplier; Setting scaleEmotesByLineHeight; - Setting showTimestamps; - Setting showTimestampSeconds; Setting showLastMessageIndicator; Setting allowDouplicateMessages; Setting linksDoubleClickOnly; @@ -76,8 +80,6 @@ public: static SettingsManager instance; return instance; } - -private: }; } // namespace chatterino diff --git a/src/widgets/chatwidget.cpp b/src/widgets/chatwidget.cpp index b6d911a50..3a01c0d32 100644 --- a/src/widgets/chatwidget.cpp +++ b/src/widgets/chatwidget.cpp @@ -188,6 +188,11 @@ void ChatWidget::updateGifEmotes() this->view.updateGifEmotes(); } +void ChatWidget::giveFocus() +{ + this->input.textInput.setFocus(); +} + void ChatWidget::paintEvent(QPaintEvent *) { // color the background of the chat diff --git a/src/widgets/chatwidget.hpp b/src/widgets/chatwidget.hpp index b25c63c99..9104ea68b 100644 --- a/src/widgets/chatwidget.hpp +++ b/src/widgets/chatwidget.hpp @@ -47,6 +47,8 @@ public: void layoutMessages(); void updateGifEmotes(); + void giveFocus(); + protected: void paintEvent(QPaintEvent *) override; diff --git a/src/widgets/chatwidgetinput.hpp b/src/widgets/chatwidgetinput.hpp index 8a02591ea..03a9419cf 100644 --- a/src/widgets/chatwidgetinput.hpp +++ b/src/widgets/chatwidgetinput.hpp @@ -29,7 +29,7 @@ protected: virtual void resizeEvent(QResizeEvent *) override; private: - ChatWidget *chatWidget; + ChatWidget *const chatWidget; QHBoxLayout hbox; QVBoxLayout vbox; @@ -46,6 +46,8 @@ private slots: } void editTextChanged(); // void editKeyPressed(QKeyEvent *event); + + friend class ChatWidget; }; } // namespace widgets diff --git a/src/widgets/chatwidgetview.cpp b/src/widgets/chatwidgetview.cpp index 9fa8bfcd3..b04e7cbb1 100644 --- a/src/widgets/chatwidgetview.cpp +++ b/src/widgets/chatwidgetview.cpp @@ -336,6 +336,8 @@ void ChatWidgetView::mousePressEvent(QMouseEvent *event) { this->isMouseDown = true; this->lastPressPosition = event->screenPos(); + + this->chatWidget->giveFocus(); } void ChatWidgetView::mouseReleaseEvent(QMouseEvent *event) diff --git a/src/widgets/chatwidgetview.hpp b/src/widgets/chatwidgetview.hpp index 48f1ac978..b5652fdf9 100644 --- a/src/widgets/chatwidgetview.hpp +++ b/src/widgets/chatwidgetview.hpp @@ -49,7 +49,7 @@ private: std::vector gifEmotes; - ChatWidget *chatWidget; + ChatWidget *const chatWidget; ScrollBar scrollBar; diff --git a/src/widgets/settingsdialog.cpp b/src/widgets/settingsdialog.cpp index a70c36ea6..30123ef73 100644 --- a/src/widgets/settingsdialog.cpp +++ b/src/widgets/settingsdialog.cpp @@ -5,6 +5,7 @@ #include "windowmanager.hpp" #include +#include #include #include #include @@ -166,6 +167,7 @@ void SettingsDialog::addTabs() auto v = new QVBoxLayout(); v->addWidget(createCheckbox("Show timestamp", settings.showTimestamps)); v->addWidget(createCheckbox("Show seconds in timestamp", settings.showTimestampSeconds)); + v->addWidget(createCheckbox("Show badges", settings.showBadges)); v->addWidget(createCheckbox("Allow sending duplicate messages (add a space at the end)", settings.allowDouplicateMessages)); v->addWidget(createCheckbox("Seperate messages", settings.seperateMessages)); @@ -323,6 +325,22 @@ QCheckBox *SettingsDialog::createCheckbox(const QString &title, Setting &s return checkbox; } +QCheckBox *SettingsDialog::createCheckbox(const QString &title, + pajlada::Settings::Setting &setting) +{ + auto checkbox = new QCheckBox(title); + + // Set checkbox initial state + checkbox->setChecked(setting.getValue()); + + QObject::connect(checkbox, &QCheckBox::toggled, this, [&setting](bool state) { + qDebug() << "update checkbox value"; + setting = state; // + }); + + return checkbox; +} + void SettingsDialog::okButtonClicked() { this->close(); diff --git a/src/widgets/settingsdialog.hpp b/src/widgets/settingsdialog.hpp index 6fd04f0ce..40aac2a55 100644 --- a/src/widgets/settingsdialog.hpp +++ b/src/widgets/settingsdialog.hpp @@ -14,6 +14,7 @@ #include #include #include +#include namespace chatterino { namespace widgets { @@ -46,6 +47,7 @@ private: /// Widget creation helpers QCheckBox *createCheckbox(const QString &title, Setting &setting); + QCheckBox *createCheckbox(const QString &title, pajlada::Settings::Setting &setting); void okButtonClicked(); void cancelButtonClicked();