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);
});
connect(&GUI::getInstance(), &GUI::themeReload, this, &ChatWidget::reloadTheme);
connect(&style, &Style::themeReload, this, &ChatWidget::reloadTheme);
reloadTheme();
retranslateUi();

View File

@ -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;

View File

@ -80,7 +80,7 @@ AboutFriendForm::AboutFriendForm(std::unique_ptr<IAboutFriend> 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();
}

View File

@ -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_}
{

View File

@ -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;

View File

@ -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)

View File

@ -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();

View File

@ -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();

View File

@ -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_)

View File

@ -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_}
{

View File

@ -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
{

View File

@ -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_}

View File

@ -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
{

View File

@ -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_}
{

View File

@ -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
{

View File

@ -19,6 +19,7 @@
#include "genericsettings.h"
#include "src/widget/gui.h"
#include "src/widget/style.h"
#include <QCheckBox>
#include <QComboBox>
@ -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()

View File

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

View File

@ -39,8 +39,8 @@
#include <chrono>
#include <random>
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_}

View File

@ -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
{

View File

@ -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();
}
/**

View File

@ -58,16 +58,16 @@ SettingsWidget::SettingsWidget(UpdateCheck* updateCheck, IAudioControl& audio,
settingsWidgets->setTabPosition(QTabWidget::North);
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);
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);
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<AdvancedForm> expfrm(new AdvancedForm(settings));
std::unique_ptr<AdvancedForm> expfrm(new AdvancedForm(settings, style));
std::unique_ptr<AboutForm> abtfrm(new AboutForm(updateCheck, style));
#if UPDATE_CHECK_ENABLED

View File

@ -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 <QVariant>
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

View File

@ -23,6 +23,7 @@
#include <QLabel>
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_);

View File

@ -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_}

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.
* @param title Title of information window.
* @param msg Text in information window.

View File

@ -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();
};

View File

@ -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()

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

View File

@ -22,13 +22,15 @@
#include <QColor>
#include <QFont>
#include <QMap>
#include <QObject>
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<ColorPalette, QColor> palette;

View File

@ -20,12 +20,13 @@
#include "activatedialog.h"
#include "src/widget/gui.h"
#include "src/widget/style.h"
#include <QEvent>
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)

View File

@ -21,14 +21,16 @@
#include <QDialog>
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;

View File

@ -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_}