mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-02-06 00:40:11 +00:00
Qt: Enable stylesheet cli args and add stylesheet option "None"
This commit is contained in:
parent
3e9ed9a17d
commit
2ab19efb90
@ -9,10 +9,8 @@ headless_application::headless_application(int& argc, char** argv) : QCoreApplic
|
||||
{
|
||||
}
|
||||
|
||||
void headless_application::Init(const bool show_gui)
|
||||
void headless_application::Init()
|
||||
{
|
||||
Q_UNUSED(show_gui);
|
||||
|
||||
// Force init the emulator
|
||||
InitializeEmulator("1", true); // TODO: get user from cli args if possible
|
||||
|
||||
|
@ -17,7 +17,7 @@ public:
|
||||
headless_application(int& argc, char** argv);
|
||||
|
||||
/** Call this method before calling app.exec */
|
||||
void Init(const bool show_gui = false) override;
|
||||
void Init() override;
|
||||
|
||||
private:
|
||||
void InitializeCallbacks();
|
||||
|
@ -97,16 +97,26 @@ static semaphore<> s_qt_mutex{};
|
||||
std::abort();
|
||||
}
|
||||
|
||||
const char* arg_headless = "headless";
|
||||
const char* arg_no_gui = "no-gui";
|
||||
const char* arg_high_dpi = "hidpi";
|
||||
const char* arg_headless = "headless";
|
||||
const char* arg_no_gui = "no-gui";
|
||||
const char* arg_high_dpi = "hidpi";
|
||||
const char* arg_style = "style";
|
||||
const char* arg_stylesheet = "stylesheet";
|
||||
|
||||
bool find_arg(std::string arg, int& argc, char* argv[])
|
||||
{
|
||||
arg = "--" + arg;
|
||||
for (int i = 1; i < argc; ++i)
|
||||
if (!strcmp(arg.c_str(), argv[i]))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
QCoreApplication* createApplication(int& argc, char* argv[])
|
||||
{
|
||||
const std::string headless("--" + std::string(arg_headless));
|
||||
for (int i = 1; i < argc; ++i)
|
||||
if (!strcmp(headless.c_str(), argv[i]))
|
||||
return new headless_application(argc, argv);
|
||||
if (find_arg(arg_headless, argc, argv))
|
||||
return new headless_application(argc, argv);
|
||||
|
||||
return new gui_application(argc, argv);
|
||||
}
|
||||
|
||||
@ -127,6 +137,11 @@ int main(int argc, char** argv)
|
||||
s_init.unlock();
|
||||
s_qt_mutex.lock();
|
||||
|
||||
// The constructor of QApplication eats the --style and --stylesheet arguments.
|
||||
// By checking for stylesheet().isEmpty() we could implicitly know if a stylesheet was passed,
|
||||
// but I haven't found an implicit way to check for style yet, so we naively check them both here for now.
|
||||
const bool use_cli_style = find_arg(arg_style, argc, argv) || find_arg(arg_stylesheet, argc, argv);
|
||||
|
||||
QScopedPointer<QCoreApplication> app(createApplication(argc, argv));
|
||||
app->setApplicationVersion(qstr(rpcs3::version.to_string()));
|
||||
app->setApplicationName("RPCS3");
|
||||
@ -142,6 +157,8 @@ int main(int argc, char** argv)
|
||||
parser.addOption(QCommandLineOption(arg_headless, "Run RPCS3 in headless mode."));
|
||||
parser.addOption(QCommandLineOption(arg_no_gui, "Run RPCS3 without its GUI."));
|
||||
parser.addOption(QCommandLineOption(arg_high_dpi, "Enables Qt High Dpi Scaling.", "enabled", "1"));
|
||||
parser.addOption(QCommandLineOption(arg_style, "Loads a custom style.", "style", ""));
|
||||
parser.addOption(QCommandLineOption(arg_stylesheet, "Loads a custom stylesheet.", "path", ""));
|
||||
parser.process(app->arguments());
|
||||
|
||||
// Don't start up the full rpcs3 gui if we just want the version or help.
|
||||
@ -152,14 +169,15 @@ int main(int argc, char** argv)
|
||||
{
|
||||
// Set QT_AUTO_SCREEN_SCALE_FACTOR from environment. Defaults to cli argument, which defaults to 1.
|
||||
const bool use_high_dpi = "1" == qEnvironmentVariable("QT_AUTO_SCREEN_SCALE_FACTOR", parser.value(arg_high_dpi));
|
||||
const bool show_gui = !parser.isSet(arg_no_gui);
|
||||
|
||||
app->setAttribute(use_high_dpi ? Qt::AA_EnableHighDpiScaling : Qt::AA_DisableHighDpiScaling);
|
||||
app->setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||
app->setAttribute(Qt::AA_DisableWindowContextHelpButton);
|
||||
app->setAttribute(Qt::AA_DontCheckOpenGLContextThreadAffinity);
|
||||
gui_app->setAttribute(use_high_dpi ? Qt::AA_EnableHighDpiScaling : Qt::AA_DisableHighDpiScaling);
|
||||
gui_app->setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||
gui_app->setAttribute(Qt::AA_DisableWindowContextHelpButton);
|
||||
gui_app->setAttribute(Qt::AA_DontCheckOpenGLContextThreadAffinity);
|
||||
|
||||
gui_app->Init(show_gui);
|
||||
gui_app->SetShowGui(!parser.isSet(arg_no_gui));
|
||||
gui_app->SetUseCliStyle(use_cli_style);
|
||||
gui_app->Init();
|
||||
}
|
||||
else if (auto headless_app = qobject_cast<headless_application*>(app.data()))
|
||||
{
|
||||
|
@ -7,7 +7,7 @@
|
||||
class main_application
|
||||
{
|
||||
public:
|
||||
virtual void Init(const bool show_gui = false) = 0;
|
||||
virtual void Init() = 0;
|
||||
|
||||
static bool InitializeEmulator(const std::string& user, bool force_init);
|
||||
|
||||
|
@ -26,12 +26,10 @@ gui_application::~gui_application()
|
||||
#endif
|
||||
}
|
||||
|
||||
void gui_application::Init(const bool show_gui)
|
||||
void gui_application::Init()
|
||||
{
|
||||
setWindowIcon(QIcon(":/rpcs3.ico"));
|
||||
|
||||
m_show_gui = show_gui;
|
||||
|
||||
m_emu_settings.reset(new emu_settings());
|
||||
m_gui_settings.reset(new gui_settings());
|
||||
|
||||
@ -211,6 +209,19 @@ void gui_application::InitializeCallbacks()
|
||||
*/
|
||||
void gui_application::OnChangeStyleSheetRequest(const QString& path)
|
||||
{
|
||||
// skip stylesheets on first repaint if a style was set from command line
|
||||
if (m_use_cli_style && gui::stylesheet.isEmpty())
|
||||
{
|
||||
gui::stylesheet = styleSheet().isEmpty() ? "/* style set by command line arg */" : styleSheet();
|
||||
|
||||
if (m_main_window)
|
||||
{
|
||||
m_main_window->RepaintGui();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
QFile file(path);
|
||||
|
||||
// If we can't open the file, try the /share or /Resources folder
|
||||
@ -227,6 +238,10 @@ void gui_application::OnChangeStyleSheetRequest(const QString& path)
|
||||
{
|
||||
setStyleSheet(gui::stylesheets::default_style_sheet);
|
||||
}
|
||||
else if (path == "-")
|
||||
{
|
||||
setStyleSheet("/* none */");
|
||||
}
|
||||
else if (file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
QString config_dir = qstr(fs::get_config_dir());
|
||||
|
@ -23,8 +23,18 @@ public:
|
||||
gui_application(int& argc, char** argv);
|
||||
~gui_application();
|
||||
|
||||
void SetShowGui(bool show_gui = true)
|
||||
{
|
||||
m_show_gui = show_gui;
|
||||
}
|
||||
|
||||
void SetUseCliStyle(bool use_cli_style = false)
|
||||
{
|
||||
m_use_cli_style = use_cli_style;
|
||||
}
|
||||
|
||||
/** Call this method before calling app.exec */
|
||||
void Init(const bool show_gui = true) override;
|
||||
void Init() override;
|
||||
|
||||
std::unique_ptr<gs_frame> get_gs_frame();
|
||||
|
||||
@ -43,6 +53,7 @@ private:
|
||||
std::shared_ptr<gui_settings> m_gui_settings;
|
||||
|
||||
bool m_show_gui = true;
|
||||
bool m_use_cli_style = false;
|
||||
|
||||
private Q_SLOTS:
|
||||
void OnChangeStyleSheetRequest(const QString& path);
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "gui_settings.h"
|
||||
#include "gui_settings.h"
|
||||
|
||||
#include "game_list_frame.h"
|
||||
#include "qt_utils.h"
|
||||
@ -388,6 +388,10 @@ QString gui_settings::GetCurrentStylesheetPath()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
else if (stylesheet == gui::None)
|
||||
{
|
||||
return "-";
|
||||
}
|
||||
|
||||
return m_settingsDir.absoluteFilePath(stylesheet + ".qss");
|
||||
}
|
||||
|
@ -117,6 +117,7 @@ namespace gui
|
||||
|
||||
const QString Settings = QObject::tr("CurrentSettings");
|
||||
const QString Default = QObject::tr("default");
|
||||
const QString None = QObject::tr("none");
|
||||
const QString main_window = "main_window";
|
||||
const QString game_list = "GameList";
|
||||
const QString logger = "Logger";
|
||||
|
@ -1605,6 +1605,7 @@ void settings_dialog::AddStylesheets()
|
||||
{
|
||||
ui->combo_stylesheets->clear();
|
||||
|
||||
ui->combo_stylesheets->addItem("None", gui::None);
|
||||
ui->combo_stylesheets->addItem("Default (Bright)", gui::Default);
|
||||
|
||||
for (const QString& entry : xgui_settings->GetStylesheetEntries())
|
||||
|
Loading…
x
Reference in New Issue
Block a user