From d89b62692ad9086cbcf396bb13b39c0f781c97a9 Mon Sep 17 00:00:00 2001 From: fourtf Date: Wed, 8 Aug 2018 15:35:54 +0200 Subject: [PATCH 01/44] refined SplitHeader --- chatterino.pro | 13 +- src/messages/MessageBuilder.cpp | 2 + src/singletons/Settings.hpp | 2 +- src/util/InitUpdateButton.cpp | 6 +- src/util/InitUpdateButton.hpp | 4 +- src/util/LayoutHelper.hpp | 40 ++ src/widgets/BaseWindow.cpp | 10 +- src/widgets/BaseWindow.hpp | 8 +- src/widgets/Window.hpp | 2 +- src/widgets/dialogs/UserInfoPopup.cpp | 56 +- src/widgets/dialogs/UserInfoPopup.hpp | 2 +- .../{RippleEffectButton.cpp => Button.cpp} | 46 +- .../{RippleEffectButton.hpp => Button.hpp} | 4 +- src/widgets/helper/ChannelView.cpp | 4 +- src/widgets/helper/ChannelView.hpp | 4 +- ...{RippleEffectLabel.cpp => EffectLabel.cpp} | 12 +- ...{RippleEffectLabel.hpp => EffectLabel.hpp} | 10 +- src/widgets/helper/NotebookButton.cpp | 12 +- src/widgets/helper/NotebookButton.hpp | 4 +- src/widgets/helper/NotebookTab.cpp | 8 +- src/widgets/helper/NotebookTab.hpp | 4 +- src/widgets/helper/TitlebarButton.cpp | 4 +- src/widgets/helper/TitlebarButton.hpp | 4 +- src/widgets/settingspages/LookPage.cpp | 4 +- src/widgets/splits/Split.cpp | 26 +- src/widgets/splits/Split.hpp | 39 +- src/widgets/splits/SplitHeader.cpp | 485 ++++++++---------- src/widgets/splits/SplitHeader.hpp | 63 +-- src/widgets/splits/SplitInput.cpp | 4 +- src/widgets/splits/SplitInput.hpp | 4 +- 30 files changed, 422 insertions(+), 464 deletions(-) create mode 100644 src/util/LayoutHelper.hpp rename src/widgets/helper/{RippleEffectButton.cpp => Button.cpp} (83%) rename src/widgets/helper/{RippleEffectButton.hpp => Button.hpp} (95%) rename src/widgets/helper/{RippleEffectLabel.cpp => EffectLabel.cpp} (72%) rename src/widgets/helper/{RippleEffectLabel.hpp => EffectLabel.hpp} (59%) diff --git a/chatterino.pro b/chatterino.pro index 1c2145ea0..bd621b861 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -186,8 +186,6 @@ SOURCES += \ src/widgets/helper/NotebookButton.cpp \ src/widgets/helper/NotebookTab.cpp \ src/widgets/helper/ResizingTextEdit.cpp \ - src/widgets/helper/RippleEffectButton.cpp \ - src/widgets/helper/RippleEffectLabel.cpp \ src/widgets/helper/ScrollbarHighlight.cpp \ src/widgets/helper/SearchPopup.cpp \ src/widgets/helper/SettingsDialogTab.cpp \ @@ -250,7 +248,9 @@ SOURCES += \ src/RunGui.cpp \ src/BrowserExtension.cpp \ src/util/FormatTime.cpp \ - src/util/FunctionEventFilter.cpp + src/util/FunctionEventFilter.cpp \ + src/widgets/helper/EffectLabel.cpp \ + src/widgets/helper/Button.cpp HEADERS += \ src/Application.hpp \ @@ -374,8 +374,6 @@ HEADERS += \ src/widgets/helper/NotebookButton.hpp \ src/widgets/helper/NotebookTab.hpp \ src/widgets/helper/ResizingTextEdit.hpp \ - src/widgets/helper/RippleEffectButton.hpp \ - src/widgets/helper/RippleEffectLabel.hpp \ src/widgets/helper/ScrollbarHighlight.hpp \ src/widgets/helper/SearchPopup.hpp \ src/widgets/helper/SettingsDialogTab.hpp \ @@ -448,7 +446,10 @@ HEADERS += \ src/RunGui.hpp \ src/BrowserExtension.hpp \ src/util/FormatTime.hpp \ - src/util/FunctionEventFilter.hpp + src/util/FunctionEventFilter.hpp \ + src/widgets/helper/EffectLabel.hpp \ + src/util/LayoutHelper.hpp \ + src/widgets/helper/Button.hpp RESOURCES += \ resources/resources.qrc \ diff --git a/src/messages/MessageBuilder.cpp b/src/messages/MessageBuilder.cpp index 42c537c67..f4ebd2301 100644 --- a/src/messages/MessageBuilder.cpp +++ b/src/messages/MessageBuilder.cpp @@ -82,6 +82,7 @@ MessageBuilder::MessageBuilder(TimeoutMessageTag, const QString &username, } MessageBuilder::MessageBuilder(const BanAction &action, uint32_t count) + : MessageBuilder() { this->emplace(); this->message().flags.set(MessageFlag::System); @@ -127,6 +128,7 @@ MessageBuilder::MessageBuilder(const BanAction &action, uint32_t count) } MessageBuilder::MessageBuilder(const UnbanAction &action) + : MessageBuilder() { this->emplace(); this->message().flags.set(MessageFlag::System); diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index 3db58f9c2..fbc813b4a 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -161,6 +161,6 @@ private: std::unique_ptr snapshot_; }; -[[deprecated]] Settings *getSettings(); +Settings *getSettings(); } // namespace chatterino diff --git a/src/util/InitUpdateButton.cpp b/src/util/InitUpdateButton.cpp index d10ba2bc1..25d131635 100644 --- a/src/util/InitUpdateButton.cpp +++ b/src/util/InitUpdateButton.cpp @@ -1,18 +1,18 @@ #include "InitUpdateButton.hpp" #include "widgets/dialogs/UpdateDialog.hpp" -#include "widgets/helper/RippleEffectButton.hpp" +#include "widgets/helper/Button.hpp" namespace chatterino { -void initUpdateButton(RippleEffectButton &button, +void initUpdateButton(Button &button, std::unique_ptr &handle, pajlada::Signals::SignalHolder &signalHolder) { button.hide(); // show update prompt when clicking the button - QObject::connect(&button, &RippleEffectButton::clicked, [&button, &handle] { + QObject::connect(&button, &Button::clicked, [&button, &handle] { (void)(handle); auto dialog = new UpdateDialog(); diff --git a/src/util/InitUpdateButton.hpp b/src/util/InitUpdateButton.hpp index 17237d593..e95fcd7bd 100644 --- a/src/util/InitUpdateButton.hpp +++ b/src/util/InitUpdateButton.hpp @@ -10,10 +10,10 @@ class SignalHolder; namespace chatterino { -class RippleEffectButton; +class Button; class UpdateDialog; -void initUpdateButton(RippleEffectButton &button, +void initUpdateButton(Button &button, std::unique_ptr &handle, pajlada::Signals::SignalHolder &signalHolder); diff --git a/src/util/LayoutHelper.hpp b/src/util/LayoutHelper.hpp new file mode 100644 index 000000000..b996aa084 --- /dev/null +++ b/src/util/LayoutHelper.hpp @@ -0,0 +1,40 @@ +#pragma once + +#include +#include +#include + +namespace chatterino { + +using LayoutItem = boost::variant; + +template +T *makeLayout(std::initializer_list items) +{ + auto t = new T; + + for (auto &item : items) { + switch (item.which()) { + case 0: + t->addItem(new QWidgetItem(boost::get(item))); + break; + case 1: + t->addItem(boost::get(item)); + break; + } + } + + return t; +} + +template +T *makeWidget(With with) +{ + auto t = new T; + + with(t); + + return t; +} + +} // namespace chatterino diff --git a/src/widgets/BaseWindow.cpp b/src/widgets/BaseWindow.cpp index 424b96e6d..e435bf6e8 100644 --- a/src/widgets/BaseWindow.cpp +++ b/src/widgets/BaseWindow.cpp @@ -9,7 +9,7 @@ #include "util/WindowsHelper.hpp" #include "widgets/Label.hpp" #include "widgets/TooltipWidget.hpp" -#include "widgets/helper/RippleEffectLabel.hpp" +#include "widgets/helper/EffectLabel.hpp" #include "widgets/helper/Shortcut.hpp" #include @@ -239,7 +239,7 @@ void BaseWindow::themeChangedEvent() this->ui_.titleLabel->setPalette(palette_title); } - for (RippleEffectButton *button : this->ui_.buttons) { + for (Button *button : this->ui_.buttons) { button->setMouseEffectColor(this->theme->window.text); } } else { @@ -371,15 +371,15 @@ TitleBarButton *BaseWindow::addTitleBarButton( return button; } -RippleEffectLabel *BaseWindow::addTitleBarLabel(std::function onClicked) +EffectLabel *BaseWindow::addTitleBarLabel(std::function onClicked) { - RippleEffectLabel *button = new RippleEffectLabel; + EffectLabel *button = new EffectLabel; button->setScaleIndependantHeight(30); this->ui_.buttons.push_back(button); this->ui_.titlebarBox->insertWidget(1, button); - QObject::connect(button, &RippleEffectLabel::clicked, this, + QObject::connect(button, &EffectLabel::clicked, this, [onClicked] { onClicked(); }); return button; diff --git a/src/widgets/BaseWindow.hpp b/src/widgets/BaseWindow.hpp index dbfb4b46b..eac2ee55e 100644 --- a/src/widgets/BaseWindow.hpp +++ b/src/widgets/BaseWindow.hpp @@ -12,8 +12,8 @@ typedef struct tagMSG MSG; namespace chatterino { -class RippleEffectButton; -class RippleEffectLabel; +class Button; +class EffectLabel; class TitleBarButton; class BaseWindow : public BaseWidget @@ -38,7 +38,7 @@ public: bool hasCustomWindowFrame(); TitleBarButton *addTitleBarButton(const TitleBarButton::Style &style, std::function onClicked); - RippleEffectLabel *addTitleBarLabel(std::function onClicked); + EffectLabel *addTitleBarLabel(std::function onClicked); void setStayInScreenRect(bool value); bool getStayInScreenRect() const; @@ -109,7 +109,7 @@ private: TitleBarButton *maxButton = nullptr; TitleBarButton *exitButton = nullptr; QWidget *layoutBase = nullptr; - std::vector buttons; + std::vector