Fix the remaining issues with dark theme (Label offsets, Quick colors, Borders, QDialogs, and any others I may be forgetting)

This commit is contained in:
CoffeeIsLife 2020-11-26 23:23:53 +00:00 committed by Adam Honse
parent fd3f2c50cb
commit 5b76b83433
6 changed files with 179 additions and 75 deletions

View file

@ -16,6 +16,9 @@
<layout class="QGridLayout" name="gridLayout">
<item row="12" column="8">
<widget class="QPushButton" name="ButtonCyan">
<property name="styleSheet">
<string notr="true">background-color: #00ffff</string>
</property>
<property name="text">
<string/>
</property>
@ -43,6 +46,9 @@
</item>
<item row="12" column="9">
<widget class="QPushButton" name="ButtonBlue">
<property name="styleSheet">
<string notr="true">background-color: #0000ff</string>
</property>
<property name="text">
<string/>
</property>
@ -64,6 +70,9 @@
</item>
<item row="12" column="6">
<widget class="QPushButton" name="ButtonYellow">
<property name="styleSheet">
<string notr="true">background-color: #ffff00</string>
</property>
<property name="text">
<string/>
</property>
@ -122,6 +131,9 @@
</item>
<item row="12" column="5">
<widget class="QPushButton" name="ButtonRed">
<property name="styleSheet">
<string notr="true">background-color: #ff0000</string>
</property>
<property name="text">
<string/>
</property>
@ -164,6 +176,9 @@
</item>
<item row="12" column="10">
<widget class="QPushButton" name="ButtonMagenta">
<property name="styleSheet">
<string notr="true">background-color: #ff00ff</string>
</property>
<property name="text">
<string/>
</property>
@ -220,6 +235,9 @@
</item>
<item row="12" column="7">
<widget class="QPushButton" name="ButtonGreen">
<property name="styleSheet">
<string notr="true">background-color: #00ff00</string>
</property>
<property name="text">
<string/>
</property>

View file

