diff --git a/src/chatlog/chatwidget.cpp b/src/chatlog/chatwidget.cpp index b0da745e9..d6748b9bb 100644 --- a/src/chatlog/chatwidget.cpp +++ b/src/chatlog/chatwidget.cpp @@ -292,7 +292,7 @@ ChatWidget::ChatWidget(IChatLog& chatLog_, const Core& core_, DocumentCache& doc copySelectedText(true); }); - connect(&GUI::getInstance(), &GUI::themeReload, this, &ChatWidget::reloadTheme); + connect(&style, &Style::themeReload, this, &ChatWidget::reloadTheme); reloadTheme(); retranslateUi(); diff --git a/src/chatlog/content/filetransferwidget.cpp b/src/chatlog/content/filetransferwidget.cpp index 56d81387f..6bb98dcba 100644 --- a/src/chatlog/content/filetransferwidget.cpp +++ b/src/chatlog/content/filetransferwidget.cpp @@ -94,7 +94,7 @@ FileTransferWidget::FileTransferWidget(QWidget* parent, CoreFile& _coreFile, connect(ui->previewButton, &QPushButton::clicked, this, &FileTransferWidget::onPreviewButtonClicked); - connect(&GUI::getInstance(), &GUI::themeReload, this, &FileTransferWidget::reloadTheme); + connect(&style, &Style::themeReload, this, &FileTransferWidget::reloadTheme); // Set lastStatus to anything but the file's current value, this forces an update lastStatus = file.status == ToxFile::FINISHED ? ToxFile::INITIALIZING : ToxFile::FINISHED; diff --git a/src/widget/about/aboutfriendform.cpp b/src/widget/about/aboutfriendform.cpp index 0c3541cfc..d3bdccb30 100644 --- a/src/widget/about/aboutfriendform.cpp +++ b/src/widget/about/aboutfriendform.cpp @@ -80,7 +80,7 @@ AboutFriendForm::AboutFriendForm(std::unique_ptr about_, ui->statusMessage->setText(about->getStatusMessage()); ui->avatar->setPixmap(about->getAvatar()); - connect(&GUI::getInstance(), &GUI::themeReload, this, &AboutFriendForm::reloadTheme); + connect(&style, &Style::themeReload, this, &AboutFriendForm::reloadTheme); reloadTheme(); } diff --git a/src/widget/categorywidget.cpp b/src/widget/categorywidget.cpp index 2ee816aff..35bf1dea0 100644 --- a/src/widget/categorywidget.cpp +++ b/src/widget/categorywidget.cpp @@ -40,7 +40,7 @@ void CategoryWidget::emitChatroomWidget(QLayout* layout, int index) CategoryWidget::CategoryWidget(bool compact_, Settings& settings_, Style& style_, QWidget* parent) - : GenericChatItemWidget(compact_, parent) + : GenericChatItemWidget(compact_, style_, parent) , settings{settings_} , style{style_} { diff --git a/src/widget/chatformheader.cpp b/src/widget/chatformheader.cpp index 0c28b55db..422853f84 100644 --- a/src/widget/chatformheader.cpp +++ b/src/widget/chatformheader.cpp @@ -170,7 +170,7 @@ ChatFormHeader::ChatFormHeader(Settings& settings_, Style& style_, QWidget* pare updateButtonsView(); Translator::registerHandler(std::bind(&ChatFormHeader::retranslateUi, this), this); - connect(&GUI::getInstance(), &GUI::themeReload, this, &ChatFormHeader::reloadTheme); + connect(&style, &Style::themeReload, this, &ChatFormHeader::reloadTheme); } ChatFormHeader::~ChatFormHeader() = default; diff --git a/src/widget/contentdialog.cpp b/src/widget/contentdialog.cpp index c1038aa87..771b8bacc 100644 --- a/src/widget/contentdialog.cpp +++ b/src/widget/contentdialog.cpp @@ -55,7 +55,7 @@ const QSize defaultSize(720, 400); ContentDialog::ContentDialog(const Core &core, Settings& settings_, Style& style_, QWidget* parent) - : ActivateDialog(parent, Qt::Window) + : ActivateDialog(style_, parent, Qt::Window) , splitter{new QSplitter(this)} , friendLayout{new FriendListLayout(this)} , activeChatroomWidget(nullptr) diff --git a/src/widget/contentlayout.cpp b/src/widget/contentlayout.cpp index d456d65b0..5afde4fbe 100644 --- a/src/widget/contentlayout.cpp +++ b/src/widget/contentlayout.cpp @@ -123,7 +123,7 @@ void ContentLayout::init() mainContent->setStyle(QStyleFactory::create(settings.getStyle())); } - connect(&GUI::getInstance(), &GUI::themeReload, this, &ContentLayout::reloadTheme); + connect(&style, &Style::themeReload, this, &ContentLayout::reloadTheme); reloadTheme(); diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index 67d3319bb..5a94d4392 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -263,7 +263,7 @@ GenericChatForm::GenericChatForm(const Core& core_, const Chat* chat, IChatLog& connect(msgEdit, &ChatTextEdit::enterPressed, this, &GenericChatForm::onSendTriggered); - connect(&GUI::getInstance(), &GUI::themeReload, this, &GenericChatForm::reloadTheme); + connect(&style, &Style::themeReload, this, &GenericChatForm::reloadTheme); reloadTheme(); diff --git a/src/widget/form/settings/aboutform.cpp b/src/widget/form/settings/aboutform.cpp index 83176613a..601368f07 100644 --- a/src/widget/form/settings/aboutform.cpp +++ b/src/widget/form/settings/aboutform.cpp @@ -55,7 +55,7 @@ enum class updateIndex * @brief Constructor of AboutForm. */ AboutForm::AboutForm(UpdateCheck* updateCheck_, Style& style_) - : GenericForm(QPixmap(":/img/settings/general.png")) + : GenericForm(QPixmap(":/img/settings/general.png"), style_) , bodyUI(new Ui::AboutSettings) , progressTimer(new QTimer(this)) , updateCheck(updateCheck_) diff --git a/src/widget/form/settings/advancedform.cpp b/src/widget/form/settings/advancedform.cpp index 4d2e6d9b4..9981dfcf0 100644 --- a/src/widget/form/settings/advancedform.cpp +++ b/src/widget/form/settings/advancedform.cpp @@ -41,8 +41,8 @@ * Is also contains "Reset settings" button and "Make portable" checkbox. */ -AdvancedForm::AdvancedForm(Settings& settings_) - : GenericForm(QPixmap(":/img/settings/general.png")) +AdvancedForm::AdvancedForm(Settings& settings_, Style& style) + : GenericForm(QPixmap(":/img/settings/general.png"), style) , bodyUI(new Ui::AdvancedSettings) , settings{settings_} { diff --git a/src/widget/form/settings/advancedform.h b/src/widget/form/settings/advancedform.h index 8d7257231..32eba6bc8 100644 --- a/src/widget/form/settings/advancedform.h +++ b/src/widget/form/settings/advancedform.h @@ -23,6 +23,7 @@ class Core; class Settings; +class Style; namespace Ui { class AdvancedSettings; @@ -32,7 +33,7 @@ class AdvancedForm : public GenericForm { Q_OBJECT public: - explicit AdvancedForm(Settings& settings); + AdvancedForm(Settings& settings, Style& style); ~AdvancedForm(); QString getFormName() final { diff --git a/src/widget/form/settings/avform.cpp b/src/widget/form/settings/avform.cpp index d4bd22bda..a4cfa2f5a 100644 --- a/src/widget/form/settings/avform.cpp +++ b/src/widget/form/settings/avform.cpp @@ -45,8 +45,9 @@ #endif AVForm::AVForm(IAudioControl& audio_, CoreAV* coreAV_, CameraSource& camera_, - IAudioSettings* audioSettings_, IVideoSettings* videoSettings_) - : GenericForm(QPixmap(":/img/settings/av.png")) + IAudioSettings* audioSettings_, IVideoSettings* videoSettings_, + Style& style) + : GenericForm(QPixmap(":/img/settings/av.png"), style) , audio(audio_) , coreAV{coreAV_} , audioSettings{audioSettings_} diff --git a/src/widget/form/settings/avform.h b/src/widget/form/settings/avform.h index 755a70614..0c2aee2c7 100644 --- a/src/widget/form/settings/avform.h +++ b/src/widget/form/settings/avform.h @@ -37,12 +37,13 @@ class CameraSource; class CoreAV; class IVideoSettings; class VideoSurface; +class Style; class AVForm : public GenericForm, private Ui::AVForm { Q_OBJECT public: AVForm(IAudioControl& audio_, CoreAV* coreAV_, CameraSource& camera_, - IAudioSettings* audioSettings_, IVideoSettings* videoSettings_); + IAudioSettings* audioSettings_, IVideoSettings* videoSettings_, Style&); ~AVForm() override; QString getFormName() final { diff --git a/src/widget/form/settings/generalform.cpp b/src/widget/form/settings/generalform.cpp index 0e5178f4e..63f2a4119 100644 --- a/src/widget/form/settings/generalform.cpp +++ b/src/widget/form/settings/generalform.cpp @@ -96,8 +96,8 @@ QStringList locales = { * * This form contains all settings that are not suited to other forms */ -GeneralForm::GeneralForm(SettingsWidget* myParent, Settings& settings_) - : GenericForm(QPixmap(":/img/settings/general.png")) +GeneralForm::GeneralForm(SettingsWidget* myParent, Settings& settings_, Style& style) + : GenericForm(QPixmap(":/img/settings/general.png"), style) , bodyUI(new Ui::GeneralSettings) , settings{settings_} { diff --git a/src/widget/form/settings/generalform.h b/src/widget/form/settings/generalform.h index ffb1948e7..8dcc8eb98 100644 --- a/src/widget/form/settings/generalform.h +++ b/src/widget/form/settings/generalform.h @@ -27,12 +27,13 @@ class GeneralSettings; class SettingsWidget; class Settings; +class Style; class GeneralForm : public GenericForm { Q_OBJECT public: - explicit GeneralForm(SettingsWidget* parent, Settings& settings); + GeneralForm(SettingsWidget* parent, Settings& settings, Style& style); ~GeneralForm(); QString getFormName() final { diff --git a/src/widget/form/settings/genericsettings.cpp b/src/widget/form/settings/genericsettings.cpp index 383059bae..6b9f896fa 100644 --- a/src/widget/form/settings/genericsettings.cpp +++ b/src/widget/form/settings/genericsettings.cpp @@ -19,6 +19,7 @@ #include "genericsettings.h" #include "src/widget/gui.h" +#include "src/widget/style.h" #include #include @@ -32,10 +33,10 @@ * It provides correct behaviour of controls for settings forms. */ -GenericForm::GenericForm(const QPixmap& icon) +GenericForm::GenericForm(const QPixmap& icon, Style& style) : formIcon(icon) { - connect(&GUI::getInstance(), &GUI::themeReload, this, &GenericForm::reloadTheme); + connect(&style, &Style::themeReload, this, &GenericForm::reloadTheme); } QPixmap GenericForm::getFormIcon() diff --git a/src/widget/form/settings/genericsettings.h b/src/widget/form/settings/genericsettings.h index eeee88d5a..43a06d163 100644 --- a/src/widget/form/settings/genericsettings.h +++ b/src/widget/form/settings/genericsettings.h @@ -21,11 +21,13 @@ #include +class Style; + class GenericForm : public QWidget { Q_OBJECT public: - explicit GenericForm(const QPixmap& icon); + GenericForm(const QPixmap& icon, Style&); virtual ~GenericForm() { } diff --git a/src/widget/form/settings/privacyform.cpp b/src/widget/form/settings/privacyform.cpp index 996974ddf..4c2cef695 100644 --- a/src/widget/form/settings/privacyform.cpp +++ b/src/widget/form/settings/privacyform.cpp @@ -39,8 +39,8 @@ #include #include -PrivacyForm::PrivacyForm(Core* core_, Settings& settings_) - : GenericForm(QPixmap(":/img/settings/privacy.png")) +PrivacyForm::PrivacyForm(Core* core_, Settings& settings_, Style& style) + : GenericForm(QPixmap(":/img/settings/privacy.png"), style) , bodyUI(new Ui::PrivacySettings) , core{core_} , settings{settings_} diff --git a/src/widget/form/settings/privacyform.h b/src/widget/form/settings/privacyform.h index 0a91a9525..e80b5ff49 100644 --- a/src/widget/form/settings/privacyform.h +++ b/src/widget/form/settings/privacyform.h @@ -23,6 +23,7 @@ class Core; class Settings; +class Style; namespace Ui { class PrivacySettings; @@ -32,7 +33,7 @@ class PrivacyForm : public GenericForm { Q_OBJECT public: - PrivacyForm(Core* core_, Settings& settings); + PrivacyForm(Core* core_, Settings& settings, Style& style); ~PrivacyForm(); QString getFormName() final { diff --git a/src/widget/form/settings/userinterfaceform.cpp b/src/widget/form/settings/userinterfaceform.cpp index a315f9d0f..52bc9d4ff 100644 --- a/src/widget/form/settings/userinterfaceform.cpp +++ b/src/widget/form/settings/userinterfaceform.cpp @@ -56,7 +56,7 @@ */ UserInterfaceForm::UserInterfaceForm(SmileyPack& smileyPack_, Settings& settings_, Style& style_, SettingsWidget* myParent) - : GenericForm(QPixmap(":/img/settings/general.png")) + : GenericForm(QPixmap(":/img/settings/general.png"), style_) , smileyPack{smileyPack_} , settings{settings_} , style{style_} @@ -342,7 +342,7 @@ void UserInterfaceForm::on_themeColorCBox_currentIndexChanged(int index) { settings.setThemeColor(index); style.setThemeColor(settings, index); - Style::applyTheme(); + style.applyTheme(); } /** diff --git a/src/widget/form/settingswidget.cpp b/src/widget/form/settingswidget.cpp index 1bfb71e6f..890ba9ee4 100644 --- a/src/widget/form/settingswidget.cpp +++ b/src/widget/form/settingswidget.cpp @@ -58,16 +58,16 @@ SettingsWidget::SettingsWidget(UpdateCheck* updateCheck, IAudioControl& audio, settingsWidgets->setTabPosition(QTabWidget::North); bodyLayout->addWidget(settingsWidgets.get()); - std::unique_ptr gfrm(new GeneralForm(this, settings)); + std::unique_ptr gfrm(new GeneralForm(this, settings, style)); connect(gfrm.get(), &GeneralForm::updateIcons, parent, &Widget::updateIcons); std::unique_ptr uifrm(new UserInterfaceForm(smileyPack, settings, style, this)); - std::unique_ptr pfrm(new PrivacyForm(core, settings)); + std::unique_ptr pfrm(new PrivacyForm(core, settings, style)); connect(pfrm.get(), &PrivacyForm::clearAllReceipts, parent, &Widget::clearAllReceipts); - AVForm* rawAvfrm = new AVForm(audio, coreAV, cameraSource, audioSettings, videoSettings); + AVForm* rawAvfrm = new AVForm(audio, coreAV, cameraSource, audioSettings, videoSettings, style); std::unique_ptr avfrm(rawAvfrm); - std::unique_ptr expfrm(new AdvancedForm(settings)); + std::unique_ptr expfrm(new AdvancedForm(settings, style)); std::unique_ptr abtfrm(new AboutForm(updateCheck, style)); #if UPDATE_CHECK_ENABLED diff --git a/src/widget/genericchatitemwidget.cpp b/src/widget/genericchatitemwidget.cpp index 08359450c..28d3106d2 100644 --- a/src/widget/genericchatitemwidget.cpp +++ b/src/widget/genericchatitemwidget.cpp @@ -21,9 +21,11 @@ #include "src/persistence/settings.h" #include "src/widget/tool/croppinglabel.h" #include "src/widget/gui.h" +#include "src/widget/style.h" #include -GenericChatItemWidget::GenericChatItemWidget(bool compact_, QWidget* parent) +GenericChatItemWidget::GenericChatItemWidget(bool compact_, Style& style, + QWidget* parent) : QFrame(parent) , compact(compact_) { @@ -33,7 +35,7 @@ GenericChatItemWidget::GenericChatItemWidget(bool compact_, QWidget* parent) nameLabel->setObjectName("name"); nameLabel->setTextFormat(Qt::PlainText); - connect(&GUI::getInstance(), &GUI::themeReload, this, &GenericChatItemWidget::reloadTheme); + connect(&style, &Style::themeReload, this, &GenericChatItemWidget::reloadTheme); } bool GenericChatItemWidget::isCompact() const diff --git a/src/widget/genericchatitemwidget.h b/src/widget/genericchatitemwidget.h index 7d13f8b9a..5c2b2b25b 100644 --- a/src/widget/genericchatitemwidget.h +++ b/src/widget/genericchatitemwidget.h @@ -23,6 +23,7 @@ #include class CroppingLabel; +class Style; class GenericChatItemWidget : public QFrame { @@ -35,7 +36,7 @@ public: FriendOnlineItem }; - explicit GenericChatItemWidget(bool compact_, QWidget* parent = nullptr); + GenericChatItemWidget(bool compact_, Style&, QWidget* parent = nullptr); bool isCompact() const; void setCompact(bool compact_); diff --git a/src/widget/genericchatroomwidget.cpp b/src/widget/genericchatroomwidget.cpp index ec66b7f8e..b1cf7997d 100644 --- a/src/widget/genericchatroomwidget.cpp +++ b/src/widget/genericchatroomwidget.cpp @@ -27,7 +27,7 @@ GenericChatroomWidget::GenericChatroomWidget(bool compact_, Settings& settings_, Style& style_, QWidget* parent) - : GenericChatItemWidget(compact_, parent) + : GenericChatItemWidget(compact_, style_, parent) , active{false} , settings{settings_} , style{style_} diff --git a/src/widget/gui.cpp b/src/widget/gui.cpp index 0397386e9..46a40c0a9 100644 --- a/src/widget/gui.cpp +++ b/src/widget/gui.cpp @@ -77,22 +77,7 @@ void GUI::setWindowTitle(const QString& title) } } -/** - * @brief Reloads the application theme and redraw the window. - * - * For reload theme need connect signal themeReload() to function for reload - * For example: connect(&GUI::getInstance(), &GUI::themeReload, this, &SomeClass::reloadTheme); - */ -void GUI::reloadTheme() -{ - if (QThread::currentThread() == qApp->thread()) { - getInstance().themeReload(); - } else { - QMetaObject::invokeMethod(&getInstance(), "themeReload", Qt::BlockingQueuedConnection); - } -} - -/** +/* * @brief Show some text to the user. * @param title Title of information window. * @param msg Text in information window. diff --git a/src/widget/gui.h b/src/widget/gui.h index 38364de56..95ffec877 100644 --- a/src/widget/gui.h +++ b/src/widget/gui.h @@ -31,7 +31,6 @@ public: static GUI& getInstance(); static QWidget* getMainWidget(); static void setWindowTitle(const QString& title); - static void reloadTheme(); static void showInfo(const QString& title, const QString& msg); static void showWarning(const QString& title, const QString& msg); static void showError(const QString& title, const QString& msg); @@ -55,7 +54,4 @@ private slots: bool warning = true, bool yesno = true); bool _askQuestion(const QString& title, const QString& msg, const QString& button1, const QString& button2, bool defaultAns = false, bool warning = true); - -signals: - void themeReload(); }; diff --git a/src/widget/searchform.cpp b/src/widget/searchform.cpp index fafa9ef29..93a768fac 100644 --- a/src/widget/searchform.cpp +++ b/src/widget/searchform.cpp @@ -96,7 +96,7 @@ SearchForm::SearchForm(Settings& settings_, Style& style_, QWidget* parent) connect(searchSettingsForm, &SearchSettingsForm::updateSettings, this, &SearchForm::changedState); - connect(&GUI::getInstance(), &GUI::themeReload, this, &SearchForm::reloadTheme); + connect(&style, &Style::themeReload, this, &SearchForm::reloadTheme); } void SearchForm::removeSearchPhrase() diff --git a/src/widget/style.cpp b/src/widget/style.cpp index fa74954f1..b870e177f 100644 --- a/src/widget/style.cpp +++ b/src/widget/style.cpp @@ -366,11 +366,14 @@ void Style::setThemeColor(const QColor& color) } /** - * @brief Reloads some CCS + * @brief Reloads the application theme and redraw the window. + * + * For reload theme need connect signal themeReload() to function for reload + * For example: connect(&style, &Style::themeReload, this, &SomeClass::reloadTheme); */ void Style::applyTheme() { - GUI::reloadTheme(); + emit themeReload(); } QPixmap Style::scaleSvgImage(const QString& path, uint32_t width, uint32_t height) diff --git a/src/widget/style.h b/src/widget/style.h index 71e5ed16e..32f287b43 100644 --- a/src/widget/style.h +++ b/src/widget/style.h @@ -22,13 +22,15 @@ #include #include #include +#include class QString; class QWidget; class Settings; -class Style +class Style : public QObject { +Q_OBJECT public: enum class ColorPalette { @@ -75,7 +77,7 @@ public: static QString getThemeName(); static QFont getFont(Font font); static void repolish(QWidget* w); - static void applyTheme(); + void applyTheme(); static QPixmap scaleSvgImage(const QString& path, uint32_t width, uint32_t height); Style() = default; @@ -90,7 +92,7 @@ public: static QString getThemePath(Settings& settings); signals: - void themeChanged(); + void themeReload(); private: QMap palette; diff --git a/src/widget/tool/activatedialog.cpp b/src/widget/tool/activatedialog.cpp index 2af70b086..f8cc48122 100644 --- a/src/widget/tool/activatedialog.cpp +++ b/src/widget/tool/activatedialog.cpp @@ -20,12 +20,13 @@ #include "activatedialog.h" #include "src/widget/gui.h" +#include "src/widget/style.h" #include -ActivateDialog::ActivateDialog(QWidget* parent, Qt::WindowFlags f) +ActivateDialog::ActivateDialog(Style& style, QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f) { - connect(&GUI::getInstance(), &GUI::themeReload, this, &ActivateDialog::reloadTheme); + connect(&style, &Style::themeReload, this, &ActivateDialog::reloadTheme); } bool ActivateDialog::event(QEvent* event) diff --git a/src/widget/tool/activatedialog.h b/src/widget/tool/activatedialog.h index 52a43ebd8..65d180e8e 100644 --- a/src/widget/tool/activatedialog.h +++ b/src/widget/tool/activatedialog.h @@ -21,14 +21,16 @@ #include +class Style; + class ActivateDialog : public QDialog { Q_OBJECT public: #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) - ActivateDialog(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); + ActivateDialog(Style&, QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); #else - ActivateDialog(QWidget* parent = nullptr, Qt::WindowFlags f = nullptr); + ActivateDialog(Style&, QWidget* parent = nullptr, Qt::WindowFlags f = nullptr); #endif bool event(QEvent* event) override; diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 744233bb5..26b18fb4b 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -498,7 +498,7 @@ void Widget::init() connect(&settings, &Settings::groupchatPositionChanged, chatListWidget, &FriendListWidget::onGroupchatPositionChanged); - connect(&GUI::getInstance(), &GUI::themeReload, this, &Widget::reloadTheme); + connect(&style, &Style::themeReload, this, &Widget::reloadTheme); reloadTheme(); updateIcons(); @@ -1898,7 +1898,7 @@ ContentLayout* Widget::createContentDialog(DialogType type) const { public: explicit Dialog(DialogType type_, Settings& settings_, Core* core_, Style& style_) - : ActivateDialog(nullptr, Qt::Window) + : ActivateDialog(style_, nullptr, Qt::Window) , type(type_) , settings(settings_) , core{core_}