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;
color: #FFF;
......
This diff is collapsed.
......@@ -1067,19 +1067,36 @@ void MainWindow::enableAutoReconnect(bool enabled)
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.
currentStyle = style;
// Load the new stylesheet.
QFile styleSheet(cssFile);
// 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;
}
// Attempt to open the stylesheet.
if (cssFile != masterCssFile) {
// Load the slave user specified stylesheet.
QFile styleSheet(cssFile);
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());
styles += styleSheet.readAll();
qApp->setStyleSheet(styles);
// And save the new stylesheet path.
if (currentStyle == QGC_MAINWINDOW_STYLE_LIGHT)
......@@ -1094,14 +1111,18 @@ bool MainWindow::loadStyle(QGC_MAINWINDOW_STYLE style, QString cssFile)
// And trigger any changes to other UI elements that are watching for
// theme changes.
emit styleChanged(style);
} else {
qDebug() << "Unable to load slave style sheet:" << cssFile;
success = false;
goto Error;
}
}
Error:
// Finally restore the cursor before returning.
qApp->restoreOverrideCursor();
return true;
}
// Otherwise alert return a failure code.
return false;
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