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

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
This commit is contained in:
TriKriSta 2019-11-21 14:25:24 +02:00 committed by Anthony Bilinski
parent 0f5ba08fd2
commit 3bf3128a4f
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
33 changed files with 179 additions and 94 deletions

View File

@ -482,6 +482,9 @@ set(${PROJECT_NAME}_SOURCES
src/widget/translator.h src/widget/translator.h
src/widget/widget.cpp src/widget/widget.cpp
src/widget/widget.h src/widget/widget.h
src/widget/widgetstyle.h
src/widget/framestyle.h
src/widget/dialogstyle.h
) )
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")

View File

@ -22,6 +22,7 @@
#include "chatlinecontentproxy.h" #include "chatlinecontentproxy.h"
#include "chatmessage.h" #include "chatmessage.h"
#include "content/filetransferwidget.h" #include "content/filetransferwidget.h"
#include "src/widget/gui.h"
#include "src/widget/translator.h" #include "src/widget/translator.h"
#include "src/widget/style.h" #include "src/widget/style.h"
@ -121,6 +122,9 @@ ChatLog::ChatLog(QWidget* parent)
copySelectedText(true); copySelectedText(true);
}); });
connect(&GUI::getInstance(), &GUI::themeReload, this, &ChatLog::reloadTheme);
reloadTheme();
retranslateUi(); retranslateUi();
Translator::registerHandler(std::bind(&ChatLog::retranslateUi, this), this); Translator::registerHandler(std::bind(&ChatLog::retranslateUi, this), this);
} }
@ -718,6 +722,7 @@ void ChatLog::fontChanged(const QFont& font)
void ChatLog::reloadTheme() void ChatLog::reloadTheme()
{ {
setStyleSheet(Style::getStylesheet("chatArea/chatArea.css"));
setBackgroundBrush(QBrush(Style::getColor(Style::GroundBase), Qt::SolidPattern)); setBackgroundBrush(QBrush(Style::getColor(Style::GroundBase), Qt::SolidPattern));
selectionRectColor = Style::getColor(Style::SelectText); selectionRectColor = Style::getColor(Style::SelectText);
selGraphItem->setBrush(QBrush(selectionRectColor)); selGraphItem->setBrush(QBrush(selectionRectColor));

View File

@ -56,7 +56,6 @@ public:
void scrollToLine(ChatLine::Ptr line); void scrollToLine(ChatLine::Ptr line);
void selectAll(); void selectAll();
void fontChanged(const QFont& font); void fontChanged(const QFont& font);
void reloadTheme();
void removeFirsts(const int num); void removeFirsts(const int num);
void removeLasts(const int num); void removeLasts(const int num);
void setScroll(const bool scroll); void setScroll(const bool scroll);
@ -83,6 +82,7 @@ signals:
public slots: public slots:
void forceRelayout(); void forceRelayout();
void reloadTheme();
private slots: private slots:
void onSelectionTimerTimeout(); void onSelectionTimerTimeout();

View File

@ -48,7 +48,7 @@
// downloaded to. // downloaded to.
FileTransferWidget::FileTransferWidget(QWidget* parent, CoreFile& _coreFile, ToxFile file) FileTransferWidget::FileTransferWidget(QWidget* parent, CoreFile& _coreFile, ToxFile file)
: QWidget(parent) : WidgetStyle(parent)
, coreFile{_coreFile} , coreFile{_coreFile}
, ui(new Ui::FileTransferWidget) , ui(new Ui::FileTransferWidget)
, fileInfo(file) , fileInfo(file)
@ -227,6 +227,11 @@ void FileTransferWidget::paintEvent(QPaintEvent*)
} }
} }
void FileTransferWidget::reloadTheme()
{
updateBackgroundColor(lastStatus);
}
QString FileTransferWidget::getHumanReadableSize(qint64 size) QString FileTransferWidget::getHumanReadableSize(qint64 size)
{ {
static const char* suffix[] = {"B", "KiB", "MiB", "GiB", "TiB"}; static const char* suffix[] = {"B", "KiB", "MiB", "GiB", "TiB"};
@ -245,23 +250,7 @@ void FileTransferWidget::updateWidgetColor(ToxFile const& file)
return; return;
} }
switch (file.status) { updateBackgroundColor(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);
}
} }
void FileTransferWidget::updateWidgetText(ToxFile const& file) void FileTransferWidget::updateWidgetText(ToxFile const& file)
@ -623,3 +612,24 @@ void FileTransferWidget::updateWidget(ToxFile const& file)
update(); 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);
}
}