@ -86,6 +86,61 @@ static void UpdateDetectionProgressCallback(void * this_ptr)
QMetaObject::invokeMethod(this_obj, "onDetectionProgressUpdated", Qt::QueuedConnection);
}
bool OpenRGBDialog2::IsDarkTheme()
{
#ifdef _WIN32
/*-------------------------------------------------*\
| Windows dark theme settings |
\*-------------------------------------------------*/
json theme_settings;
/*-------------------------------------------------*\
| Get prefered theme from settings manager |
\*-------------------------------------------------*/
theme_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("Setting_Theme");
/*-------------------------------------------------*\
| Read the theme key and adjust accordingly |
\*-------------------------------------------------*/
std::string current_theme = "light";
if(theme_settings.contains("theme"))
{
current_theme = theme_settings["theme"];
}
if((current_theme == "auto") || (current_theme == "dark"))
{
if(current_theme == "auto")
{
QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", QSettings::NativeFormat);
if(settings.value("AppsUseLightTheme") != 0)
{
return false;
}
else if(settings.value("AppsUseLightTheme") == 0)
{
return true;
}
}
else if(current_theme == "dark")
{
return true;
}
}
return false;
#else
if(QPalette().window().color().value() < 127)
{
return true;
}
#endif
return false;
}
OpenRGBDialog2::OpenRGBDialog2(std::vector<i2c_smbus_interface *>& bus, std::vector<RGBController *>& control, QWidget *parent) : QMainWindow(parent), busses(bus), controllers(control), ui(new OpenRGBDialog2Ui)
{
ui->setupUi(this);
@ -154,7 +209,7 @@ OpenRGBDialog2::OpenRGBDialog2(std::vector<i2c_smbus_interface *>& bus, std::vec
QAction* actionQuickBlue = new QAction("Blue", this);
connect(actionQuickBlue, SIGNAL(triggered()), this, SLOT(on_QuickBlue()));
quickColorsMenu->addAction(actionQuickBlue);
QAction* actionQuickMagenta = new QAction("Magenta", this);
connect(actionQuickMagenta, SIGNAL(triggered()), this, SLOT(on_QuickMagenta()));
quickColorsMenu->addAction(actionQuickMagenta);
@ -177,62 +232,20 @@ OpenRGBDialog2::OpenRGBDialog2(std::vector<i2c_smbus_interface *>& bus, std::vec
trayIcon->setToolTip("OpenRGB");
trayIcon->setContextMenu(trayIconMenu);
trayIcon->show();
darkTheme = palette().window().color().value() < 127; // Adjust
#ifdef _WIN32
/*-------------------------------------------------*\
| Windows dark theme settings |
| Apply dark theme on Windows if configured |
\*-------------------------------------------------*/
json theme_settings;
/*-------------------------------------------------*\
| Get prefered theme from settings manager |
\*-------------------------------------------------*/
theme_settings = ResourceManager::get()->GetSettingsManager()->GetSettings("Setting_Theme");
/*-------------------------------------------------*\
| Read the theme key and adjust accordingly |
\*-------------------------------------------------*/
std::string current_theme = "light";
if(theme_settings.contains("theme"))
if(IsDarkTheme())
{
current_theme = theme_settings["theme"];
}
if((current_theme == "auto") || (current_theme == "dark"))
{
darkTheme = true;
if(current_theme == "auto")
{
QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", QSettings::NativeFormat);
if(settings.value("AppsUseLightTheme") != 0)
{
darkTheme = false;
}
}
/*-------------------------------------------------*\
| Apply dark theme on Windows if configured |
\*-------------------------------------------------*/
if(darkTheme)
{
darkTheme = 1;
QPalette pal = palette();
pal.setColor(QPalette::WindowText, Qt::white);
QApplication::setPalette(pal);
QFile darkTheme(":/windows_dark.qss");
darkTheme.open(QFile::ReadOnly);
setStyleSheet(darkTheme.readAll());
}
}
else if (current_theme == "light")
{
/*-----------------------------------------------------------------*\
| It defaults to light theme so just an empty statement should work |
\*-----------------------------------------------------------------*/
QPalette pal = palette();
pal.setColor(QPalette::WindowText, Qt::white);
QApplication::setPalette(pal);
QFile darkTheme(":/windows_dark.qss");
darkTheme.open(QFile::ReadOnly);
setStyleSheet(darkTheme.readAll());
}
#endif
@ -293,13 +306,20 @@ void OpenRGBDialog2::AddSoftwareInfoPage()
QString SoftwareLabelString = "<html><table><tr><td width='30'><img src='";
SoftwareLabelString += ":/software";
if(darkTheme) SoftwareLabelString += "_dark";
if(IsDarkTheme()) SoftwareLabelString += "_dark";
SoftwareLabelString += ".png' height='16' width='16'></td><td>Software</td></tr></table></html>";
QLabel *SoftwareTabLabel = new QLabel();
SoftwareTabLabel->setText(SoftwareLabelString);
SoftwareTabLabel->setIndent(20);
SoftwareTabLabel->setGeometry(0, 0, 200, 20);
if(IsDarkTheme())
{
SoftwareTabLabel->setGeometry(0, 25, 200, 50);
}
else
{
SoftwareTabLabel->setGeometry(0, 0, 200, 25);
}
ui->InformationTabBar->tabBar()->setTabButton(ui->InformationTabBar->tabBar()->count() - 1, QTabBar::LeftSide, SoftwareTabLabel);
}
@ -320,14 +340,20 @@ void OpenRGBDialog2::AddI2CToolsPage()
QString SMBusToolsLabelString = "<html><table><tr><td width='30'><img src='";
SMBusToolsLabelString += ":/tools";
if(darkTheme) SMBusToolsLabelString += "_dark";
if(IsDarkTheme()) SMBusToolsLabelString += "_dark";
SMBusToolsLabelString += ".png' height='16' width='16'></td><td>SMBus Tools</td></tr></table></html>";
QLabel *SMBusToolsTabLabel = new QLabel();
SMBusToolsTabLabel->setText(SMBusToolsLabelString);
SMBusToolsTabLabel->setIndent(20);
SMBusToolsTabLabel->setGeometry(0, 0, 200, 20);
if(IsDarkTheme())
{
SMBusToolsTabLabel->setGeometry(0, 25, 200, 50);
}
else
{
SMBusToolsTabLabel->setGeometry(0, 0, 200, 25);
}
ui->InformationTabBar->tabBar()->setTabButton(ui->InformationTabBar->tabBar()->count() - 1, QTabBar::LeftSide, SMBusToolsTabLabel);
}
@ -445,13 +471,20 @@ void OpenRGBDialog2::UpdateDevicesList()
| type and append device name string. |
\*-----------------------------------------------------*/
QString NewLabelString = "<html><table><tr><td width='30'><img src=':/";
NewLabelString += GetIconString(controllers[controller_idx]->type, darkTheme);
NewLabelString += GetIconString(controllers[controller_idx]->type, IsDarkTheme());
NewLabelString += "' height='16' width='16'></td><td>" + QString::fromStdString(controllers[controller_idx]->name) + "</td></tr></table></html>";
QLabel *NewTabLabel = new QLabel();
NewTabLabel->setText(NewLabelString);
NewTabLabel->setIndent(20);
NewTabLabel->setGeometry(0, 0, 200, 20);
if(IsDarkTheme())
{
NewTabLabel->setGeometry(0, 25, 200, 50);
}
else
{
NewTabLabel->setGeometry(0, 0, 200, 25);
}
ui->DevicesTabBar->tabBar()->setTabButton(ui->DevicesTabBar->count() - 1, QTabBar::LeftSide, NewTabLabel);
@ -504,13 +537,20 @@ void OpenRGBDialog2::UpdateDevicesList()
| type and append device name string. |
\*-----------------------------------------------------*/
QString NewLabelString = "<html><table><tr><td width='30'><img src=':/";
NewLabelString += GetIconString(controllers[controller_idx]->type, darkTheme);
NewLabelString += GetIconString(controllers[controller_idx]->type, IsDarkTheme());
NewLabelString += "' height='16' width='16'></td><td>" + QString::fromStdString(controllers[controller_idx]->name) + "</td></tr></table></html>";
QLabel *NewTabLabel = new QLabel();
NewTabLabel->setText(NewLabelString);
NewTabLabel->setIndent(20);
NewTabLabel->setGeometry(0, 0, 200, 20);
if(IsDarkTheme())
{
NewTabLabel->setGeometry(0, 25, 200, 50);
}
else
{
NewTabLabel->setGeometry(0, 0, 200, 25);
}
ui->InformationTabBar->tabBar()->setTabButton(ui->InformationTabBar->count() - 1, QTabBar::LeftSide, NewTabLabel);

View file

@ -39,6 +39,8 @@ public:
void setMode(unsigned char mode_val);
static bool IsDarkTheme();
protected:
std::vector<i2c_smbus_interface *>& busses;
std::vector<RGBController *>& controllers;
@ -74,7 +76,6 @@ private:
void SetDetectionViewState(bool detection_showing);
bool device_view_showing = false;
bool darkTheme = false;
private slots:
void on_Exit();

View file

@ -1,9 +1,32 @@
#include <QCloseEvent>
#include "ResourceManager.h"
#include "OpenRGBDialog2.h"
#include "OpenRGBProfileSaveDialog.h"
#include "ui_OpenRGBProfileSaveDialog.h"
#ifdef _WIN32
#include <QSettings>
#endif
Ui::OpenRGBProfileSaveDialog::OpenRGBProfileSaveDialog(QWidget *parent) :
QDialog(parent), ui(new Ui::OpenRGBProfileSaveDialogUi)
{
#ifdef _WIN32
bool DarkTheme = OpenRGBDialog2::IsDarkTheme();
/*-------------------------------------------------*\
| Apply dark theme on Windows if configured |
\*-------------------------------------------------*/
if(DarkTheme)
{
darkTheme = 1;
QPalette pal = palette();
pal.setColor(QPalette::WindowText, Qt::white);
QApplication::setPalette(pal);
QFile darkTheme(":/windows_dark.qss");
darkTheme.open(QFile::ReadOnly);
setStyleSheet(darkTheme.readAll());
}
#endif
ui->setupUi(this);
}

View file

@ -3,6 +3,7 @@
#include <QDialog>
#include "ui_OpenRGBProfileSaveDialog.h"
#include "OpenRGBDialog2.h"
namespace Ui
{
@ -21,6 +22,7 @@ public:
private:
Ui::OpenRGBProfileSaveDialogUi *ui;
bool darkTheme = false;
};
#endif // OPENRGBPROFILESAVEDIALOG_H

View file

@ -33,11 +33,11 @@ QTabBar::tab:hover
{
background-color: #757575;
border: 1px solid #404040;
border-bottom: 1px solid #2B2B2B;
}
QTabWidget::pane
{
/* This is the housing for all of the tabs*/
background-color: #5c5c5c;
border: 1px solid #2e2e2e;
position: absolute;
@ -49,43 +49,36 @@ QTabWidget::pane
QTabWidget::pane QTabBar
{
background-color: #5c5c5c;
border-right: 1px solid #2e2e2e;
}
QTabWidget QWidget QTabBar::tab
{
background-color: #5c5c5c;
/*padding: 5px;*/
padding-top: 4px;
padding-bottom: 5px;
height: 50px;
border: 10px;
border-bottom: 1px;
border-right: 1px solid #5c5c5c;
border-right: 1px solid #2e2e2e;
margin-right: 0px;
/*margin-bottom: 1px;*/
}
QTabWidget QWidget QTabBar::tab QLabel
{
/*background-color: darkred;*/
margin-bottom: 2px;
}
QTabWidget QWidget QTabBar::tab:selected
{
background-color: #454545;
border: 1px solid #2e2e2e;
border-top: 1px solid #2e2e2e;
border-right: 1px solid #454545;
}
QTabWidget QWidget QTabBar::tab:hover
{
background-color: #757575;
border: 1px solid #2e2e2e;
/*border-right: 1px solid #2e2e2e;*/
border: 1px solid #5c5c5c;
border-right: 1px solid #2e2e2e;
}
QTabWidget QWidget QTabWidget::pane
QTabWidget QWidget QTabWidget::pane /* The contents of the tab (colors, modes, leds, etc.) */
{
background-color: #454545;
border-top: 1px solid #2e2e2e;
@ -95,6 +88,33 @@ QTabWidget QWidget QTabWidget::pane
left: -1px;
}
/* QDialog boxes */
QDialog::QWidget
{
background: #454545;
background-color: #454545;
color: white;
}
QDialog QWidget::QDialogButtonBox
{
background-color: #454545;
color: white;
}
QDialog QWidget::QLabel
{
background-color: #454545;
color: white;
}
QDialog QWidget::QLineEdit
{
background-color: #454545;
color: white;
}
/* Buttons and combo boxes */
QPushButton