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)
{
QString iconset = ":/icons/blackicons/";
if (QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark)
iconset = ":/icons/whiteicons/";
QString iconset = app->iconPrefix();
keyboard_icon.addFile(iconset + "key.svg");
joypad_icon.addFile(iconset + "joypad.svg");
this->binding_table_widget = bindingTableWidget;

View File

@ -6,7 +6,6 @@
#include <optional>
#include <QtEvents>
#include <QTimer>
#include <QStyleHints>
ControllerPanel::ControllerPanel(EmuApplication *app)
: BindingPanel(app)
@ -49,7 +48,7 @@ ControllerPanel::ControllerPanel(EmuApplication *app)
editToolButton->setMenu(&edit_menu);
editToolButton->setPopupMode(QToolButton::InstantPopup);
QString iconset = QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark ? ":/icons/whiteicons/" : ":/icons/blackicons/";
QString iconset = app->iconPrefix();
const char *icons[] = {
"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 <QScreen>
#include <QThread>
#include <QStyleHints>
#include <thread>
#include <chrono>
using namespace std::chrono_literals;
@ -523,6 +524,23 @@ bool EmuApplication::isCoreActive()
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)
{
if (QThread::currentThread() != this)

View File

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

View File

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

View File

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

View File

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