View File

@ -20,11 +20,11 @@
#pragma once #pragma once
#include <QTime> #include <QTime>
#include <QWidget>
#include "src/chatlog/chatlinecontent.h" #include "src/chatlog/chatlinecontent.h"
#include "src/chatlog/toxfileprogress.h" #include "src/chatlog/toxfileprogress.h"
#include "src/core/toxfile.h" #include "src/core/toxfile.h"
#include "src/widget/widgetstyle.h"
class CoreFile; class CoreFile;
@ -35,7 +35,7 @@ class FileTransferWidget;
class QVariantAnimation; class QVariantAnimation;
class QPushButton; class QPushButton;
class FileTransferWidget : public QWidget class FileTransferWidget : public WidgetStyle
{ {
Q_OBJECT Q_OBJECT
@ -64,6 +64,9 @@ protected:
void paintEvent(QPaintEvent*) final; void paintEvent(QPaintEvent*) final;
public slots:
void reloadTheme() override;
private slots: private slots:
void onLeftButtonClicked(); void onLeftButtonClicked();
void onRightButtonClicked(); void onRightButtonClicked();
@ -76,6 +79,7 @@ private:
static bool tryRemoveFile(const QString &filepath); static bool tryRemoveFile(const QString &filepath);
void updateWidget(ToxFile const& file); void updateWidget(ToxFile const& file);
void updateBackgroundColor(const ToxFile::FileStatus status);
private: private:
CoreFile& coreFile; CoreFile& coreFile;

View File

@ -27,7 +27,7 @@
#include <QMessageBox> #include <QMessageBox>
AboutFriendForm::AboutFriendForm(std::unique_ptr<IAboutFriend> _about, QWidget* parent) AboutFriendForm::AboutFriendForm(std::unique_ptr<IAboutFriend> _about, QWidget* parent)
: QDialog(parent) : DialogStyle(parent)
, ui(new Ui::AboutFriendForm) , ui(new Ui::AboutFriendForm)
, about{std::move(_about)} , about{std::move(_about)}
{ {
@ -67,7 +67,7 @@ AboutFriendForm::AboutFriendForm(std::unique_ptr<IAboutFriend> _about, QWidget*
ui->statusMessage->setText(about->getStatusMessage()); ui->statusMessage->setText(about->getStatusMessage());
ui->avatar->setPixmap(about->getAvatar()); ui->avatar->setPixmap(about->getAvatar());
setStyleSheet(Style::getStylesheet("window/general.css")); reloadTheme();
} }
static QString getAutoAcceptDir(const QString& dir) static QString getAutoAcceptDir(const QString& dir)
@ -90,6 +90,11 @@ void AboutFriendForm::onAutoAcceptDirClicked()
about->setAutoAcceptDir(dir); about->setAutoAcceptDir(dir);
} }
void AboutFriendForm::reloadTheme()
{
setStyleSheet(Style::getStylesheet("window/general.css"));
}
void AboutFriendForm::onAutoAcceptDirChanged(const QString& path) void AboutFriendForm::onAutoAcceptDirChanged(const QString& path)
{ {
const bool enabled = !path.isNull(); const bool enabled = !path.isNull();

View File

@ -20,8 +20,8 @@
#pragma once #pragma once
#include "src/model/about/iaboutfriend.h" #include "src/model/about/iaboutfriend.h"
#include "src/widget/dialogstyle.h"
#include <QDialog>
#include <QPointer> #include <QPointer>
#include <memory> #include <memory>
@ -30,7 +30,7 @@ namespace Ui {
class AboutFriendForm; class AboutFriendForm;
} }
class AboutFriendForm : public QDialog class AboutFriendForm : public DialogStyle
{ {
Q_OBJECT Q_OBJECT
@ -45,6 +45,9 @@ private:
signals: signals:
void histroyRemoved(); void histroyRemoved();
public slots:
void reloadTheme() override;
private slots: private slots:
void onAutoAcceptDirChanged(const QString& path); void onAutoAcceptDirChanged(const QString& path);
void onAcceptedClicked(); void onAcceptedClicked();

View File

@ -105,7 +105,7 @@ void setStateName(QAbstractButton* btn, State state)
} }
ChatFormHeader::ChatFormHeader(QWidget* parent) ChatFormHeader::ChatFormHeader(QWidget* parent)
: QWidget(parent) : WidgetStyle(parent)
, mode{Mode::AV} , mode{Mode::AV}
, callState{CallButtonState::Disabled} , callState{CallButtonState::Disabled}
, videoState{CallButtonState::Disabled} , videoState{CallButtonState::Disabled}
@ -283,6 +283,7 @@ QSize ChatFormHeader::getAvatarSize() const
void ChatFormHeader::reloadTheme() void ChatFormHeader::reloadTheme()
{ {
setStyleSheet(Style::getStylesheet("chatArea/chatHead.css"));
callButton->setStyleSheet(Style::getStylesheet(STYLE_PATH)); callButton->setStyleSheet(Style::getStylesheet(STYLE_PATH));
videoButton->setStyleSheet(Style::getStylesheet(STYLE_PATH)); videoButton->setStyleSheet(Style::getStylesheet(STYLE_PATH));
volButton->setStyleSheet(Style::getStylesheet(STYLE_PATH)); volButton->setStyleSheet(Style::getStylesheet(STYLE_PATH));

View File

@ -19,9 +19,8 @@
#pragma once #pragma once
#include <QWidget>
#include <memory> #include <memory>
#include "src/widget/widgetstyle.h"
class MaskablePixmapWidget; class MaskablePixmapWidget;
class QVBoxLayout; class QVBoxLayout;
@ -30,7 +29,7 @@ class QPushButton;
class QToolButton; class QToolButton;
class CallConfirmWidget; class CallConfirmWidget;
class ChatFormHeader : public QWidget class ChatFormHeader : public WidgetStyle
{ {
Q_OBJECT Q_OBJECT
public: public:
@ -71,13 +70,14 @@ public:
void setAvatar(const QPixmap& img); void setAvatar(const QPixmap& img);
QSize getAvatarSize() const; QSize getAvatarSize() const;
void reloadTheme();
// TODO: Remove // TODO: Remove
void addWidget(QWidget* widget, int stretch = 0, Qt::Alignment alignment = Qt::Alignment()); void addWidget(QWidget* widget, int stretch = 0, Qt::Alignment alignment = Qt::Alignment());
void addLayout(QLayout* layout); void addLayout(QLayout* layout);
void addStretch(); void addStretch();
public slots:
void reloadTheme() override;
signals: signals:
void callTriggered(); void callTriggered();
void videoCallTriggered(); void videoCallTriggered();

View File

@ -60,7 +60,6 @@ ContentDialog::ContentDialog(const Core &core, QWidget* parent)
, videoCount(0) , videoCount(0)
{ {
const Settings& s = Settings::getInstance(); const Settings& s = Settings::getInstance();
setStyleSheet(Style::getStylesheet("contentDialog/contentDialog.css"));
friendLayout->setMargin(0); friendLayout->setMargin(0);
friendLayout->setSpacing(0); friendLayout->setSpacing(0);
@ -88,7 +87,6 @@ ContentDialog::ContentDialog(const Core &core, QWidget* parent)
friendScroll->setFrameStyle(QFrame::NoFrame); friendScroll->setFrameStyle(QFrame::NoFrame);
friendScroll->setLayoutDirection(Qt::RightToLeft); friendScroll->setLayoutDirection(Qt::RightToLeft);
friendScroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); friendScroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
friendScroll->setStyleSheet(Style::getStylesheet("friendList/friendList.css"));
friendScroll->setWidgetResizable(true); friendScroll->setWidgetResizable(true);
friendScroll->setWidget(friendWidget); friendScroll->setWidget(friendWidget);
@ -128,6 +126,8 @@ ContentDialog::ContentDialog(const Core &core, QWidget* parent)
setAcceptDrops(true); setAcceptDrops(true);
reloadTheme();
new QShortcut(Qt::CTRL + Qt::Key_Q, this, SLOT(close())); 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::SHIFT + Qt::Key_Tab, this, SLOT(previousContact()));
new QShortcut(Qt::CTRL + Qt::Key_Tab, this, SLOT(nextContact())); new QShortcut(Qt::CTRL + Qt::Key_Tab, this, SLOT(nextContact()));
@ -435,6 +435,12 @@ void ContentDialog::setUsername(const QString& newName)
updateTitleAndStatusIcon(); updateTitleAndStatusIcon();
} }
void ContentDialog::reloadTheme()
{
setStyleSheet(Style::getStylesheet("contentDialog/contentDialog.css"));
splitter->widget(0)->setStyleSheet(Style::getStylesheet("friendList/friendList.css"));
}
bool ContentDialog::event(QEvent* event) bool ContentDialog::event(QEvent* event)
{ {
switch (event->type()) { switch (event->type()) {

View File

@ -90,6 +90,7 @@ public slots:
void previousContact(); void previousContact();
void nextContact(); void nextContact();
void setUsername(const QString& newName); void setUsername(const QString& newName);
void reloadTheme() override;
protected: protected:
bool event(QEvent* event) final; bool event(QEvent* event) final;

View File

@ -20,6 +20,7 @@
#include "contentlayout.h" #include "contentlayout.h"
#include "style.h" #include "style.h"
#include "src/persistence/settings.h" #include "src/persistence/settings.h"
#include "src/widget/gui.h"
#include <QFrame> #include <QFrame>
#include <QStyleFactory> #include <QStyleFactory>
@ -118,6 +119,8 @@ void ContentLayout::init()
mainContent->setStyle(QStyleFactory::create(Settings::getInstance().getStyle())); mainContent->setStyle(QStyleFactory::create(Settings::getInstance().getStyle()));
} }
connect(&GUI::getInstance(), &GUI::themeReload, this, &ContentLayout::reloadTheme);
reloadTheme(); reloadTheme();
mainHLineLayout.addSpacing(4); mainHLineLayout.addSpacing(4);

View File

@ -29,7 +29,6 @@ public:
explicit ContentLayout(QWidget* parent); explicit ContentLayout(QWidget* parent);
~ContentLayout(); ~ContentLayout();
void reloadTheme();
void clear(); void clear();
QFrame mainHLine; QFrame mainHLine;
@ -37,6 +36,9 @@ public:
QWidget* mainContent; QWidget* mainContent;
QWidget* mainHead; QWidget* mainHead;
public slots:
void reloadTheme();
private: private:
void init(); void init();
}; };

21
src/widget/dialogstyle.h Normal file
View File

@ -0,0 +1,21 @@
#ifndef DIALOGSTYLE_H
#define DIALOGSTYLE_H
#include <QDialog>
#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

View File

@ -53,7 +53,6 @@ public:
void setFriendTyping(bool isTyping); void setFriendTyping(bool isTyping);
void show(ContentLayout* contentLayout) final; void show(ContentLayout* contentLayout) final;
void reloadTheme() final;
static const QString ACTION_PREFIX; static const QString ACTION_PREFIX;
@ -76,6 +75,7 @@ public slots:
void clearChatArea(); void clearChatArea();
void onShowMessagesClicked(); void onShowMessagesClicked();
void onSplitterMoved(int pos, int index); void onSplitterMoved(int pos, int index);
void reloadTheme() final;
private slots: private slots:
void updateFriendActivityForFile(const ToxFile& file); void updateFriendActivityForFile(const ToxFile& file);

View File

@ -210,7 +210,7 @@ ChatLogIdx firstItemAfterDate(QDate date, const IChatLog& chatLog)
GenericChatForm::GenericChatForm(const Core& _core, const Contact* contact, IChatLog& chatLog, GenericChatForm::GenericChatForm(const Core& _core, const Contact* contact, IChatLog& chatLog,
IMessageDispatcher& messageDispatcher, QWidget* parent) IMessageDispatcher& messageDispatcher, QWidget* parent)
: QWidget(parent, Qt::Window) : WidgetStyle(parent, Qt::Window)
, core{_core} , core{_core}
, audioInputFlag(false) , audioInputFlag(false)
, audioOutputFlag(false) , audioOutputFlag(false)
@ -414,12 +414,6 @@ void GenericChatForm::reloadTheme()
msgEdit->setStyleSheet(Style::getStylesheet("msgEdit/msgEdit.css") msgEdit->setStyleSheet(Style::getStylesheet("msgEdit/msgEdit.css")
+ fontToCss(s.getChatMessageFont(), "QTextEdit")); + 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)); emoteButton->setStyleSheet(Style::getStylesheet(STYLE_PATH));
fileButton->setStyleSheet(Style::getStylesheet(STYLE_PATH)); fileButton->setStyleSheet(Style::getStylesheet(STYLE_PATH));
screenshotButton->setStyleSheet(Style::getStylesheet(STYLE_PATH)); screenshotButton->setStyleSheet(Style::getStylesheet(STYLE_PATH));

View File

@ -24,9 +24,9 @@
#include "src/model/ichatlog.h" #include "src/model/ichatlog.h"
#include "src/widget/form/loadhistorydialog.h" #include "src/widget/form/loadhistorydialog.h"
#include "src/widget/searchtypes.h" #include "src/widget/searchtypes.h"
#include "src/widget/widgetstyle.h"
#include <QMenu> #include <QMenu>
#include <QWidget>
/** /**
* Spacing in px inserted when the author of the last message changes * Spacing in px inserted when the author of the last message changes
@ -65,7 +65,7 @@ class SpellCheckDecorator;
} }
#endif #endif
class GenericChatForm : public QWidget class GenericChatForm : public WidgetStyle
{ {
Q_OBJECT Q_OBJECT
public: public:
@ -75,7 +75,6 @@ public:
void setName(const QString& newName); void setName(const QString& newName);
virtual void show(ContentLayout* contentLayout); virtual void show(ContentLayout* contentLayout);
virtual void reloadTheme();
void addSystemInfoMessage(const QString& message, ChatMessage::SystemMessageType type, void addSystemInfoMessage(const QString& message, ChatMessage::SystemMessageType type,
const QDateTime& datetime); const QDateTime& datetime);
@ -91,6 +90,7 @@ public slots:
void focusInput(); void focusInput();
void onChatMessageFontChanged(const QFont& font); void onChatMessageFontChanged(const QFont& font);
void setColorizedNames(bool enable); void setColorizedNames(bool enable);
void reloadTheme() override;
protected slots: protected slots:
void onChatContextMenuRequested(QPoint pos); void onChatContextMenuRequested(QPoint pos);

View File

@ -182,6 +182,11 @@ void AboutForm::onUpdateCheckFailed()
bodyUI->updateStack->setCurrentIndex(static_cast<int>(updateIndex::failed)); bodyUI->updateStack->setCurrentIndex(static_cast<int>(updateIndex::failed));
} }
void AboutForm::reloadTheme()
{
replaceVersions();
}
/** /**
* @brief Creates hyperlink with specific style. * @brief Creates hyperlink with specific style.
* @param path The URL of the page the link goes to. * @param path The URL of the page the link goes to.

View File

@ -47,6 +47,7 @@ public slots:
void onUpdateAvailable(QString latestVersion, QUrl link); void onUpdateAvailable(QString latestVersion, QUrl link);
void onUpToDate(); void onUpToDate();
void onUpdateCheckFailed(); void onUpdateCheckFailed();
void reloadTheme() override;
private: private:
void retranslateUi(); void retranslateUi();

View File

@ -19,9 +19,9 @@
#pragma once #pragma once
#include <QWidget> #include "src/widget/widgetstyle.h"
class GenericForm : public QWidget class GenericForm : public WidgetStyle
{ {
Q_OBJECT Q_OBJECT
public: public:

21
src/widget/framestyle.h Normal file
View File

@ -0,0 +1,21 @@
#ifndef FRAMESTYLE_H
#define FRAMESTYLE_H
#include <QFrame>
#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

View File

@ -19,12 +19,11 @@
#include "genericchatitemwidget.h" #include "genericchatitemwidget.h"
#include "src/persistence/settings.h" #include "src/persistence/settings.h"
#include "src/widget/style.h"
#include "src/widget/tool/croppinglabel.h" #include "src/widget/tool/croppinglabel.h"
#include <QVariant> #include <QVariant>
GenericChatItemWidget::GenericChatItemWidget(bool compact, QWidget* parent) GenericChatItemWidget::GenericChatItemWidget(bool compact, QWidget* parent)
: QFrame(parent) : FrameStyle(parent)
, compact(false) , compact(false)
{ {
setProperty("compact", compact); setProperty("compact", compact);

View File

@ -19,12 +19,12 @@
#pragma once #pragma once
#include <QFrame>
#include <QLabel> #include <QLabel>
#include "src/widget/framestyle.h"
class CroppingLabel; class CroppingLabel;
class GenericChatItemWidget : public QFrame class GenericChatItemWidget : public FrameStyle
{ {
Q_OBJECT Q_OBJECT
public: public:

View File

@ -60,10 +60,9 @@ public slots:
QString getStatusMsg() const; QString getStatusMsg() const;
QString getTitle() const; QString getTitle() const;
void reloadTheme();
void activate(); void activate();
void compactChange(bool compact); void compactChange(bool compact);
void reloadTheme() override;
signals: signals:
void chatroomWidgetClicked(GenericChatroomWidget* widget); void chatroomWidgetClicked(GenericChatroomWidget* widget);

View File

@ -98,9 +98,9 @@ void GUI::setWindowTitle(const QString& title)
void GUI::reloadTheme() void GUI::reloadTheme()
{ {
if (QThread::currentThread() == qApp->thread()) { if (QThread::currentThread() == qApp->thread()) {
getInstance()._reloadTheme(); getInstance().themeReload();
} else { } 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); w->setWindowTitle("qTox - " + title);
} }
void GUI::_reloadTheme()
{
Widget* w = Nexus::getDesktopGUI();
if (w)
w->reloadTheme();
}
void GUI::_showInfo(const QString& title, const QString& msg) void GUI::_showInfo(const QString& title, const QString& msg)
{ {
QMessageBox messageBox(QMessageBox::Information, title, msg, QMessageBox::Ok, getMainWidget()); QMessageBox messageBox(QMessageBox::Information, title, msg, QMessageBox::Ok, getMainWidget());

View File

@ -50,7 +50,6 @@ private slots:
// Private implementation, those must be called from the GUI thread // Private implementation, those must be called from the GUI thread
void _setEnabled(bool state); void _setEnabled(bool state);
void _setWindowTitle(const QString& title); void _setWindowTitle(const QString& title);
void _reloadTheme();
void _showInfo(const QString& title, const QString& msg); void _showInfo(const QString& title, const QString& msg);
void _showWarning(const QString& title, const QString& msg); void _showWarning(const QString& title, const QString& msg);
void _showError(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 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

@ -35,7 +35,7 @@ static std::array<QString, 3> STATE_NAME = {
QStringLiteral("red"), QStringLiteral("red"),
}; };
SearchForm::SearchForm(QWidget* parent) : QWidget(parent) SearchForm::SearchForm(QWidget* parent) : WidgetStyle(parent)
{ {
QVBoxLayout* layout = new QVBoxLayout(); QVBoxLayout* layout = new QVBoxLayout();
QHBoxLayout* layoutNavigation = new QHBoxLayout(); QHBoxLayout* layoutNavigation = new QHBoxLayout();

View File

@ -19,8 +19,8 @@
#pragma once #pragma once
#include <QWidget>
#include <QLineEdit> #include <QLineEdit>
#include "src/widget/widgetstyle.h"
#include "searchtypes.h" #include "searchtypes.h"
class QPushButton; class QPushButton;
@ -28,7 +28,7 @@ class QLabel;
class LineEdit; class LineEdit;
class SearchSettingsForm; class SearchSettingsForm;
class SearchForm final : public QWidget class SearchForm final : public WidgetStyle
{ {
Q_OBJECT Q_OBJECT
public: public:
@ -44,7 +44,6 @@ public:
ParameterSearch getParameterSearch(); ParameterSearch getParameterSearch();
void setFocusEditor(); void setFocusEditor();
void insertEditor(const QString &text); void insertEditor(const QString &text);
void reloadTheme();
protected: protected:
void showEvent(QShowEvent* event) final; void showEvent(QShowEvent* event) final;
@ -84,6 +83,7 @@ private slots:
public slots: public slots:
void showMessageNotFound(SearchDirection direction); void showMessageNotFound(SearchDirection direction);
void reloadTheme() override;
signals: signals:
void searchInBegin(const QString& phrase, const ParameterSearch& parameter); void searchInBegin(const QString& phrase, const ParameterSearch& parameter);

View File

@ -22,7 +22,7 @@
#include <QEvent> #include <QEvent>
ActivateDialog::ActivateDialog(QWidget* parent, Qt::WindowFlags f) ActivateDialog::ActivateDialog(QWidget* parent, Qt::WindowFlags f)
: QDialog(parent, f) : DialogStyle(parent, f)
{ {
} }

View File

@ -19,9 +19,9 @@
#pragma once #pragma once
#include <QDialog> #include "src/widget/dialogstyle.h"
class ActivateDialog : public QDialog class ActivateDialog : public DialogStyle
{ {
Q_OBJECT Q_OBJECT
public: public:

View File

@ -463,6 +463,8 @@ void Widget::init()
connect(&settings, &Settings::groupchatPositionChanged, contactListWidget, connect(&settings, &Settings::groupchatPositionChanged, contactListWidget,
&FriendListWidget::onGroupchatPositionChanged); &FriendListWidget::onGroupchatPositionChanged);
connect(&GUI::getInstance(), &GUI::themeReload, this, &Widget::reloadTheme);
reloadTheme(); reloadTheme();
updateIcons(); updateIcons();
retranslateUi(); retranslateUi();
@ -1825,7 +1827,7 @@ ContentLayout* Widget::createContentDialog(DialogType type) const
Translator::registerHandler(std::bind(&Dialog::retranslateUi, this), this); Translator::registerHandler(std::bind(&Dialog::retranslateUi, this), this);
retranslateUi(); retranslateUi();
setWindowIcon(QIcon(":/img/icons/qtox.svg")); setWindowIcon(QIcon(":/img/icons/qtox.svg"));
setStyleSheet(Style::getStylesheet("window/general.css")); reloadTheme();
connect(core, &Core::usernameSet, this, &Dialog::retranslateUi); connect(core, &Core::usernameSet, this, &Dialog::retranslateUi);
} }
@ -1842,6 +1844,11 @@ ContentLayout* Widget::createContentDialog(DialogType type) const
setWindowTitle(core->getUsername() + QStringLiteral(" - ") + Widget::fromDialogType(type)); setWindowTitle(core->getUsername() + QStringLiteral(" - ") + Widget::fromDialogType(type));
} }
void reloadTheme() final
{
setStyleSheet(Style::getStylesheet("window/general.css"));
}
protected: protected:
void resizeEvent(QResizeEvent* event) override void resizeEvent(QResizeEvent* event) override
{ {
@ -2404,27 +2411,6 @@ void Widget::reloadTheme()
contactListWidget->reDraw(); contactListWidget->reDraw();
profilePicture->setStyleSheet(Style::getStylesheet("window/profile.css")); 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() void Widget::nextContact()

View File

@ -142,7 +142,6 @@ public:
void clearAllReceipts(); void clearAllReceipts();
void reloadTheme();
static inline QIcon prepareIcon(QString path, int w = 0, int h = 0); static inline QIcon prepareIcon(QString path, int w = 0, int h = 0);
bool groupsVisible() const; bool groupsVisible() const;
@ -150,6 +149,7 @@ public:
void resetIcon(); void resetIcon();
public slots: public slots:
void reloadTheme();
void onShowSettings(); void onShowSettings();
void onSeparateWindowClicked(bool separate); void onSeparateWindowClicked(bool separate);
void onSeparateWindowChanged(bool separate, bool clicked); void onSeparateWindowChanged(bool separate, bool clicked);

21
src/widget/widgetstyle.h Normal file
View File

@ -0,0 +1,21 @@
#ifndef WIDGETSTYLE_H
#define WIDGETSTYLE_H
#include <QWidget>
#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