Browse Source

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.
reviewable/pr6566/r3
Anthony Bilinski 4 years ago
parent
commit
cebc6e0fbf
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
  1. 2
      src/chatlog/chatwidget.cpp
  2. 2
      src/chatlog/content/filetransferwidget.cpp
  3. 2
      src/widget/about/aboutfriendform.cpp
  4. 2
      src/widget/categorywidget.cpp
  5. 2
      src/widget/chatformheader.cpp
  6. 2
      src/widget/contentdialog.cpp
  7. 2
      src/widget/contentlayout.cpp
  8. 2
      src/widget/form/genericchatform.cpp
  9. 2
      src/widget/form/settings/aboutform.cpp
  10. 4
      src/widget/form/settings/advancedform.cpp
  11. 3
      src/widget/form/settings/advancedform.h
  12. 5
      src/widget/form/settings/avform.cpp
  13. 3
      src/widget/form/settings/avform.h
  14. 4
      src/widget/form/settings/generalform.cpp
  15. 3
      src/widget/form/settings/generalform.h
  16. 5
      src/widget/form/settings/genericsettings.cpp
  17. 4
      src/widget/form/settings/genericsettings.h
  18. 4
      src/widget/form/settings/privacyform.cpp
  19. 3
      src/widget/form/settings/privacyform.h
  20. 4
      src/widget/form/settings/userinterfaceform.cpp
  21. 8
      src/widget/form/settingswidget.cpp
  22. 6
      src/widget/genericchatitemwidget.cpp
  23. 3
      src/widget/genericchatitemwidget.h
  24. 2
      src/widget/genericchatroomwidget.cpp
  25. 17
      src/widget/gui.cpp
  26. 4
      src/widget/gui.h
  27. 2
      src/widget/searchform.cpp
  28. 7
      src/widget/style.cpp
  29. 8
      src/widget/style.h
  30. 5
      src/widget/tool/activatedialog.cpp
  31. 6
      src/widget/tool/activatedialog.h
  32. 4
      src/widget/widget.cpp

2
src/chatlog/chatwidget.cpp

@ -292,7 +292,7 @@ ChatWidget::ChatWidget(IChatLog& chatLog_, const Core& core_, DocumentCache& doc @@ -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();

2
src/chatlog/content/filetransferwidget.cpp

@ -94,7 +94,7 @@ FileTransferWidget::FileTransferWidget(QWidget* parent, CoreFile& _coreFile, @@ -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;

2
src/widget/about/aboutfriendform.cpp

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

2
src/widget/categorywidget.cpp

@ -40,7 +40,7 @@ void CategoryWidget::emitChatroomWidget(QLayout* layout, int index) @@ -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_}
{

2
src/widget/chatformheader.cpp

@ -170,7 +170,7 @@ ChatFormHeader::ChatFormHeader(Settings& settings_, Style& style_, QWidget* pare @@ -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;

2
src/widget/contentdialog.cpp

@ -55,7 +55,7 @@ const QSize defaultSize(720, 400); @@ -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)

2
src/widget/contentlayout.cpp

@ -123,7 +123,7 @@ void ContentLayout::init() @@ -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();

2
src/widget/form/genericchatform.cpp

@ -263,7 +263,7 @@ GenericChatForm::GenericChatForm(const Core& core_, const Chat* chat, IChatLog& @@ -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();

2
src/widget/form/settings/aboutform.cpp

@ -55,7 +55,7 @@ enum class updateIndex @@ -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_)

4
src/widget/form/settings/advancedform.cpp

@ -41,8 +41,8 @@ @@ -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_}
{

3
src/widget/form/settings/advancedform.h

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

5
src/widget/form/settings/avform.cpp

@ -45,8 +45,9 @@ @@ -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_}

3
src/widget/form/settings/avform.h

@ -37,12 +37,13 @@ class CameraSource; @@ -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
{

4
src/widget/form/settings/generalform.cpp

@ -96,8 +96,8 @@ QStringList locales = { @@ -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_}
{

3
src/widget/form/settings/generalform.h

@ -27,12 +27,13 @@ class GeneralSettings; @@ -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
{

5
src/widget/form/settings/genericsettings.cpp

@ -19,6 +19,7 @@ @@ -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 @@ @@ -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()

4
src/widget/form/settings/genericsettings.h

@ -21,11 +21,13 @@ @@ -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()
{
}

4
src/widget/form/settings/privacyform.cpp

@ -39,8 +39,8 @@ @@ -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_}

3
src/widget/form/settings/privacyform.h

@ -23,6 +23,7 @@ @@ -23,6 +23,7 @@
class Core;
class Settings;
class Style;
namespace Ui {
class PrivacySettings;
@ -32,7 +33,7 @@ class PrivacyForm : public GenericForm @@ -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
{

4
src/widget/form/settings/userinterfaceform.cpp

@ -56,7 +56,7 @@ @@ -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) @@ -342,7 +342,7 @@ void UserInterfaceForm::on_themeColorCBox_currentIndexChanged(int index)
{
settings.setThemeColor(index);
style.setThemeColor(settings, index);
Style::applyTheme();
style.applyTheme();
}
/**

8
src/widget/form/settingswidget.cpp

@ -58,16 +58,16 @@ SettingsWidget::SettingsWidget(UpdateCheck* updateCheck, IAudioControl& audio, @@ -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

6
src/widget/genericchatitemwidget.cpp

@ -21,9 +21,11 @@ @@ -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) @@ -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

3
src/widget/genericchatitemwidget.h

@ -23,6 +23,7 @@ @@ -23,6 +23,7 @@
#include <QLabel>
class CroppingLabel;
class Style;
class GenericChatItemWidget : public QFrame
{
@ -35,7 +36,7 @@ public: @@ -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_);

2
src/widget/genericchatroomwidget.cpp

@ -27,7 +27,7 @@ @@ -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_}

17
src/widget/gui.cpp

@ -77,22 +77,7 @@ void GUI::setWindowTitle(const QString& title) @@ -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.

4
src/widget/gui.h

@ -31,7 +31,6 @@ public: @@ -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: @@ -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();
};

2
src/widget/searchform.cpp

@ -96,7 +96,7 @@ SearchForm::SearchForm(Settings& settings_, Style& style_, QWidget* parent) @@ -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()

7
src/widget/style.cpp

@ -366,11 +366,14 @@ void Style::setThemeColor(const QColor& color) @@ -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)

8
src/widget/style.h

@ -22,13 +22,15 @@ @@ -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: @@ -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: @@ -90,7 +92,7 @@ public:
static QString getThemePath(Settings& settings);
signals:
void themeChanged();
void themeReload();
private:
QMap<ColorPalette, QColor> palette;

5
src/widget/tool/activatedialog.cpp

@ -20,12 +20,13 @@ @@ -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)

6
src/widget/tool/activatedialog.h

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

4
src/widget/widget.cpp

@ -498,7 +498,7 @@ void Widget::init() @@ -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 @@ -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_}

Loading…
Cancel
Save