From 52dcc2130ee5a6be4c17208d3131093a5e91569b Mon Sep 17 00:00:00 2001 From: fourtf Date: Sun, 25 Nov 2018 21:14:42 +0100 Subject: [PATCH] moved more stuff into appbase --- chatterino.pro | 7 -- lib/appbase | 2 +- src/common/FlagsEnum.hpp | 82 ----------------------- src/common/Outcome.hpp | 51 -------------- src/singletons/Settings.hpp | 4 ++ src/singletons/WindowManager.cpp | 54 --------------- src/singletons/WindowManager.hpp | 7 -- src/util/CombinePath.hpp | 14 ---- src/util/DistanceBetweenPoints.hpp | 20 ------ src/util/FuzzyConvert.cpp | 33 --------- src/util/FuzzyConvert.hpp | 10 --- src/util/LayoutHelper.hpp | 42 ------------ src/widgets/Window.cpp | 10 +-- src/widgets/helper/EffectLabel.cpp | 45 ------------- src/widgets/helper/EffectLabel.hpp | 41 ------------ src/widgets/helper/NotebookTab.cpp | 9 ++- src/widgets/settingspages/GeneralPage.cpp | 12 +++- src/widgets/settingspages/LookPage.cpp | 35 ---------- src/widgets/settingspages/LookPage.hpp | 1 - 19 files changed, 27 insertions(+), 452 deletions(-) delete mode 100644 src/common/FlagsEnum.hpp delete mode 100644 src/common/Outcome.hpp delete mode 100644 src/util/CombinePath.hpp delete mode 100644 src/util/DistanceBetweenPoints.hpp delete mode 100644 src/util/FuzzyConvert.cpp delete mode 100644 src/util/FuzzyConvert.hpp delete mode 100644 src/util/LayoutHelper.hpp delete mode 100644 src/widgets/helper/EffectLabel.cpp delete mode 100644 src/widgets/helper/EffectLabel.hpp diff --git a/chatterino.pro b/chatterino.pro index fa4f35fe..9167e5d7 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -206,14 +206,12 @@ SOURCES += \ src/widgets/splits/ClosedSplits.cpp \ src/providers/ffz/FfzModBadge.cpp \ src/widgets/settingspages/GeneralPage.cpp \ - src/util/FuzzyConvert.cpp HEADERS += \ src/Application.hpp \ src/common/Channel.hpp \ src/common/Common.hpp \ src/common/CompletionModel.hpp \ - src/common/FlagsEnum.hpp \ src/common/Atomic.hpp \ src/common/NetworkCommon.hpp \ src/common/NetworkData.hpp \ @@ -282,10 +280,8 @@ HEADERS += \ src/singletons/helper/LoggingChannel.hpp \ src/controllers/moderationactions/ModerationAction.hpp \ src/singletons/WindowManager.hpp \ - src/util/CombinePath.hpp \ src/util/ConcurrentMap.hpp \ src/util/DebugCount.hpp \ - src/util/DistanceBetweenPoints.hpp \ src/util/IrcHelpers.hpp \ src/util/LayoutCreator.hpp \ src/util/QStringHash.hpp \ @@ -365,7 +361,6 @@ HEADERS += \ src/providers/twitch/TwitchApi.hpp \ src/messages/Emote.hpp \ src/messages/ImageSet.hpp \ - src/common/Outcome.hpp \ src/providers/bttv/BttvEmotes.hpp \ src/providers/LinkResolver.hpp \ src/providers/ffz/FfzEmotes.hpp \ @@ -383,7 +378,6 @@ HEADERS += \ src/controllers/notifications/NotificationModel.hpp \ src/singletons/Toasts.hpp \ src/common/DownloadManager.hpp \ - src/util/LayoutHelper.hpp \ src/messages/MessageContainer.hpp \ src/common/UsernameSet.hpp \ src/widgets/settingspages/AdvancedPage.hpp \ @@ -391,7 +385,6 @@ HEADERS += \ src/widgets/splits/ClosedSplits.hpp \ src/providers/ffz/FfzModBadge.hpp \ src/widgets/settingspages/GeneralPage.hpp \ - src/util/FuzzyConvert.hpp RESOURCES += \ resources/resources.qrc \ diff --git a/lib/appbase b/lib/appbase index a830d369..6b588cb3 160000 --- a/lib/appbase +++ b/lib/appbase @@ -1 +1 @@ -Subproject commit a830d3692bdbe53b79f244cf1d4695e2a49fb7ed +Subproject commit 6b588cb381334417fb82f4829894ae26d0366588 diff --git a/src/common/FlagsEnum.hpp b/src/common/FlagsEnum.hpp deleted file mode 100644 index 1a393e9c..00000000 --- a/src/common/FlagsEnum.hpp +++ /dev/null @@ -1,82 +0,0 @@ -#pragma once - -#include - -namespace chatterino { - -template ::type> -class FlagsEnum -{ -public: - FlagsEnum() - : value_(static_cast(0)) - { - } - - FlagsEnum(T value) - : value_(value) - { - } - - FlagsEnum(std::initializer_list flags) - { - for (auto flag : flags) - { - this->set(flag); - } - } - - bool operator==(const FlagsEnum &other) - { - return this->value_ == other.value_; - } - - bool operator!=(const FlagsEnum &other) - { - return this->value_ != other.value_; - } - - void set(T flag) - { - reinterpret_cast(this->value_) |= static_cast(flag); - } - - void unset(T flag) - { - reinterpret_cast(this->value_) &= ~static_cast(flag); - } - - void set(T flag, bool value) - { - if (value) - this->set(flag); - else - this->unset(flag); - } - - bool has(T flag) const - { - return static_cast(this->value_) & static_cast(flag); - } - - bool hasAny(FlagsEnum flags) const - { - return static_cast(this->value_) & static_cast(flags.value_); - } - - bool hasAll(FlagsEnum flags) const - { - return (static_cast(this->value_) & static_cast(flags.value_)) && - static_cast(flags->value); - } - - bool hasNone(std::initializer_list flags) const - { - return !this->hasAny(flags); - } - -private: - T value_{}; -}; - -} // namespace chatterino diff --git a/src/common/Outcome.hpp b/src/common/Outcome.hpp deleted file mode 100644 index 01be69fd..00000000 --- a/src/common/Outcome.hpp +++ /dev/null @@ -1,51 +0,0 @@ -#pragma once - -namespace chatterino { - -struct SuccessTag { -}; - -struct FailureTag { -}; - -const SuccessTag Success{}; -const FailureTag Failure{}; - -class Outcome -{ -public: - Outcome(SuccessTag) - : success_(true) - { - } - - Outcome(FailureTag) - : success_(false) - { - } - - explicit operator bool() const - { - return this->success_; - } - - bool operator!() const - { - return !this->success_; - } - - bool operator==(const Outcome &other) const - { - return this->success_ == other.success_; - } - - bool operator!=(const Outcome &other) const - { - return !this->operator==(other); - } - -private: - bool success_; -}; - -} // namespace chatterino diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index 4a807b50..7a31036f 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -193,3 +193,7 @@ private: }; } // namespace chatterino + +#ifdef CHATTERINO +# include "singletons/Settings.hpp" +#endif diff --git a/src/singletons/WindowManager.cpp b/src/singletons/WindowManager.cpp index b468e47b..1be6f401 100644 --- a/src/singletons/WindowManager.cpp +++ b/src/singletons/WindowManager.cpp @@ -32,9 +32,6 @@ namespace chatterino { using SplitNode = SplitContainer::Node; using SplitDirection = SplitContainer::Direction; -const int WindowManager::uiScaleMin = -5; -const int WindowManager::uiScaleMax = 10; - void WindowManager::showSettingsDialog(SettingsDialogPreference preference) { QTimer::singleShot( @@ -625,55 +622,4 @@ void WindowManager::incGeneration() this->generation_++; } -int WindowManager::clampUiScale(int scale) -{ - return clamp(scale, uiScaleMin, uiScaleMax); -} - -float WindowManager::getUiScaleValue() -{ - return getUiScaleValue(getSettings()->uiScale.getValue()); -} - -float WindowManager::getUiScaleValue(int scale) -{ - switch (clampUiScale(scale)) - { - case -5: - return 0.5f; - case -4: - return 0.6f; - case -3: - return 0.7f; - case -2: - return 0.8f; - case -1: - return 0.9f; - case 0: - return 1; - case 1: - return 1.2f; - case 2: - return 1.4f; - case 3: - return 1.6f; - case 4: - return 1.8f; - case 5: - return 2; - case 6: - return 2.33f; - case 7: - return 2.66f; - case 8: - return 3; - case 9: - return 3.5f; - case 10: - return 4; - default: - assert(false); - } -} - } // namespace chatterino diff --git a/src/singletons/WindowManager.hpp b/src/singletons/WindowManager.hpp index a9f88355..038eb41a 100644 --- a/src/singletons/WindowManager.hpp +++ b/src/singletons/WindowManager.hpp @@ -27,13 +27,6 @@ public: static void encodeChannel(IndirectChannel channel, QJsonObject &obj); static IndirectChannel decodeChannel(const QJsonObject &obj); - static int clampUiScale(int scale); - static float getUiScaleValue(); - static float getUiScaleValue(int scale); - - static const int uiScaleMin; - static const int uiScaleMax; - void showSettingsDialog( SettingsDialogPreference preference = SettingsDialogPreference()); diff --git a/src/util/CombinePath.hpp b/src/util/CombinePath.hpp deleted file mode 100644 index d0ed8e7a..00000000 --- a/src/util/CombinePath.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include -#include - -namespace chatterino { - -// https://stackoverflow.com/a/13014491 -inline QString combinePath(const QString &a, const QString &b) -{ - return QDir::cleanPath(a + QDir::separator() + b); -} - -} // namespace chatterino diff --git a/src/util/DistanceBetweenPoints.hpp b/src/util/DistanceBetweenPoints.hpp deleted file mode 100644 index 7a2a834c..00000000 --- a/src/util/DistanceBetweenPoints.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include - -#include - -namespace chatterino { - -inline float distanceBetweenPoints(const QPointF &p1, const QPointF &p2) -{ - QPointF tmp = p1 - p2; - - float distance = 0.f; - distance += tmp.x() * tmp.x(); - distance += tmp.y() * tmp.y(); - - return sqrt(distance); -} - -} // namespace chatterino diff --git a/src/util/FuzzyConvert.cpp b/src/util/FuzzyConvert.cpp deleted file mode 100644 index cfdc3f01..00000000 --- a/src/util/FuzzyConvert.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "FuzzyConvert.hpp" - -#include - -namespace chatterino { - -int fuzzyToInt(const QString &str, int default_) -{ - static auto intFinder = QRegularExpression("[0-9]+"); - - auto match = intFinder.match(str); - if (match.hasMatch()) - { - return match.captured().toInt(); - } - - return default_; -} - -float fuzzyToFloat(const QString &str, float default_) -{ - static auto floatFinder = QRegularExpression("[0-9]+(\\.[0-9]+)?"); - - auto match = floatFinder.match(str); - if (match.hasMatch()) - { - return match.captured().toFloat(); - } - - return default_; -} - -} // namespace chatterino diff --git a/src/util/FuzzyConvert.hpp b/src/util/FuzzyConvert.hpp deleted file mode 100644 index a3875da9..00000000 --- a/src/util/FuzzyConvert.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include - -namespace chatterino { - -int fuzzyToInt(const QString &str, int default_); -float fuzzyToFloat(const QString &str, float default_); - -} // namespace chatterino diff --git a/src/util/LayoutHelper.hpp b/src/util/LayoutHelper.hpp deleted file mode 100644 index f66fbef8..00000000 --- a/src/util/LayoutHelper.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#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/Window.cpp b/src/widgets/Window.cpp index 66969879..fb555152 100644 --- a/src/widgets/Window.cpp +++ b/src/widgets/Window.cpp @@ -9,6 +9,7 @@ #include "singletons/Updates.hpp" #include "singletons/WindowManager.hpp" #include "util/InitUpdateButton.hpp" +#include "util/Shortcut.hpp" #include "widgets/AccountSwitchPopupWidget.hpp" #include "widgets/Notebook.hpp" #include "widgets/dialogs/SettingsDialog.hpp" @@ -16,7 +17,6 @@ #include "widgets/dialogs/WelcomeDialog.hpp" #include "widgets/helper/EffectLabel.hpp" #include "widgets/helper/NotebookTab.hpp" -#include "util/Shortcut.hpp" #include "widgets/helper/TitlebarButton.hpp" #include "widgets/splits/ClosedSplits.hpp" #include "widgets/splits/Split.hpp" @@ -289,8 +289,8 @@ void Window::addShortcuts() auto s = new QShortcut(QKeySequence::ZoomIn, this); s->setContext(Qt::WindowShortcut); QObject::connect(s, &QShortcut::activated, this, [] { - getSettings()->uiScale.setValue(WindowManager::clampUiScale( - getSettings()->uiScale.getValue() + 1)); + getSettings()->setClampedUiScale( + getSettings()->getClampedUiScale() + 0.1f); }); } @@ -299,8 +299,8 @@ void Window::addShortcuts() auto s = new QShortcut(QKeySequence::ZoomOut, this); s->setContext(Qt::WindowShortcut); QObject::connect(s, &QShortcut::activated, this, [] { - getSettings()->uiScale.setValue(WindowManager::clampUiScale( - getSettings()->uiScale.getValue() - 1)); + getSettings()->setClampedUiScale( + getSettings()->getClampedUiScale() - 0.1f); }); } diff --git a/src/widgets/helper/EffectLabel.cpp b/src/widgets/helper/EffectLabel.cpp deleted file mode 100644 index 7b181998..00000000 --- a/src/widgets/helper/EffectLabel.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "widgets/helper/EffectLabel.hpp" -#include "singletons/Theme.hpp" -#include "widgets/splits/SplitHeader.hpp" - -#include -#include - -namespace chatterino { - -EffectLabel::EffectLabel(BaseWidget *parent, int spacing) - : Button(parent) - , label_(this) -{ - setLayout(&this->hbox_); - - this->label_.setAlignment(Qt::AlignCenter); - - this->hbox_.setMargin(0); - this->hbox_.addSpacing(spacing); - this->hbox_.addWidget(&this->label_); - this->hbox_.addSpacing(spacing); -} - -EffectLabel2::EffectLabel2(BaseWidget *parent, int padding) - : Button(parent) - , label_(this) -{ - auto *hbox = new QHBoxLayout(this); - this->setLayout(hbox); - - // this->label_.setAlignment(Qt::AlignCenter); - this->label_.setCentered(true); - - hbox->setMargin(0); - // hbox.addSpacing(spacing); - hbox->addWidget(&this->label_); - // hbox.addSpacing(spacing); -} - -Label &EffectLabel2::getLabel() -{ - return this->label_; -} - -} // namespace chatterino diff --git a/src/widgets/helper/EffectLabel.hpp b/src/widgets/helper/EffectLabel.hpp deleted file mode 100644 index ea13671a..00000000 --- a/src/widgets/helper/EffectLabel.hpp +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -#include "widgets/BaseWidget.hpp" -#include "widgets/Label.hpp" -#include "widgets/helper/Button.hpp" -#include "widgets/helper/SignalLabel.hpp" - -#include -#include -#include -#include - -namespace chatterino { - -class EffectLabel : public Button -{ -public: - explicit EffectLabel(BaseWidget *parent = nullptr, int spacing = 6); - - SignalLabel &getLabel() - { - return this->label_; - } - -private: - QHBoxLayout hbox_; - SignalLabel label_; -}; - -class EffectLabel2 : public Button -{ -public: - explicit EffectLabel2(BaseWidget *parent = nullptr, int padding = 6); - - Label &getLabel(); - -private: - Label label_; -}; - -} // namespace chatterino diff --git a/src/widgets/helper/NotebookTab.cpp b/src/widgets/helper/NotebookTab.cpp index ca8f2d75..04d2fc4d 100644 --- a/src/widgets/helper/NotebookTab.cpp +++ b/src/widgets/helper/NotebookTab.cpp @@ -100,7 +100,14 @@ void NotebookTab::updateSize() width = (metrics.width(this->getTitle()) + int(16 * scale)); } - width = clamp(width, this->height(), int(150 * scale)); + if (this->height() > 150 * scale) + { + width = this->height(); + } + else + { + width = clamp(width, this->height(), int(150 * scale)); + } auto height = int(NOTEBOOK_TAB_HEIGHT * scale); if (this->width() != width || this->height() != height) diff --git a/src/widgets/settingspages/GeneralPage.cpp b/src/widgets/settingspages/GeneralPage.cpp index 80b70c8d..f370765e 100644 --- a/src/widgets/settingspages/GeneralPage.cpp +++ b/src/widgets/settingspages/GeneralPage.cpp @@ -158,12 +158,18 @@ void GeneralPage::initLayout(SettingsLayout &layout) getApp()->fonts->chatFontSize, [](auto val) { return QString::number(val) + "pt"; }, [](auto args) { return fuzzyToInt(args.value, 10); }); - layout.addDropdown( + layout.addDropdown( "UI Scale", {"0.5x", "0.6x", "0.7x", "0.8x", "0.9x", "Default", "1.2x", "1.4x", "1.6x", "1.8x", "2x", "2.33x", "2.66x", "3x", "3.5x", "4x"}, - s.uiScale, [](auto val) { return val + 5; }, - [](auto args) { return args.index - 5; }, false); + s.uiScale, + [](auto val) { + if (val == 1) + return QString("Default"); + else + return QString::number(val) + "x"; + }, + [](auto args) { return fuzzyToFloat(args.value, 1.f); }); layout.addCheckbox("Always on top", s.windowTopMost); layout.addTitle("Interface"); diff --git a/src/widgets/settingspages/LookPage.cpp b/src/widgets/settingspages/LookPage.cpp index f45fc69c..7fcf68e8 100644 --- a/src/widgets/settingspages/LookPage.cpp +++ b/src/widgets/settingspages/LookPage.cpp @@ -125,13 +125,6 @@ void LookPage::addInterfaceTab(LayoutCreator layout) box->addStretch(1); } - // ui scale - { - auto box = layout.emplace().withoutMargin(); - box.emplace("Window scale: "); - box.append(this->createUiScaleSlider()); - } - layout.append( this->createCheckBox(WINDOW_TOPMOST, getSettings()->windowTopMost)); @@ -567,34 +560,6 @@ QLayout *LookPage::createFontChanger() return layout; } -QLayout *LookPage::createUiScaleSlider() -{ - auto layout = new QHBoxLayout(); - auto slider = new QSlider(Qt::Horizontal); - auto label = new QLabel(); - layout->addWidget(slider); - layout->addWidget(label); - - slider->setMinimum(WindowManager::uiScaleMin); - slider->setMaximum(WindowManager::uiScaleMax); - slider->setValue( - WindowManager::clampUiScale(getSettings()->uiScale.getValue())); - - label->setMinimumWidth(100); - - QObject::connect(slider, &QSlider::valueChanged, [](auto value) { - getSettings()->uiScale.setValue(value); - }); - - getSettings()->uiScale.connect( - [label](auto, auto) { - label->setText(QString::number(WindowManager::getUiScaleValue())); - }, - this->connections_); - - return layout; -} - QLayout *LookPage::createBoldScaleSlider() { auto layout = new QHBoxLayout(); diff --git a/src/widgets/settingspages/LookPage.hpp b/src/widgets/settingspages/LookPage.hpp index a69c3f2f..87b8195b 100644 --- a/src/widgets/settingspages/LookPage.hpp +++ b/src/widgets/settingspages/LookPage.hpp @@ -30,7 +30,6 @@ private: QLayout *createThemeColorChanger(); QLayout *createFontChanger(); - QLayout *createUiScaleSlider(); QLayout *createBoldScaleSlider(); ChannelPtr createPreviewChannel();