diff --git a/src/messages/image.cpp b/src/messages/image.cpp index 732d56cd3..62c137214 100644 --- a/src/messages/image.cpp +++ b/src/messages/image.cpp @@ -147,10 +147,10 @@ void Image::loadImage() loadedEventQueued = true; QTimer::singleShot(500, [] { - getApp()->emotes->incGeneration(); + getApp()->windows->incGeneration(); auto app = getApp(); - app->windows->layoutVisibleChatWidgets(); + app->windows->layoutChannelViews(); loadedEventQueued = false; }); } diff --git a/src/messages/layouts/messagelayout.cpp b/src/messages/layouts/messagelayout.cpp index b80ef6f81..d99de85d9 100644 --- a/src/messages/layouts/messagelayout.cpp +++ b/src/messages/layouts/messagelayout.cpp @@ -3,6 +3,7 @@ #include "application.hpp" #include "singletons/emotemanager.hpp" #include "singletons/settingsmanager.hpp" +#include "singletons/windowmanager.hpp" #include "util/benchmark.hpp" #include @@ -59,52 +60,24 @@ bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags) layoutRequired |= widthChanged; this->currentLayoutWidth_ = width; - // check if emotes changed - bool imagesChanged = this->emoteGeneration_ != app->emotes->getGeneration(); - layoutRequired |= imagesChanged; - this->emoteGeneration_ = app->emotes->getGeneration(); - - // check if text changed - bool textChanged = this->fontGeneration_ != app->fonts->getGeneration(); - layoutRequired |= textChanged; - this->fontGeneration_ = app->fonts->getGeneration(); + // check if layout state changed + if (this->layoutState_ != app->windows->getGeneration()) { + layoutRequired = true; + this->flags |= RequiresBufferUpdate; + this->layoutState_ = app->windows->getGeneration(); + } // check if work mask changed - bool wordMaskChanged = this->currentWordFlags_ != flags; // app->settings->getWordTypeMask(); - layoutRequired |= wordMaskChanged; + layoutRequired |= this->currentWordFlags_ != flags; this->currentWordFlags_ = flags; // app->settings->getWordTypeMask(); - // check if timestamp format changed - bool timestampFormatChanged = this->timestampFormat_ != app->settings->timestampFormat; - this->timestampFormat_ = app->settings->timestampFormat.getValue(); - - layoutRequired |= timestampFormatChanged; - // check if layout was requested manually layoutRequired |= bool(this->flags & RequiresLayout); - this->flags &= ~RequiresLayout; + this->flags &= decltype(RequiresLayout)(~RequiresLayout); // check if dpi changed - bool scaleChanged = this->scale_ != scale; - layoutRequired |= scaleChanged; + layoutRequired |= this->scale_ != scale; this->scale_ = scale; - imagesChanged |= scaleChanged; - textChanged |= scaleChanged; - - // update word sizes if needed - if (imagesChanged) { - // this->container.updateImages(); - this->flags |= MessageLayout::RequiresBufferUpdate; - } - if (textChanged) { - // this->container.updateText(); - this->flags |= MessageLayout::RequiresBufferUpdate; - } - if (widthChanged || wordMaskChanged) { - this->deleteBuffer(); - } - - // return if no layout is required if (!layoutRequired) { return false; @@ -112,7 +85,7 @@ bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags) int oldHeight = this->container_.getHeight(); this->actuallyLayout(width, flags); - if (this->container_.getHeight() != oldHeight) { + if (widthChanged || this->container_.getHeight() != oldHeight) { this->deleteBuffer(); } this->invalidateBuffer(); diff --git a/src/messages/layouts/messagelayout.hpp b/src/messages/layouts/messagelayout.hpp index da63ac50a..7b3c074ae 100644 --- a/src/messages/layouts/messagelayout.hpp +++ b/src/messages/layouts/messagelayout.hpp @@ -67,9 +67,7 @@ private: int height_ = 0; int currentLayoutWidth_ = -1; - int fontGeneration_ = -1; - int emoteGeneration_ = -1; - QString timestampFormat_; + int layoutState_ = -1; float scale_ = -1; unsigned int bufferUpdatedCount_ = 0; diff --git a/src/singletons/emotemanager.hpp b/src/singletons/emotemanager.hpp index 483c16d1f..37b56ca6d 100644 --- a/src/singletons/emotemanager.hpp +++ b/src/singletons/emotemanager.hpp @@ -46,16 +46,6 @@ public: util::EmoteData getTwitchEmoteById(long int id, const QString &emoteName); - int getGeneration() - { - return _generation; - } - - void incGeneration() - { - _generation++; - } - pajlada::Signals::NoArgSignal &getGifUpdateSignal(); // Bit badge/emotes? @@ -145,8 +135,6 @@ private: pajlada::Signals::NoArgSignal gifUpdateTimerSignal; QTimer gifUpdateTimer; bool gifUpdateTimerInitiated = false; - - int _generation = 0; }; } // namespace singletons diff --git a/src/singletons/fontmanager.cpp b/src/singletons/fontmanager.cpp index d57649ff4..240492484 100644 --- a/src/singletons/fontmanager.cpp +++ b/src/singletons/fontmanager.cpp @@ -3,7 +3,9 @@ #include #include +#include "application.hpp" #include "util/assertinguithread.hpp" +#include "windowmanager.hpp" #ifdef Q_OS_WIN32 #define DEFAULT_FONT_FAMILY "Segoe UI" @@ -27,27 +29,33 @@ FontManager::FontManager() { qDebug() << "init FontManager"; - this->chatFontFamily.connect([this](const std::string &newValue, auto) { + this->chatFontFamily.connect([this](const std::string &, auto) { util::assertInGuiThread(); - this->incGeneration(); + if (getApp()->windows) { + getApp()->windows->incGeneration(); + } + for (auto &map : this->fontsByType) { map.clear(); } this->fontChanged.invoke(); }); - this->chatFontSize.connect([this](const int &newValue, auto) { + this->chatFontSize.connect([this](const int &, auto) { util::assertInGuiThread(); - this->incGeneration(); + if (getApp()->windows) { + getApp()->windows->incGeneration(); + } + for (auto &map : this->fontsByType) { map.clear(); } this->fontChanged.invoke(); }); - this->fontsByType.resize((size_t)EndType); + this->fontsByType.resize(size_t(EndType)); } QFont FontManager::getFont(FontManager::Type type, float scale) @@ -60,23 +68,13 @@ QFontMetrics FontManager::getFontMetrics(FontManager::Type type, float scale) return this->getOrCreateFontData(type, scale).metrics; } -int FontManager::getGeneration() const -{ - return this->generation; -} - -void FontManager::incGeneration() -{ - this->generation++; -} - FontManager::FontData &FontManager::getOrCreateFontData(Type type, float scale) { util::assertInGuiThread(); assert(type >= 0 && type < EndType); - auto &map = this->fontsByType[(size_t)type]; + auto &map = this->fontsByType[size_t(type)]; // find element auto it = map.find(scale); @@ -109,7 +107,7 @@ FontManager::FontData FontManager::createFontData(Type type, float scale) auto data = sizeScale[type]; return FontData(QFont(QString::fromStdString(this->chatFontFamily.getValue()), - this->chatFontSize.getValue() * data.scale * scale, data.weight, + int(this->chatFontSize.getValue() * data.scale * scale), data.weight, data.italic)); } @@ -128,7 +126,7 @@ FontManager::FontData FontManager::createFontData(Type type, float scale) }; UiFontData &data = defaultSize[type]; - QFont font(data.name, data.size * scale, data.weight, data.italic); + QFont font(data.name, int(data.size * scale), data.weight, data.italic); return FontData(font); } } diff --git a/src/singletons/fontmanager.hpp b/src/singletons/fontmanager.hpp index 1a6ddf811..4e4f489e1 100644 --- a/src/singletons/fontmanager.hpp +++ b/src/singletons/fontmanager.hpp @@ -42,9 +42,6 @@ public: QFont getFont(Type type, float scale); QFontMetrics getFontMetrics(Type type, float scale); - int getGeneration() const; - void incGeneration(); - pajlada::Settings::Setting chatFontFamily; pajlada::Settings::Setting chatFontSize; @@ -79,8 +76,6 @@ private: FontData createFontData(Type type, float scale); std::vector> fontsByType; - - int generation = 0; }; } // namespace singletons diff --git a/src/singletons/settingsmanager.cpp b/src/singletons/settingsmanager.cpp index 33755a52a..32fe79bdc 100644 --- a/src/singletons/settingsmanager.cpp +++ b/src/singletons/settingsmanager.cpp @@ -39,13 +39,18 @@ void SettingManager::initialize() this->timestampFormat.connect([](auto, auto) { auto app = getApp(); - app->windows->layoutVisibleChatWidgets(); + app->windows->layoutChannelViews(); }); - this->emoteScale.connect([](auto, auto) { - getApp()->fonts->incGeneration(); - getApp()->windows->layoutVisibleChatWidgets(); - }); + this->emoteScale.connect([](auto, auto) { getApp()->windows->forceLayoutChannelViews(); }); + + this->timestampFormat.connect([](auto, auto) { getApp()->windows->forceLayoutChannelViews(); }); + this->alternateMessageBackground.connect( + [](auto, auto) { getApp()->windows->forceLayoutChannelViews(); }); + this->seperateMessages.connect( + [](auto, auto) { getApp()->windows->forceLayoutChannelViews(); }); + this->collapseLongMessages.connect( + [](auto, auto) { getApp()->windows->forceLayoutChannelViews(); }); } MessageElement::Flags SettingManager::getWordFlags() diff --git a/src/singletons/windowmanager.cpp b/src/singletons/windowmanager.cpp index 294a03d33..69e0046b7 100644 --- a/src/singletons/windowmanager.cpp +++ b/src/singletons/windowmanager.cpp @@ -58,11 +58,17 @@ WindowManager::WindowManager() qDebug() << "init WindowManager"; } -void WindowManager::layoutVisibleChatWidgets(Channel *channel) +void WindowManager::layoutChannelViews(Channel *channel) { this->layout.invoke(channel); } +void WindowManager::forceLayoutChannelViews() +{ + this->incGeneration(); + this->layoutChannelViews(nullptr); +} + void WindowManager::repaintVisibleChatWidgets(Channel *channel) { if (this->mainWindow != nullptr) { @@ -394,5 +400,15 @@ void WindowManager::closeAll() } } +int WindowManager::getGeneration() const +{ + return this->generation; +} + +void WindowManager::incGeneration() +{ + this->generation++; +} + } // namespace singletons } // namespace chatterino diff --git a/src/singletons/windowmanager.hpp b/src/singletons/windowmanager.hpp index 28c2cace9..ccee1d875 100644 --- a/src/singletons/windowmanager.hpp +++ b/src/singletons/windowmanager.hpp @@ -1,11 +1,11 @@ #pragma once -#include "widgets/window.hpp" #include "widgets/splitcontainer.hpp" +#include "widgets/window.hpp" namespace chatterino { -//namespace widgets { -//struct SplitContainer::Node; +// namespace widgets { +// struct SplitContainer::Node; //} namespace singletons { @@ -19,7 +19,8 @@ public: void showSettingsDialog(); void showAccountSelectPopup(QPoint point); - void layoutVisibleChatWidgets(Channel *channel = nullptr); + void layoutChannelViews(Channel *channel = nullptr); + void forceLayoutChannelViews(); void repaintVisibleChatWidgets(Channel *channel = nullptr); void repaintGifEmotes(); // void updateAll(); @@ -35,12 +36,17 @@ public: void initialize(); void closeAll(); + int getGeneration() const; + void incGeneration(); + pajlada::Signals::NoArgSignal repaintGifs; pajlada::Signals::Signal layout; private: bool initialized = false; + std::atomic generation{0}; + std::vector windows; widgets::Window *mainWindow = nullptr; diff --git a/src/widgets/settingspages/appearancepage.cpp b/src/widgets/settingspages/appearancepage.cpp index c94264d15..3ab1c80bd 100644 --- a/src/widgets/settingspages/appearancepage.cpp +++ b/src/widgets/settingspages/appearancepage.cpp @@ -51,25 +51,23 @@ AppearancePage::AppearancePage() auto form = application.emplace(); auto *theme = this->createComboBox({THEME_ITEMS}, app->themes->themeName); - QObject::connect(theme, &QComboBox::currentTextChanged, [](const QString &) { - getApp()->fonts->incGeneration(); - getApp()->windows->repaintVisibleChatWidgets(); - }); + QObject::connect(theme, &QComboBox::currentTextChanged, + [](const QString &) { getApp()->windows->forceLayoutChannelViews(); }); - // clang-format off - form->addRow("Theme:", theme); - // form->addRow("Theme color:", this->createThemeColorChanger()); - form->addRow("Font:", this->createFontChanger()); + form->addRow("Theme:", theme); + // form->addRow("Theme color:", this->createThemeColorChanger()); + form->addRow("Font:", this->createFontChanger()); - form->addRow("Tabs:", this->createCheckBox(TAB_X, app->settings->showTabCloseButton)); - #ifndef USEWINSDK - form->addRow("", this->createCheckBox(TAB_PREF, app->settings->hidePreferencesButton)); - form->addRow("", this->createCheckBox(TAB_USER, app->settings->hideUserButton)); - #endif + form->addRow("Tabs:", this->createCheckBox(TAB_X, app->settings->showTabCloseButton)); +#ifndef USEWINSDK + form->addRow("", this->createCheckBox(TAB_PREF, app->settings->hidePreferencesButton)); + form->addRow("", this->createCheckBox(TAB_USER, app->settings->hideUserButton)); +#endif - form->addRow("Scrolling:", this->createCheckBox(SCROLL_SMOOTH, app->settings->enableSmoothScrolling)); - form->addRow("", this->createCheckBox(SCROLL_NEWMSG, app->settings->enableSmoothScrollingNewMessages)); - // clang-format on + form->addRow("Scrolling:", + this->createCheckBox(SCROLL_SMOOTH, app->settings->enableSmoothScrolling)); + form->addRow("", this->createCheckBox(SCROLL_NEWMSG, + app->settings->enableSmoothScrollingNewMessages)); } auto messages = layout.emplace("Messages").emplace(); @@ -84,27 +82,11 @@ AppearancePage::AppearancePage() messages.append(this->createCheckBox("Show badges", app->settings->showBadges)); - auto *collapseMessages = this->createCheckBox("Collapse large messages (3+ lines)", - app->settings->collapseLongMessages); - QObject::connect(collapseMessages, &QCheckBox::toggled, - [] { getApp()->windows->layoutVisibleChatWidgets(); }); - messages.append(collapseMessages); - { - auto checkbox = - this->createCheckBox("Seperate messages", app->settings->seperateMessages); - messages.append(checkbox); - QObject::connect(checkbox, &QCheckBox::toggled, - [](bool) { getApp()->windows->repaintVisibleChatWidgets(); }); - } - { - auto checkbox = this->createCheckBox("Alternate message background color", - app->settings->alternateMessageBackground); - messages.append(checkbox); - QObject::connect(checkbox, &QCheckBox::toggled, [](bool) { - getApp()->fonts->incGeneration(); // fourtf: hacky solution - getApp()->windows->repaintVisibleChatWidgets(); - }); - } + messages.append(this->createCheckBox("Collapse large messages (3+ lines)", + app->settings->collapseLongMessages)); + messages.append(this->createCheckBox("Seperate messages", app->settings->seperateMessages)); + messages.append(this->createCheckBox("Alternate message background color", + app->settings->alternateMessageBackground)); messages.append(this->createCheckBox("Show message length while typing", app->settings->showMessageLength)); @@ -160,7 +142,7 @@ QLayout *AppearancePage::createThemeColorChanger() // SLIDER QSlider *slider = new QSlider(Qt::Horizontal); layout->addWidget(slider); - slider->setValue(std::min(std::max(themeHue.getValue(), 0.0), 1.0) * 100); + slider->setValue(int(std::min(std::max(themeHue.getValue(), 0.0), 1.0) * 100)); // BUTTON QPushButton *button = new QPushButton;