#6514 Dark Theme : Move define to RiaDefines

This commit is contained in:
Magne Sjaastad 2020-09-16 11:55:28 +02:00 committed by Gaute Lindkvist
parent 87bc6acd65
commit 4841d19d02
8 changed files with 353 additions and 353 deletions

View File

@ -114,6 +114,16 @@ void caf::AppEnum<RiaDefines::GridCaseAxis>::setUp()
setDefault( RiaDefines::GridCaseAxis::AXIS_K );
}
template <>
void caf::AppEnum<RiaDefines::ThemeEnum>::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
//--------------------------------------------------------------------------------------------------

View File

@ -215,4 +215,11 @@ enum class GridCaseAxis
UNDEFINED_AXIS
};
enum class ThemeEnum
{
DEFAULT,
DARK,
LIGHT
};
}; // namespace RiaDefines

View File

@ -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"

View File

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

View File

@ -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<RiaDefines::FontSettingType, RiaFontCache::FontSize> defaultFontSizes() const;
@ -215,7 +214,7 @@ private:
caf::PdmField<bool> m_showProgressBar;
caf::PdmField<QString> m_gtestFilter;
caf::PdmField<caf::AppEnum<RiuGuiTheme::ThemeEnum>> m_guiTheme;
caf::PdmField<caf::AppEnum<RiaDefines::ThemeEnum>> m_guiTheme;
caf::PdmField<PageSizeEnum> m_pageSize;
caf::PdmField<PageOrientationEnum> m_pageOrientation;

View File

@ -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 <QAction>
@ -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<RiuGuiTheme::ThemeEnum> themes;
QComboBox* themeSelector = new QComboBox();
caf::AppEnum<RiaDefines::ThemeEnum> themes;
for ( size_t index = 0; index < themes.size(); index++ )
{
themeSelector->addItem( themes.uiTextFromIndex( index ), QVariant::fromValue( index ) );
if ( static_cast<RiuGuiTheme::ThemeEnum>( index ) == theme )
if ( static_cast<RiaDefines::ThemeEnum>( index ) == theme )
{
themeSelector->setCurrentIndex( static_cast<int>( 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<RiuGuiTheme::ThemeEnum>( themeSelector->currentData().toInt() );
RiaDefines::ThemeEnum theme = static_cast<RiaDefines::ThemeEnum>( themeSelector->currentData().toInt() );
QMap<QString, QString> variableValueMap = RiuGuiTheme::getVariableValueMap( theme );
QMap<QString, QString> variableGuiTextMap = RiuGuiTheme::getVariableGuiTextMap( theme );
for ( const QString variableName : variableValueMap.keys() )
@ -139,8 +141,8 @@ void RicThemeColorEditorFeature::onActionTriggered( bool isChecked )
// connect( themeSelector, qOverload<int>( &QComboBox::currentIndexChanged ), [=]() {
connect( themeSelector, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), [=]() {
generateColorFields();
RiuGuiTheme::ThemeEnum theme = static_cast<RiuGuiTheme::ThemeEnum>( themeSelector->currentData().toInt() );
RiuGuiTheme::updateGuiTheme( static_cast<RiuGuiTheme::ThemeEnum>( theme ) );
RiaDefines::ThemeEnum theme = static_cast<RiaDefines::ThemeEnum>( themeSelector->currentData().toInt() );
RiuGuiTheme::updateGuiTheme( static_cast<RiaDefines::ThemeEnum>( 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<RiuGuiTheme::ThemeEnum>( themeSelector->currentData().toInt() );
RiaDefines::ThemeEnum theme = static_cast<RiaDefines::ThemeEnum>( themeSelector->currentData().toInt() );
RiuGuiTheme::writeStyleSheetToFile( theme, editor->toPlainText() );
generateColorFields();
} );

View File

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

View File

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