Commit 34e85677 authored by Don Gagne's avatar Don Gagne

Create master/slave relationship for styles

The dark css is the master and contains all style information. The
light css is the slave and only contains color information.
parent a16ca740
/*
This is the master style sheet as well as the dark style. This style sheet should contain both
color and size/positioning information for all styled controls. This sheet is always loaded first
Then the user specified style sheet is loaded after it to override and color settings.
*/
* { * {
background-color: #222; background-color: #222;
color: #FFF; color: #FFF;
......
This diff is collapsed.
...@@ -1067,41 +1067,62 @@ void MainWindow::enableAutoReconnect(bool enabled) ...@@ -1067,41 +1067,62 @@ void MainWindow::enableAutoReconnect(bool enabled)
bool MainWindow::loadStyle(QGC_MAINWINDOW_STYLE style, QString cssFile) bool MainWindow::loadStyle(QGC_MAINWINDOW_STYLE style, QString cssFile)
{ {
bool success = true;
QString styles;
static const char* masterCssFile = ":/files/styles/style-dark.css";
// Signal to the user that the app will pause to apply a new stylesheet
qApp->setOverrideCursor(Qt::WaitCursor);
// Store the new style classification. // Store the new style classification.
currentStyle = style; currentStyle = style;
// The dark style sheet is the master. Any other selected style sheet just overrides
// the colors of the master sheet.
QFile masterStyleSheet(masterCssFile);
if (masterStyleSheet.open(QIODevice::ReadOnly | QIODevice::Text)) {
styles = masterStyleSheet.readAll();
} else {
qDebug() << "Unable to load master style sheet";
success = false;
goto Error;
}
// Load the new stylesheet. if (cssFile != masterCssFile) {
QFile styleSheet(cssFile); // Load the slave user specified stylesheet.
QFile styleSheet(cssFile);
if (styleSheet.open(QIODevice::ReadOnly | QIODevice::Text))
{
styles += styleSheet.readAll();
// Attempt to open the stylesheet. qApp->setStyleSheet(styles);
if (styleSheet.open(QIODevice::ReadOnly | QIODevice::Text))
{
// Signal to the user that the app will pause to apply a new stylesheet
qApp->setOverrideCursor(Qt::WaitCursor);
qApp->setStyleSheet(styleSheet.readAll()); // And save the new stylesheet path.
if (currentStyle == QGC_MAINWINDOW_STYLE_LIGHT)
{
lightStyleFileName = cssFile;
}
else
{
darkStyleFileName = cssFile;
}
// And save the new stylesheet path. // And trigger any changes to other UI elements that are watching for
if (currentStyle == QGC_MAINWINDOW_STYLE_LIGHT) // theme changes.
{ emit styleChanged(style);
lightStyleFileName = cssFile; } else {
} qDebug() << "Unable to load slave style sheet:" << cssFile;
else success = false;
{ goto Error;
darkStyleFileName = cssFile;
} }
// And trigger any changes to other UI elements that are watching for
// theme changes.
emit styleChanged(style);
// Finally restore the cursor before returning.
qApp->restoreOverrideCursor();
return true;
} }
// Otherwise alert return a failure code. Error:
return false; // Finally restore the cursor before returning.
qApp->restoreOverrideCursor();
return success;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment