From 2d61e288bbc4fd7022fbae0ddbf23acb08e26e1a Mon Sep 17 00:00:00 2001 From: Bryant Date: Mon, 20 May 2013 16:23:08 -0700 Subject: [PATCH] Reworked the styling UI. Now there are 4 options: light, dark, custom_light, and custom_dark. Things don't quite work right, but the proof-of-concept is done. --- src/ui/MainWindow.cc | 106 +++++++++------------------------- src/ui/MainWindow.h | 30 +++++----- src/ui/MainWindow.ui | 27 +-------- src/ui/QGCSettingsWidget.cc | 103 +++++++++++++++++++++++++++------ src/ui/QGCSettingsWidget.h | 3 + src/ui/QGCSettingsWidget.ui | 110 ++++++++++++++++++++++++++---------- 6 files changed, 212 insertions(+), 167 deletions(-) diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index e8bd78e53..2d46cfd38 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -96,7 +96,7 @@ MainWindow* MainWindow::instance(QSplashScreen* screen) MainWindow::MainWindow(QWidget *parent): QMainWindow(parent), currentView(VIEW_FLIGHT), - currentStyle(QGC_MAINWINDOW_STYLE_INDOOR), + currentStyle(QGC_MAINWINDOW_STYLE_DARK), aboutToCloseFlag(false), changingViewsFlag(false), centerStackActionGroup(new QActionGroup(this)), @@ -111,7 +111,7 @@ MainWindow::MainWindow(QWidget *parent): loadSettings(); emit initStatusChanged("Loading Style."); - loadStyle(currentStyle); + loadStyle(currentStyle, QString()); if (settings.contains("ADVANCED_MODE")) { @@ -182,8 +182,6 @@ MainWindow::MainWindow(QWidget *parent): setStatusBar(customStatusBar); statusBar()->setSizeGripEnabled(true); - - emit initStatusChanged("Building common widgets."); buildCommonWidgets(); @@ -1220,96 +1218,47 @@ void MainWindow::enableAutoReconnect(bool enabled) autoReconnect = enabled; } -void MainWindow::loadNativeStyle() -{ - loadStyle(QGC_MAINWINDOW_STYLE_NATIVE); -} - -void MainWindow::loadIndoorStyle() +bool MainWindow::loadStyle(QGC_MAINWINDOW_STYLE style, QString cssFile) { - loadStyle(QGC_MAINWINDOW_STYLE_INDOOR); -} - -void MainWindow::loadOutdoorStyle() -{ - loadStyle(QGC_MAINWINDOW_STYLE_OUTDOOR); -} - -void MainWindow::loadStyle(QGC_MAINWINDOW_STYLE style) -{ - switch (style) { - case QGC_MAINWINDOW_STYLE_NATIVE: { - // Native mode means setting no style - // so if we were already in native mode - // take no action - // Only if a style was set, remove it. - if (style != currentStyle) { - qApp->setStyleSheet(""); - showInfoMessage(tr("Please restart QGroundControl"), tr("Please restart QGroundControl to switch to fully native look and feel. Currently you have loaded Qt's plastique style.")); - } - } - break; - case QGC_MAINWINDOW_STYLE_INDOOR: qApp->setStyle("plastique"); - styleFileName = ":files/styles/style-indoor.css"; - reloadStylesheet(); + + // Set up the + switch (style) + { + default: + style = QGC_MAINWINDOW_STYLE_DARK; + case QGC_MAINWINDOW_STYLE_DARK: + styleFileName = ":files/styles/style-dark.css"; break; - case QGC_MAINWINDOW_STYLE_OUTDOOR: - qApp->setStyle("plastique"); - styleFileName = ":files/styles/style-outdoor.css"; - reloadStylesheet(); + 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; -} - -void MainWindow::selectStylesheet() -{ - // Let user select style sheet - QString newStyleFileName = QFileDialog::getOpenFileName(this, tr("Specify stylesheet"), styleFileName, tr("CSS Stylesheet (*.css);;")); - // Load the new style sheet if a valid one was selected. - if (!newStyleFileName.isNull()) - { - QFile styleSheet(newStyleFileName); - if (styleSheet.exists()) - { - styleFileName = newStyleFileName; - reloadStylesheet(); - } - } + return loadStyleSheet(styleFileName); } -void MainWindow::reloadStylesheet() +bool MainWindow::loadStyleSheet(QString cssFile) { - // Load style sheet - QFile styleSheet(styleFileName); - - // Default to the indoor stylesheet if an invalid stylesheet was chosen. - if (!styleSheet.exists()) - { - styleSheet.setFileName(":files/styles/style-indoor.css"); - } - // Load the new stylesheet. - // We also replace an 'ICONDIR' token here with the proper application path. + 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)) { QString style = QString(styleSheet.readAll()); style.replace("ICONDIR", QCoreApplication::applicationDirPath()+ "files/styles/"); qApp->setStyleSheet(style); + return true; } - // Otherwise alert the user to the failure. - 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(styleFileName)); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - msgBox.exec(); - } + + // Otherwise alert return a failure code. + return false; } /** @@ -1450,9 +1399,6 @@ void MainWindow::connectCommonActions() connect(ui.actionFirmwareUpdateView, SIGNAL(triggered()), this, SLOT(loadFirmwareUpdateView())); connect(ui.actionMavlinkView, SIGNAL(triggered()), this, SLOT(loadMAVLinkView())); - connect(ui.actionReloadStylesheet, SIGNAL(triggered()), this, SLOT(reloadStylesheet())); - connect(ui.actionSelectStylesheet, SIGNAL(triggered()), this, SLOT(selectStylesheet())); - // Help Actions connect(ui.actionOnline_Documentation, SIGNAL(triggered()), this, SLOT(showHelp())); connect(ui.actionDeveloper_Credits, SIGNAL(triggered()), this, SLOT(showCredits())); diff --git a/src/ui/MainWindow.h b/src/ui/MainWindow.h index 06264b9dc..58d9eee8e 100644 --- a/src/ui/MainWindow.h +++ b/src/ui/MainWindow.h @@ -103,9 +103,10 @@ public: enum QGC_MAINWINDOW_STYLE { - QGC_MAINWINDOW_STYLE_NATIVE, - QGC_MAINWINDOW_STYLE_INDOOR, - QGC_MAINWINDOW_STYLE_OUTDOOR + QGC_MAINWINDOW_STYLE_DARK, + QGC_MAINWINDOW_STYLE_LIGHT, + QGC_MAINWINDOW_STYLE_CUSTOM_DARK, + QGC_MAINWINDOW_STYLE_CUSTOM_LIGHT }; /** @brief Get current visual style */ @@ -113,6 +114,12 @@ public: { return currentStyle; } + + /** @brief Get current visual style */ + QString getStyleSheet() + { + return styleFileName; + } /** @brief Get auto link reconnect setting */ bool autoReconnectEnabled() { @@ -188,24 +195,17 @@ public slots: /** @brief Show the project roadmap */ void showRoadMap(); - /** @brief Reload the CSS style sheet */ - void reloadStylesheet(); - /** @brief Let the user select the CSS style sheet */ - void selectStylesheet(); /** @breif Enable title bars on dock widgets when no in advanced mode */ void enableDockWidgetTitleBars(bool enabled); /** @brief Automatically reconnect last link */ void enableAutoReconnect(bool enabled); /** @brief Save power by reducing update rates */ void enableLowPowerMode(bool enabled) { lowPowerMode = enabled; } - /** @brief Switch to native application style */ - void loadNativeStyle(); - /** @brief Switch to indoor mission style */ - void loadIndoorStyle(); - /** @brief Switch to outdoor mission style */ - void loadOutdoorStyle(); - /** @brief Load a specific style */ - void loadStyle(QGC_MAINWINDOW_STYLE style); + /** @brief Load a specific style. + * 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(); diff --git a/src/ui/MainWindow.ui b/src/ui/MainWindow.ui index 4d16d9f33..73f38cea0 100644 --- a/src/ui/MainWindow.ui +++ b/src/ui/MainWindow.ui @@ -51,27 +51,19 @@ 0 0 800 - 22 + 21 File - - - Display - - - - - @@ -321,15 +313,6 @@ Meta+M - - - - :/files/images/categories/applications-internet.svg:/files/images/categories/applications-internet.svg - - - Select Stylesheet - - true @@ -400,14 +383,6 @@ Shutdown the onboard computer - works not during flight - - - Reload Stylesheet - - - Meta+R - - Settings diff --git a/src/ui/QGCSettingsWidget.cc b/src/ui/QGCSettingsWidget.cc index f5fb0a6d0..a4d676f26 100644 --- a/src/ui/QGCSettingsWidget.cc +++ b/src/ui/QGCSettingsWidget.cc @@ -17,6 +17,9 @@ QGCSettingsWidget::QGCSettingsWidget(QWidget *parent, Qt::WindowFlags flags) : { ui->setupUi(this); + // Set the frame holding the options for the custom style frame to hidden by default + ui->customStyleFrame->setVisible(false); + // Add all protocols QList protocols = LinkManager::instance()->getProtocols(); foreach (ProtocolInterface* protocol, protocols) { @@ -48,29 +51,95 @@ QGCSettingsWidget::QGCSettingsWidget(QWidget *parent, Qt::WindowFlags flags) : // Style MainWindow::QGC_MAINWINDOW_STYLE style = (MainWindow::QGC_MAINWINDOW_STYLE)MainWindow::instance()->getStyle(); - switch (style) { - case MainWindow::QGC_MAINWINDOW_STYLE_NATIVE: - ui->nativeStyle->setChecked(true); - break; - case MainWindow::QGC_MAINWINDOW_STYLE_INDOOR: - ui->indoorStyle->setChecked(true); - break; - case MainWindow::QGC_MAINWINDOW_STYLE_OUTDOOR: - ui->outdoorStyle->setChecked(true); - break; - } - connect(ui->nativeStyle, SIGNAL(clicked()), MainWindow::instance(), SLOT(loadNativeStyle())); - connect(ui->indoorStyle, SIGNAL(clicked()), MainWindow::instance(), SLOT(loadIndoorStyle())); - connect(ui->outdoorStyle, SIGNAL(clicked()), MainWindow::instance(), SLOT(loadOutdoorStyle())); + ui->styleChooser->setCurrentIndex(style); + connect(ui->styleChooser, SIGNAL(currentIndexChanged(int)), this, SLOT(styleChanged(int))); + connect(ui->customStyleFileButton, SIGNAL(clicked()), this, SLOT(selectStylesheet())); // Close / destroy connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(deleteLater())); - - // Set layout options - ui->generalPaneGridLayout->setAlignment(Qt::AlignTop); } QGCSettingsWidget::~QGCSettingsWidget() { delete ui; } + +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()) + { + QFile styleSheet(newStyleFileName); + if (styleSheet.exists()) + { + 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(); + } + } + 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() +{ + 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; + } +} + +void QGCSettingsWidget::styleChanged(int index) +{ + // If a custom style is selected, enable the advanced view for the custom stylesheet. Otherwise, + // make sure it's hidden. + if (index == 2 || index == 3) + { + ui->customStyleFrame->setVisible(true); + } + else + { + ui->customStyleFrame->setVisible(false); + } + + // And trigger a style update. + updateStyle(); +} \ No newline at end of file diff --git a/src/ui/QGCSettingsWidget.h b/src/ui/QGCSettingsWidget.h index 5537c5808..9ee73151a 100644 --- a/src/ui/QGCSettingsWidget.h +++ b/src/ui/QGCSettingsWidget.h @@ -17,9 +17,12 @@ public: ~QGCSettingsWidget(); public slots: + void styleChanged(int index); private: Ui::QGCSettingsWidget *ui; + void selectStylesheet(); + bool updateStyle(); }; #endif // QGCSETTINGSWIDGET_H diff --git a/src/ui/QGCSettingsWidget.ui b/src/ui/QGCSettingsWidget.ui index a26ae5f7b..86ed8f065 100644 --- a/src/ui/QGCSettingsWidget.ui +++ b/src/ui/QGCSettingsWidget.ui @@ -10,6 +10,12 @@ 427 + + + 0 + 0 + + Dialog @@ -23,8 +29,8 @@ General Settings - - + + Mute all audio output @@ -35,7 +41,7 @@ - + Automatically reconnect last link on application startup @@ -46,31 +52,7 @@ - - - - Use native platform look and feel (Windows/Linux/Mac OS) - - - true - - - - - - - Use indoor mission style (black background) - - - - - - - Use outdoor mission style (light background) - - - - + Lowers all update rates to save battery power @@ -80,7 +62,7 @@ - + Show Docked Widget title bars when NOT in advanced Mode. @@ -90,6 +72,76 @@ + + + + + 0 + 0 + + + + QFrame::Box + + + QFrame::Sunken + + + + + + + Dark (for indoor use) + + + + + Light (for outdoor use) + + + + + Custom dark (for indoor use) + + + + + Custom light (for outdoor use) + + + + + + + + + 0 + 0 + + + + QFrame::NoFrame + + + QFrame::Plain + + + + + + + + + Select + + + + + + + + + -- 2.22.0