+ event to restore/clear action style scheme

This commit is contained in:
wmayer 2015-07-09 23:08:10 +02:00
parent 82a4eb0cec
commit af793f16b0
4 changed files with 58 additions and 14 deletions

View File

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

View File

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

View File

@ -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<TaskView::TaskView*> tasks = findChildren<TaskView::TaskView*>();
if (static_cast<ActionStyleEvent*>(e)->getType() == ActionStyleEvent::Clear) {
for (QList<TaskView::TaskView*>::iterator it = tasks.begin(); it != tasks.end(); ++it) {
(*it)->clearActionStyle();
}
}
else {
for (QList<TaskView::TaskView*>::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"

View File

@ -29,6 +29,7 @@
#include <string>
#include <vector>
#include <QEvent>
#include <QMainWindow>
#include <QMdiArea>
@ -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