From 4841d19d022abe8359c647feb051c815af429bf8 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Wed, 16 Sep 2020 11:55:28 +0200 Subject: [PATCH] #6514 Dark Theme : Move define to RiaDefines --- ApplicationCode/Application/RiaDefines.cpp | 10 + ApplicationCode/Application/RiaDefines.h | 7 + .../Application/RiaGuiApplication.cpp | 1 + .../Application/RiaPreferences.cpp | 3 +- ApplicationCode/Application/RiaPreferences.h | 5 +- .../Commands/RicThemeColorEditorFeature.cpp | 20 +- ApplicationCode/UserInterface/RiuGuiTheme.cpp | 626 +++++++++--------- ApplicationCode/UserInterface/RiuGuiTheme.h | 34 +- 8 files changed, 353 insertions(+), 353 deletions(-) diff --git a/ApplicationCode/Application/RiaDefines.cpp b/ApplicationCode/Application/RiaDefines.cpp index 2c64a712cd..1da66eeede 100644 --- a/ApplicationCode/Application/RiaDefines.cpp +++ b/ApplicationCode/Application/RiaDefines.cpp @@ -114,6 +114,16 @@ void caf::AppEnum::setUp() setDefault( RiaDefines::GridCaseAxis::AXIS_K ); } + +template <> +void caf::AppEnum::setUp() +{ + addItem( RiaDefines::ThemeEnum::DEFAULT, "DEFAULT", "Default theme" ); + addItem( RiaDefines::ThemeEnum::DARK, "DARK", "Dark theme" ); + addItem( RiaDefines::ThemeEnum::LIGHT, "LIGHT", "Light theme" ); + setDefault( RiaDefines::ThemeEnum::DEFAULT ); +} + } // namespace caf //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Application/RiaDefines.h b/ApplicationCode/Application/RiaDefines.h index 6fcc3310bb..ae08414083 100644 --- a/ApplicationCode/Application/RiaDefines.h +++ b/ApplicationCode/Application/RiaDefines.h @@ -215,4 +215,11 @@ enum class GridCaseAxis UNDEFINED_AXIS }; +enum class ThemeEnum +{ + DEFAULT, + DARK, + LIGHT +}; + }; // namespace RiaDefines diff --git a/ApplicationCode/Application/RiaGuiApplication.cpp b/ApplicationCode/Application/RiaGuiApplication.cpp index 1982e45779..1719aa8098 100644 --- a/ApplicationCode/Application/RiaGuiApplication.cpp +++ b/ApplicationCode/Application/RiaGuiApplication.cpp @@ -93,6 +93,7 @@ #include "Riu3dSelectionManager.h" #include "RiuDockWidgetTools.h" #include "RiuFileDialogTools.h" +#include "RiuGuiTheme.h" #include "RiuMainWindow.h" #include "RiuMainWindowTools.h" #include "RiuMdiMaximizeWindowGuard.h" diff --git a/ApplicationCode/Application/RiaPreferences.cpp b/ApplicationCode/Application/RiaPreferences.cpp index 226f34e41f..6511b22497 100644 --- a/ApplicationCode/Application/RiaPreferences.cpp +++ b/ApplicationCode/Application/RiaPreferences.cpp @@ -23,6 +23,7 @@ #include "RiaColorTables.h" #include "RifReaderSettings.h" +#include "RiuGuiTheme.h" #include "cafPdmFieldCvfColor.h" #include "cafPdmSettings.h" @@ -1002,7 +1003,7 @@ bool RiaPreferences::openExportedPdfInViewer() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RiuGuiTheme::ThemeEnum RiaPreferences::guiTheme() const +RiaDefines::ThemeEnum RiaPreferences::guiTheme() const { return m_guiTheme(); } diff --git a/ApplicationCode/Application/RiaPreferences.h b/ApplicationCode/Application/RiaPreferences.h index 6b156aa605..c84d840f0a 100644 --- a/ApplicationCode/Application/RiaPreferences.h +++ b/ApplicationCode/Application/RiaPreferences.h @@ -25,7 +25,6 @@ #include "RiaFontCache.h" #include "RiaGuiApplication.h" #include "RiaQDateTimeTools.h" -#include "RiuGuiTheme.h" #include "cafAppEnum.h" #include "cafPdmChildField.h" @@ -113,7 +112,7 @@ public: bool showProgressBar() const; bool openExportedPdfInViewer() const; - RiuGuiTheme::ThemeEnum guiTheme() const; + RiaDefines::ThemeEnum guiTheme() const; std::map defaultFontSizes() const; @@ -215,7 +214,7 @@ private: caf::PdmField m_showProgressBar; caf::PdmField m_gtestFilter; - caf::PdmField> m_guiTheme; + caf::PdmField> m_guiTheme; caf::PdmField m_pageSize; caf::PdmField m_pageOrientation; diff --git a/ApplicationCode/Commands/RicThemeColorEditorFeature.cpp b/ApplicationCode/Commands/RicThemeColorEditorFeature.cpp index 374d509eb0..52bbcff31b 100644 --- a/ApplicationCode/Commands/RicThemeColorEditorFeature.cpp +++ b/ApplicationCode/Commands/RicThemeColorEditorFeature.cpp @@ -18,13 +18,15 @@ #include "RicThemeColorEditorFeature.h" +#include "RiaDefines.h" #include "RiaGuiApplication.h" #include "RiaPreferences.h" -#include "RiuMainWindow.h" #include "RiuGuiTheme.h" +#include "RiuMainWindow.h" #include "RiuQssSyntaxHighlighter.h" #include "RiuTextEditWithCompletion.h" + #include "cafAppEnum.h" #include @@ -51,7 +53,7 @@ bool RicThemeColorEditorFeature::isCommandEnabled() //-------------------------------------------------------------------------------------------------- void RicThemeColorEditorFeature::onActionTriggered( bool isChecked ) { - RiuGuiTheme::ThemeEnum theme = RiaGuiApplication::instance()->preferences()->guiTheme(); + RiaDefines::ThemeEnum theme = RiaGuiApplication::instance()->preferences()->guiTheme(); QDialog* dialog = new QDialog( RiuMainWindow::instance() ); connect( dialog, &QDialog::close, [this, theme]() { RiuGuiTheme::updateGuiTheme( theme ); } ); @@ -62,12 +64,12 @@ void RicThemeColorEditorFeature::onActionTriggered( bool isChecked ) layout->addWidget( new QLabel( "GUI theme" ), 0, 0 ); - QComboBox* themeSelector = new QComboBox(); - caf::AppEnum themes; + QComboBox* themeSelector = new QComboBox(); + caf::AppEnum themes; for ( size_t index = 0; index < themes.size(); index++ ) { themeSelector->addItem( themes.uiTextFromIndex( index ), QVariant::fromValue( index ) ); - if ( static_cast( index ) == theme ) + if ( static_cast( index ) == theme ) { themeSelector->setCurrentIndex( static_cast( index ) ); } @@ -104,7 +106,7 @@ void RicThemeColorEditorFeature::onActionTriggered( bool isChecked ) QGridLayout* innerLayout = new QGridLayout(); int row = 0; int column = 0; - RiuGuiTheme::ThemeEnum theme = static_cast( themeSelector->currentData().toInt() ); + RiaDefines::ThemeEnum theme = static_cast( themeSelector->currentData().toInt() ); QMap variableValueMap = RiuGuiTheme::getVariableValueMap( theme ); QMap variableGuiTextMap = RiuGuiTheme::getVariableGuiTextMap( theme ); for ( const QString variableName : variableValueMap.keys() ) @@ -139,8 +141,8 @@ void RicThemeColorEditorFeature::onActionTriggered( bool isChecked ) // connect( themeSelector, qOverload( &QComboBox::currentIndexChanged ), [=]() { connect( themeSelector, static_cast( &QComboBox::currentIndexChanged ), [=]() { generateColorFields(); - RiuGuiTheme::ThemeEnum theme = static_cast( themeSelector->currentData().toInt() ); - RiuGuiTheme::updateGuiTheme( static_cast( theme ) ); + RiaDefines::ThemeEnum theme = static_cast( themeSelector->currentData().toInt() ); + RiuGuiTheme::updateGuiTheme( static_cast( theme ) ); editor->setPlainText( RiuGuiTheme::loadStyleSheet( theme ) ); } ); @@ -157,7 +159,7 @@ void RicThemeColorEditorFeature::onActionTriggered( bool isChecked ) QPushButton* button = new QPushButton( "Apply style sheet changes" ); layout->addWidget( button, 6, 1 ); connect( button, &QPushButton::clicked, [this, themeSelector, editor, generateColorFields]() { - RiuGuiTheme::ThemeEnum theme = static_cast( themeSelector->currentData().toInt() ); + RiaDefines::ThemeEnum theme = static_cast( themeSelector->currentData().toInt() ); RiuGuiTheme::writeStyleSheetToFile( theme, editor->toPlainText() ); generateColorFields(); } ); diff --git a/ApplicationCode/UserInterface/RiuGuiTheme.cpp b/ApplicationCode/UserInterface/RiuGuiTheme.cpp index d6a169e1cb..e38066b80d 100644 --- a/ApplicationCode/UserInterface/RiuGuiTheme.cpp +++ b/ApplicationCode/UserInterface/RiuGuiTheme.cpp @@ -45,331 +45,315 @@ #include "qwt_plot_marker.h" #include "qwt_symbol.h" -namespace caf -{ -template <> -void caf::AppEnum::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::s_variableValueMap = {}; -QMap> RiuGuiTheme::s_variableGuiTextMap = {}; +QMap> RiuGuiTheme::s_variableValueMap = {}; +QMap> RiuGuiTheme::s_variableGuiTextMap = {}; QMap>>> RiuGuiTheme::s_qwtPlotItemPropertiesMap = {}; QMap RiuGuiTheme::s_customStyleSheetApplicators = - { { QString( - "QwtPlot\\[\"(?[a-zA-Z0-9-_\\*]+)\"\\]::curve\\[\"(?[a-zA-Z0-9-_\\*]+)\"\\]\\s*\\{(" - "?([\\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\\[\"(?[a-zA-Z0-9-_\\*]+)\"\\]::curve\\[\"(?[a-zA-Z0-9-_\\*]+)\"\\]\\s*\\{(" + "?([\\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() ) - { - if ( plotNameRegExp.exactMatch( plotWidget->property( "qss-class" ).toString() ) ) - { - for ( QwtPlotItem* item : plotWidget->itemList() ) - { - if ( QwtPlotCurve* curve = dynamic_cast( 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() ) + { + if ( plotNameRegExp.exactMatch( plotWidget->property( "qss-class" ).toString() ) ) + { + for ( QwtPlotItem* item : plotWidget->itemList() ) + { + if ( QwtPlotCurve* curve = dynamic_cast( 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\\[\"(?[a-zA-Z0-9-_\\*]+)\"\\]::grid\\[\"(?[a-zA-Z0-9-_\\*]+)\"\\]\\s*\\{(" - "?([\\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\\[\"(?[a-zA-Z0-9-_\\*]+)\"\\]::grid\\[\"(?[a-zA-Z0-9-_\\*]+)\"\\]\\s*\\{(" + "?([\\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() ) - { - if ( plotNameRegExp.exactMatch( plotWidget->property( "qss-class" ).toString() ) || - match.captured( "plotName" ) == "*" ) - { - for ( QwtPlotItem* item : plotWidget->itemList() ) - { - if ( QwtPlotGrid* grid = dynamic_cast( 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\\[\"(?[a-zA-Z0-9-_\\*]+)\"\\]::legend\\s*\\{(" - "?([\\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() ) + { + if ( plotNameRegExp.exactMatch( plotWidget->property( "qss-class" ).toString() ) || + match.captured( "plotName" ) == "*" ) + { + for ( QwtPlotItem* item : plotWidget->itemList() ) + { + if ( QwtPlotGrid* grid = dynamic_cast( 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\\[\"(?[a-zA-Z0-9-_\\*]+)\"\\]::legend\\s*\\{(" + "?([\\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() ) - { - if ( plotNameRegExp.exactMatch( plotWidget->property( "qss-class" ).toString() ) || - match.captured( "plotName" ) == "*" ) - { - for ( QwtLegendLabel* label : plotWidget->findChildren() ) - { - QwtText text = label->text(); - text.setColor( QColor( color ) ); - label->setText( text ); - label->repaint(); - } - } - plotWidget->replot(); - } - } - } }, - { QString( "QwtPlot\\[\"(?[a-zA-Z0-9-_\\*]+)\"\\]::lineMarker\\[\"(?[a-zA-Z0-9-_\\*]+)\"\\]" - "\\s*\\{(" - "?([\\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() ) + { + if ( plotNameRegExp.exactMatch( plotWidget->property( "qss-class" ).toString() ) || + match.captured( "plotName" ) == "*" ) + { + for ( QwtLegendLabel* label : plotWidget->findChildren() ) + { + QwtText text = label->text(); + text.setColor( QColor( color ) ); + label->setText( text ); + label->repaint(); + } + } + plotWidget->replot(); + } + } + }}, + {QString( "QwtPlot\\[\"(?[a-zA-Z0-9-_\\*]+)\"\\]::lineMarker\\[\"(?[a-zA-Z0-9-_\\*]+)\"\\]" + "\\s*\\{(" + "?([\\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() ) - { - if ( plotNameRegExp.exactMatch( plotWidget->property( "qss-class" ).toString() ) || - match.captured( "plotName" ) == "*" ) - { - for ( QwtPlotItem* item : plotWidget->itemList() ) - { - if ( QwtPlotMarker* marker = dynamic_cast( 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\\[\"(?[a-zA-Z0-9-_\\*]+)\"\\]::pointMarker\\[\"(?[a-zA-Z0-9-_\\*]+)\"\\]" - "\\s*\\{(" - "?([\\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() ) + { + if ( plotNameRegExp.exactMatch( plotWidget->property( "qss-class" ).toString() ) || + match.captured( "plotName" ) == "*" ) + { + for ( QwtPlotItem* item : plotWidget->itemList() ) + { + if ( QwtPlotMarker* marker = dynamic_cast( 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\\[\"(?[a-zA-Z0-9-_\\*]+)\"\\]::pointMarker\\[\"(?[a-zA-Z0-9-_\\*]+)\"\\]" + "\\s*\\{(" + "?([\\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() ) - { - if ( plotNameRegExp.exactMatch( plotWidget->property( "qss-class" ).toString() ) || - match.captured( "plotName" ) == "*" ) - { - for ( QwtPlotItem* item : plotWidget->itemList() ) - { - if ( QwtPlotMarker* marker = dynamic_cast( 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\\[\"(?[a-zA-Z0-9-_\\*]+)\"\\]::picker" - "\\s*\\{(" - "?([\\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() ) + { + if ( plotNameRegExp.exactMatch( plotWidget->property( "qss-class" ).toString() ) || + match.captured( "plotName" ) == "*" ) + { + for ( QwtPlotItem* item : plotWidget->itemList() ) + { + if ( QwtPlotMarker* marker = dynamic_cast( 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\\[\"(?[a-zA-Z0-9-_\\*]+)\"\\]::picker" + "\\s*\\{(" + "?([\\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() ) - { - if ( plotNameRegExp.exactMatch( plotWidget->property( "qss-class" ).toString() ) || - match.captured( "plotName" ) == "*" ) - { - QWidget* canvas = plotWidget->canvas(); - if ( canvas ) - { - for ( QwtPicker* picker : canvas->findChildren() ) - { - 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() ) + { + if ( plotNameRegExp.exactMatch( plotWidget->property( "qss-class" ).toString() ) || + match.captured( "plotName" ) == "*" ) + { + QWidget* canvas = plotWidget->canvas(); + if ( canvas ) + { + for ( QwtPicker* picker : canvas->findChildren() ) + { + 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 RiuGuiTheme::getVariableValueMap( RiuGuiTheme::ThemeEnum theme ) +QMap RiuGuiTheme::getVariableValueMap( RiaDefines::ThemeEnum theme ) { if ( !s_variableValueMap.keys().contains( theme ) ) { @@ -448,7 +432,7 @@ QMap RiuGuiTheme::getVariableValueMap( RiuGuiTheme::ThemeEnum //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -QMap RiuGuiTheme::getVariableGuiTextMap( RiuGuiTheme::ThemeEnum theme ) +QMap RiuGuiTheme::getVariableGuiTextMap( RiaDefines::ThemeEnum theme ) { if ( !s_variableGuiTextMap.keys().contains( theme ) ) { @@ -474,7 +458,7 @@ QMap 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( caf::AppEnum().size() ) ) + RiaDefines::ThemeEnum eTheme = RiaGuiApplication::instance()->preferences()->guiTheme(); + if ( theme >= 0 && theme < static_cast( caf::AppEnum().size() ) ) { - eTheme = static_cast( theme ); + eTheme = static_cast( 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]*(?\\$[a-zA-z0-9_]+)[ \\t]*:[ \\t]*(?[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( theme ).text().toLower() ); + return QString( ":/themes/%0.qss" ).arg( caf::AppEnum( theme ).text().toLower() ); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/UserInterface/RiuGuiTheme.h b/ApplicationCode/UserInterface/RiuGuiTheme.h index 8b488b5707..9d2381f7b8 100644 --- a/ApplicationCode/UserInterface/RiuGuiTheme.h +++ b/ApplicationCode/UserInterface/RiuGuiTheme.h @@ -18,6 +18,8 @@ #pragma once +#include "RiaPreferences.h" + #include #include @@ -34,27 +36,21 @@ class QwtSymbol; class QwtPlotMarker; class QwtPlotCurve; class QwtPicker; +class QwtText; typedef std::function 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 getVariableValueMap( RiuGuiTheme::ThemeEnum theme ); - static QMap 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 getVariableValueMap( RiaDefines::ThemeEnum theme ); + static QMap 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> s_variableValueMap; - static QMap> s_variableGuiTextMap; + static QMap> s_variableValueMap; + static QMap> s_variableGuiTextMap; static QMap>>> s_qwtPlotItemPropertiesMap; static QMap s_customStyleSheetApplicators; };