1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
#include "style.h"
#include "themetuner.h"
#include "mainwindow.h"
#include "common/unused.h"
#include "syntaxhighlighterplugin.h"
#include "services/pluginmanager.h"
#include <QApplication>
#include <QToolTip>
#include <QDebug>
Style* Style::instance = nullptr;
Style* Style::getInstance()
{
if (instance == nullptr)
instance = new Style(QApplication::style());
return instance;
}
bool Style::isDark(const QStyle* style)
{
return style->standardPalette().text().color().value() >= 80;
}
const ExtendedPalette& Style::extendedPalette() const
{
return extPalette;
}
void Style::setStyle(QStyle *style, const QString &styleName)
{
setBaseStyle(style);
QApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton);
if (styleName != "qt5ct-style")
{
QApplication::setPalette(initialPalette); // reset palette, cause styles don't provide
// full palette when changed in runtime (i.e. windowsvista)
}
QApplication::setStyle(this);
if (styleName != "qt5ct-style")
{
QApplication::setPalette(standardPalette());
QToolTip::setPalette(standardPalette());
}
THEME_TUNER->tuneTheme(styleName);
MAINWINDOW->getMdiArea()->setBackground(extPalette.mdiAreaBase());
}
QString Style::name() const
{
return baseStyle()->objectName();
}
bool Style::isDark() const
{
return isDark(this);
}
bool Style::eventFilter(QObject *obj, QEvent *ev)
{
UNUSED(obj);
if (ev->type() == QEvent::PaletteChange)
{
if (extPalette.styleChanged(this, name()))
{
QList<SyntaxHighlighterPlugin*> plugins = PLUGINS->getLoadedPlugins<SyntaxHighlighterPlugin>();
auto it = plugins.begin();
while (it != plugins.end())
{
(*it)->refreshFormats();
it++;
}
emit paletteChanged();
}
}
return false;
}
Style::Style(QStyle *style)
: QProxyStyle(style)
{
initialPalette = style->standardPalette();
extPalette.styleChanged(this, name());
qApp->installEventFilter(this);
}
|