mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#6514 Dark Theme : Move define to RiaDefines
This commit is contained in:
committed by
Gaute Lindkvist
parent
87bc6acd65
commit
4841d19d02
@@ -45,331 +45,315 @@
|
||||
#include "qwt_plot_marker.h"
|
||||
#include "qwt_symbol.h"
|
||||
|
||||
namespace caf
|
||||
{
|
||||
template <>
|
||||
void caf::AppEnum<RiuGuiTheme::ThemeEnum>::setUp()
|
||||
{
|
||||
addItem( RiuGuiTheme::ThemeEnum::DEFAULT, "DEFAULT", "Default theme" );
|
||||
addItem( RiuGuiTheme::ThemeEnum::DARK, "DARK", "Dark theme" );
|
||||
addItem( RiuGuiTheme::ThemeEnum::LIGHT, "LIGHT", "Light theme" );
|
||||
setDefault( RiuGuiTheme::ThemeEnum::DEFAULT );
|
||||
}
|
||||
|
||||
} // End namespace caf
|
||||
|
||||
QMap<RiuGuiTheme::ThemeEnum, QMap<QString, QString>> RiuGuiTheme::s_variableValueMap = {};
|
||||
QMap<RiuGuiTheme::ThemeEnum, QMap<QString, QString>> RiuGuiTheme::s_variableGuiTextMap = {};
|
||||
QMap<RiaDefines::ThemeEnum, QMap<QString, QString>> RiuGuiTheme::s_variableValueMap = {};
|
||||
QMap<RiaDefines::ThemeEnum, QMap<QString, QString>> RiuGuiTheme::s_variableGuiTextMap = {};
|
||||
QMap<QString, QMap<QString, QMap<QString, QMap<QString, QString>>>> RiuGuiTheme::s_qwtPlotItemPropertiesMap = {};
|
||||
QMap<QString, CustomStyleSheetApplicator> RiuGuiTheme::s_customStyleSheetApplicators =
|
||||
{ { QString(
|
||||
"QwtPlot\\[\"(?<plotName>[a-zA-Z0-9-_\\*]+)\"\\]::curve\\[\"(?<itemName>[a-zA-Z0-9-_\\*]+)\"\\]\\s*\\{("
|
||||
"?<properties>([\\n\\r]*\\s*((line-color|symbol-color):"
|
||||
"\\s*([a-zA-Z0-9#]+)\\s*;))*)[\\n\\r]*\\s*\\}" ),
|
||||
[]( QRegularExpressionMatch& match ) {
|
||||
QRegExp plotNameRegExp( match.captured( "plotName" ) );
|
||||
QRegExp itemNameRegExp( match.captured( "itemName" ) );
|
||||
{{QString( "QwtPlot\\[\"(?<plotName>[a-zA-Z0-9-_\\*]+)\"\\]::curve\\[\"(?<itemName>[a-zA-Z0-9-_\\*]+)\"\\]\\s*\\{("
|
||||
"?<properties>([\\n\\r]*\\s*((line-color|symbol-color):"
|
||||
"\\s*([a-zA-Z0-9#]+)\\s*;))*)[\\n\\r]*\\s*\\}" ),
|
||||
[]( QRegularExpressionMatch& match ) {
|
||||
QRegExp plotNameRegExp( match.captured( "plotName" ) );
|
||||
QRegExp itemNameRegExp( match.captured( "itemName" ) );
|
||||
|
||||
QRegularExpression lineColorRegExp( "line-color:\\s*([#0-9a-zA-Z]+)" );
|
||||
QString lineColor = lineColorRegExp.match( match.captured( "properties" ) ).captured( 1 );
|
||||
QRegularExpression symbolColorRegExp( "symbol-color:\\s*([#0-9a-zA-Z]+)" );
|
||||
QString symbolColor = symbolColorRegExp.match( match.captured( "properties" ) ).captured( 1 );
|
||||
if ( !lineColor.isEmpty() )
|
||||
{
|
||||
storeQwtStyleSheetProperty( match.captured( "plotName" ),
|
||||
QString( "curve" ),
|
||||
match.captured( "itemName" ),
|
||||
"line-color",
|
||||
lineColor );
|
||||
}
|
||||
if ( !symbolColor.isEmpty() )
|
||||
{
|
||||
// Symbols get the same color assigned as curves.
|
||||
storeQwtStyleSheetProperty( match.captured( "plotName" ),
|
||||
QString( "curve" ),
|
||||
match.captured( "itemName" ),
|
||||
"symbol-color",
|
||||
symbolColor );
|
||||
}
|
||||
if ( lineColor.isEmpty() && symbolColor.isEmpty() ) return;
|
||||
QRegularExpression lineColorRegExp( "line-color:\\s*([#0-9a-zA-Z]+)" );
|
||||
QString lineColor = lineColorRegExp.match( match.captured( "properties" ) ).captured( 1 );
|
||||
QRegularExpression symbolColorRegExp( "symbol-color:\\s*([#0-9a-zA-Z]+)" );
|
||||
QString symbolColor = symbolColorRegExp.match( match.captured( "properties" ) ).captured( 1 );
|
||||
if ( !lineColor.isEmpty() )
|
||||
{
|
||||
storeQwtStyleSheetProperty( match.captured( "plotName" ),
|
||||
QString( "curve" ),
|
||||
match.captured( "itemName" ),
|
||||
"line-color",
|
||||
lineColor );
|
||||
}
|
||||
if ( !symbolColor.isEmpty() )
|
||||
{
|
||||
// Symbols get the same color assigned as curves.
|
||||
storeQwtStyleSheetProperty( match.captured( "plotName" ),
|
||||
QString( "curve" ),
|
||||
match.captured( "itemName" ),
|
||||
"symbol-color",
|
||||
symbolColor );
|
||||
}
|
||||
if ( lineColor.isEmpty() && symbolColor.isEmpty() ) return;
|
||||
|
||||
const QWidgetList topLevelWidgets = RiaGuiApplication::instance()->topLevelWidgets();
|
||||
for ( QWidget* widget : topLevelWidgets )
|
||||
{
|
||||
for ( QwtPlot* plotWidget : widget->findChildren<QwtPlot*>() )
|
||||
{
|
||||
if ( plotNameRegExp.exactMatch( plotWidget->property( "qss-class" ).toString() ) )
|
||||
{
|
||||
for ( QwtPlotItem* item : plotWidget->itemList() )
|
||||
{
|
||||
if ( QwtPlotCurve* curve = dynamic_cast<QwtPlotCurve*>( item ) )
|
||||
{
|
||||
if ( itemNameRegExp.exactMatch( item->title().text() ) ||
|
||||
match.captured( "itemName" ) == "*" )
|
||||
{
|
||||
QPen pen = curve->pen();
|
||||
pen.setColor( QColor( lineColor ) );
|
||||
curve->setPen( pen );
|
||||
const QWidgetList topLevelWidgets = RiaGuiApplication::instance()->topLevelWidgets();
|
||||
for ( QWidget* widget : topLevelWidgets )
|
||||
{
|
||||
for ( QwtPlot* plotWidget : widget->findChildren<QwtPlot*>() )
|
||||
{
|
||||
if ( plotNameRegExp.exactMatch( plotWidget->property( "qss-class" ).toString() ) )
|
||||
{
|
||||
for ( QwtPlotItem* item : plotWidget->itemList() )
|
||||
{
|
||||
if ( QwtPlotCurve* curve = dynamic_cast<QwtPlotCurve*>( item ) )
|
||||
{
|
||||
if ( itemNameRegExp.exactMatch( item->title().text() ) || match.captured( "itemName" ) == "*" )
|
||||
{
|
||||
QPen pen = curve->pen();
|
||||
pen.setColor( QColor( lineColor ) );
|
||||
curve->setPen( pen );
|
||||
|
||||
if ( curve->symbol() && curve->symbol()->style() != QwtSymbol::NoSymbol )
|
||||
{
|
||||
QPen pen = curve->symbol()->pen();
|
||||
pen.setColor( QColor( symbolColor ) );
|
||||
QwtSymbol* symbol = cloneCurveSymbol( curve );
|
||||
symbol->setPen( pen );
|
||||
curve->setSymbol( symbol );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
plotWidget->replot();
|
||||
}
|
||||
}
|
||||
} },
|
||||
{ QString( "QwtPlot\\[\"(?<plotName>[a-zA-Z0-9-_\\*]+)\"\\]::grid\\[\"(?<itemName>[a-zA-Z0-9-_\\*]+)\"\\]\\s*\\{("
|
||||
"?<properties>([\\n\\r]*\\s*((color):"
|
||||
"\\s*([a-zA-Z0-9#]+)\\s*;))*)[\\n\\r]*\\s*\\}" ),
|
||||
[]( QRegularExpressionMatch& match ) {
|
||||
QRegExp plotNameRegExp( match.captured( "plotName" ) );
|
||||
QRegExp itemNameRegExp( match.captured( "itemName" ) );
|
||||
QRegularExpression colorRegExp( "color:\\s*([#0-9a-zA-Z]+)" );
|
||||
QString color = colorRegExp.match( match.captured( "properties" ) ).captured( 1 );
|
||||
const QWidgetList topLevelWidgets = RiaGuiApplication::instance()->topLevelWidgets();
|
||||
if ( curve->symbol() && curve->symbol()->style() != QwtSymbol::NoSymbol )
|
||||
{
|
||||
QPen pen = curve->symbol()->pen();
|
||||
pen.setColor( QColor( symbolColor ) );
|
||||
QwtSymbol* symbol = cloneCurveSymbol( curve );
|
||||
symbol->setPen( pen );
|
||||
curve->setSymbol( symbol );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
plotWidget->replot();
|
||||
}
|
||||
}
|
||||
}},
|
||||
{QString( "QwtPlot\\[\"(?<plotName>[a-zA-Z0-9-_\\*]+)\"\\]::grid\\[\"(?<itemName>[a-zA-Z0-9-_\\*]+)\"\\]\\s*\\{("
|
||||
"?<properties>([\\n\\r]*\\s*((color):"
|
||||
"\\s*([a-zA-Z0-9#]+)\\s*;))*)[\\n\\r]*\\s*\\}" ),
|
||||
[]( QRegularExpressionMatch& match ) {
|
||||
QRegExp plotNameRegExp( match.captured( "plotName" ) );
|
||||
QRegExp itemNameRegExp( match.captured( "itemName" ) );
|
||||
QRegularExpression colorRegExp( "color:\\s*([#0-9a-zA-Z]+)" );
|
||||
QString color = colorRegExp.match( match.captured( "properties" ) ).captured( 1 );
|
||||
const QWidgetList topLevelWidgets = RiaGuiApplication::instance()->topLevelWidgets();
|
||||
|
||||
if ( !color.isEmpty() )
|
||||
{
|
||||
storeQwtStyleSheetProperty( match.captured( "plotName" ),
|
||||
QString( "grid" ),
|
||||
match.captured( "itemName" ),
|
||||
"color",
|
||||
color );
|
||||
}
|
||||
for ( QWidget* widget : topLevelWidgets )
|
||||
{
|
||||
for ( QwtPlot* plotWidget : widget->findChildren<QwtPlot*>() )
|
||||
{
|
||||
if ( plotNameRegExp.exactMatch( plotWidget->property( "qss-class" ).toString() ) ||
|
||||
match.captured( "plotName" ) == "*" )
|
||||
{
|
||||
for ( QwtPlotItem* item : plotWidget->itemList() )
|
||||
{
|
||||
if ( QwtPlotGrid* grid = dynamic_cast<QwtPlotGrid*>( item ) )
|
||||
{
|
||||
if ( itemNameRegExp.exactMatch( item->title().text() ) ||
|
||||
match.captured( "itemName" ) == "*" )
|
||||
{
|
||||
QPen pen = grid->majorPen();
|
||||
pen.setColor( QColor( color ) );
|
||||
grid->setPen( pen );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
plotWidget->replot();
|
||||
}
|
||||
}
|
||||
} },
|
||||
{ QString( "QwtPlot\\[\"(?<plotName>[a-zA-Z0-9-_\\*]+)\"\\]::legend\\s*\\{("
|
||||
"?<properties>([\\n\\r]*\\s*((text-color):"
|
||||
"\\s*([a-zA-Z0-9#]+)\\s*;))*)[\\n\\r]*\\s*\\}" ),
|
||||
[]( QRegularExpressionMatch& match ) {
|
||||
QRegExp plotNameRegExp( match.captured( "plotName" ) );
|
||||
QRegExp itemNameRegExp( match.captured( "itemName" ) );
|
||||
QRegularExpression colorRegExp( "text-color:\\s*([#0-9a-zA-Z]+)" );
|
||||
QString color = colorRegExp.match( match.captured( "properties" ) ).captured( 1 );
|
||||
const QWidgetList topLevelWidgets = RiaGuiApplication::instance()->topLevelWidgets();
|
||||
if ( !color.isEmpty() )
|
||||
{
|
||||
storeQwtStyleSheetProperty( match.captured( "plotName" ),
|
||||
QString( "grid" ),
|
||||
match.captured( "itemName" ),
|
||||
"color",
|
||||
color );
|
||||
}
|
||||
for ( QWidget* widget : topLevelWidgets )
|
||||
{
|
||||
for ( QwtPlot* plotWidget : widget->findChildren<QwtPlot*>() )
|
||||
{
|
||||
if ( plotNameRegExp.exactMatch( plotWidget->property( "qss-class" ).toString() ) ||
|
||||
match.captured( "plotName" ) == "*" )
|
||||
{
|
||||
for ( QwtPlotItem* item : plotWidget->itemList() )
|
||||
{
|
||||
if ( QwtPlotGrid* grid = dynamic_cast<QwtPlotGrid*>( item ) )
|
||||
{
|
||||
if ( itemNameRegExp.exactMatch( item->title().text() ) || match.captured( "itemName" ) == "*" )
|
||||
{
|
||||
QPen pen = grid->majorPen();
|
||||
pen.setColor( QColor( color ) );
|
||||
grid->setPen( pen );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
plotWidget->replot();
|
||||
}
|
||||
}
|
||||
}},
|
||||
{QString( "QwtPlot\\[\"(?<plotName>[a-zA-Z0-9-_\\*]+)\"\\]::legend\\s*\\{("
|
||||
"?<properties>([\\n\\r]*\\s*((text-color):"
|
||||
"\\s*([a-zA-Z0-9#]+)\\s*;))*)[\\n\\r]*\\s*\\}" ),
|
||||
[]( QRegularExpressionMatch& match ) {
|
||||
QRegExp plotNameRegExp( match.captured( "plotName" ) );
|
||||
QRegExp itemNameRegExp( match.captured( "itemName" ) );
|
||||
QRegularExpression colorRegExp( "text-color:\\s*([#0-9a-zA-Z]+)" );
|
||||
QString color = colorRegExp.match( match.captured( "properties" ) ).captured( 1 );
|
||||
const QWidgetList topLevelWidgets = RiaGuiApplication::instance()->topLevelWidgets();
|
||||
|
||||
if ( !color.isEmpty() )
|
||||
{
|
||||
storeQwtStyleSheetProperty( match.captured( "plotName" ),
|
||||
QString( "legend" ),
|
||||
match.captured( "itemName" ),
|
||||
"text-color",
|
||||
color );
|
||||
}
|
||||
for ( QWidget* widget : topLevelWidgets )
|
||||
{
|
||||
for ( QwtPlot* plotWidget : widget->findChildren<QwtPlot*>() )
|
||||
{
|
||||
if ( plotNameRegExp.exactMatch( plotWidget->property( "qss-class" ).toString() ) ||
|
||||
match.captured( "plotName" ) == "*" )
|
||||
{
|
||||
for ( QwtLegendLabel* label : plotWidget->findChildren<QwtLegendLabel*>() )
|
||||
{
|
||||
QwtText text = label->text();
|
||||
text.setColor( QColor( color ) );
|
||||
label->setText( text );
|
||||
label->repaint();
|
||||
}
|
||||
}
|
||||
plotWidget->replot();
|
||||
}
|
||||
}
|
||||
} },
|
||||
{ QString( "QwtPlot\\[\"(?<plotName>[a-zA-Z0-9-_\\*]+)\"\\]::lineMarker\\[\"(?<itemName>[a-zA-Z0-9-_\\*]+)\"\\]"
|
||||
"\\s*\\{("
|
||||
"?<properties>([\\n\\r]*\\s*((color|text-color):"
|
||||
"\\s*([a-zA-Z0-9#]+)\\s*;))*)[\\n\\r]*\\s*\\}" ),
|
||||
[]( QRegularExpressionMatch& match ) {
|
||||
QRegExp plotNameRegExp( match.captured( "plotName" ) );
|
||||
QRegExp itemNameRegExp( match.captured( "itemName" ) );
|
||||
QRegularExpression colorRegExp( "color:\\s*([#0-9a-zA-Z]+)" );
|
||||
QString color = colorRegExp.match( match.captured( "properties" ) ).captured( 1 );
|
||||
QRegularExpression textColorRegExp( "text-color:\\s*([#0-9a-zA-Z]+)" );
|
||||
QString textColor = textColorRegExp.match( match.captured( "properties" ) ).captured( 1 );
|
||||
if ( !color.isEmpty() )
|
||||
{
|
||||
storeQwtStyleSheetProperty( match.captured( "plotName" ),
|
||||
QString( "legend" ),
|
||||
match.captured( "itemName" ),
|
||||
"text-color",
|
||||
color );
|
||||
}
|
||||
for ( QWidget* widget : topLevelWidgets )
|
||||
{
|
||||
for ( QwtPlot* plotWidget : widget->findChildren<QwtPlot*>() )
|
||||
{
|
||||
if ( plotNameRegExp.exactMatch( plotWidget->property( "qss-class" ).toString() ) ||
|
||||
match.captured( "plotName" ) == "*" )
|
||||
{
|
||||
for ( QwtLegendLabel* label : plotWidget->findChildren<QwtLegendLabel*>() )
|
||||
{
|
||||
QwtText text = label->text();
|
||||
text.setColor( QColor( color ) );
|
||||
label->setText( text );
|
||||
label->repaint();
|
||||
}
|
||||
}
|
||||
plotWidget->replot();
|
||||
}
|
||||
}
|
||||
}},
|
||||
{QString( "QwtPlot\\[\"(?<plotName>[a-zA-Z0-9-_\\*]+)\"\\]::lineMarker\\[\"(?<itemName>[a-zA-Z0-9-_\\*]+)\"\\]"
|
||||
"\\s*\\{("
|
||||
"?<properties>([\\n\\r]*\\s*((color|text-color):"
|
||||
"\\s*([a-zA-Z0-9#]+)\\s*;))*)[\\n\\r]*\\s*\\}" ),
|
||||
[]( QRegularExpressionMatch& match ) {
|
||||
QRegExp plotNameRegExp( match.captured( "plotName" ) );
|
||||
QRegExp itemNameRegExp( match.captured( "itemName" ) );
|
||||
QRegularExpression colorRegExp( "color:\\s*([#0-9a-zA-Z]+)" );
|
||||
QString color = colorRegExp.match( match.captured( "properties" ) ).captured( 1 );
|
||||
QRegularExpression textColorRegExp( "text-color:\\s*([#0-9a-zA-Z]+)" );
|
||||
QString textColor = textColorRegExp.match( match.captured( "properties" ) ).captured( 1 );
|
||||
|
||||
const QWidgetList topLevelWidgets = RiaGuiApplication::instance()->topLevelWidgets();
|
||||
const QWidgetList topLevelWidgets = RiaGuiApplication::instance()->topLevelWidgets();
|
||||
|
||||
if ( !color.isEmpty() )
|
||||
{
|
||||
storeQwtStyleSheetProperty( match.captured( "plotName" ),
|
||||
QString( "lineMarker" ),
|
||||
match.captured( "itemName" ),
|
||||
"color",
|
||||
color );
|
||||
}
|
||||
if ( !textColor.isEmpty() )
|
||||
{
|
||||
storeQwtStyleSheetProperty( match.captured( "plotName" ),
|
||||
QString( "lineMarker" ),
|
||||
match.captured( "itemName" ),
|
||||
"text-color",
|
||||
textColor );
|
||||
}
|
||||
for ( QWidget* widget : topLevelWidgets )
|
||||
{
|
||||
for ( QwtPlot* plotWidget : widget->findChildren<QwtPlot*>() )
|
||||
{
|
||||
if ( plotNameRegExp.exactMatch( plotWidget->property( "qss-class" ).toString() ) ||
|
||||
match.captured( "plotName" ) == "*" )
|
||||
{
|
||||
for ( QwtPlotItem* item : plotWidget->itemList() )
|
||||
{
|
||||
if ( QwtPlotMarker* marker = dynamic_cast<QwtPlotMarker*>( item ) )
|
||||
{
|
||||
if ( marker->symbol() == nullptr || marker->symbol()->style() == QwtSymbol::NoSymbol )
|
||||
{
|
||||
if ( itemNameRegExp.exactMatch( item->title().text() ) ||
|
||||
match.captured( "itemName" ) == "*" )
|
||||
{
|
||||
QPen pen = marker->linePen();
|
||||
pen.setColor( QColor( color ) );
|
||||
marker->setLinePen( pen );
|
||||
marker->label().setColor( QColor( textColor ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
plotWidget->replot();
|
||||
}
|
||||
}
|
||||
} },
|
||||
{ QString( "QwtPlot\\[\"(?<plotName>[a-zA-Z0-9-_\\*]+)\"\\]::pointMarker\\[\"(?<itemName>[a-zA-Z0-9-_\\*]+)\"\\]"
|
||||
"\\s*\\{("
|
||||
"?<properties>([\\n\\r]*\\s*((color|text-color):"
|
||||
"\\s*([a-zA-Z0-9#]+)\\s*;))*)[\\n\\r]*\\s*\\}" ),
|
||||
[]( QRegularExpressionMatch& match ) {
|
||||
QRegExp plotNameRegExp( match.captured( "plotName" ) );
|
||||
QRegExp itemNameRegExp( match.captured( "itemName" ) );
|
||||
QRegularExpression colorRegExp( "color:\\s*([#0-9a-zA-Z]+)" );
|
||||
QString color = colorRegExp.match( match.captured( "properties" ) ).captured( 1 );
|
||||
QRegularExpression textColorRegExp( "text-color:\\s*([#0-9a-zA-Z]+)" );
|
||||
QString textColor = textColorRegExp.match( match.captured( "properties" ) ).captured( 1 );
|
||||
if ( !color.isEmpty() )
|
||||
{
|
||||
storeQwtStyleSheetProperty( match.captured( "plotName" ),
|
||||
QString( "lineMarker" ),
|
||||
match.captured( "itemName" ),
|
||||
"color",
|
||||
color );
|
||||
}
|
||||
if ( !textColor.isEmpty() )
|
||||
{
|
||||
storeQwtStyleSheetProperty( match.captured( "plotName" ),
|
||||
QString( "lineMarker" ),
|
||||
match.captured( "itemName" ),
|
||||
"text-color",
|
||||
textColor );
|
||||
}
|
||||
for ( QWidget* widget : topLevelWidgets )
|
||||
{
|
||||
for ( QwtPlot* plotWidget : widget->findChildren<QwtPlot*>() )
|
||||
{
|
||||
if ( plotNameRegExp.exactMatch( plotWidget->property( "qss-class" ).toString() ) ||
|
||||
match.captured( "plotName" ) == "*" )
|
||||
{
|
||||
for ( QwtPlotItem* item : plotWidget->itemList() )
|
||||
{
|
||||
if ( QwtPlotMarker* marker = dynamic_cast<QwtPlotMarker*>( item ) )
|
||||
{
|
||||
if ( marker->symbol() == nullptr || marker->symbol()->style() == QwtSymbol::NoSymbol )
|
||||
{
|
||||
if ( itemNameRegExp.exactMatch( item->title().text() ) ||
|
||||
match.captured( "itemName" ) == "*" )
|
||||
{
|
||||
QPen pen = marker->linePen();
|
||||
pen.setColor( QColor( color ) );
|
||||
marker->setLinePen( pen );
|
||||
marker->label().setColor( QColor( textColor ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
plotWidget->replot();
|
||||
}
|
||||
}
|
||||
}},
|
||||
{QString( "QwtPlot\\[\"(?<plotName>[a-zA-Z0-9-_\\*]+)\"\\]::pointMarker\\[\"(?<itemName>[a-zA-Z0-9-_\\*]+)\"\\]"
|
||||
"\\s*\\{("
|
||||
"?<properties>([\\n\\r]*\\s*((color|text-color):"
|
||||
"\\s*([a-zA-Z0-9#]+)\\s*;))*)[\\n\\r]*\\s*\\}" ),
|
||||
[]( QRegularExpressionMatch& match ) {
|
||||
QRegExp plotNameRegExp( match.captured( "plotName" ) );
|
||||
QRegExp itemNameRegExp( match.captured( "itemName" ) );
|
||||
QRegularExpression colorRegExp( "color:\\s*([#0-9a-zA-Z]+)" );
|
||||
QString color = colorRegExp.match( match.captured( "properties" ) ).captured( 1 );
|
||||
QRegularExpression textColorRegExp( "text-color:\\s*([#0-9a-zA-Z]+)" );
|
||||
QString textColor = textColorRegExp.match( match.captured( "properties" ) ).captured( 1 );
|
||||
|
||||
const QWidgetList topLevelWidgets = RiaGuiApplication::instance()->topLevelWidgets();
|
||||
const QWidgetList topLevelWidgets = RiaGuiApplication::instance()->topLevelWidgets();
|
||||
|
||||
if ( !color.isEmpty() )
|
||||
{
|
||||
storeQwtStyleSheetProperty( match.captured( "plotName" ),
|
||||
QString( "pointMarker" ),
|
||||
match.captured( "itemName" ),
|
||||
"color",
|
||||
color );
|
||||
}
|
||||
if ( !textColor.isEmpty() )
|
||||
{
|
||||
storeQwtStyleSheetProperty( match.captured( "plotName" ),
|
||||
QString( "pointMarker" ),
|
||||
match.captured( "itemName" ),
|
||||
"text-color",
|
||||
textColor );
|
||||
}
|
||||
for ( QWidget* widget : topLevelWidgets )
|
||||
{
|
||||
for ( QwtPlot* plotWidget : widget->findChildren<QwtPlot*>() )
|
||||
{
|
||||
if ( plotNameRegExp.exactMatch( plotWidget->property( "qss-class" ).toString() ) ||
|
||||
match.captured( "plotName" ) == "*" )
|
||||
{
|
||||
for ( QwtPlotItem* item : plotWidget->itemList() )
|
||||
{
|
||||
if ( QwtPlotMarker* marker = dynamic_cast<QwtPlotMarker*>( item ) )
|
||||
{
|
||||
if ( marker->symbol() && marker->symbol()->style() != QwtSymbol::NoSymbol )
|
||||
{
|
||||
if ( itemNameRegExp.exactMatch( item->title().text() ) ||
|
||||
match.captured( "itemName" ) == "*" )
|
||||
{
|
||||
QPen pen = marker->symbol()->pen();
|
||||
pen.setColor( QColor( color ) );
|
||||
QwtSymbol* symbol = cloneMarkerSymbol( marker );
|
||||
symbol->setPen( pen );
|
||||
marker->setSymbol( symbol );
|
||||
marker->label().setColor( QColor( textColor ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
plotWidget->replot();
|
||||
}
|
||||
}
|
||||
} },
|
||||
{ QString( "QwtPlot\\[\"(?<plotName>[a-zA-Z0-9-_\\*]+)\"\\]::picker"
|
||||
"\\s*\\{("
|
||||
"?<properties>([\\n\\r]*\\s*((text-color):"
|
||||
"\\s*([a-zA-Z0-9#]+)\\s*;))*)[\\n\\r]*\\s*\\}" ),
|
||||
[]( QRegularExpressionMatch& match ) {
|
||||
QRegExp plotNameRegExp( match.captured( "plotName" ) );
|
||||
QRegExp itemNameRegExp( match.captured( "itemName" ) );
|
||||
QRegularExpression textColorRegExp( "text-color:\\s*([#a-zA-Z0-9]+)" );
|
||||
QString textColor = textColorRegExp.match( match.captured( "properties" ) ).captured( 1 );
|
||||
if ( !color.isEmpty() )
|
||||
{
|
||||
storeQwtStyleSheetProperty( match.captured( "plotName" ),
|
||||
QString( "pointMarker" ),
|
||||
match.captured( "itemName" ),
|
||||
"color",
|
||||
color );
|
||||
}
|
||||
if ( !textColor.isEmpty() )
|
||||
{
|
||||
storeQwtStyleSheetProperty( match.captured( "plotName" ),
|
||||
QString( "pointMarker" ),
|
||||
match.captured( "itemName" ),
|
||||
"text-color",
|
||||
textColor );
|
||||
}
|
||||
for ( QWidget* widget : topLevelWidgets )
|
||||
{
|
||||
for ( QwtPlot* plotWidget : widget->findChildren<QwtPlot*>() )
|
||||
{
|
||||
if ( plotNameRegExp.exactMatch( plotWidget->property( "qss-class" ).toString() ) ||
|
||||
match.captured( "plotName" ) == "*" )
|
||||
{
|
||||
for ( QwtPlotItem* item : plotWidget->itemList() )
|
||||
{
|
||||
if ( QwtPlotMarker* marker = dynamic_cast<QwtPlotMarker*>( item ) )
|
||||
{
|
||||
if ( marker->symbol() && marker->symbol()->style() != QwtSymbol::NoSymbol )
|
||||
{
|
||||
if ( itemNameRegExp.exactMatch( item->title().text() ) ||
|
||||
match.captured( "itemName" ) == "*" )
|
||||
{
|
||||
QPen pen = marker->symbol()->pen();
|
||||
pen.setColor( QColor( color ) );
|
||||
QwtSymbol* symbol = cloneMarkerSymbol( marker );
|
||||
symbol->setPen( pen );
|
||||
marker->setSymbol( symbol );
|
||||
marker->label().setColor( QColor( textColor ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
plotWidget->replot();
|
||||
}
|
||||
}
|
||||
}},
|
||||
{QString( "QwtPlot\\[\"(?<plotName>[a-zA-Z0-9-_\\*]+)\"\\]::picker"
|
||||
"\\s*\\{("
|
||||
"?<properties>([\\n\\r]*\\s*((text-color):"
|
||||
"\\s*([a-zA-Z0-9#]+)\\s*;))*)[\\n\\r]*\\s*\\}" ),
|
||||
[]( QRegularExpressionMatch& match ) {
|
||||
QRegExp plotNameRegExp( match.captured( "plotName" ) );
|
||||
QRegExp itemNameRegExp( match.captured( "itemName" ) );
|
||||
QRegularExpression textColorRegExp( "text-color:\\s*([#a-zA-Z0-9]+)" );
|
||||
QString textColor = textColorRegExp.match( match.captured( "properties" ) ).captured( 1 );
|
||||
|
||||
const QWidgetList topLevelWidgets = RiaGuiApplication::instance()->topLevelWidgets();
|
||||
const QWidgetList topLevelWidgets = RiaGuiApplication::instance()->topLevelWidgets();
|
||||
|
||||
if ( !textColor.isEmpty() )
|
||||
{
|
||||
storeQwtStyleSheetProperty( match.captured( "plotName" ), QString( "picker" ), "*", "text-color", textColor );
|
||||
}
|
||||
for ( QWidget* widget : topLevelWidgets )
|
||||
{
|
||||
for ( QwtPlot* plotWidget : widget->findChildren<QwtPlot*>() )
|
||||
{
|
||||
if ( plotNameRegExp.exactMatch( plotWidget->property( "qss-class" ).toString() ) ||
|
||||
match.captured( "plotName" ) == "*" )
|
||||
{
|
||||
QWidget* canvas = plotWidget->canvas();
|
||||
if ( canvas )
|
||||
{
|
||||
for ( QwtPicker* picker : canvas->findChildren<QwtPicker*>() )
|
||||
{
|
||||
QPen pen = picker->trackerPen();
|
||||
pen.setColor( QColor( textColor ) );
|
||||
picker->setTrackerPen( pen );
|
||||
}
|
||||
}
|
||||
}
|
||||
plotWidget->replot();
|
||||
}
|
||||
}
|
||||
} } };
|
||||
if ( !textColor.isEmpty() )
|
||||
{
|
||||
storeQwtStyleSheetProperty( match.captured( "plotName" ), QString( "picker" ), "*", "text-color", textColor );
|
||||
}
|
||||
for ( QWidget* widget : topLevelWidgets )
|
||||
{
|
||||
for ( QwtPlot* plotWidget : widget->findChildren<QwtPlot*>() )
|
||||
{
|
||||
if ( plotNameRegExp.exactMatch( plotWidget->property( "qss-class" ).toString() ) ||
|
||||
match.captured( "plotName" ) == "*" )
|
||||
{
|
||||
QWidget* canvas = plotWidget->canvas();
|
||||
if ( canvas )
|
||||
{
|
||||
for ( QwtPicker* picker : canvas->findChildren<QwtPicker*>() )
|
||||
{
|
||||
QPen pen = picker->trackerPen();
|
||||
pen.setColor( QColor( textColor ) );
|
||||
picker->setTrackerPen( pen );
|
||||
}
|
||||
}
|
||||
}
|
||||
plotWidget->replot();
|
||||
}
|
||||
}
|
||||
}}};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuGuiTheme::updateGuiTheme( ThemeEnum theme )
|
||||
void RiuGuiTheme::updateGuiTheme( RiaDefines::ThemeEnum theme )
|
||||
{
|
||||
s_qwtPlotItemPropertiesMap.clear();
|
||||
applyStyleSheet( theme );
|
||||
@@ -384,7 +368,7 @@ void RiuGuiTheme::updateGuiTheme( ThemeEnum theme )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiuGuiTheme::applyStyleSheet( ThemeEnum theme )
|
||||
bool RiuGuiTheme::applyStyleSheet( RiaDefines::ThemeEnum theme )
|
||||
{
|
||||
QString styleSheetPath = getStyleSheetPath( theme );
|
||||
QFile styleSheetFile( styleSheetPath );
|
||||
@@ -406,7 +390,7 @@ bool RiuGuiTheme::applyStyleSheet( ThemeEnum theme )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuGuiTheme::changeVariableValue( RiuGuiTheme::ThemeEnum theme, const QString& variableName, const QString& newValue )
|
||||
void RiuGuiTheme::changeVariableValue( RiaDefines::ThemeEnum theme, const QString& variableName, const QString& newValue )
|
||||
{
|
||||
if ( !s_variableValueMap.keys().contains( theme ) )
|
||||
{
|
||||
@@ -422,7 +406,7 @@ void RiuGuiTheme::changeVariableValue( RiuGuiTheme::ThemeEnum theme, const QStri
|
||||
}
|
||||
}
|
||||
|
||||
QMap<QString, QString> RiuGuiTheme::getVariableValueMap( RiuGuiTheme::ThemeEnum theme )
|
||||
QMap<QString, QString> RiuGuiTheme::getVariableValueMap( RiaDefines::ThemeEnum theme )
|
||||
{
|
||||
if ( !s_variableValueMap.keys().contains( theme ) )
|
||||
{
|
||||
@@ -448,7 +432,7 @@ QMap<QString, QString> RiuGuiTheme::getVariableValueMap( RiuGuiTheme::ThemeEnum
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QMap<QString, QString> RiuGuiTheme::getVariableGuiTextMap( RiuGuiTheme::ThemeEnum theme )
|
||||
QMap<QString, QString> RiuGuiTheme::getVariableGuiTextMap( RiaDefines::ThemeEnum theme )
|
||||
{
|
||||
if ( !s_variableGuiTextMap.keys().contains( theme ) )
|
||||
{
|
||||
@@ -474,7 +458,7 @@ QMap<QString, QString> RiuGuiTheme::getVariableGuiTextMap( RiuGuiTheme::ThemeEnu
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiuGuiTheme::applyVariableValueMapToStyleSheet( RiuGuiTheme::ThemeEnum theme )
|
||||
QString RiuGuiTheme::applyVariableValueMapToStyleSheet( RiaDefines::ThemeEnum theme )
|
||||
{
|
||||
QFileInfo info( getStyleSheetPath( theme ) );
|
||||
QString absoluteStyleSheetPath = QString( "%0/%1" ).arg( GUI_THEMES_DIR ).arg( info.fileName() );
|
||||
@@ -512,7 +496,7 @@ QString RiuGuiTheme::applyVariableValueMapToStyleSheet( RiuGuiTheme::ThemeEnum t
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiuGuiTheme::writeStyleSheetToFile( RiuGuiTheme::ThemeEnum theme, const QString& styleSheet )
|
||||
bool RiuGuiTheme::writeStyleSheetToFile( RiaDefines::ThemeEnum theme, const QString& styleSheet )
|
||||
{
|
||||
QFileInfo info( getStyleSheetPath( theme ) );
|
||||
QString absoluteStyleSheetPath = QString( "%0/%1" ).arg( GUI_THEMES_DIR ).arg( info.fileName() );
|
||||
@@ -542,7 +526,7 @@ bool RiuGuiTheme::writeStyleSheetToFile( RiuGuiTheme::ThemeEnum theme, const QSt
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiuGuiTheme::loadStyleSheet( RiuGuiTheme::ThemeEnum theme )
|
||||
QString RiuGuiTheme::loadStyleSheet( RiaDefines::ThemeEnum theme )
|
||||
{
|
||||
QFile styleSheetFile( getStyleSheetPath( theme ) );
|
||||
QString styleSheet;
|
||||
@@ -580,10 +564,10 @@ QAbstractItemModel* RiuGuiTheme::getQssCompletionModel( QCompleter* completer )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QColor RiuGuiTheme::getColorByVariableName( const QString& variable, int theme /*= -1 */ )
|
||||
{
|
||||
RiuGuiTheme::ThemeEnum eTheme = RiaGuiApplication::instance()->preferences()->guiTheme();
|
||||
if ( theme >= 0 && theme < static_cast<int>( caf::AppEnum<RiuGuiTheme::ThemeEnum>().size() ) )
|
||||
RiaDefines::ThemeEnum eTheme = RiaGuiApplication::instance()->preferences()->guiTheme();
|
||||
if ( theme >= 0 && theme < static_cast<int>( caf::AppEnum<RiaDefines::ThemeEnum>().size() ) )
|
||||
{
|
||||
eTheme = static_cast<RiuGuiTheme::ThemeEnum>( theme );
|
||||
eTheme = static_cast<RiaDefines::ThemeEnum>( theme );
|
||||
}
|
||||
|
||||
if ( s_variableValueMap.keys().contains( eTheme ) && s_variableValueMap[eTheme].keys().contains( "$" + variable ) )
|
||||
@@ -759,7 +743,7 @@ void RiuGuiTheme::styleQwtItem( QwtPicker* item )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuGuiTheme::preparseStyleSheet( RiuGuiTheme::ThemeEnum theme, QString& styleSheet )
|
||||
void RiuGuiTheme::preparseStyleSheet( RiaDefines::ThemeEnum theme, QString& styleSheet )
|
||||
{
|
||||
QRegularExpression variableRegExp(
|
||||
"[ \\t]*(?<name>\\$[a-zA-z0-9_]+)[ \\t]*:[ \\t]*(?<value>[a-zA-Z-_0-9#]+);[ \\t]*(\\/\\/[ "
|
||||
@@ -811,9 +795,9 @@ void RiuGuiTheme::preparseStyleSheet( RiuGuiTheme::ThemeEnum theme, QString& sty
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RiuGuiTheme::getStyleSheetPath( ThemeEnum theme )
|
||||
QString RiuGuiTheme::getStyleSheetPath( RiaDefines::ThemeEnum theme )
|
||||
{
|
||||
return QString( ":/themes/%0.qss" ).arg( caf::AppEnum<RiuGuiTheme::ThemeEnum>( theme ).text().toLower() );
|
||||
return QString( ":/themes/%0.qss" ).arg( caf::AppEnum<RiaDefines::ThemeEnum>( theme ).text().toLower() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RiaPreferences.h"
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <QMap>
|
||||
@@ -34,27 +36,21 @@ class QwtSymbol;
|
||||
class QwtPlotMarker;
|
||||
class QwtPlotCurve;
|
||||
class QwtPicker;
|
||||
class QwtText;
|
||||
|
||||
typedef std::function<void( QRegularExpressionMatch& )> CustomStyleSheetApplicator;
|
||||
|
||||
class RiuGuiTheme
|
||||
{
|
||||
public:
|
||||
enum class ThemeEnum
|
||||
{
|
||||
DEFAULT,
|
||||
DARK,
|
||||
LIGHT
|
||||
};
|
||||
|
||||
static void updateGuiTheme( ThemeEnum theme );
|
||||
static bool applyStyleSheet( ThemeEnum theme );
|
||||
static void changeVariableValue( RiuGuiTheme::ThemeEnum theme, const QString& variableName, const QString& newValue );
|
||||
static QMap<QString, QString> getVariableValueMap( RiuGuiTheme::ThemeEnum theme );
|
||||
static QMap<QString, QString> getVariableGuiTextMap( RiuGuiTheme::ThemeEnum theme );
|
||||
static QString applyVariableValueMapToStyleSheet( RiuGuiTheme::ThemeEnum theme );
|
||||
static bool writeStyleSheetToFile( RiuGuiTheme::ThemeEnum theme, const QString& styleSheet );
|
||||
static QString loadStyleSheet( RiuGuiTheme::ThemeEnum theme );
|
||||
static void updateGuiTheme( RiaDefines::ThemeEnum theme );
|
||||
static bool applyStyleSheet( RiaDefines::ThemeEnum theme );
|
||||
static void changeVariableValue( RiaDefines::ThemeEnum theme, const QString& variableName, const QString& newValue );
|
||||
static QMap<QString, QString> getVariableValueMap( RiaDefines::ThemeEnum theme );
|
||||
static QMap<QString, QString> getVariableGuiTextMap( RiaDefines::ThemeEnum theme );
|
||||
static QString applyVariableValueMapToStyleSheet( RiaDefines::ThemeEnum theme );
|
||||
static bool writeStyleSheetToFile( RiaDefines::ThemeEnum theme, const QString& styleSheet );
|
||||
static QString loadStyleSheet( RiaDefines::ThemeEnum theme );
|
||||
static QAbstractItemModel* getQssCompletionModel( QCompleter* completer );
|
||||
static QColor getColorByVariableName( const QString& variable, int theme = -1 );
|
||||
static QString
|
||||
@@ -63,8 +59,8 @@ public:
|
||||
static void styleQwtItem( QwtPicker* item );
|
||||
|
||||
private:
|
||||
static void preparseStyleSheet( RiuGuiTheme::ThemeEnum theme, QString& styleSheet );
|
||||
static QString getStyleSheetPath( RiuGuiTheme::ThemeEnum theme );
|
||||
static void preparseStyleSheet( RiaDefines::ThemeEnum theme, QString& styleSheet );
|
||||
static QString getStyleSheetPath( RiaDefines::ThemeEnum theme );
|
||||
static void storeQwtStyleSheetProperty( const QString& plotName,
|
||||
const QString& itemType,
|
||||
const QString& itemName,
|
||||
@@ -75,8 +71,8 @@ private:
|
||||
static QwtSymbol* cloneCurveSymbol( QwtPlotCurve* curve );
|
||||
|
||||
private:
|
||||
static QMap<RiuGuiTheme::ThemeEnum, QMap<QString, QString>> s_variableValueMap;
|
||||
static QMap<RiuGuiTheme::ThemeEnum, QMap<QString, QString>> s_variableGuiTextMap;
|
||||
static QMap<RiaDefines::ThemeEnum, QMap<QString, QString>> s_variableValueMap;
|
||||
static QMap<RiaDefines::ThemeEnum, QMap<QString, QString>> s_variableGuiTextMap;
|
||||
static QMap<QString, QMap<QString, QMap<QString, QMap<QString, QString>>>> s_qwtPlotItemPropertiesMap;
|
||||
static QMap<QString, CustomStyleSheetApplicator> s_customStyleSheetApplicators;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user