From 3bf3128a4fa4fe53694789da07a9669d12020179 Mon Sep 17 00:00:00 2001 From: TriKriSta Date: Thu, 21 Nov 2019 14:25:24 +0200 Subject: [PATCH] fix(ui): implement and connect reloadTheme in leaf classes This allows leaf classes to update independently when the GUI has changed themes, without their parent having to call updateTheme() manually. Fix #5924 Fix #5592 --- CMakeLists.txt | 3 ++ src/chatlog/chatlog.cpp | 5 +++ src/chatlog/chatlog.h | 2 +- src/chatlog/content/filetransferwidget.cpp | 46 +++++++++++++--------- src/chatlog/content/filetransferwidget.h | 8 +++- src/widget/about/aboutfriendform.cpp | 9 ++++- src/widget/about/aboutfriendform.h | 7 +++- src/widget/chatformheader.cpp | 3 +- src/widget/chatformheader.h | 10 ++--- src/widget/contentdialog.cpp | 12 ++++-- src/widget/contentdialog.h | 1 + src/widget/contentlayout.cpp | 3 ++ src/widget/contentlayout.h | 4 +- src/widget/dialogstyle.h | 21 ++++++++++ src/widget/form/chatform.h | 2 +- src/widget/form/genericchatform.cpp | 8 +--- src/widget/form/genericchatform.h | 6 +-- src/widget/form/settings/aboutform.cpp | 5 +++ src/widget/form/settings/aboutform.h | 1 + src/widget/form/settings/genericsettings.h | 4 +- src/widget/framestyle.h | 21 ++++++++++ src/widget/genericchatitemwidget.cpp | 3 +- src/widget/genericchatitemwidget.h | 4 +- src/widget/genericchatroomwidget.h | 3 +- src/widget/gui.cpp | 11 +----- src/widget/gui.h | 4 +- src/widget/searchform.cpp | 2 +- src/widget/searchform.h | 6 +-- src/widget/tool/activatedialog.cpp | 2 +- src/widget/tool/activatedialog.h | 4 +- src/widget/widget.cpp | 30 ++++---------- src/widget/widget.h | 2 +- src/widget/widgetstyle.h | 21 ++++++++++ 33 files changed, 179 insertions(+), 94 deletions(-) create mode 100644 src/widget/dialogstyle.h create mode 100644 src/widget/framestyle.h create mode 100644 src/widget/widgetstyle.h diff --git a/CMakeLists.txt b/CMakeLists.txt index f807a9c8d..cf494edf8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -482,6 +482,9 @@ set(${PROJECT_NAME}_SOURCES src/widget/translator.h src/widget/widget.cpp src/widget/widget.h + src/widget/widgetstyle.h + src/widget/framestyle.h + src/widget/dialogstyle.h ) if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index 35da7f38b..e0c5e7637 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -22,6 +22,7 @@ #include "chatlinecontentproxy.h" #include "chatmessage.h" #include "content/filetransferwidget.h" +#include "src/widget/gui.h" #include "src/widget/translator.h" #include "src/widget/style.h" @@ -121,6 +122,9 @@ ChatLog::ChatLog(QWidget* parent) copySelectedText(true); }); + connect(&GUI::getInstance(), &GUI::themeReload, this, &ChatLog::reloadTheme); + + reloadTheme(); retranslateUi(); Translator::registerHandler(std::bind(&ChatLog::retranslateUi, this), this); } @@ -718,6 +722,7 @@ void ChatLog::fontChanged(const QFont& font) void ChatLog::reloadTheme() { + setStyleSheet(Style::getStylesheet("chatArea/chatArea.css")); setBackgroundBrush(QBrush(Style::getColor(Style::GroundBase), Qt::SolidPattern)); selectionRectColor = Style::getColor(Style::SelectText); selGraphItem->setBrush(QBrush(selectionRectColor)); diff --git a/src/chatlog/chatlog.h b/src/chatlog/chatlog.h index 30eb0a872..6d5b3bf49 100644 --- a/src/chatlog/chatlog.h +++ b/src/chatlog/chatlog.h @@ -56,7 +56,6 @@ public: void scrollToLine(ChatLine::Ptr line); void selectAll(); void fontChanged(const QFont& font); - void reloadTheme(); void removeFirsts(const int num); void removeLasts(const int num); void setScroll(const bool scroll); @@ -83,6 +82,7 @@ signals: public slots: void forceRelayout(); + void reloadTheme(); private slots: void onSelectionTimerTimeout(); diff --git a/src/chatlog/content/filetransferwidget.cpp b/src/chatlog/content/filetransferwidget.cpp index ef5599cba..436c74710 100644 --- a/src/chatlog/content/filetransferwidget.cpp +++ b/src/chatlog/content/filetransferwidget.cpp @@ -48,7 +48,7 @@ // downloaded to. FileTransferWidget::FileTransferWidget(QWidget* parent, CoreFile& _coreFile, ToxFile file) - : QWidget(parent) + : WidgetStyle(parent) , coreFile{_coreFile} , ui(new Ui::FileTransferWidget) , fileInfo(file) @@ -227,6 +227,11 @@ void FileTransferWidget::paintEvent(QPaintEvent*) } } +void FileTransferWidget::reloadTheme() +{ + updateBackgroundColor(lastStatus); +} + QString FileTransferWidget::getHumanReadableSize(qint64 size) { static const char* suffix[] = {"B", "KiB", "MiB", "GiB", "TiB"}; @@ -245,23 +250,7 @@ void FileTransferWidget::updateWidgetColor(ToxFile const& file) return; } - switch (file.status) { - case ToxFile::INITIALIZING: - case ToxFile::PAUSED: - case ToxFile::TRANSMITTING: - setBackgroundColor(Style::getColor(Style::TransferMiddle), false); - break; - case ToxFile::BROKEN: - case ToxFile::CANCELED: - setBackgroundColor(Style::getColor(Style::TransferBad), true); - break; - case ToxFile::FINISHED: - setBackgroundColor(Style::getColor(Style::TransferGood), true); - break; - default: - qCritical() << "Invalid file status"; - assert(false); - } + updateBackgroundColor(file.status); } void FileTransferWidget::updateWidgetText(ToxFile const& file) @@ -623,3 +612,24 @@ void FileTransferWidget::updateWidget(ToxFile const& file) update(); } } + +void FileTransferWidget::updateBackgroundColor(const ToxFile::FileStatus status) +{ + switch (status) { + case ToxFile::INITIALIZING: + case ToxFile::PAUSED: + case ToxFile::TRANSMITTING: + setBackgroundColor(Style::getColor(Style::TransferMiddle), false); + break; + case ToxFile::BROKEN: + case ToxFile::CANCELED: + setBackgroundColor(Style::getColor(Style::TransferBad), true); + break; + case ToxFile::FINISHED: + setBackgroundColor(Style::getColor(Style::TransferGood), true); + break; + default: + qCritical() << "Invalid file status"; + assert(false); + } +} diff --git a/src/chatlog/content/filetransferwidget.h b/src/chatlog/content/filetransferwidget.h index 087969d3a..c41f13ff2 100644 --- a/src/chatlog/content/filetransferwidget.h +++ b/src/chatlog/content/filetransferwidget.h @@ -20,11 +20,11 @@ #pragma once #include -#include #include "src/chatlog/chatlinecontent.h" #include "src/chatlog/toxfileprogress.h" #include "src/core/toxfile.h" +#include "src/widget/widgetstyle.h" class CoreFile; @@ -35,7 +35,7 @@ class FileTransferWidget; class QVariantAnimation; class QPushButton; -class FileTransferWidget : public QWidget +class FileTransferWidget : public WidgetStyle { Q_OBJECT @@ -64,6 +64,9 @@ protected: void paintEvent(QPaintEvent*) final; +public slots: + void reloadTheme() override; + private slots: void onLeftButtonClicked(); void onRightButtonClicked(); @@ -76,6 +79,7 @@ private: static bool tryRemoveFile(const QString &filepath); void updateWidget(ToxFile const& file); + void updateBackgroundColor(const ToxFile::FileStatus status); private: CoreFile& coreFile; diff --git a/src/widget/about/aboutfriendform.cpp b/src/widget/about/aboutfriendform.cpp index 7390291a5..a00543cdc 100644 --- a/src/widget/about/aboutfriendform.cpp +++ b/src/widget/about/aboutfriendform.cpp @@ -27,7 +27,7 @@ #include AboutFriendForm::AboutFriendForm(std::unique_ptr _about, QWidget* parent) - : QDialog(parent) + : DialogStyle(parent) , ui(new Ui::AboutFriendForm) , about{std::move(_about)} { @@ -67,7 +67,7 @@ AboutFriendForm::AboutFriendForm(std::unique_ptr _about, QWidget* ui->statusMessage->setText(about->getStatusMessage()); ui->avatar->setPixmap(about->getAvatar()); - setStyleSheet(Style::getStylesheet("window/general.css")); + reloadTheme(); } static QString getAutoAcceptDir(const QString& dir) @@ -90,6 +90,11 @@ void AboutFriendForm::onAutoAcceptDirClicked() about->setAutoAcceptDir(dir); } +void AboutFriendForm::reloadTheme() +{ + setStyleSheet(Style::getStylesheet("window/general.css")); +} + void AboutFriendForm::onAutoAcceptDirChanged(const QString& path) { const bool enabled = !path.isNull(); diff --git a/src/widget/about/aboutfriendform.h b/src/widget/about/aboutfriendform.h index 66acdf0e8..7148bdc76 100644 --- a/src/widget/about/aboutfriendform.h +++ b/src/widget/about/aboutfriendform.h @@ -20,8 +20,8 @@ #pragma once #include "src/model/about/iaboutfriend.h" +#include "src/widget/dialogstyle.h" -#include #include #include @@ -30,7 +30,7 @@ namespace Ui { class AboutFriendForm; } -class AboutFriendForm : public QDialog +class AboutFriendForm : public DialogStyle { Q_OBJECT @@ -45,6 +45,9 @@ private: signals: void histroyRemoved(); +public slots: + void reloadTheme() override; + private slots: void onAutoAcceptDirChanged(const QString& path); void onAcceptedClicked(); diff --git a/src/widget/chatformheader.cpp b/src/widget/chatformheader.cpp index 97f91b720..4a108efa4 100644 --- a/src/widget/chatformheader.cpp +++ b/src/widget/chatformheader.cpp @@ -105,7 +105,7 @@ void setStateName(QAbstractButton* btn, State state) } ChatFormHeader::ChatFormHeader(QWidget* parent) - : QWidget(parent) + : WidgetStyle(parent) , mode{Mode::AV} , callState{CallButtonState::Disabled} , videoState{CallButtonState::Disabled} @@ -283,6 +283,7 @@ QSize ChatFormHeader::getAvatarSize() const void ChatFormHeader::reloadTheme() { + setStyleSheet(Style::getStylesheet("chatArea/chatHead.css")); callButton->setStyleSheet(Style::getStylesheet(STYLE_PATH)); videoButton->setStyleSheet(Style::getStylesheet(STYLE_PATH)); volButton->setStyleSheet(Style::getStylesheet(STYLE_PATH)); diff --git a/src/widget/chatformheader.h b/src/widget/chatformheader.h index fa37f3f1a..31db65451 100644 --- a/src/widget/chatformheader.h +++ b/src/widget/chatformheader.h @@ -19,9 +19,8 @@ #pragma once -#include - #include +#include "src/widget/widgetstyle.h" class MaskablePixmapWidget; class QVBoxLayout; @@ -30,7 +29,7 @@ class QPushButton; class QToolButton; class CallConfirmWidget; -class ChatFormHeader : public QWidget +class ChatFormHeader : public WidgetStyle { Q_OBJECT public: @@ -71,13 +70,14 @@ public: void setAvatar(const QPixmap& img); QSize getAvatarSize() const; - void reloadTheme(); - // TODO: Remove void addWidget(QWidget* widget, int stretch = 0, Qt::Alignment alignment = Qt::Alignment()); void addLayout(QLayout* layout); void addStretch(); +public slots: + void reloadTheme() override; + signals: void callTriggered(); void videoCallTriggered(); diff --git a/src/widget/contentdialog.cpp b/src/widget/contentdialog.cpp index 2a4bffc42..2fdf5b64b 100644 --- a/src/widget/contentdialog.cpp +++ b/src/widget/contentdialog.cpp @@ -59,8 +59,7 @@ ContentDialog::ContentDialog(const Core &core, QWidget* parent) , videoSurfaceSize(QSize()) , videoCount(0) { - const Settings& s = Settings::getInstance(); - setStyleSheet(Style::getStylesheet("contentDialog/contentDialog.css")); + const Settings& s = Settings::getInstance(); friendLayout->setMargin(0); friendLayout->setSpacing(0); @@ -88,7 +87,6 @@ ContentDialog::ContentDialog(const Core &core, QWidget* parent) friendScroll->setFrameStyle(QFrame::NoFrame); friendScroll->setLayoutDirection(Qt::RightToLeft); friendScroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - friendScroll->setStyleSheet(Style::getStylesheet("friendList/friendList.css")); friendScroll->setWidgetResizable(true); friendScroll->setWidget(friendWidget); @@ -128,6 +126,8 @@ ContentDialog::ContentDialog(const Core &core, QWidget* parent) setAcceptDrops(true); + reloadTheme(); + new QShortcut(Qt::CTRL + Qt::Key_Q, this, SLOT(close())); new QShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_Tab, this, SLOT(previousContact())); new QShortcut(Qt::CTRL + Qt::Key_Tab, this, SLOT(nextContact())); @@ -435,6 +435,12 @@ void ContentDialog::setUsername(const QString& newName) updateTitleAndStatusIcon(); } +void ContentDialog::reloadTheme() +{ + setStyleSheet(Style::getStylesheet("contentDialog/contentDialog.css")); + splitter->widget(0)->setStyleSheet(Style::getStylesheet("friendList/friendList.css")); +} + bool ContentDialog::event(QEvent* event) { switch (event->type()) { diff --git a/src/widget/contentdialog.h b/src/widget/contentdialog.h index 519f85f6a..b279dfd0d 100644 --- a/src/widget/contentdialog.h +++ b/src/widget/contentdialog.h @@ -90,6 +90,7 @@ public slots: void previousContact(); void nextContact(); void setUsername(const QString& newName); + void reloadTheme() override; protected: bool event(QEvent* event) final; diff --git a/src/widget/contentlayout.cpp b/src/widget/contentlayout.cpp index 4fa772b2e..d72c792f1 100644 --- a/src/widget/contentlayout.cpp +++ b/src/widget/contentlayout.cpp @@ -20,6 +20,7 @@ #include "contentlayout.h" #include "style.h" #include "src/persistence/settings.h" +#include "src/widget/gui.h" #include #include @@ -118,6 +119,8 @@ void ContentLayout::init() mainContent->setStyle(QStyleFactory::create(Settings::getInstance().getStyle())); } + connect(&GUI::getInstance(), &GUI::themeReload, this, &ContentLayout::reloadTheme); + reloadTheme(); mainHLineLayout.addSpacing(4); diff --git a/src/widget/contentlayout.h b/src/widget/contentlayout.h index 5200dfde7..fd315a45e 100644 --- a/src/widget/contentlayout.h +++ b/src/widget/contentlayout.h @@ -29,7 +29,6 @@ public: explicit ContentLayout(QWidget* parent); ~ContentLayout(); - void reloadTheme(); void clear(); QFrame mainHLine; @@ -37,6 +36,9 @@ public: QWidget* mainContent; QWidget* mainHead; +public slots: + void reloadTheme(); + private: void init(); }; diff --git a/src/widget/dialogstyle.h b/src/widget/dialogstyle.h new file mode 100644 index 000000000..c737e33b4 --- /dev/null +++ b/src/widget/dialogstyle.h @@ -0,0 +1,21 @@ +#ifndef DIALOGSTYLE_H +#define DIALOGSTYLE_H + +#include +#include "src/widget/gui.h" + +class DialogStyle : public QDialog { + Q_OBJECT + +public: + DialogStyle(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()) : QDialog(parent, f) + { + connect(&GUI::getInstance(), &GUI::themeReload, this, &DialogStyle::reloadTheme); + } + virtual ~DialogStyle() {} + +public slots: + virtual void reloadTheme() {} +}; + +#endif //DIALOGSTYLE_H diff --git a/src/widget/form/chatform.h b/src/widget/form/chatform.h index 045a82984..318980393 100644 --- a/src/widget/form/chatform.h +++ b/src/widget/form/chatform.h @@ -53,7 +53,6 @@ public: void setFriendTyping(bool isTyping); void show(ContentLayout* contentLayout) final; - void reloadTheme() final; static const QString ACTION_PREFIX; @@ -76,6 +75,7 @@ public slots: void clearChatArea(); void onShowMessagesClicked(); void onSplitterMoved(int pos, int index); + void reloadTheme() final; private slots: void updateFriendActivityForFile(const ToxFile& file); diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index 078706e1c..68ca69f6d 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -210,7 +210,7 @@ ChatLogIdx firstItemAfterDate(QDate date, const IChatLog& chatLog) GenericChatForm::GenericChatForm(const Core& _core, const Contact* contact, IChatLog& chatLog, IMessageDispatcher& messageDispatcher, QWidget* parent) - : QWidget(parent, Qt::Window) + : WidgetStyle(parent, Qt::Window) , core{_core} , audioInputFlag(false) , audioOutputFlag(false) @@ -414,12 +414,6 @@ void GenericChatForm::reloadTheme() msgEdit->setStyleSheet(Style::getStylesheet("msgEdit/msgEdit.css") + fontToCss(s.getChatMessageFont(), "QTextEdit")); - chatWidget->setStyleSheet(Style::getStylesheet("chatArea/chatArea.css")); - headWidget->setStyleSheet(Style::getStylesheet("chatArea/chatHead.css")); - chatWidget->reloadTheme(); - headWidget->reloadTheme(); - searchForm->reloadTheme(); - emoteButton->setStyleSheet(Style::getStylesheet(STYLE_PATH)); fileButton->setStyleSheet(Style::getStylesheet(STYLE_PATH)); screenshotButton->setStyleSheet(Style::getStylesheet(STYLE_PATH)); diff --git a/src/widget/form/genericchatform.h b/src/widget/form/genericchatform.h index 8173f896a..4eb0160f9 100644 --- a/src/widget/form/genericchatform.h +++ b/src/widget/form/genericchatform.h @@ -24,9 +24,9 @@ #include "src/model/ichatlog.h" #include "src/widget/form/loadhistorydialog.h" #include "src/widget/searchtypes.h" +#include "src/widget/widgetstyle.h" #include -#include /** * Spacing in px inserted when the author of the last message changes @@ -65,7 +65,7 @@ class SpellCheckDecorator; } #endif -class GenericChatForm : public QWidget +class GenericChatForm : public WidgetStyle { Q_OBJECT public: @@ -75,7 +75,6 @@ public: void setName(const QString& newName); virtual void show(ContentLayout* contentLayout); - virtual void reloadTheme(); void addSystemInfoMessage(const QString& message, ChatMessage::SystemMessageType type, const QDateTime& datetime); @@ -91,6 +90,7 @@ public slots: void focusInput(); void onChatMessageFontChanged(const QFont& font); void setColorizedNames(bool enable); + void reloadTheme() override; protected slots: void onChatContextMenuRequested(QPoint pos); diff --git a/src/widget/form/settings/aboutform.cpp b/src/widget/form/settings/aboutform.cpp index f82886447..65d4c056d 100644 --- a/src/widget/form/settings/aboutform.cpp +++ b/src/widget/form/settings/aboutform.cpp @@ -182,6 +182,11 @@ void AboutForm::onUpdateCheckFailed() bodyUI->updateStack->setCurrentIndex(static_cast(updateIndex::failed)); } +void AboutForm::reloadTheme() +{ + replaceVersions(); +} + /** * @brief Creates hyperlink with specific style. * @param path The URL of the page the link goes to. diff --git a/src/widget/form/settings/aboutform.h b/src/widget/form/settings/aboutform.h index b8ce6a7ca..9a884cb34 100644 --- a/src/widget/form/settings/aboutform.h +++ b/src/widget/form/settings/aboutform.h @@ -47,6 +47,7 @@ public slots: void onUpdateAvailable(QString latestVersion, QUrl link); void onUpToDate(); void onUpdateCheckFailed(); + void reloadTheme() override; private: void retranslateUi(); diff --git a/src/widget/form/settings/genericsettings.h b/src/widget/form/settings/genericsettings.h index ca9d15163..ef1467290 100644 --- a/src/widget/form/settings/genericsettings.h +++ b/src/widget/form/settings/genericsettings.h @@ -19,9 +19,9 @@ #pragma once -#include +#include "src/widget/widgetstyle.h" -class GenericForm : public QWidget +class GenericForm : public WidgetStyle { Q_OBJECT public: diff --git a/src/widget/framestyle.h b/src/widget/framestyle.h new file mode 100644 index 000000000..7261a4c9a --- /dev/null +++ b/src/widget/framestyle.h @@ -0,0 +1,21 @@ +#ifndef FRAMESTYLE_H +#define FRAMESTYLE_H + +#include +#include "src/widget/gui.h" + +class FrameStyle : public QFrame { + Q_OBJECT + +public: + FrameStyle(QWidget* parent = nullptr) : QFrame(parent) + { + connect(&GUI::getInstance(), &GUI::themeReload, this, &FrameStyle::reloadTheme); + } + virtual ~FrameStyle() {} + +public slots: + virtual void reloadTheme() {} +}; + +#endif //FRAMESTYLE_H diff --git a/src/widget/genericchatitemwidget.cpp b/src/widget/genericchatitemwidget.cpp index d76826b24..8e6262437 100644 --- a/src/widget/genericchatitemwidget.cpp +++ b/src/widget/genericchatitemwidget.cpp @@ -19,12 +19,11 @@ #include "genericchatitemwidget.h" #include "src/persistence/settings.h" -#include "src/widget/style.h" #include "src/widget/tool/croppinglabel.h" #include GenericChatItemWidget::GenericChatItemWidget(bool compact, QWidget* parent) - : QFrame(parent) + : FrameStyle(parent) , compact(false) { setProperty("compact", compact); diff --git a/src/widget/genericchatitemwidget.h b/src/widget/genericchatitemwidget.h index b5ec91709..2adc2dbed 100644 --- a/src/widget/genericchatitemwidget.h +++ b/src/widget/genericchatitemwidget.h @@ -19,12 +19,12 @@ #pragma once -#include #include +#include "src/widget/framestyle.h" class CroppingLabel; -class GenericChatItemWidget : public QFrame +class GenericChatItemWidget : public FrameStyle { Q_OBJECT public: diff --git a/src/widget/genericchatroomwidget.h b/src/widget/genericchatroomwidget.h index 81924b260..42a4c38bf 100644 --- a/src/widget/genericchatroomwidget.h +++ b/src/widget/genericchatroomwidget.h @@ -60,10 +60,9 @@ public slots: QString getStatusMsg() const; QString getTitle() const; - void reloadTheme(); - void activate(); void compactChange(bool compact); + void reloadTheme() override; signals: void chatroomWidgetClicked(GenericChatroomWidget* widget); diff --git a/src/widget/gui.cpp b/src/widget/gui.cpp index cf19aa50a..708cf5a1e 100644 --- a/src/widget/gui.cpp +++ b/src/widget/gui.cpp @@ -98,9 +98,9 @@ void GUI::setWindowTitle(const QString& title) void GUI::reloadTheme() { if (QThread::currentThread() == qApp->thread()) { - getInstance()._reloadTheme(); + getInstance().themeReload(); } else { - QMetaObject::invokeMethod(&getInstance(), "_reloadTheme", Qt::BlockingQueuedConnection); + QMetaObject::invokeMethod(&getInstance(), "themeReload", Qt::BlockingQueuedConnection); } } @@ -224,13 +224,6 @@ void GUI::_setWindowTitle(const QString& title) w->setWindowTitle("qTox - " + title); } -void GUI::_reloadTheme() -{ - Widget* w = Nexus::getDesktopGUI(); - if (w) - w->reloadTheme(); -} - void GUI::_showInfo(const QString& title, const QString& msg) { QMessageBox messageBox(QMessageBox::Information, title, msg, QMessageBox::Ok, getMainWidget()); diff --git a/src/widget/gui.h b/src/widget/gui.h index 929016e6e..a6ce6ee35 100644 --- a/src/widget/gui.h +++ b/src/widget/gui.h @@ -50,7 +50,6 @@ private slots: // Private implementation, those must be called from the GUI thread void _setEnabled(bool state); void _setWindowTitle(const QString& title); - void _reloadTheme(); void _showInfo(const QString& title, const QString& msg); void _showWarning(const QString& title, const QString& msg); void _showError(const QString& title, const QString& msg); @@ -58,4 +57,7 @@ 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 e23fd63fe..5c91b6387 100644 --- a/src/widget/searchform.cpp +++ b/src/widget/searchform.cpp @@ -35,7 +35,7 @@ static std::array STATE_NAME = { QStringLiteral("red"), }; -SearchForm::SearchForm(QWidget* parent) : QWidget(parent) +SearchForm::SearchForm(QWidget* parent) : WidgetStyle(parent) { QVBoxLayout* layout = new QVBoxLayout(); QHBoxLayout* layoutNavigation = new QHBoxLayout(); diff --git a/src/widget/searchform.h b/src/widget/searchform.h index cd13bea09..cf01de2dc 100644 --- a/src/widget/searchform.h +++ b/src/widget/searchform.h @@ -19,8 +19,8 @@ #pragma once -#include #include +#include "src/widget/widgetstyle.h" #include "searchtypes.h" class QPushButton; @@ -28,7 +28,7 @@ class QLabel; class LineEdit; class SearchSettingsForm; -class SearchForm final : public QWidget +class SearchForm final : public WidgetStyle { Q_OBJECT public: @@ -44,7 +44,6 @@ public: ParameterSearch getParameterSearch(); void setFocusEditor(); void insertEditor(const QString &text); - void reloadTheme(); protected: void showEvent(QShowEvent* event) final; @@ -84,6 +83,7 @@ private slots: public slots: void showMessageNotFound(SearchDirection direction); + void reloadTheme() override; signals: void searchInBegin(const QString& phrase, const ParameterSearch& parameter); diff --git a/src/widget/tool/activatedialog.cpp b/src/widget/tool/activatedialog.cpp index 433991f49..5c347825a 100644 --- a/src/widget/tool/activatedialog.cpp +++ b/src/widget/tool/activatedialog.cpp @@ -22,7 +22,7 @@ #include ActivateDialog::ActivateDialog(QWidget* parent, Qt::WindowFlags f) - : QDialog(parent, f) + : DialogStyle(parent, f) { } diff --git a/src/widget/tool/activatedialog.h b/src/widget/tool/activatedialog.h index 7aacc9355..29e87b99e 100644 --- a/src/widget/tool/activatedialog.h +++ b/src/widget/tool/activatedialog.h @@ -19,9 +19,9 @@ #pragma once -#include +#include "src/widget/dialogstyle.h" -class ActivateDialog : public QDialog +class ActivateDialog : public DialogStyle { Q_OBJECT public: diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 673b10092..24402436a 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -463,6 +463,8 @@ void Widget::init() connect(&settings, &Settings::groupchatPositionChanged, contactListWidget, &FriendListWidget::onGroupchatPositionChanged); + connect(&GUI::getInstance(), &GUI::themeReload, this, &Widget::reloadTheme); + reloadTheme(); updateIcons(); retranslateUi(); @@ -1825,7 +1827,7 @@ ContentLayout* Widget::createContentDialog(DialogType type) const Translator::registerHandler(std::bind(&Dialog::retranslateUi, this), this); retranslateUi(); setWindowIcon(QIcon(":/img/icons/qtox.svg")); - setStyleSheet(Style::getStylesheet("window/general.css")); + reloadTheme(); connect(core, &Core::usernameSet, this, &Dialog::retranslateUi); } @@ -1842,6 +1844,11 @@ ContentLayout* Widget::createContentDialog(DialogType type) const setWindowTitle(core->getUsername() + QStringLiteral(" - ") + Widget::fromDialogType(type)); } + void reloadTheme() final + { + setStyleSheet(Style::getStylesheet("window/general.css")); + } + protected: void resizeEvent(QResizeEvent* event) override { @@ -2404,27 +2411,6 @@ void Widget::reloadTheme() contactListWidget->reDraw(); profilePicture->setStyleSheet(Style::getStylesheet("window/profile.css")); - - if (contentLayout != nullptr) { - contentLayout->reloadTheme(); - } - - for (Friend* f : FriendList::getAllFriends()) { - friendWidgets[f->getPublicKey()]->reloadTheme(); - } - - for (Group* g : GroupList::getAllGroups()) { - groupWidgets[g->getPersistentId()]->reloadTheme(); - } - - - for (auto f : FriendList::getAllFriends()) { - chatForms[f->getPublicKey()]->reloadTheme(); - } - - for (auto g : GroupList::getAllGroups()) { - groupChatForms[g->getPersistentId()]->reloadTheme(); - } } void Widget::nextContact() diff --git a/src/widget/widget.h b/src/widget/widget.h index 482889a3b..ed6184b35 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -142,7 +142,6 @@ public: void clearAllReceipts(); - void reloadTheme(); static inline QIcon prepareIcon(QString path, int w = 0, int h = 0); bool groupsVisible() const; @@ -150,6 +149,7 @@ public: void resetIcon(); public slots: + void reloadTheme(); void onShowSettings(); void onSeparateWindowClicked(bool separate); void onSeparateWindowChanged(bool separate, bool clicked); diff --git a/src/widget/widgetstyle.h b/src/widget/widgetstyle.h new file mode 100644 index 000000000..ff468b163 --- /dev/null +++ b/src/widget/widgetstyle.h @@ -0,0 +1,21 @@ +#ifndef WIDGETSTYLE_H +#define WIDGETSTYLE_H + +#include +#include "src/widget/gui.h" + +class WidgetStyle : public QWidget { + Q_OBJECT + +public: + WidgetStyle(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()) : QWidget(parent, f) + { + connect(&GUI::getInstance(), &GUI::themeReload, this, &WidgetStyle::reloadTheme); + } + virtual ~WidgetStyle() {} + +public slots: + virtual void reloadTheme() {} +}; + +#endif //WIDGETSTYLE_H