Qt: Clean up style tweaking.

This commit is contained in:
BearOso 2023-08-20 14:01:13 -05:00
parent 2be85e8a44
commit 6fce8bd2ca
7 changed files with 24 additions and 17 deletions

View File

@ -12,9 +12,7 @@ BindingPanel::BindingPanel(EmuApplication *app)
void BindingPanel::setTableWidget(QTableWidget *bindingTableWidget, EmuBinding *binding, int width, int height) void BindingPanel::setTableWidget(QTableWidget *bindingTableWidget, EmuBinding *binding, int width, int height)
{ {
QString iconset = ":/icons/blackicons/"; QString iconset = app->iconPrefix();
if (QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark)
iconset = ":/icons/whiteicons/";
keyboard_icon.addFile(iconset + "key.svg"); keyboard_icon.addFile(iconset + "key.svg");
joypad_icon.addFile(iconset + "joypad.svg"); joypad_icon.addFile(iconset + "joypad.svg");
this->binding_table_widget = bindingTableWidget; this->binding_table_widget = bindingTableWidget;

View File

@ -6,7 +6,6 @@
#include <optional> #include <optional>
#include <QtEvents> #include <QtEvents>
#include <QTimer> #include <QTimer>
#include <QStyleHints>
ControllerPanel::ControllerPanel(EmuApplication *app) ControllerPanel::ControllerPanel(EmuApplication *app)
: BindingPanel(app) : BindingPanel(app)
@ -49,7 +48,7 @@ ControllerPanel::ControllerPanel(EmuApplication *app)
editToolButton->setMenu(&edit_menu); editToolButton->setMenu(&edit_menu);
editToolButton->setPopupMode(QToolButton::InstantPopup); editToolButton->setPopupMode(QToolButton::InstantPopup);
QString iconset = QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark ? ":/icons/whiteicons/" : ":/icons/blackicons/"; QString iconset = app->iconPrefix();
const char *icons[] = { const char *icons[] = {
"up", "down", "left", "right", "a", "b", "x", "y", "l", "r", "start", "select", "a", "b", "x", "y", "l", "r" "up", "down", "left", "right", "a", "b", "x", "y", "l", "r", "start", "select", "a", "b", "x", "y", "l", "r"
}; };

View File

@ -11,6 +11,7 @@
#include <QTimer> #include <QTimer>
#include <QScreen> #include <QScreen>
#include <QThread> #include <QThread>
#include <QStyleHints>
#include <thread> #include <thread>
#include <chrono> #include <chrono>
using namespace std::chrono_literals; using namespace std::chrono_literals;
@ -523,6 +524,23 @@ bool EmuApplication::isCoreActive()
return core->active; return core->active;
} }
QString EmuApplication::iconPrefix()
{
const char *whiteicons = ":/icons/whiteicons/";
const char *blackicons = ":/icons/blackicons/";
if (QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark)
return whiteicons;
if (QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Light)
return blackicons;
if (QGuiApplication::palette().color(QPalette::WindowText).lightness() >
QGuiApplication::palette().color(QPalette::Window).lightness())
return whiteicons;
return blackicons;
}
void EmuThread::runOnThread(std::function<void()> func, bool blocking) void EmuThread::runOnThread(std::function<void()> func, bool blocking)
{ {
if (QThread::currentThread() != this) if (QThread::currentThread() != this)

View File

@ -37,7 +37,7 @@ Q_OBJECT
}; };
int status = eDead; int status = eDead;
public slots: public slots:
void runOnThread(std::function<void()> func, bool blocking = false); void runOnThread(std::function<void()> func, bool blocking = false);
}; };
@ -82,6 +82,7 @@ struct EmuApplication
void startThread(); void startThread();
void stopThread(); void stopThread();
bool isCoreActive(); bool isCoreActive();
QString iconPrefix();
enum Handler enum Handler
{ {

View File

@ -309,10 +309,7 @@ void EmuMainWindow::createWidgets()
tr("&Controllers..."), tr("&Controllers..."),
tr("Shortcu&ts..."), tr("Shortcu&ts..."),
tr("&Files...") }; tr("&Files...") };
QString iconset = QString iconset = app->iconPrefix();
QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark
? ":/icons/whiteicons/"
: ":/icons/blackicons/";
const char *setting_icons[] = { "settings.svg", const char *setting_icons[] = { "settings.svg",
"display.svg", "display.svg",
"sound.svg", "sound.svg",

View File

@ -3,7 +3,6 @@
#include "EmuConfig.hpp" #include "EmuConfig.hpp"
#include <QScrollArea> #include <QScrollArea>
#include <QStyleHints>
#include <QWhatsThis> #include <QWhatsThis>
EmuSettingsWindow::EmuSettingsWindow(QWidget *parent, EmuApplication *app_) EmuSettingsWindow::EmuSettingsWindow(QWidget *parent, EmuApplication *app_)
@ -46,9 +45,7 @@ EmuSettingsWindow::EmuSettingsWindow(QWidget *parent, EmuApplication *app_)
stackedWidget->setCurrentIndex(panelList->currentRow()); stackedWidget->setCurrentIndex(panelList->currentRow());
}); });
QString iconset = ":/icons/whiteicons/"; auto iconset = app->iconPrefix();
if (QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Light)
iconset = ":/icons/blackicons/";
auto icon = [iconset](QString name) -> QIcon { return QIcon(iconset + name); }; auto icon = [iconset](QString name) -> QIcon { return QIcon(iconset + name); };
panelList->item(0)->setIcon(icon("settings.svg")); panelList->item(0)->setIcon(icon("settings.svg"));

View File

@ -3,8 +3,6 @@
#include "EmuMainWindow.hpp" #include "EmuMainWindow.hpp"
#include "SDLInputManager.hpp" #include "SDLInputManager.hpp"
#include <QStyle>
#include <QStyleHints>
#include <clocale> #include <clocale>
#include <qnamespace.h> #include <qnamespace.h>
@ -26,7 +24,6 @@ int main(int argc, char *argv[])
emu.qtapp = std::make_unique<QApplication>(argc, argv); emu.qtapp = std::make_unique<QApplication>(argc, argv);
QGuiApplication::setDesktopFileName("snes9x-gtk"); QGuiApplication::setDesktopFileName("snes9x-gtk");
//emu.qtapp->setStyle("fusion");
#ifndef _WIN32 #ifndef _WIN32
auto quit_handler = [](int) { QApplication::quit(); }; auto quit_handler = [](int) { QApplication::quit(); };