Dark Mode

This commit is contained in:
Chris Esposito 2021-06-04 15:55:20 +10:00
parent 2aa9340c03
commit 19454671e2
4 changed files with 86 additions and 8 deletions

View File

@ -31,6 +31,9 @@ MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
defaultPalette = qApp->palette();
defaultStyleName = qApp->style()->objectName();
QCoreApplication::setOrganizationName(kOrganisationName);
QCoreApplication::setApplicationName(kApplicationName);
@ -1247,6 +1250,12 @@ void MainWindow::readSettingsFile(){
ui->actionShow_Range_Dialog_on_Main_Page->setChecked(true);
on_actionShow_Range_Dialog_on_Main_Page_triggered(true);
}
if(settings->value("DarkModeEnabled").toBool())
{
ui->actionDark_Mode->setChecked(true);
setDarkMode(true);
}
#endif
daq_num_to_average = settings->value("daq_defaultAverage", 1).toInt();
@ -2511,3 +2520,50 @@ void MainWindow::on_actionHide_Widget_LogicAnalyzer_triggered(bool checked)
ui->busSnifferGroup_CH2->setVisible(!checked);
ui->digitalOutputGroup->setVisible(!checked);
}
// Thanks Medo
// https://www.medo64.com/2020/08/dark-mode-for-qt-application/
void MainWindow::setDarkMode(bool dark)
{
if(dark)
{
qApp->setStyle(QStyleFactory::create("Fusion"));
QPalette newPalette;
newPalette.setColor(QPalette::Window, QColor( 37, 37, 37));
newPalette.setColor(QPalette::WindowText, QColor(212, 212, 212));
newPalette.setColor(QPalette::Base, QColor( 60, 60, 60));
newPalette.setColor(QPalette::AlternateBase, QColor( 45, 45, 45));
newPalette.setColor(QPalette::PlaceholderText, QColor(127, 127, 127));
newPalette.setColor(QPalette::Text, QColor(212, 212, 212));
newPalette.setColor(QPalette::Button, QColor( 45, 45, 45));
newPalette.setColor(QPalette::ButtonText, QColor(212, 212, 212));
newPalette.setColor(QPalette::BrightText, QColor(240, 240, 240));
newPalette.setColor(QPalette::Highlight, QColor( 38, 79, 120));
newPalette.setColor(QPalette::HighlightedText, QColor(240, 240, 240));
newPalette.setColor(QPalette::Light, QColor( 60, 60, 60));
newPalette.setColor(QPalette::Midlight, QColor( 52, 52, 52));
newPalette.setColor(QPalette::Dark, QColor( 30, 30, 30) );
newPalette.setColor(QPalette::Mid, QColor( 37, 37, 37));
newPalette.setColor(QPalette::Shadow, QColor( 0, 0, 0));
newPalette.setColor(QPalette::Disabled, QPalette::Text, QColor(127, 127, 127));
qApp->setPalette(newPalette);
}
else
{
qApp->setStyle(defaultStyleName);
qApp->setPalette(defaultPalette);
}
QSettings settings;
settings.setValue("DarkModeEnabled", dark);
}
void MainWindow::on_actionDark_Mode_triggered(bool checked)
{
setDarkMode(checked);
}

View File

@ -227,6 +227,8 @@ private slots:
void on_actionHide_Widget_LogicAnalyzer_triggered(bool checked);
void on_actionDark_Mode_triggered(bool checked);
private:
//Generic Vars
Ui::MainWindow *ui;
@ -247,12 +249,16 @@ private:
QSettings *settings;
bool calibrationCanceled = false;
QPalette defaultPalette;
QString defaultStyleName;
//Generic Functions
void initialisePlot();
void labelPsu();
void menuSetup();
void initShortcuts();
void readSettingsFile();
void setDarkMode(bool dark);
//Shortcut pointers
QActionGroup *gainGroup;

View File

@ -1,21 +1,22 @@
#include "deviceconnecteddisplay.h"
#include "platformspecific.h"
#include <QApplication>
deviceConnectedDisplay::deviceConnectedDisplay(QWidget *parent) : QLabel(parent)
{
this->setText("Device Not Connected!");
this->setStyleSheet("QLabel { color:red; }");
setText("Device Not Connected!");
setStyleSheet("QLabel { color:red; }");
}
void deviceConnectedDisplay::connectedStatusChanged(bool status){
qDebug() << "deviceConnectedDisplay::connectedStatusChanged running!";
if(status){
this->setText("Device Connected");
this->setStyleSheet("QLabel { color:black; }");
setText("Device Connected");
setStyleSheet("");
}
else{
this->setText("Device Not Connected!");
this->setStyleSheet("QLabel { color:red; }");
setText("Device Not Connected!");
setStyleSheet("QLabel { color:red; }");
}
#ifdef PLATFORM_ANDROID
this->setVisible(!status);
@ -24,6 +25,6 @@ void deviceConnectedDisplay::connectedStatusChanged(bool status){
void deviceConnectedDisplay::flashingFirmware(void){
qDebug() << "deviceConnectedDisplay::flashingFirmware";
this->setText("Flashing Device Firmware");
this->setStyleSheet("QLabel { color:green; }");
setText("Flashing Device Firmware");
setStyleSheet("QLabel { color:green; }");
}

View File

@ -1797,6 +1797,12 @@
<addaction name="separator"/>
<addaction name="actionHide_Widget_SignalGen"/>
</widget>
<widget class="QMenu" name="menuAccessibility">
<property name="title">
<string>Accessibility</string>
</property>
<addaction name="actionDark_Mode"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuOscilloscope_2"/>
<addaction name="menuSignal_Generator"/>
@ -1805,6 +1811,7 @@
<addaction name="menuPower_Supply"/>
<addaction name="menuConnection_Type"/>
<addaction name="menuHelp"/>
<addaction name="menuAccessibility"/>
</widget>
<action name="actionGainAuto">
<property name="checkable">
@ -2629,6 +2636,14 @@
<string>Hide Widget</string>
</property>
</action>
<action name="actionDark_Mode">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Dark Mode</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>