Commit 9d969f1f authored by Bryant's avatar Bryant

The style changing UI now works somewhat. Doesn't interact with QSettings yet.

parent ac2522d2
......@@ -68,9 +68,12 @@ This file is part of the QGROUNDCONTROL project
#include "PxQuadMAV.h"
#include "SlugsMAV.h"
#include "LogCompressor.h"
// Set up some constants
const QString MainWindow::defaultDarkStyle = ":files/styles/style-dark.css";
const QString MainWindow::defaultLightStyle = ":files/styles/style-light.css";
MainWindow* MainWindow::instance(QSplashScreen* screen)
{
static MainWindow* _instance = 0;
......@@ -156,7 +159,7 @@ MainWindow::MainWindow(QWidget *parent):
setCorner(Qt::BottomRightCorner, Qt::BottomDockWidgetArea);
// Setup UI state machines
centerStackActionGroup->setExclusive(true);
centerStackActionGroup->setExclusive(true);
centerStack = new QStackedWidget(this);
setCentralWidget(centerStack);
......@@ -1220,45 +1223,31 @@ void MainWindow::enableAutoReconnect(bool enabled)
bool MainWindow::loadStyle(QGC_MAINWINDOW_STYLE style, QString cssFile)
{
qApp->setStyle("plastique");
// Set up the
switch (style)
{
default:
style = QGC_MAINWINDOW_STYLE_DARK;
case QGC_MAINWINDOW_STYLE_DARK:
darkStyleFileName = ":files/styles/style-dark.css";
break;
case QGC_MAINWINDOW_STYLE_LIGHT:
styleFileName = ":files/styles/style-light.css";
break;
case QGC_MAINWINDOW_STYLE_CUSTOM_DARK:
case QGC_MAINWINDOW_STYLE_CUSTOM_LIGHT:
styleFileName = cssFile;
break;
}
currentStyle = style;
qApp->setStyle("plastique");
return loadStyleSheet(styleFileName);
}
// Store the new style classification.
currentStyle = style;
bool MainWindow::loadStyleSheet(QString cssFile)
{
// Load the new stylesheet.
QFile styleSheet(cssFile);
// Attempt to open the stylesheet, replacing the 'ICONDIR' token here with the proper application path.
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);
QString style = QString(styleSheet.readAll());
style.replace("ICONDIR", QCoreApplication::applicationDirPath()+ "files/styles/");
style.replace("ICONDIR", QCoreApplication::applicationDirPath() + "files/styles/");
qApp->setStyleSheet(style);
return true;
// And restore the cursor before returning.
qApp->restoreOverrideCursor();
return true;
}
// Otherwise alert return a failure code.
return false;
return false;
}
/**
......@@ -1499,8 +1488,8 @@ void MainWindow::addLink()
// Go fishing for this link's configuration window
QList<QAction*> actions = ui.menuNetwork->actions();
const int32_t& linkIndex(LinkManager::instance()->getLinks().indexOf(link));
const int32_t& linkID(LinkManager::instance()->getLinks()[linkIndex]->getId());
const int32_t& linkIndex(LinkManager::instance()->getLinks().indexOf(link));
const int32_t& linkID(LinkManager::instance()->getLinks()[linkIndex]->getId());
foreach (QAction* act, actions)
{
......@@ -1526,8 +1515,8 @@ void MainWindow::addLink(LinkInterface *link)
bool found(false);
const int32_t& linkIndex(LinkManager::instance()->getLinks().indexOf(link));
const int32_t& linkID(LinkManager::instance()->getLinks()[linkIndex]->getId());
const int32_t& linkIndex(LinkManager::instance()->getLinks().indexOf(link));
const int32_t& linkID(LinkManager::instance()->getLinks()[linkIndex]->getId());
foreach (QAction* act, actions)
{
......@@ -1614,7 +1603,7 @@ void MainWindow::UASCreated(UASInterface* uas)
QIcon icon;
// Set matching icon
switch (uas->getSystemType())
{
{
case MAV_TYPE_GENERIC:
icon = QIcon(":files/images/mavs/generic.svg");
break;
......
......@@ -104,13 +104,14 @@ public:
enum QGC_MAINWINDOW_STYLE
{
QGC_MAINWINDOW_STYLE_DARK,
QGC_MAINWINDOW_STYLE_LIGHT,
QGC_MAINWINDOW_STYLE_CUSTOM_DARK,
QGC_MAINWINDOW_STYLE_CUSTOM_LIGHT
QGC_MAINWINDOW_STYLE_LIGHT
};
static const QString defaultDarkStyle;
static const QString defaultLightStyle;
/** @brief Get current visual style */
int getStyle()
QGC_MAINWINDOW_STYLE getStyle()
{
return currentStyle;
}
......@@ -202,10 +203,9 @@ public slots:
/** @brief Save power by reducing update rates */
void enableLowPowerMode(bool enabled) { lowPowerMode = enabled; }
/** @brief Load a specific style.
* If it's a custom style, load the file indicated by the cssFile path.
*/
* If it's a custom style, load the file indicated by the cssFile path.
*/
bool loadStyle(QGC_MAINWINDOW_STYLE style, QString cssFile);
bool loadStyleSheet(QString cssFile);
/** @brief Add a custom tool widget */
void createCustomWidget();
......@@ -328,7 +328,7 @@ protected:
void buildCommonWidgets();
void connectCommonWidgets();
void connectCommonActions();
void connectSenseSoarActions();
void connectSenseSoarActions();
void loadSettings();
void storeSettings();
......
......@@ -47,11 +47,11 @@ QGCSettingsWidget::QGCSettingsWidget(QWidget *parent, Qt::WindowFlags flags) :
connect(ui->titleBarCheckBox,SIGNAL(clicked(bool)),MainWindow::instance(),SLOT(enableDockWidgetTitleBars(bool)));
// Style
MainWindow::QGC_MAINWINDOW_STYLE style = (MainWindow::QGC_MAINWINDOW_STYLE)MainWindow::instance()->getStyle();
MainWindow::QGC_MAINWINDOW_STYLE style = MainWindow::instance()->getStyle();
ui->styleChooser->setCurrentIndex(style);
connect(ui->styleChooser, SIGNAL(currentIndexChanged(int)), this, SLOT(styleChanged(int)));
connect(ui->darkStyleCustomButton, SIGNAL(clicked()), this, SLOT(selectStylesheet()));
connect(ui->lightStyleCustomButton, SIGNAL(clicked()), this, SLOT(selectStylesheet()));
connect(ui->styleChooser, SIGNAL(currentIndexChanged(int)), this, SLOT(styleChanged(int)));
connect(ui->styleCustomButton, SIGNAL(clicked()), this, SLOT(selectStylesheet()));
connect(ui->styleDefaultButton, SIGNAL(clicked()), this, SLOT(setDefaultStyle()));
// Close / destroy
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(deleteLater()));
......@@ -65,68 +65,96 @@ QGCSettingsWidget::~QGCSettingsWidget()
void QGCSettingsWidget::selectStylesheet()
{
// Let user select style sheet. The root directory for the file picker is the user's home directory if they haven't loaded a custom style.
// Otherwise it defaults to the directory of that custom file.
QString findDir;
if (MainWindow::instance()->getStyle() == MainWindow::QGC_MAINWINDOW_STYLE_CUSTOM_DARK || MainWindow::instance()->getStyle() == MainWindow::QGC_MAINWINDOW_STYLE_CUSTOM_LIGHT)
{
findDir = QDir::homePath();
}
else
{
findDir = MainWindow::instance()->getStyleSheet();
}
QString newStyleFileName = QFileDialog::getOpenFileName(this, tr("Specify stylesheet"), findDir, tr("CSS Stylesheet (*.css);;"));
// Load the new style sheet if a valid one was selected.
if (!newStyleFileName.isNull())
// Otherwise it defaults to the directory of that custom file.
QString findDir;
QString oldStylesheet(ui->styleSheetFile->text());
QFile styleSheet(oldStylesheet);
if (styleSheet.exists() && oldStylesheet[0] != ':')
{
QFile styleSheet(newStyleFileName);
if (styleSheet.exists())
findDir = styleSheet.fileName();
}
else
{
findDir = QDir::homePath();
}
// Prompt the user to select a new style sheet. Do nothing if they cancel.
QString newStyleFileName = QFileDialog::getOpenFileName(this, tr("Specify stylesheet"), findDir, tr("CSS Stylesheet (*.css);;"));
if (newStyleFileName.isNull()) {
return;
}
// Load the new style sheet if a valid one was selected, notifying the user
// of an error if necessary.
QFile newStyleFile(newStyleFileName);
if (!newStyleFile.exists() || !updateStyle(newStyleFileName))
{
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Information);
msgBox.setText(tr("QGroundControl did not load a new style"));
msgBox.setInformativeText(tr("Stylesheet file %1 was not readable").arg(newStyleFileName));
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec();
}
// And update the UI as needed.
else
{
switch (ui->styleChooser->currentIndex())
{
if (!updateStyle())
{
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Information);
msgBox.setText(tr("QGroundControl did not load a new style"));
msgBox.setInformativeText(tr("Stylesheet file %1 was not readable").arg(newStyleFileName));
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec();
}
case 0:
darkStyleSheet = newStyleFileName;
ui->styleSheetFile->setText(darkStyleSheet);
MainWindow::instance()->loadStyle(MainWindow::QGC_MAINWINDOW_STYLE_DARK, darkStyleSheet);
case 1:
lightStyleSheet = newStyleFileName;
ui->styleSheetFile->setText(lightStyleSheet);
MainWindow::instance()->loadStyle(MainWindow::QGC_MAINWINDOW_STYLE_LIGHT, lightStyleSheet);
}
else
{
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Information);
msgBox.setText(tr("QGroundControl did not load a new style"));
msgBox.setInformativeText(tr("Stylesheet file %1 was not readable").arg(newStyleFileName));
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.exec();
}
}
}
bool QGCSettingsWidget::updateStyle()
bool QGCSettingsWidget::updateStyle(QString style)
{
switch (ui->styleChooser->currentIndex())
{
case 0:
return MainWindow::instance()->loadStyle(MainWindow::QGC_MAINWINDOW_STYLE_DARK, QString());
case 1:
return MainWindow::instance()->loadStyle(MainWindow::QGC_MAINWINDOW_STYLE_LIGHT, QString());
case 2:
return MainWindow::instance()->loadStyle(MainWindow::QGC_MAINWINDOW_STYLE_CUSTOM_DARK, QString());
case 3:
return MainWindow::instance()->loadStyle(MainWindow::QGC_MAINWINDOW_STYLE_CUSTOM_LIGHT, QString());
default:
return false;
}
switch (ui->styleChooser->currentIndex())
{
case 0:
darkStyleSheet = style;
return MainWindow::instance()->loadStyle(MainWindow::QGC_MAINWINDOW_STYLE_DARK, darkStyleSheet);
case 1:
lightStyleSheet = style;
return MainWindow::instance()->loadStyle(MainWindow::QGC_MAINWINDOW_STYLE_LIGHT, lightStyleSheet);
default:
return false;
}
}
void QGCSettingsWidget::styleChanged(int index)
{
// And trigger a style update.
updateStyle();
}
\ No newline at end of file
{
if (index == 1)
{
ui->styleSheetFile->setText(lightStyleSheet);
updateStyle(lightStyleSheet);
}
else
{
ui->styleSheetFile->setText(darkStyleSheet);
updateStyle(darkStyleSheet);
}
}
void QGCSettingsWidget::setDefaultStyle()
{
if (ui->styleChooser->currentIndex() == 1)
{
lightStyleSheet = MainWindow::defaultLightStyle;
ui->styleSheetFile->setText(lightStyleSheet);
updateStyle(lightStyleSheet);
}
else
{
darkStyleSheet = MainWindow::defaultDarkStyle;
ui->styleSheetFile->setText(darkStyleSheet);
updateStyle(darkStyleSheet);
}
}
......@@ -17,12 +17,15 @@ public:
~QGCSettingsWidget();
public slots:
void styleChanged(int index);
void styleChanged(int index);
void setDefaultStyle();
void selectStylesheet();
private:
Ui::QGCSettingsWidget *ui;
void selectStylesheet();
bool updateStyle();
Ui::QGCSettingsWidget* ui;
QString darkStyleSheet;
QString lightStyleSheet;
bool updateStyle(QString style);
};
#endif // QGCSETTINGSWIDGET_H
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>392</width>
<height>313</height>
<width>528</width>
<height>321</height>
</rect>
</property>
<property name="sizePolicy">
......@@ -77,38 +77,18 @@
<property name="title">
<string>Style</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Use:</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QComboBox" name="styleChooser">
<item>
......@@ -128,41 +108,7 @@
<item>
<layout class="QHBoxLayout" name="DarkStyleLayout">
<item>
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Dark:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="darkStyleFile"/>
</item>
<item>
<widget class="QPushButton" name="darkStyleCustomButton">
<property name="text">
<string>Custom</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="darkStyleDefaultButton">
<property name="text">
<string>Default</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="LightStyleLayout">
<item>
<widget class="QLabel" name="label_3">
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
......@@ -170,22 +116,22 @@
</sizepolicy>
</property>
<property name="text">
<string>Light:</string>
<string>Stylesheet:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lightStyleFile"/>
<widget class="QLineEdit" name="styleSheetFile"/>
</item>
<item>
<widget class="QPushButton" name="lightStyleCustomButton">
<widget class="QPushButton" name="styleCustomButton">
<property name="text">
<string>Custom</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="lightStyleDefaultButton">
<widget class="QPushButton" name="styleDefaultButton">
<property name="text">
<string>Default</string>
</property>
......
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