From be92a82891af8ebfa49dadd4ee294c31a957edcb Mon Sep 17 00:00:00 2001 From: fourtf Date: Sun, 22 Jan 2017 12:46:35 +0100 Subject: [PATCH] updated settingsdialog --- .../StatusAnnotations_Blocked_16xLG_color.png | Bin 0 -> 1618 bytes images/UserProfile_22x.png | Bin 0 -> 286 bytes images/VSO_Link_blue_16x.png | Bin 0 -> 480 bytes messages/message.cpp | 11 +- messages/word.h | 4 +- resources.qrc | 3 + settings/settings.cpp | 151 ++++++++--- settings/settings.h | 252 +++++++++--------- widgets/chatwidget.cpp | 5 +- widgets/chatwidget.h | 1 + widgets/chatwidgetinput.cpp | 15 ++ widgets/chatwidgetinput.h | 6 + widgets/chatwidgetview.cpp | 13 +- widgets/chatwidgetview.h | 11 + widgets/mainwindow.cpp | 4 - widgets/notebook.cpp | 55 +++- widgets/notebook.h | 5 +- widgets/notebooktab.cpp | 84 ++++-- widgets/notebooktab.h | 10 +- widgets/settingsdialog.cpp | 85 +++++- widgets/settingsdialog.h | 4 +- 21 files changed, 487 insertions(+), 232 deletions(-) create mode 100644 images/StatusAnnotations_Blocked_16xLG_color.png create mode 100644 images/UserProfile_22x.png create mode 100644 images/VSO_Link_blue_16x.png diff --git a/images/StatusAnnotations_Blocked_16xLG_color.png b/images/StatusAnnotations_Blocked_16xLG_color.png new file mode 100644 index 0000000000000000000000000000000000000000..b58166e3064edc117c8b97942e585dc84d36a27b GIT binary patch literal 1618 zcmbVMPi)&%7!QmNQE6HaYzMeJxsw2?j_v%h8_VuU>y$>C)2NBGawzJH{hGYhvCZ>K zlXgf86B2MiLP7#@=m`l92yNnsrd~K8AwWnwY=>QtI8GhA0f+H9PNIaNYRs}@zxVyV z-}k=n`{nzvT6yEl>`Sw$RO(E5&DwzXT>LzD3V!e3`wcc`d|Kb+oAxE$3EFAw1`U$# zwL`F{QpUwzh@D-+QG+z8ZwklX9SMlKrf@lL%XYXzT6FDzk=j9}?i}no1y{JZG;8#9 zAZQbgQLpX!k=`?f0k00<@wOzO0fg_GLNN}AHti}}2^c~7bXIg^MM0{XR&se&RTfZ2 zRx*+dw<;<*J+JB+4Gk}0X%-pG-O)F!)nPDLnL>;6P?w}`x0~)}(*bKrN}*7QNirD` z5Ms3NbKDdCXg;P$I4lx5jE0;BK8iVUBj|8b5WtRxol$qhYxItZkBN~StU!4E&&ErS>SdY{!V?h zhSq(L`oxf8Re^aRsAM(rHKY^57_Os7PZ0J=L;Z`+7|2LpqY)3-{zPIm^7eFMgM%Y9 z5Rs0Z_@8155#A$iBKeVtK5fsT-U)fPMS%KbeT~6Uu*18Ukzx~sG8!q%jJi#NR%$AG z^)mI{pc}n5eM+Z={U(87CdET3R<$5a_GXm6Aw5>0q6T_qVFQznFS(H3ZACw{3jhpnyBgH!8K%Hu~l0 z`0&=sGqAH&wu<%MTcwYFe4#JT&Ak7`%pVJP`gh)aWp{4<(0l!B{L|Kr_imiqJpA>C zoyw`d_s@P+f4;wW?(Ws_+Y3LRzIKc8+YfKbJ9j^L^I4@OoWJ?8_-SS%rD%& ZV)P$s#V`L_d>I0z%B70+&GPp3e*mip`8EIm literal 0 HcmV?d00001 diff --git a/images/UserProfile_22x.png b/images/UserProfile_22x.png new file mode 100644 index 0000000000000000000000000000000000000000..c47f61243ff1731e5b9d01a5bb04a7de5e2efddb GIT binary patch literal 286 zcmeAS@N?(olHy`uVBq!ia0vp^Vj#@H1|*Mc$*~4foCO|{#S9F5M?jcysy3fAQ1F7M zi(^Pd+})`gxeghKxaO;Rzr1(z+}Ge;D-!;2Sl?dCx9f_%VbiWJ>aTL@7ge8(s60H| zh-H$<5$49zvV8d!o{KVP8L&4sU9(zY+xOU`AW($W>B2VM4%TM}_53EWO#jS!{&+WE z>Z?CTuWodjxBfuDvUA~Qf);yUzM@o?BEe=~c)wm}?&2Lg&2*A9OE)McB+9s7SuVx4 zE-6aa?XKvQU5yip_;*fDFuT3=_7RrOd$GrFrYB8yjx6HQJ~wUVn&mOjZw#KUelF{r5}E+X)^#`l literal 0 HcmV?d00001 diff --git a/images/VSO_Link_blue_16x.png b/images/VSO_Link_blue_16x.png new file mode 100644 index 0000000000000000000000000000000000000000..eb3882929648613f91bccc6c7ac9758abf566c63 GIT binary patch literal 480 zcmV<60U!Q}P))+3xEnKP~`I&NJwkN!5li+b=IKAIc8_rGBZ%J zC6y}{`scSv9o-;|+&d83qnxHw?Ch3oW51~`5TTXLG%-Fou<&UyDK4m<2vfsUMA-Nx zDk85xM``^aL;mkaVt)5EPE14&B-}GGvitu~UNcD34f>hPP>I!@8xbA)b|_}=Qj%Uy zhKWhButEUE5HTRD=~&y(f*%L|ZWo3-T!?w!!dY&?MYf3DQ~@@t3MR*z0YuwhIhyA- zF3}m>!mp2R^fbP}_>U7zubo3xfOKAm$@@1>FbR1d%m#XE;AyRbW)S|K=CJH(g0IVk zGK&I6+(9MVR`0-cUoDs*``|NvVB_>}uGm2^(mN2FDFlFp8MFbgo3pg;8WPXoXSxGN W(LnN591BemoteGeneration != Emotes::getGeneration(); bool recalculateText = this->fontGeneration != Fonts::getGeneration(); - qreal emoteScale = settings::Settings::getEmoteScale().get(); - bool scaleEmotesByLineHeight = - settings::Settings::getScaleEmotesByLineHeight().get(); + qreal emoteScale = settings.getEmoteScale().get(); + bool scaleEmotesByLineHeight = settings.getScaleEmotesByLineHeight().get(); if (recalculateImages || recalculateText) { this->emoteGeneration = Emotes::getGeneration(); @@ -474,7 +475,7 @@ Message::layout(int width, bool enableEmoteMargins) } }; - int flags = settings::Settings::getWordTypeMask(); + uint32_t flags = settings::Settings::getInstance().getWordTypeMask(); for (auto it = this->words.begin(); it != this->words.end(); ++it) { Word &word = *it; diff --git a/messages/word.h b/messages/word.h index 68312a234..1e3d3808f 100644 --- a/messages/word.h +++ b/messages/word.h @@ -34,7 +34,7 @@ public: EmoteImages = TwitchEmoteImage | BttvEmoteImage | BttvGifEmoteImage | FfzEmoteImage, - Bits = (1 << 12), + BitsStatic = (1 << 12), BitsAnimated = (1 << 13), BadgeStaff = (1 << 14), @@ -59,7 +59,7 @@ public: EmojiImage = (1 << 27), EmojiText = (1 << 28), - Default = TimestampNoSeconds | Badges | Username | Bits | + Default = TimestampNoSeconds | Badges | Username | BitsStatic | FfzEmoteImage | BttvEmoteImage | BttvGifEmoteImage | TwitchEmoteImage | BitsAmount | Text | ButtonBan | ButtonTimeout diff --git a/resources.qrc b/resources.qrc index 489d0d6d3..0c300cabf 100644 --- a/resources.qrc +++ b/resources.qrc @@ -27,5 +27,8 @@ emojidata.txt images/button_ban.png images/button_timeout.png + images/StatusAnnotations_Blocked_16xLG_color.png + images/UserProfile_22x.png + images/VSO_Link_blue_16x.png diff --git a/settings/settings.cpp b/settings/settings.cpp index 5262a897c..9aaba2af7 100644 --- a/settings/settings.cpp +++ b/settings/settings.cpp @@ -6,44 +6,85 @@ namespace chatterino { namespace settings { -StringSetting Settings::theme("", "dark"); -StringSetting Settings::user("", ""); -FloatSetting Settings::emoteScale("", 1.0); -BoolSetting Settings::scaleEmotesByLineHeight("", false); -BoolSetting Settings::showTimestamps("", true); -BoolSetting Settings::showTimestampSeconds("", false); -BoolSetting Settings::allowDouplicateMessages("", true); -BoolSetting Settings::linksDoubleClickOnly("", false); -BoolSetting Settings::hideEmptyInput("", false); -BoolSetting Settings::showMessageLength("", false); -BoolSetting Settings::seperateMessages("", false); -BoolSetting Settings::mentionUsersWithAt("", false); -BoolSetting Settings::allowCommandsAtEnd("", false); -BoolSetting Settings::enableHighlights("", true); -BoolSetting Settings::enableHighlightSound("", true); -BoolSetting Settings::enableHighlightTaskbar("", true); -BoolSetting Settings::customHighlightSound("", false); -BoolSetting Settings::enableTwitchEmotes("", true); -BoolSetting Settings::enableBttvEmotes("", true); -BoolSetting Settings::enableFFzEmotes("", true); -BoolSetting Settings::enableEmojis("", true); -BoolSetting Settings::enableGifAnimations("", true); -BoolSetting Settings::enableGifs("", true); -BoolSetting Settings::inlineWhispers("", true); -BoolSetting Settings::windowTopMost("", true); -BoolSetting Settings::hideTabX("", false); +Settings Settings::_; -QSettings Settings::settings( - QStandardPaths::writableLocation(QStandardPaths::AppDataLocation), - QSettings::IniFormat); +Settings::Settings() + : settings( + QStandardPaths::writableLocation(QStandardPaths::AppDataLocation), + QSettings::IniFormat) + , settingsItems() + , portable(false) + , wordTypeMask(messages::Word::Default) + , theme("", "dark") + , user("", "") + , emoteScale("", 1.0) + , scaleEmotesByLineHeight("", false) + , showTimestamps("", true) + , showTimestampSeconds("", false) + , showLastMessageIndicator("", false) + , allowDouplicateMessages("", true) + , linksDoubleClickOnly("", false) + , hideEmptyInput("", false) + , showMessageLength("", false) + , seperateMessages("", false) + , mentionUsersWithAt("", false) + , allowCommandsAtEnd("", false) + , enableHighlights("", true) + , enableHighlightSound("", true) + , enableHighlightTaskbar("", true) + , customHighlightSound("", false) + , enableTwitchEmotes("", true) + , enableBttvEmotes("", true) + , enableFfzEmotes("", true) + , enableEmojis("", true) + , enableGifAnimations("", true) + , enableGifs("", true) + , inlineWhispers("", true) + , windowTopMost("", true) + , hideTabX("", false) +{ + settingsItems.reserve(25); + settingsItems.push_back(&theme); + settingsItems.push_back(&user); + settingsItems.push_back(&emoteScale); + settingsItems.push_back(&scaleEmotesByLineHeight); + settingsItems.push_back(&showTimestamps); + settingsItems.push_back(&showTimestampSeconds); + settingsItems.push_back(&showLastMessageIndicator); + settingsItems.push_back(&allowDouplicateMessages); + settingsItems.push_back(&linksDoubleClickOnly); + settingsItems.push_back(&hideEmptyInput); + settingsItems.push_back(&showMessageLength); + settingsItems.push_back(&seperateMessages); + settingsItems.push_back(&mentionUsersWithAt); + settingsItems.push_back(&allowCommandsAtEnd); + settingsItems.push_back(&enableHighlights); + settingsItems.push_back(&enableHighlightSound); + settingsItems.push_back(&enableHighlightTaskbar); + settingsItems.push_back(&customHighlightSound); + settingsItems.push_back(&enableTwitchEmotes); + settingsItems.push_back(&enableBttvEmotes); + settingsItems.push_back(&enableFfzEmotes); + settingsItems.push_back(&enableEmojis); + settingsItems.push_back(&enableGifAnimations); + settingsItems.push_back(&enableGifs); + settingsItems.push_back(&inlineWhispers); + settingsItems.push_back(&windowTopMost); + settingsItems.push_back(&hideTabX); -std::vector Settings::settingsItems; - -bool Settings::portable(false); - -messages::Word::Type Settings::wordTypeMask = messages::Word::Default; - -int Settings::_ = Settings::_init(); + QObject::connect(&showTimestamps, &BoolSetting::valueChanged, this, + &Settings::updateWordTypeMask); + QObject::connect(&showTimestampSeconds, &BoolSetting::valueChanged, this, + &Settings::updateWordTypeMask); + QObject::connect(&enableBttvEmotes, &BoolSetting::valueChanged, this, + &Settings::updateWordTypeMask); + QObject::connect(&enableEmojis, &BoolSetting::valueChanged, this, + &Settings::updateWordTypeMask); + QObject::connect(&enableFfzEmotes, &BoolSetting::valueChanged, this, + &Settings::updateWordTypeMask); + QObject::connect(&enableTwitchEmotes, &BoolSetting::valueChanged, this, + &Settings::updateWordTypeMask); +} void Settings::save() @@ -62,9 +103,45 @@ Settings::load() } bool -Settings::isIgnoredEmote(const QString &emote) +Settings::isIgnoredEmote(const QString &) { return false; } + +void +Settings::updateWordTypeMask(bool) + +{ + using namespace messages; + + uint32_t mask = Word::Text; + + if (showTimestamps.get()) { + mask |= showTimestampSeconds.get() ? Word::TimestampWithSeconds + : Word::TimestampNoSeconds; + } + + mask |= enableTwitchEmotes.get() ? Word::TwitchEmoteImage + : Word::TwitchEmoteText; + mask |= enableFfzEmotes.get() ? Word::FfzEmoteImage : Word::FfzEmoteText; + mask |= enableBttvEmotes.get() ? Word::BttvEmoteImage : Word::BttvEmoteText; + mask |= (enableBttvEmotes.get() && enableGifs.get()) ? Word::BttvEmoteImage + : Word::BttvEmoteText; + mask |= enableEmojis.get() ? Word::EmojiImage : Word::EmojiText; + + mask |= Word::BitsAmount; + mask |= enableGifs.get() ? Word::BitsAnimated : Word::BitsStatic; + + mask |= Word::Badges; + mask |= Word::Username; + + Word::Type _mask = (Word::Type)mask; + + // if (mask != _mask) { + wordTypeMask = _mask; + + emit wordTypeMaskChanged(); + // } +} } } diff --git a/settings/settings.h b/settings/settings.h index 741841272..97f72f05d 100644 --- a/settings/settings.h +++ b/settings/settings.h @@ -12,243 +12,231 @@ namespace chatterino { namespace settings { -class Settings +class Settings : public QObject { + Q_OBJECT + public: - static messages::Word::Type + static Settings & + getInstance() + { + return _; + } + + void load(); + void save(); + + messages::Word::Type getWordTypeMask() { return wordTypeMask; } - static bool isIgnoredEmote(const QString &emote); + bool isIgnoredEmote(const QString &emote); - static void load(); - static void save(); - - static bool + bool getPortable() { return portable; } - static void + void setPortable(bool value) { portable = value; } +signals: + void wordTypeMaskChanged(); + private: Settings(); - static int _; - static int - _init() - { - settingsItems.reserve(25); - settingsItems.push_back(&theme); - settingsItems.push_back(&user); - settingsItems.push_back(&emoteScale); - settingsItems.push_back(&scaleEmotesByLineHeight); - settingsItems.push_back(&showTimestamps); - settingsItems.push_back(&showTimestampSeconds); - settingsItems.push_back(&allowDouplicateMessages); - settingsItems.push_back(&linksDoubleClickOnly); - settingsItems.push_back(&hideEmptyInput); - settingsItems.push_back(&showMessageLength); - settingsItems.push_back(&seperateMessages); - settingsItems.push_back(&mentionUsersWithAt); - settingsItems.push_back(&allowCommandsAtEnd); - settingsItems.push_back(&enableHighlights); - settingsItems.push_back(&enableHighlightSound); - settingsItems.push_back(&enableHighlightTaskbar); - settingsItems.push_back(&customHighlightSound); - settingsItems.push_back(&enableTwitchEmotes); - settingsItems.push_back(&enableBttvEmotes); - settingsItems.push_back(&enableFFzEmotes); - settingsItems.push_back(&enableEmojis); - settingsItems.push_back(&enableGifAnimations); - settingsItems.push_back(&enableGifs); - settingsItems.push_back(&inlineWhispers); - settingsItems.push_back(&windowTopMost); - settingsItems.push_back(&hideTabX); - } + static Settings _; - static QSettings settings; - static std::vector settingsItems; + void updateWordTypeMask(bool); - template - static T - addSetting(T setting) - { - settingsItems.push_back(setting); - return setting; - } + QSettings settings; + std::vector settingsItems; - static bool portable; + // template + // T + // addSetting(T setting) + // { + // settingsItems.push_back(setting); + // return setting; + // } - static messages::Word::Type wordTypeMask; + bool portable; + + messages::Word::Type wordTypeMask; + +private: + StringSetting theme; + StringSetting user; + FloatSetting emoteScale; + BoolSetting scaleEmotesByLineHeight; + BoolSetting showTimestamps; + BoolSetting showTimestampSeconds; + BoolSetting showLastMessageIndicator; + BoolSetting allowDouplicateMessages; + BoolSetting linksDoubleClickOnly; + BoolSetting hideEmptyInput; + BoolSetting showMessageLength; + BoolSetting seperateMessages; + BoolSetting mentionUsersWithAt; + BoolSetting allowCommandsAtEnd; + BoolSetting enableHighlights; + BoolSetting enableHighlightSound; + BoolSetting enableHighlightTaskbar; + BoolSetting customHighlightSound; + BoolSetting enableTwitchEmotes; + BoolSetting enableBttvEmotes; + BoolSetting enableFfzEmotes; + BoolSetting enableEmojis; + BoolSetting enableGifAnimations; + BoolSetting enableGifs; + BoolSetting inlineWhispers; + BoolSetting windowTopMost; + BoolSetting hideTabX; // settings public: - static StringSetting & + StringSetting & getTheme() { - return Settings::theme; + return this->theme; } - static StringSetting & + StringSetting & getUser() { - return Settings::user; + return this->user; } - static FloatSetting & + FloatSetting & getEmoteScale() { - return Settings::emoteScale; + return this->emoteScale; } - static BoolSetting & + BoolSetting & getScaleEmotesByLineHeight() { - return Settings::scaleEmotesByLineHeight; + return this->scaleEmotesByLineHeight; } - static BoolSetting & + BoolSetting & getShowTimestamps() { - return Settings::showTimestamps; + return this->showTimestamps; } - static BoolSetting & + BoolSetting & getShowTimestampSeconds() { - return Settings::showTimestampSeconds; + return this->showTimestampSeconds; } - static BoolSetting & + BoolSetting & + getShowLastMessageIndicator() + { + return this->showLastMessageIndicator; + } + BoolSetting & getAllowDouplicateMessages() { - return Settings::allowDouplicateMessages; + return this->allowDouplicateMessages; } - static BoolSetting & + BoolSetting & getLinksDoubleClickOnly() { - return Settings::linksDoubleClickOnly; + return this->linksDoubleClickOnly; } - static BoolSetting & + BoolSetting & getHideEmptyInput() { - return Settings::hideEmptyInput; + return this->hideEmptyInput; } - static BoolSetting & + BoolSetting & getShowMessageLength() { - return Settings::showMessageLength; + return this->showMessageLength; } - static BoolSetting & + BoolSetting & getSeperateMessages() { - return Settings::seperateMessages; + return this->seperateMessages; } - static BoolSetting & + BoolSetting & getMentionUsersWithAt() { - return Settings::mentionUsersWithAt; + return this->mentionUsersWithAt; } - static BoolSetting & + BoolSetting & getAllowCommandsAtEnd() { - return Settings::allowCommandsAtEnd; + return this->allowCommandsAtEnd; } - static BoolSetting & + BoolSetting & getEnableHighlights() { - return Settings::enableHighlights; + return this->enableHighlights; } - static BoolSetting & + BoolSetting & getEnableHighlightSound() { - return Settings::enableHighlightSound; + return this->enableHighlightSound; } - static BoolSetting & + BoolSetting & getEnableHighlightTaskbar() { - return Settings::enableHighlightTaskbar; + return this->enableHighlightTaskbar; } - static BoolSetting & + BoolSetting & getCustomHighlightSound() { - return Settings::customHighlightSound; + return this->customHighlightSound; } - static BoolSetting & + BoolSetting & getEnableTwitchEmotes() { - return Settings::enableTwitchEmotes; + return this->enableTwitchEmotes; } - static BoolSetting & + BoolSetting & getEnableBttvEmotes() { - return Settings::enableBttvEmotes; + return this->enableBttvEmotes; } - static BoolSetting & - getEnableFFzEmotes() + BoolSetting & + getEnableFfzEmotes() { - return Settings::enableFFzEmotes; + return this->enableFfzEmotes; } - static BoolSetting & + BoolSetting & getEnableEmojis() { - return Settings::enableEmojis; + return this->enableEmojis; } - static BoolSetting & + BoolSetting & getEnableGifAnimations() { - return Settings::enableGifAnimations; + return this->enableGifAnimations; } - static BoolSetting & + BoolSetting & getEnableGifs() { - return Settings::enableGifs; + return this->enableGifs; } - static BoolSetting & + BoolSetting & getInlineWhispers() { - return Settings::inlineWhispers; + return this->inlineWhispers; } - static BoolSetting & + BoolSetting & getWindowTopMost() { - return Settings::windowTopMost; + return this->windowTopMost; } - static BoolSetting & + BoolSetting & getHideTabX() { - return Settings::hideTabX; + return this->hideTabX; } - -private: - static StringSetting theme; - static StringSetting user; - static FloatSetting emoteScale; - static BoolSetting scaleEmotesByLineHeight; - static BoolSetting showTimestamps; - static BoolSetting showTimestampSeconds; - static BoolSetting allowDouplicateMessages; - static BoolSetting linksDoubleClickOnly; - static BoolSetting hideEmptyInput; - static BoolSetting showMessageLength; - static BoolSetting seperateMessages; - static BoolSetting mentionUsersWithAt; - static BoolSetting allowCommandsAtEnd; - static BoolSetting enableHighlights; - static BoolSetting enableHighlightSound; - static BoolSetting enableHighlightTaskbar; - static BoolSetting customHighlightSound; - static BoolSetting enableTwitchEmotes; - static BoolSetting enableBttvEmotes; - static BoolSetting enableFFzEmotes; - static BoolSetting enableEmojis; - static BoolSetting enableGifAnimations; - static BoolSetting enableGifs; - static BoolSetting inlineWhispers; - static BoolSetting windowTopMost; - static BoolSetting hideTabX; }; } } diff --git a/widgets/chatwidget.cpp b/widgets/chatwidget.cpp index 695d99a83..493b41d26 100644 --- a/widgets/chatwidget.cpp +++ b/widgets/chatwidget.cpp @@ -1,6 +1,7 @@ #include "widgets/chatwidget.h" #include "channels.h" #include "colorscheme.h" +#include "settings/settings.h" #include "widgets/textinputdialog.h" #include @@ -23,10 +24,6 @@ ChatWidget::ChatWidget(QWidget *parent) this->vbox.setSpacing(0); this->vbox.setMargin(1); - // header.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); - // view.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); - // input.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); - this->vbox.addWidget(&header); this->vbox.addWidget(&view, 1); this->vbox.addWidget(&input); diff --git a/widgets/chatwidget.h b/widgets/chatwidget.h index cf88ea30e..cff83f8c5 100644 --- a/widgets/chatwidget.h +++ b/widgets/chatwidget.h @@ -2,6 +2,7 @@ #define CHATWIDGET_H #include "channel.h" +#include "messages/word.h" #include "widgets/chatwidgetheader.h" #include "widgets/chatwidgetinput.h" #include "widgets/chatwidgetview.h" diff --git a/widgets/chatwidgetinput.cpp b/widgets/chatwidgetinput.cpp index 489db3abf..8d292c259 100644 --- a/widgets/chatwidgetinput.cpp +++ b/widgets/chatwidgetinput.cpp @@ -1,5 +1,6 @@ #include "widgets/chatwidgetinput.h" #include "colorscheme.h" +#include "settings/settings.h" #include @@ -38,6 +39,20 @@ ChatWidgetInput::ChatWidgetInput() // this->emotesLabel.setMaximumSize(12, 12); this->refreshTheme(); + + this->setMessageLengthVisisble( + settings::Settings::getInstance().getShowMessageLength().get()); + + QObject::connect(&settings::Settings::getInstance().getShowMessageLength(), + &settings::BoolSetting::valueChanged, this, + &setMessageLengthVisisble); +} + +ChatWidgetInput::~ChatWidgetInput() +{ + QObject::disconnect( + &settings::Settings::getInstance().getShowMessageLength(), + &settings::BoolSetting::valueChanged, this, &setMessageLengthVisisble); } void diff --git a/widgets/chatwidgetinput.h b/widgets/chatwidgetinput.h index 9ce7ca5cb..b86087527 100644 --- a/widgets/chatwidgetinput.h +++ b/widgets/chatwidgetinput.h @@ -21,6 +21,7 @@ class ChatWidgetInput : public QWidget public: ChatWidgetInput(); + ~ChatWidgetInput(); protected: void paintEvent(QPaintEvent *); @@ -37,6 +38,11 @@ private: private slots: void refreshTheme(); + void + setMessageLengthVisisble(bool value) + { + this->textLengthLabel.setHidden(!value); + } }; } } diff --git a/widgets/chatwidgetview.cpp b/widgets/chatwidgetview.cpp index 0d49708f4..fb7d21273 100644 --- a/widgets/chatwidgetview.cpp +++ b/widgets/chatwidgetview.cpp @@ -2,8 +2,8 @@ #include "channels.h" #include "colorscheme.h" #include "messages/message.h" -#include "messages/word.h" #include "messages/wordpart.h" +#include "settings/settings.h" #include "widgets/chatwidget.h" #include @@ -22,6 +22,17 @@ ChatWidgetView::ChatWidgetView(ChatWidget *parent) auto scroll = QScroller::scroller(this); scroll->scrollTo(QPointF(0, 100)); + + QObject::connect(&settings::Settings::getInstance(), + &settings::Settings::wordTypeMaskChanged, this, + &wordTypeMaskChanged); +} + +ChatWidgetView::~ChatWidgetView() +{ + QObject::disconnect(&settings::Settings::getInstance(), + &settings::Settings::wordTypeMaskChanged, this, + &wordTypeMaskChanged); } bool diff --git a/widgets/chatwidgetview.h b/widgets/chatwidgetview.h index 108d6a6fa..1585436cf 100644 --- a/widgets/chatwidgetview.h +++ b/widgets/chatwidgetview.h @@ -2,6 +2,7 @@ #define CHATVIEW_H #include "channel.h" +#include "messages/word.h" #include "widgets/scrollbar.h" #include @@ -17,6 +18,7 @@ class ChatWidgetView : public QWidget public: explicit ChatWidgetView(ChatWidget *parent); + ~ChatWidgetView(); bool layoutMessages(); @@ -29,6 +31,15 @@ private: ChatWidget *chatWidget; ScrollBar scrollbar; + +private slots: + void + wordTypeMaskChanged() + { + if (layoutMessages()) { + repaint(); + } + } }; } } diff --git a/widgets/mainwindow.cpp b/widgets/mainwindow.cpp index 8b205fefb..937c869ec 100644 --- a/widgets/mainwindow.cpp +++ b/widgets/mainwindow.cpp @@ -14,10 +14,6 @@ MainWindow::MainWindow(QWidget *parent) { setCentralWidget(&this->notebook); - this->notebook.addPage(); - this->notebook.addPage(); - this->notebook.addPage(); - QPalette palette; palette.setColor(QPalette::Background, ColorScheme::instance().TabPanelBackground); diff --git a/widgets/notebook.cpp b/widgets/notebook.cpp index 26a1d10c1..83e707189 100644 --- a/widgets/notebook.cpp +++ b/widgets/notebook.cpp @@ -18,6 +18,7 @@ Notebook::Notebook(QWidget *parent) , addButton(this) , settingsButton(this) , userButton(this) + , selectedPage(nullptr) { connect(&this->settingsButton, SIGNAL(clicked()), this, SLOT(settingsButtonClicked())); @@ -34,6 +35,8 @@ Notebook::Notebook(QWidget *parent) this->userButton.icon = NotebookButton::IconUser; this->addButton.resize(24, 24); + + this->addPage(); } NotebookPage * @@ -42,13 +45,15 @@ Notebook::addPage(bool select) auto tab = new NotebookTab(this); auto page = new NotebookPage(this, tab); + tab->show(); + if (select || this->pages.count() == 0) { this->select(page); } this->pages.append(page); - performLayout(); + this->performLayout(); return page; } @@ -56,20 +61,24 @@ Notebook::addPage(bool select) void Notebook::removePage(NotebookPage *page) { - int index = pages.indexOf(page); + int index = this->pages.indexOf(page); if (pages.size() == 1) { - select(NULL); + this->select(NULL); } else if (index == pages.count() - 1) { - select(pages[index - 1]); + this->select(pages[index - 1]); } else { - select(pages[index + 1]); + this->select(pages[index + 1]); } delete page->tab; delete page; - pages.removeOne(page); + this->pages.removeOne(page); + + if (this->pages.size() == 0) { + addPage(); + } performLayout(); } @@ -95,6 +104,36 @@ Notebook::select(NotebookPage *page) performLayout(); } +NotebookPage * +Notebook::tabAt(QPoint point, int &index) +{ + int i = 0; + + for (auto *page : pages) { + if (page->tab->geometry().contains(point)) { + index = i; + return page; + } + + i++; + } + + index = -1; + return nullptr; +} + +void +Notebook::rearrangePage(NotebookPage *page, int index) +{ + int i1 = pages.indexOf(page); + + pages.move(pages.indexOf(page), index); + + int i2 = pages.indexOf(page); + + performLayout(); +} + void Notebook::performLayout() { @@ -109,10 +148,10 @@ Notebook::performLayout() (i == this->pages.last() ? tabHeight : 0) + x + i->tab->width() > width()) { y += i->tab->height(); - i->tab->move(0, y); + i->tab->moveAnimated(QPoint(0, y)); x = i->tab->width(); } else { - i->tab->move(x, y); + i->tab->moveAnimated(QPoint(x, y)); x += i->tab->width(); } diff --git a/widgets/notebook.h b/widgets/notebook.h index 3c33687e0..0fce894af 100644 --- a/widgets/notebook.h +++ b/widgets/notebook.h @@ -33,6 +33,9 @@ public: void performLayout(); + NotebookPage *tabAt(QPoint point, int &index); + void rearrangePage(NotebookPage *page, int index); + protected: void resizeEvent(QResizeEvent *); @@ -50,7 +53,7 @@ private: NotebookButton settingsButton; NotebookButton userButton; - NotebookPage *selectedPage = nullptr; + NotebookPage *selectedPage; }; } } diff --git a/widgets/notebooktab.cpp b/widgets/notebooktab.cpp index 131801af7..a20729294 100644 --- a/widgets/notebooktab.cpp +++ b/widgets/notebooktab.cpp @@ -10,6 +10,8 @@ namespace widgets { NotebookTab::NotebookTab(Notebook *notebook) : QWidget(notebook) + // , posAnimation(this, "pos") + // , posAnimated(false) , notebook(notebook) , text("") , selected(false) @@ -19,36 +21,56 @@ NotebookTab::NotebookTab(Notebook *notebook) , mouseDownX(false) , highlightStyle(HighlightNone) { - calcSize(); + this->calcSize(); + this->setAcceptDrops(true); - setAcceptDrops(true); - - QObject::connect(&settings::Settings::getHideTabX(), - SIGNAL(settings::BoolSetting::valueChanged(bool)), this, - SLOT(NotebookTab::hideTabXChanged(bool))); - - this->installEventFilter(this); + QObject::connect(&settings::Settings::getInstance().getHideTabX(), + &settings::BoolSetting::valueChanged, this, + &NotebookTab::hideTabXChanged); this->setMouseTracking(true); } NotebookTab::~NotebookTab() { - QObject::disconnect(&settings::Settings::getHideTabX(), - SIGNAL(settings::BoolSetting::valueChanged(bool)), this, - SLOT(NotebookTab::hideTabXChanged(bool))); + QObject::disconnect(&settings::Settings::getInstance().getHideTabX(), + &settings::BoolSetting::valueChanged, this, + &NotebookTab::hideTabXChanged); } void NotebookTab::calcSize() { - if (settings::Settings::getHideTabX().get()) { + if (settings::Settings::getInstance().getHideTabX().get()) { this->resize(this->fontMetrics().width(this->text) + 8, 24); } else { this->resize(this->fontMetrics().width(this->text) + 8 + 24, 24); } } +void +NotebookTab::moveAnimated(QPoint pos) +{ + move(pos); + + // if (posAnimated == false) { + // move(pos); + + // posAnimated = true; + // return; + // } + + // if (this->posAnimation.endValue() == pos) { + // return; + // } + + // this->posAnimation.stop(); + // this->posAnimation.setDuration(50); + // this->posAnimation.setStartValue(this->pos()); + // this->posAnimation.setEndValue(pos); + // this->posAnimation.start(); +} + void NotebookTab::paintEvent(QPaintEvent *) { @@ -77,25 +99,28 @@ NotebookTab::paintEvent(QPaintEvent *) painter.setPen(fg); - QRect rect(0, 0, - width() - (settings::Settings::getHideTabX().get() ? 0 : 16), - height()); + QRect rect( + 0, 0, + width() - + (settings::Settings::getInstance().getHideTabX().get() ? 0 : 16), + height()); painter.drawText(rect, this->text, QTextOption(Qt::AlignCenter)); - if (!settings::Settings::getHideTabX().get() && (mouseOver || selected)) { - if (mouseOverX) { - painter.fillRect(getXRect(), QColor(0, 0, 0, 64)); + if (!settings::Settings::getInstance().getHideTabX().get() && + (this->mouseOver || this->selected)) { + if (this->mouseOverX) { + painter.fillRect(this->getXRect(), QColor(0, 0, 0, 64)); - if (mouseDownX) { - painter.fillRect(getXRect(), QColor(0, 0, 0, 64)); + if (this->mouseDownX) { + painter.fillRect(this->getXRect(), QColor(0, 0, 0, 64)); } } - painter.drawLine(getXRect().topLeft() + QPoint(4, 4), - getXRect().bottomRight() + QPoint(-4, -4)); - painter.drawLine(getXRect().topRight() + QPoint(-4, 4), - getXRect().bottomLeft() + QPoint(4, -4)); + painter.drawLine(this->getXRect().topLeft() + QPoint(4, 4), + this->getXRect().bottomRight() + QPoint(-4, -4)); + painter.drawLine(this->getXRect().topRight() + QPoint(-4, 4), + this->getXRect().bottomLeft() + QPoint(4, -4)); } } @@ -156,6 +181,17 @@ NotebookTab::mouseMoveEvent(QMouseEvent *event) this->repaint(); } + + if (this->mouseDown && !this->rect().contains(event->pos())) { + QPoint relPoint = this->mapToParent(event->pos()); + + int index; + NotebookPage *page = notebook->tabAt(relPoint, index); + + if (page != nullptr && page != this->page) { + notebook->rearrangePage(this->page, index); + } + } } } } diff --git a/widgets/notebooktab.h b/widgets/notebooktab.h index 147c9350a..c008e0d96 100644 --- a/widgets/notebooktab.h +++ b/widgets/notebooktab.h @@ -1,6 +1,7 @@ #ifndef NOTEBOOKTAB_H #define NOTEBOOKTAB_H +#include #include namespace chatterino { @@ -20,7 +21,7 @@ public: HighlightNewMessage }; - NotebookTab(Notebook *notebook); + explicit NotebookTab(Notebook *notebook); ~NotebookTab(); void calcSize(); @@ -65,6 +66,8 @@ public: repaint(); } + void moveAnimated(QPoint pos); + protected: void paintEvent(QPaintEvent *) override; @@ -78,6 +81,9 @@ protected: void mouseMoveEvent(QMouseEvent *event) override; private: + // QPropertyAnimation posAnimation; + // bool posAnimated; + Notebook *notebook; QString text; @@ -98,7 +104,7 @@ private: private slots: void - hideTabXChanged(bool value) + hideTabXChanged(bool) { calcSize(); repaint(); diff --git a/widgets/settingsdialog.cpp b/widgets/settingsdialog.cpp index 2e75fa502..d1358043b 100644 --- a/widgets/settingsdialog.cpp +++ b/widgets/settingsdialog.cpp @@ -54,6 +54,8 @@ SettingsDialog::SettingsDialog() void SettingsDialog::addTabs() { + settings::Settings &settings = settings::Settings::getInstance(); + QVBoxLayout *vbox; // Appearance @@ -80,12 +82,17 @@ SettingsDialog::addTabs() auto group = new QGroupBox("Messages"); auto v = new QVBoxLayout(); - v->addWidget(createCheckbox("Show timestamp", "")); - v->addWidget(createCheckbox("Show seconds in timestamp", "")); + v->addWidget( + createCheckbox("Show timestamp", settings.getShowTimestamps())); + v->addWidget(createCheckbox("Show seconds in timestamp", + settings.getShowTimestampSeconds())); v->addWidget(createCheckbox( - "Allow sending duplicate messages (add a space at the end)", "")); - v->addWidget(createCheckbox("Seperate messages", "")); - v->addWidget(createCheckbox("Show message length", "")); + "Allow sending duplicate messages (add a space at the end)", + settings.getAllowDouplicateMessages())); + v->addWidget(createCheckbox("Seperate messages", + settings.getSeperateMessages())); + v->addWidget(createCheckbox("Show message length", + settings.getShowMessageLength())); group->setLayout(v); @@ -99,11 +106,15 @@ SettingsDialog::addTabs() // Behaviour vbox = new QVBoxLayout(); - vbox->addWidget(createCheckbox("Hide input box if empty", "")); + vbox->addWidget(createCheckbox("Hide input box if empty", + settings.getHideEmptyInput())); vbox->addWidget( - createCheckbox("Mention users with a @ (except in commands)", "")); - vbox->addWidget(createCheckbox("Window always on top", "")); - vbox->addWidget(createCheckbox("Show last read message indicator", "")); + createCheckbox("Mention users with a @ (except in commands)", + settings.getMentionUsersWithAt())); + vbox->addWidget( + createCheckbox("Window always on top", settings.getWindowTopMost())); + vbox->addWidget(createCheckbox("Show last read message indicator", + settings.getShowLastMessageIndicator())); { auto v = new QVBoxLayout(); @@ -128,14 +139,66 @@ SettingsDialog::addTabs() addTab(vbox, "Commands", ":/images/CustomActionEditor_16x.png"); + // Emotes + vbox = new QVBoxLayout(); + + vbox->addWidget(createCheckbox("Enable Twitch Emotes", + settings.getEnableTwitchEmotes())); + vbox->addWidget(createCheckbox("Enable BetterTTV Emotes", + settings.getEnableBttvEmotes())); + vbox->addWidget(createCheckbox("Enable FrankerFaceZ Emotes", + settings.getEnableFfzEmotes())); + vbox->addWidget( + createCheckbox("Enable Gif Emotes", settings.getEnableGifs())); + vbox->addWidget( + createCheckbox("Enable Emojis", settings.getEnableEmojis())); + + vbox->addWidget(createCheckbox("Enable Twitch Emotes", + settings.getEnableTwitchEmotes())); + + vbox->addStretch(1); + addTab(vbox, "Emotes", ":/images/Emoji_Color_1F60A_19.png"); + + // Ignored Users + vbox = new QVBoxLayout(); + vbox->addStretch(1); + addTab(vbox, "Ignored Users", + ":/images/StatusAnnotations_Blocked_16xLG_color.png"); + + // Ignored Messages + vbox = new QVBoxLayout(); + vbox->addStretch(1); + addTab(vbox, "Ignored Messages", ":/images/Filter_16x.png"); + + // Links + vbox = new QVBoxLayout(); + vbox->addStretch(1); + addTab(vbox, "Links", ":/images/VSO_Link_blue_16x.png"); + + // Highlighting + vbox = new QVBoxLayout(); + vbox->addStretch(1); + addTab(vbox, "Highlighting", ":/images/format_Bold_16xLG.png"); + + // Whispers + vbox = new QVBoxLayout(); + vbox->addStretch(1); + addTab(vbox, "Whispers", ":/images/Message_16xLG.png"); + // Add stretch tabs.addStretch(1); } QCheckBox * -SettingsDialog::createCheckbox(QString title, QString settingsId) +SettingsDialog::createCheckbox(const QString &title, + settings::BoolSetting &setting) { - return new QCheckBox(title); + auto checkbox = new QCheckBox(title); + + QObject::connect(checkbox, &QCheckBox::toggled, this, + [&setting, this](bool state) { setting.set(state); }); + + return checkbox; } void diff --git a/widgets/settingsdialog.h b/widgets/settingsdialog.h index 79d709b4f..e63bcd32f 100644 --- a/widgets/settingsdialog.h +++ b/widgets/settingsdialog.h @@ -1,6 +1,7 @@ #ifndef SETTINGSDIALOG_H #define SETTINGSDIALOG_H +#include "settings/settings.h" #include "widgets/settingsdialogtab.h" #include @@ -39,7 +40,8 @@ private: SettingsDialogTab *selectedTab = NULL; - QCheckBox *createCheckbox(QString title, QString settingsId); + QCheckBox *createCheckbox(const QString &title, + settings::BoolSetting &setting); }; } }