From af793f16b07b63f0313c334ef2dbdac84f7182ac Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 9 Jul 2015 23:08:10 +0200 Subject: [PATCH] + event to restore/clear action style scheme --- src/Gui/Application.cpp | 8 +++++--- src/Gui/DlgGeneralImp.cpp | 17 ++++++----------- src/Gui/MainWindow.cpp | 28 ++++++++++++++++++++++++++++ src/Gui/MainWindow.h | 19 +++++++++++++++++++ 4 files changed, 58 insertions(+), 14 deletions(-) diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index 517fa97f9..ef790c90e 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -1647,6 +1647,9 @@ void Application::runApplication(void) << QLatin1String(":/stylesheets"); QDir::setSearchPaths(QString::fromLatin1("qss"), qssPaths); + // register action style event type + ActionStyleEvent::EventType = QEvent::registerEventType(QEvent::User + 1); + // check for OpenGL if (!QGLFormat::hasOpenGL()) { QMessageBox::critical(0, QObject::tr("No OpenGL"), QObject::tr("This system does not support OpenGL")); @@ -1795,9 +1798,8 @@ void Application::runApplication(void) QTextStream str(&f); qApp->setStyleSheet(str.readAll()); - Gui::TaskView::TaskView* taskPanel = Control().taskPanel(); - if (taskPanel) - taskPanel->clearActionStyle(); + ActionStyleEvent e(ActionStyleEvent::Clear); + qApp->sendEvent(&mw, &e); } } diff --git a/src/Gui/DlgGeneralImp.cpp b/src/Gui/DlgGeneralImp.cpp index 75ebc75ab..80bc3380a 100644 --- a/src/Gui/DlgGeneralImp.cpp +++ b/src/Gui/DlgGeneralImp.cpp @@ -36,8 +36,6 @@ #include "MainWindow.h" #include "PrefWidgets.h" #include "Language/Translator.h" -#include "Control.h" -#include "TaskView/TaskView.h" using namespace Gui::Dialog; @@ -165,9 +163,8 @@ void DlgGeneralImp::saveSettings() QTextStream str(&f); qApp->setStyleSheet(str.readAll()); - Gui::TaskView::TaskView* taskPanel = Control().taskPanel(); - if (taskPanel) - taskPanel->clearActionStyle(); + ActionStyleEvent e(ActionStyleEvent::Clear); + qApp->sendEvent(getMainWindow(), &e); } } } @@ -175,16 +172,14 @@ void DlgGeneralImp::saveSettings() if (sheet.toString().isEmpty()) { if (this->tiledBackground->isChecked()) { qApp->setStyleSheet(QString()); - Gui::TaskView::TaskView* taskPanel = Control().taskPanel(); - if (taskPanel) - taskPanel->restoreActionStyle(); + ActionStyleEvent e(ActionStyleEvent::Restore); + qApp->sendEvent(getMainWindow(), &e); mdi->setBackground(QPixmap(QLatin1String(":/icons/background.png"))); } else { qApp->setStyleSheet(QString()); - Gui::TaskView::TaskView* taskPanel = Control().taskPanel(); - if (taskPanel) - taskPanel->restoreActionStyle(); + ActionStyleEvent e(ActionStyleEvent::Restore); + qApp->sendEvent(getMainWindow(), &e); mdi->setBackground(QBrush(QColor(160,160,160))); } } diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp index 7ffbe3a77..d9b6b7d2e 100644 --- a/src/Gui/MainWindow.cpp +++ b/src/Gui/MainWindow.cpp @@ -97,6 +97,7 @@ #include "ReportView.h" #include "CombiView.h" #include "PythonConsole.h" +#include "TaskView/TaskView.h" #include "DlgTipOfTheDayImp.h" #include "DlgUndoRedo.h" @@ -1543,6 +1544,19 @@ void MainWindow::customEvent(QEvent* e) d->actionTimer->start(5000); } } + else if (e->type() == ActionStyleEvent::EventType) { + QList tasks = findChildren(); + if (static_cast(e)->getType() == ActionStyleEvent::Clear) { + for (QList::iterator it = tasks.begin(); it != tasks.end(); ++it) { + (*it)->clearActionStyle(); + } + } + else { + for (QList::iterator it = tasks.begin(); it != tasks.end(); ++it) { + (*it)->restoreActionStyle(); + } + } + } } // ---------------------------------------------------------- @@ -1624,5 +1638,19 @@ void StatusBarObserver::Log(const char *m) QApplication::postEvent(getMainWindow(), ev); } +// ------------------------------------------------------------- + +int ActionStyleEvent::EventType = -1; + +ActionStyleEvent::ActionStyleEvent(Style type) + : QEvent(QEvent::Type(EventType)), type(type) +{ +} + +ActionStyleEvent::Style ActionStyleEvent::getType() const +{ + return type; +} + #include "moc_MainWindow.cpp" diff --git a/src/Gui/MainWindow.h b/src/Gui/MainWindow.h index ae1b41f3c..49e4d841a 100644 --- a/src/Gui/MainWindow.h +++ b/src/Gui/MainWindow.h @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -313,6 +314,24 @@ private: QString msg, wrn, err; }; +// ------------------------------------------------------------- + +/** This is a helper class needed when a style sheet is restored or cleared. + * @author Werner Mayer + */ +class ActionStyleEvent : public QEvent +{ +public: + static int EventType; + enum Style {Restore, Clear}; + + ActionStyleEvent(Style type); + Style getType() const; + +private: + Style type; +}; + } // namespace Gui #endif // GUI_MAINWINDOW_H