1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor(GUI): Remove GUI::themeReload, give responsibility to Style

Style already has themeChanged, which was unused. GUI's themeReload just
dispatches to Style, which is already piped to GUI classes. Give the signal
to Style itself so that classes can connect to that, rather than relying on
GUI's singleton.
This commit is contained in:
Anthony Bilinski 2022-03-13 04:42:56 -07:00
parent 3444fed0ac
commit 94d0f29603
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
32 changed files with 66 additions and 66 deletions

View File

@ -292,7 +292,7 @@ ChatWidget::ChatWidget(IChatLog& chatLog_, const Core& core_, DocumentCache& doc
copySelectedText(true); copySelectedText(true);
}); });
connect(&GUI::getInstance(), &GUI::themeReload, this, &ChatWidget::reloadTheme); connect(&style, &Style::themeReload, this, &ChatWidget::reloadTheme);
reloadTheme(); reloadTheme();
retranslateUi(); retranslateUi();

View File

@ -94,7 +94,7 @@ FileTransferWidget::FileTransferWidget(QWidget* parent, CoreFile& _coreFile,
connect(ui->previewButton, &QPushButton::clicked, this, connect(ui->previewButton, &QPushButton::clicked, this,
&FileTransferWidget::onPreviewButtonClicked); &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 // Set lastStatus to anything but the file's current value, this forces an update
lastStatus = file.status == ToxFile::FINISHED ? ToxFile::INITIALIZING : ToxFile::FINISHED; lastStatus = file.status == ToxFile::FINISHED ? ToxFile::INITIALIZING : ToxFile::FINISHED;

View File

@ -80,7 +80,7 @@ AboutFriendForm::AboutFriendForm(std::unique_ptr<IAboutFriend> about_,
ui->statusMessage->setText(about->getStatusMessage()); ui->statusMessage->setText(about->getStatusMessage());
ui->avatar->setPixmap(about->getAvatar()); ui->avatar->setPixmap(about->getAvatar());
connect(&GUI::getInstance(), &GUI::themeReload, this, &AboutFriendForm::reloadTheme); connect(&style, &Style::themeReload, this, &AboutFriendForm::reloadTheme);
reloadTheme(); reloadTheme();
} }

View File

@ -40,7 +40,7 @@ void CategoryWidget::emitChatroomWidget(QLayout* layout, int index)
CategoryWidget::CategoryWidget(bool compact_, Settings& settings_, Style& style_, CategoryWidget::CategoryWidget(bool compact_, Settings& settings_, Style& style_,
QWidget* parent) QWidget* parent)
: GenericChatItemWidget(compact_, parent) : GenericChatItemWidget(compact_, style_, parent)
, settings{settings_} , settings{settings_}
, style{style_} , style{style_}
{ {

View File

@ -170,7 +170,7 @@ ChatFormHeader::ChatFormHeader(Settings& settings_, Style& style_, QWidget* pare
updateButtonsView(); updateButtonsView();
Translator::registerHandler(std::bind(&ChatFormHeader::retranslateUi, this), this); 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; ChatFormHeader::~ChatFormHeader() = default;

View File

@ -55,7 +55,7 @@ const QSize defaultSize(720, 400);
ContentDialog::ContentDialog(const Core &core, Settings& settings_, ContentDialog::ContentDialog(const Core &core, Settings& settings_,
Style& style_, QWidget* parent) Style& style_, QWidget* parent)
: ActivateDialog(parent, Qt::Window) : ActivateDialog(style_, parent, Qt::Window)
, splitter{new QSplitter(this)} , splitter{new QSplitter(this)}
, friendLayout{new FriendListLayout(this)} , friendLayout{new FriendListLayout(this)}
, activeChatroomWidget(nullptr) , activeChatroomWidget(nullptr)

View File

@ -123,7 +123,7 @@ void ContentLayout::init()
mainContent->setStyle(QStyleFactory::create(settings.getStyle())); mainContent->setStyle(QStyleFactory::create(settings.getStyle()));
} }
connect(&GUI::getInstance(), &GUI::themeReload, this, &ContentLayout::reloadTheme); connect(&style, &Style::themeReload, this, &ContentLayout::reloadTheme);
reloadTheme(); reloadTheme();

View File

@ -263,7 +263,7 @@ GenericChatForm::GenericChatForm(const Core& core_, const Chat* chat, IChatLog&
connect(msgEdit, &ChatTextEdit::enterPressed, this, &GenericChatForm::onSendTriggered); connect(msgEdit, &ChatTextEdit::enterPressed, this, &GenericChatForm::onSendTriggered);
connect(&GUI::getInstance(), &GUI::themeReload, this, &GenericChatForm::reloadTheme); connect(&style, &Style::themeReload, this, &GenericChatForm::reloadTheme);
reloadTheme(); reloadTheme();

View File

@ -55,7 +55,7 @@ enum class updateIndex
* @brief Constructor of AboutForm. * @brief Constructor of AboutForm.
*/ */
AboutForm::AboutForm(UpdateCheck* updateCheck_, Style& style_) AboutForm::AboutForm(UpdateCheck* updateCheck_, Style& style_)
: GenericForm(QPixmap(":/img/settings/general.png")) : GenericForm(QPixmap(":/img/settings/general.png"), style_)
, bodyUI(new Ui::AboutSettings) , bodyUI(new Ui::AboutSettings)
, progressTimer(new QTimer(this)) , progressTimer(new QTimer(this))
, updateCheck(updateCheck_) , updateCheck(updateCheck_)

View File

@ -41,8 +41,8 @@
* Is also contains "Reset settings" button and "Make portable" checkbox. * Is also contains "Reset settings" button and "Make portable" checkbox.
*/ */
AdvancedForm::AdvancedForm(Settings& settings_) AdvancedForm::AdvancedForm(Settings& settings_, Style& style)
: GenericForm(QPixmap(":/img/settings/general.png")) : GenericForm(QPixmap(":/img/settings/general.png"), style)
, bodyUI(new Ui::AdvancedSettings) , bodyUI(new Ui::AdvancedSettings)
, settings{settings_} , settings{settings_}
{ {

View File

@ -23,6 +23,7 @@
class Core; class Core;
class Settings; class Settings;
class Style;
namespace Ui { namespace Ui {
class AdvancedSettings; class AdvancedSettings;
@ -32,7 +33,7 @@ class AdvancedForm : public GenericForm
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit AdvancedForm(Settings& settings); AdvancedForm(Settings& settings, Style& style);
~AdvancedForm(); ~AdvancedForm();
QString getFormName() final QString getFormName() final
{ {

View File

@ -45,8 +45,9 @@
#endif #endif
AVForm::AVForm(IAudioControl& audio_, CoreAV* coreAV_, CameraSource& camera_, AVForm::AVForm(IAudioControl& audio_, CoreAV* coreAV_, CameraSource& camera_,
IAudioSettings* audioSettings_, IVideoSettings* videoSettings_) IAudioSettings* audioSettings_, IVideoSettings* videoSettings_,
: GenericForm(QPixmap(":/img/settings/av.png")) Style& style)
: GenericForm(QPixmap(":/img/settings/av.png"), style)
, audio(audio_) , audio(audio_)
, coreAV{coreAV_} , coreAV{coreAV_}
, audioSettings{audioSettings_} , audioSettings{audioSettings_}

View File

@ -37,12 +37,13 @@ class CameraSource;
class CoreAV; class CoreAV;
class IVideoSettings; class IVideoSettings;
class VideoSurface; class VideoSurface;
class Style;
class AVForm : public GenericForm, private Ui::AVForm class AVForm : public GenericForm, private Ui::AVForm
{ {
Q_OBJECT Q_OBJECT
public: public:
AVForm(IAudioControl& audio_, CoreAV* coreAV_, CameraSource& camera_, AVForm(IAudioControl& audio_, CoreAV* coreAV_, CameraSource& camera_,
IAudioSettings* audioSettings_, IVideoSettings* videoSettings_); IAudioSettings* audioSettings_, IVideoSettings* videoSettings_, Style&);
~AVForm() override; ~AVForm() override;
QString getFormName() final QString getFormName() final
{ {

View File

@ -96,8 +96,8 @@ QStringList locales = {
* *
* This form contains all settings that are not suited to other forms * This form contains all settings that are not suited to other forms
*/ */
GeneralForm::GeneralForm(SettingsWidget* myParent, Settings& settings_) GeneralForm::GeneralForm(SettingsWidget* myParent, Settings& settings_, Style& style)
: GenericForm(QPixmap(":/img/settings/general.png")) : GenericForm(QPixmap(":/img/settings/general.png"), style)
, bodyUI(new Ui::GeneralSettings) , bodyUI(new Ui::GeneralSettings)
, settings{settings_} , settings{settings_}
{ {

View File

@ -27,12 +27,13 @@ class GeneralSettings;
class SettingsWidget; class SettingsWidget;
class Settings; class Settings;
class Style;
class GeneralForm : public GenericForm class GeneralForm : public GenericForm
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit GeneralForm(SettingsWidget* parent, Settings& settings); GeneralForm(SettingsWidget* parent, Settings& settings, Style& style);
~GeneralForm(); ~GeneralForm();
QString getFormName() final QString getFormName() final
{ {

View File

@ -19,6 +19,7 @@
#include "genericsettings.h" #include "genericsettings.h"
#include "src/widget/gui.h" #include "src/widget/gui.h"
#include "src/widget/style.h"
#include <QCheckBox> #include <QCheckBox>
#include <QComboBox> #include <QComboBox>
@ -32,10 +33,10 @@
* It provides correct behaviour of controls for settings forms. * It provides correct behaviour of controls for settings forms.
*/ */
GenericForm::GenericForm(const QPixmap& icon) GenericForm::GenericForm(const QPixmap& icon, Style& style)
: formIcon(icon) : formIcon(icon)
{ {
connect(&GUI::getInstance(), &GUI::themeReload, this, &GenericForm::reloadTheme); connect(&style, &Style::themeReload, this, &GenericForm::reloadTheme);
} }
QPixmap GenericForm::getFormIcon() QPixmap GenericForm::getFormIcon()

View File

@ -21,11 +21,13 @@
#include <QWidget> #include <QWidget>
class Style;
class GenericForm : public QWidget class GenericForm : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit GenericForm(const QPixmap& icon); GenericForm(const QPixmap& icon, Style&);
virtual ~GenericForm() virtual ~GenericForm()
{ {
} }

View File

@ -39,8 +39,8 @@
#include <chrono> #include <chrono>
#include <random> #include <random>
PrivacyForm::PrivacyForm(Core* core_, Settings& settings_) PrivacyForm::PrivacyForm(Core* core_, Settings& settings_, Style& style)
: GenericForm(QPixmap(":/img/settings/privacy.png")) : GenericForm(QPixmap(":/img/settings/privacy.png"), style)
, bodyUI(new Ui::PrivacySettings) , bodyUI(new Ui::PrivacySettings)
, core{core_} , core{core_}
, settings{settings_} , settings{settings_}

View File

@ -23,6 +23,7 @@
class Core; class Core;
class Settings; class Settings;
class Style;
namespace Ui { namespace Ui {
class PrivacySettings; class PrivacySettings;
@ -32,7 +33,7 @@ class PrivacyForm : public GenericForm
{ {
Q_OBJECT Q_OBJECT
public: public:
PrivacyForm(Core* core_, Settings& settings); PrivacyForm(Core* core_, Settings& settings, Style& style);
~PrivacyForm(); ~PrivacyForm();
QString getFormName() final QString getFormName() final
{ {

View File

@ -56,7 +56,7 @@
*/ */
UserInterfaceForm::UserInterfaceForm(SmileyPack& smileyPack_, Settings& settings_, UserInterfaceForm::UserInterfaceForm(SmileyPack& smileyPack_, Settings& settings_,
Style& style_, SettingsWidget* myParent) Style& style_, SettingsWidget* myParent)
: GenericForm(QPixmap(":/img/settings/general.png")) : GenericForm(QPixmap(":/img/settings/general.png"), style_)
, smileyPack{smileyPack_} , smileyPack{smileyPack_}
, settings{settings_} , settings{settings_}
, style{style_} , style{style_}
@ -342,7 +342,7 @@ void UserInterfaceForm::on_themeColorCBox_currentIndexChanged(int index)
{ {
settings.setThemeColor(index); settings.setThemeColor(index);
style.setThemeColor(settings, index); style.setThemeColor(settings, index);
Style::applyTheme(); style.applyTheme();
} }
/** /**

View File

@ -58,16 +58,16 @@ SettingsWidget::SettingsWidget(UpdateCheck* updateCheck, IAudioControl& audio,
settingsWidgets->setTabPosition(QTabWidget::North); settingsWidgets->setTabPosition(QTabWidget::North);
bodyLayout->addWidget(settingsWidgets.get()); bodyLayout->addWidget(settingsWidgets.get());
std::unique_ptr<GeneralForm> gfrm(new GeneralForm(this, settings)); std::unique_ptr<GeneralForm> gfrm(new GeneralForm(this, settings, style));
connect(gfrm.get(), &GeneralForm::updateIcons, parent, &Widget::updateIcons); connect(gfrm.get(), &GeneralForm::updateIcons, parent, &Widget::updateIcons);
std::unique_ptr<UserInterfaceForm> uifrm(new UserInterfaceForm(smileyPack, settings, style, this)); std::unique_ptr<UserInterfaceForm> uifrm(new UserInterfaceForm(smileyPack, settings, style, this));
std::unique_ptr<PrivacyForm> pfrm(new PrivacyForm(core, settings)); std::unique_ptr<PrivacyForm> pfrm(new PrivacyForm(core, settings, style));
connect(pfrm.get(), &PrivacyForm::clearAllReceipts, parent, &Widget::clearAllReceipts); 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<AVForm> avfrm(rawAvfrm); std::unique_ptr<AVForm> avfrm(rawAvfrm);
std::unique_ptr<AdvancedForm> expfrm(new AdvancedForm(settings)); std::unique_ptr<AdvancedForm> expfrm(new AdvancedForm(settings, style));
std::unique_ptr<AboutForm> abtfrm(new AboutForm(updateCheck, style)); std::unique_ptr<AboutForm> abtfrm(new AboutForm(updateCheck, style));
#if UPDATE_CHECK_ENABLED #if UPDATE_CHECK_ENABLED

View File

@ -21,9 +21,11 @@
#include "src/persistence/settings.h" #include "src/persistence/settings.h"
#include "src/widget/tool/croppinglabel.h" #include "src/widget/tool/croppinglabel.h"
#include "src/widget/gui.h" #include "src/widget/gui.h"
#include "src/widget/style.h"
#include <QVariant> #include <QVariant>
GenericChatItemWidget::GenericChatItemWidget(bool compact_, QWidget* parent) GenericChatItemWidget::GenericChatItemWidget(bool compact_, Style& style,
QWidget* parent)
: QFrame(parent) : QFrame(parent)
, compact(compact_) , compact(compact_)
{ {
@ -33,7 +35,7 @@ GenericChatItemWidget::GenericChatItemWidget(bool compact_, QWidget* parent)
nameLabel->setObjectName("name"); nameLabel->setObjectName("name");
nameLabel->setTextFormat(Qt::PlainText); nameLabel->setTextFormat(Qt::PlainText);
connect(&GUI::getInstance(), &GUI::themeReload, this, &GenericChatItemWidget::reloadTheme); connect(&style, &Style::themeReload, this, &GenericChatItemWidget::reloadTheme);
} }
bool GenericChatItemWidget::isCompact() const bool GenericChatItemWidget::isCompact() const

View File

@ -23,6 +23,7 @@
#include <QLabel> #include <QLabel>
class CroppingLabel; class CroppingLabel;
class Style;
class GenericChatItemWidget : public QFrame class GenericChatItemWidget : public QFrame
{ {
@ -35,7 +36,7 @@ public:
FriendOnlineItem FriendOnlineItem
}; };
explicit GenericChatItemWidget(bool compact_, QWidget* parent = nullptr); GenericChatItemWidget(bool compact_, Style&, QWidget* parent = nullptr);
bool isCompact() const; bool isCompact() const;
void setCompact(bool compact_); void setCompact(bool compact_);

View File

@ -27,7 +27,7 @@
GenericChatroomWidget::GenericChatroomWidget(bool compact_, Settings& settings_, GenericChatroomWidget::GenericChatroomWidget(bool compact_, Settings& settings_,
Style& style_, QWidget* parent) Style& style_, QWidget* parent)
: GenericChatItemWidget(compact_, parent) : GenericChatItemWidget(compact_, style_, parent)
, active{false} , active{false}
, settings{settings_} , settings{settings_}
, style{style_} , style{style_}

View File

@ -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. * @brief Show some text to the user.
* @param title Title of information window. * @param title Title of information window.
* @param msg Text in information window. * @param msg Text in information window.

View File

@ -31,7 +31,6 @@ public:
static GUI& getInstance(); static GUI& getInstance();
static QWidget* getMainWidget(); static QWidget* getMainWidget();
static void setWindowTitle(const QString& title); static void setWindowTitle(const QString& title);
static void reloadTheme();
static void showInfo(const QString& title, const QString& msg); static void showInfo(const QString& title, const QString& msg);
static void showWarning(const QString& title, const QString& msg); static void showWarning(const QString& title, const QString& msg);
static void showError(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 warning = true, bool yesno = true);
bool _askQuestion(const QString& title, const QString& msg, const QString& button1, bool _askQuestion(const QString& title, const QString& msg, const QString& button1,
const QString& button2, bool defaultAns = false, bool warning = true); const QString& button2, bool defaultAns = false, bool warning = true);
signals:
void themeReload();
}; };

View File

@ -96,7 +96,7 @@ SearchForm::SearchForm(Settings& settings_, Style& style_, QWidget* parent)
connect(searchSettingsForm, &SearchSettingsForm::updateSettings, this, &SearchForm::changedState); 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() void SearchForm::removeSearchPhrase()

View File

@ -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() void Style::applyTheme()
{ {
GUI::reloadTheme(); emit themeReload();
} }
QPixmap Style::scaleSvgImage(const QString& path, uint32_t width, uint32_t height) QPixmap Style::scaleSvgImage(const QString& path, uint32_t width, uint32_t height)

View File

@ -22,13 +22,15 @@
#include <QColor> #include <QColor>
#include <QFont> #include <QFont>
#include <QMap> #include <QMap>
#include <QObject>
class QString; class QString;
class QWidget; class QWidget;
class Settings; class Settings;
class Style class Style : public QObject
{ {
Q_OBJECT
public: public:
enum class ColorPalette enum class ColorPalette
{ {
@ -75,7 +77,7 @@ public:
static QString getThemeName(); static QString getThemeName();
static QFont getFont(Font font); static QFont getFont(Font font);
static void repolish(QWidget* w); static void repolish(QWidget* w);
static void applyTheme(); void applyTheme();
static QPixmap scaleSvgImage(const QString& path, uint32_t width, uint32_t height); static QPixmap scaleSvgImage(const QString& path, uint32_t width, uint32_t height);
Style() = default; Style() = default;
@ -90,7 +92,7 @@ public:
static QString getThemePath(Settings& settings); static QString getThemePath(Settings& settings);
signals: signals:
void themeChanged(); void themeReload();
private: private:
QMap<ColorPalette, QColor> palette; QMap<ColorPalette, QColor> palette;

View File

@ -20,12 +20,13 @@
#include "activatedialog.h" #include "activatedialog.h"
#include "src/widget/gui.h" #include "src/widget/gui.h"
#include "src/widget/style.h"
#include <QEvent> #include <QEvent>
ActivateDialog::ActivateDialog(QWidget* parent, Qt::WindowFlags f) ActivateDialog::ActivateDialog(Style& style, QWidget* parent, Qt::WindowFlags f)
: QDialog(parent, f) : QDialog(parent, f)
{ {
connect(&GUI::getInstance(), &GUI::themeReload, this, &ActivateDialog::reloadTheme); connect(&style, &Style::themeReload, this, &ActivateDialog::reloadTheme);
} }
bool ActivateDialog::event(QEvent* event) bool ActivateDialog::event(QEvent* event)

View File

@ -21,14 +21,16 @@
#include <QDialog> #include <QDialog>
class Style;
class ActivateDialog : public QDialog class ActivateDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) #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 #else
ActivateDialog(QWidget* parent = nullptr, Qt::WindowFlags f = nullptr); ActivateDialog(Style&, QWidget* parent = nullptr, Qt::WindowFlags f = nullptr);
#endif #endif
bool event(QEvent* event) override; bool event(QEvent* event) override;

View File

@ -498,7 +498,7 @@ void Widget::init()
connect(&settings, &Settings::groupchatPositionChanged, chatListWidget, connect(&settings, &Settings::groupchatPositionChanged, chatListWidget,
&FriendListWidget::onGroupchatPositionChanged); &FriendListWidget::onGroupchatPositionChanged);
connect(&GUI::getInstance(), &GUI::themeReload, this, &Widget::reloadTheme); connect(&style, &Style::themeReload, this, &Widget::reloadTheme);
reloadTheme(); reloadTheme();
updateIcons(); updateIcons();
@ -1898,7 +1898,7 @@ ContentLayout* Widget::createContentDialog(DialogType type) const
{ {
public: public:
explicit Dialog(DialogType type_, Settings& settings_, Core* core_, Style& style_) explicit Dialog(DialogType type_, Settings& settings_, Core* core_, Style& style_)
: ActivateDialog(nullptr, Qt::Window) : ActivateDialog(style_, nullptr, Qt::Window)
, type(type_) , type(type_)
, settings(settings_) , settings(settings_)
, core{core_} , core{core_}