mirror of https://github.com/snes9xgit/snes9x.git
qt: Clean up.
This commit is contained in:
parent
819e1740fb
commit
acb821e367
|
@ -240,7 +240,7 @@ void EmuApplication::startThread()
|
|||
}
|
||||
}
|
||||
|
||||
bool EmuApplication::openFile(std::string filename)
|
||||
bool EmuApplication::openFile(const std::string &filename)
|
||||
{
|
||||
window->gameChanging();
|
||||
updateSettings();
|
||||
|
@ -428,7 +428,7 @@ void EmuApplication::updateSettings()
|
|||
|
||||
void EmuApplication::pollJoysticks()
|
||||
{
|
||||
while (1)
|
||||
while (true)
|
||||
{
|
||||
auto event = input_manager->processEvent();
|
||||
if (!event)
|
||||
|
@ -436,6 +436,8 @@ void EmuApplication::pollJoysticks()
|
|||
|
||||
switch (event->type)
|
||||
{
|
||||
default:
|
||||
break;
|
||||
case SDL_EVENT_JOYSTICK_ADDED:
|
||||
case SDL_EVENT_JOYSTICK_REMOVED:
|
||||
if (joypads_changed_callback)
|
||||
|
@ -506,7 +508,7 @@ void EmuApplication::loadState(int slot)
|
|||
});
|
||||
}
|
||||
|
||||
void EmuApplication::loadState(std::string filename)
|
||||
void EmuApplication::loadState(const std::string& filename)
|
||||
{
|
||||
emu_thread->runOnThread([&, filename] {
|
||||
core->loadState(filename);
|
||||
|
@ -520,7 +522,7 @@ void EmuApplication::saveState(int slot)
|
|||
});
|
||||
}
|
||||
|
||||
void EmuApplication::saveState(std::string filename)
|
||||
void EmuApplication::saveState(const std::string& filename)
|
||||
{
|
||||
emu_thread->runOnThread([&, filename] {
|
||||
core->saveState(filename);
|
||||
|
@ -583,7 +585,8 @@ void EmuApplication::disableCheat(int index)
|
|||
});
|
||||
}
|
||||
|
||||
bool EmuApplication::addCheat(std::string description, std::string code)
|
||||
bool EmuApplication::addCheat(const std::string &description,
|
||||
const std::string &code)
|
||||
{
|
||||
suspendThread();
|
||||
auto retval = core->addCheat(description, code);
|
||||
|
@ -605,7 +608,7 @@ void EmuApplication::deleteAllCheats()
|
|||
});
|
||||
}
|
||||
|
||||
int EmuApplication::tryImportCheats(std::string filename)
|
||||
int EmuApplication::tryImportCheats(const std::string &filename)
|
||||
{
|
||||
suspendThread();
|
||||
auto retval = core->tryImportCheats(filename);
|
||||
|
@ -613,7 +616,7 @@ int EmuApplication::tryImportCheats(std::string filename)
|
|||
return retval;
|
||||
}
|
||||
|
||||
std::string EmuApplication::validateCheat(std::string code)
|
||||
std::string EmuApplication::validateCheat(const std::string &code)
|
||||
{
|
||||
suspendThread();
|
||||
auto retval = core->validateCheat(code);
|
||||
|
@ -621,7 +624,8 @@ std::string EmuApplication::validateCheat(std::string code)
|
|||
return retval;
|
||||
}
|
||||
|
||||
int EmuApplication::modifyCheat(int index, std::string name, std::string code)
|
||||
int EmuApplication::modifyCheat(int index, const std::string &name,
|
||||
const std::string &code)
|
||||
{
|
||||
suspendThread();
|
||||
auto retval = core->modifyCheat(index, name, code);
|
||||
|
@ -651,7 +655,7 @@ std::string EmuApplication::getContentFolder()
|
|||
return core->getContentFolder();
|
||||
}
|
||||
|
||||
void EmuThread::runOnThread(std::function<void()> func, bool blocking)
|
||||
void EmuThread::runOnThread(const std::function<void()> &func, bool blocking)
|
||||
{
|
||||
if (QThread::currentThread() != this)
|
||||
{
|
||||
|
@ -667,7 +671,7 @@ void EmuThread::runOnThread(std::function<void()> func, bool blocking)
|
|||
}
|
||||
|
||||
EmuThread::EmuThread(QThread *main_thread_)
|
||||
: main_thread(main_thread_), QThread()
|
||||
: QThread(), main_thread(main_thread_)
|
||||
{
|
||||
qRegisterMetaType<std::function<void()>>("std::function<void()>");
|
||||
}
|
||||
|
@ -687,7 +691,7 @@ void EmuThread::waitForStatusBit(int new_status)
|
|||
if (status & new_status)
|
||||
return;
|
||||
|
||||
while (1)
|
||||
while (true)
|
||||
{
|
||||
QThread::yieldCurrentThread();
|
||||
if (status & new_status)
|
||||
|
@ -700,7 +704,7 @@ void EmuThread::waitForStatusBitCleared(int new_status)
|
|||
if (!(status & new_status))
|
||||
return;
|
||||
|
||||
while (1)
|
||||
while (true)
|
||||
{
|
||||
QThread::yieldCurrentThread();
|
||||
if (!(status & new_status))
|
||||
|
@ -720,11 +724,11 @@ void EmuThread::unpause()
|
|||
|
||||
void EmuThread::run()
|
||||
{
|
||||
auto event_loop = new QEventLoop();
|
||||
auto event_loop = std::make_unique<QEventLoop>();
|
||||
|
||||
setStatusBits(ePaused);
|
||||
|
||||
while (1)
|
||||
while (true)
|
||||
{
|
||||
event_loop->processEvents();
|
||||
|
||||
|
@ -742,7 +746,7 @@ void EmuThread::run()
|
|||
}
|
||||
}
|
||||
|
||||
void EmuThread::setMainLoop(std::function<void ()> loop)
|
||||
void EmuThread::setMainLoop(const std::function<void()> &loop)
|
||||
{
|
||||
main_loop = loop;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ Q_OBJECT
|
|||
void unsetStatusBits(int);
|
||||
void pause();
|
||||
void unpause();
|
||||
void setMainLoop(std::function<void()> loop);
|
||||
void setMainLoop(const std::function<void()> &loop);
|
||||
|
||||
std::function<void()> main_loop = nullptr;
|
||||
|
||||
|
@ -39,7 +39,7 @@ Q_OBJECT
|
|||
int status = eDead;
|
||||
|
||||
public slots:
|
||||
void runOnThread(std::function<void()> func, bool blocking = false);
|
||||
void runOnThread(const std::function<void()> &func, bool blocking = false);
|
||||
};
|
||||
|
||||
struct EmuApplication
|
||||
|
@ -54,7 +54,7 @@ struct EmuApplication
|
|||
|
||||
EmuApplication();
|
||||
~EmuApplication();
|
||||
bool openFile(std::string filename);
|
||||
bool openFile(const std::string &filename);
|
||||
void handleBinding(std::string name, bool pressed);
|
||||
void updateSettings();
|
||||
void updateBindings();
|
||||
|
@ -75,9 +75,9 @@ struct EmuApplication
|
|||
bool isPaused();
|
||||
void unpause();
|
||||
void loadState(int slot);
|
||||
void loadState(std::string filename);
|
||||
void loadState(const std::string& filename);
|
||||
void saveState(int slot);
|
||||
void saveState(std::string filename);
|
||||
void saveState(const std::string& filename);
|
||||
std::string getStateFolder();
|
||||
void loadUndoState();
|
||||
void startGame();
|
||||
|
@ -91,12 +91,13 @@ struct EmuApplication
|
|||
void disableAllCheats();
|
||||
void enableCheat(int index);
|
||||
void disableCheat(int index);
|
||||
bool addCheat(std::string description, std::string code);
|
||||
bool addCheat(const std::string &description, const std::string &code);
|
||||
void deleteCheat(int index);
|
||||
void deleteAllCheats();
|
||||
int tryImportCheats(std::string filename);
|
||||
std::string validateCheat(std::string code);
|
||||
int modifyCheat(int index, std::string name, std::string code);
|
||||
int tryImportCheats(const std::string &filename);
|
||||
std::string validateCheat(const std::string &code);
|
||||
int modifyCheat(int index, const std::string &name,
|
||||
const std::string &code);
|
||||
|
||||
enum Handler
|
||||
{
|
||||
|
|
|
@ -2,11 +2,8 @@
|
|||
#include <QMenu>
|
||||
#include <QMenuBar>
|
||||
#include <QFileDialog>
|
||||
#include <QtWidgets>
|
||||
#include <QtEvents>
|
||||
#include <QGuiApplication>
|
||||
#include <QStackedWidget>
|
||||
#include <qguiapplication.h>
|
||||
#include <qnamespace.h>
|
||||
#include <qpa/qplatformnativeinterface.h>
|
||||
|
||||
|
@ -14,14 +11,16 @@
|
|||
#include <dwmapi.h>
|
||||
#endif
|
||||
|
||||
#include "EmuMainWindow.hpp"
|
||||
#include "EmuSettingsWindow.hpp"
|
||||
#include "CheatsDialog.hpp"
|
||||
#include "EmuApplication.hpp"
|
||||
#include "EmuBinding.hpp"
|
||||
#include "EmuCanvasVulkan.hpp"
|
||||
#include "EmuCanvasOpenGL.hpp"
|
||||
#include "EmuCanvasQt.hpp"
|
||||
#include "CheatsDialog.hpp"
|
||||
#include "EmuCanvasVulkan.hpp"
|
||||
#include "EmuMainWindow.hpp"
|
||||
#include "EmuSettingsWindow.hpp"
|
||||
|
||||
#include <QMessageBox>
|
||||
#undef KeyPress
|
||||
|
||||
static EmuSettingsWindow *g_emu_settings_window = nullptr;
|
||||
|
@ -30,7 +29,7 @@ class DefaultBackground
|
|||
: public QWidget
|
||||
{
|
||||
public:
|
||||
DefaultBackground(QWidget *parent)
|
||||
explicit DefaultBackground(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
}
|
||||
|
@ -67,9 +66,7 @@ EmuMainWindow::EmuMainWindow(EmuApplication *app)
|
|||
});
|
||||
}
|
||||
|
||||
EmuMainWindow::~EmuMainWindow()
|
||||
{
|
||||
}
|
||||
EmuMainWindow::~EmuMainWindow() = default;
|
||||
|
||||
void EmuMainWindow::destroyCanvas()
|
||||
{
|
||||
|
@ -80,8 +77,7 @@ void EmuMainWindow::destroyCanvas()
|
|||
if (using_stacked_widget)
|
||||
{
|
||||
auto stackwidget = (QStackedWidget *)central_widget;
|
||||
EmuCanvas *widget = (EmuCanvas *)stackwidget->widget(0);
|
||||
if (widget)
|
||||
if (auto widget = (EmuCanvas *)stackwidget->widget(0))
|
||||
{
|
||||
widget->deinit();
|
||||
stackwidget->removeWidget(widget);
|
||||
|
@ -91,7 +87,7 @@ void EmuMainWindow::destroyCanvas()
|
|||
}
|
||||
else
|
||||
{
|
||||
EmuCanvas *widget = (EmuCanvas *)takeCentralWidget();
|
||||
auto widget = (EmuCanvas *)takeCentralWidget();
|
||||
widget->deinit();
|
||||
delete widget;
|
||||
}
|
||||
|
@ -174,7 +170,7 @@ void EmuMainWindow::createWidgets()
|
|||
// File menu
|
||||
auto file_menu = new QMenu(tr("&File"));
|
||||
auto open_item = file_menu->addAction(QIcon(iconset + "open.svg"), tr("&Open File..."));
|
||||
open_item->connect(open_item, &QAction::triggered, this, [&] {
|
||||
connect(open_item, &QAction::triggered, this, [&] {
|
||||
openFile();
|
||||
});
|
||||
// File->Recent Files submenu
|
||||
|
@ -229,7 +225,7 @@ void EmuMainWindow::createWidgets()
|
|||
file_menu->addMenu(save_state_menu);
|
||||
|
||||
auto exit_item = new QAction(QIcon(iconset + "exit.svg"), tr("E&xit"));
|
||||
exit_item->connect(exit_item, &QAction::triggered, this, [&](bool checked) {
|
||||
connect(exit_item, &QAction::triggered, this, [&](bool checked) {
|
||||
close();
|
||||
});
|
||||
|
||||
|
@ -304,7 +300,7 @@ void EmuMainWindow::createWidgets()
|
|||
{
|
||||
auto string = (i == 10) ? tr("1&0x") : tr("&%1x").arg(i);
|
||||
auto item = set_size_menu->addAction(string);
|
||||
item->connect(item, &QAction::triggered, this, [&, i](bool checked) {
|
||||
connect(item, &QAction::triggered, this, [&, i](bool checked) {
|
||||
resizeToMultiple(i);
|
||||
});
|
||||
}
|
||||
|
@ -314,7 +310,7 @@ void EmuMainWindow::createWidgets()
|
|||
|
||||
auto fullscreen_item = new QAction(QIcon(iconset + "fullscreen.svg"), tr("&Fullscreen"));
|
||||
view_menu->addAction(fullscreen_item);
|
||||
fullscreen_item->connect(fullscreen_item, &QAction::triggered, [&](bool checked) {
|
||||
connect(fullscreen_item, &QAction::triggered, [&](bool checked) {
|
||||
toggleFullscreen();
|
||||
});
|
||||
|
||||
|
@ -444,12 +440,12 @@ void EmuMainWindow::openFile()
|
|||
app->unpause();
|
||||
}
|
||||
|
||||
bool EmuMainWindow::openFile(std::string filename)
|
||||
bool EmuMainWindow::openFile(const std::string &filename)
|
||||
{
|
||||
if (app->openFile(filename))
|
||||
{
|
||||
auto &ru = app->config->recently_used;
|
||||
auto it = std::find(ru.begin(), ru.end(), filename);
|
||||
auto it = std::ranges::find(ru, filename);
|
||||
if (it != ru.end())
|
||||
ru.erase(it);
|
||||
ru.insert(ru.begin(), filename);
|
||||
|
|
|
@ -33,7 +33,7 @@ class EmuMainWindow : public QMainWindow
|
|||
void pauseContinue();
|
||||
bool isActivelyDrawing();
|
||||
void openFile();
|
||||
bool openFile(std::string filename);
|
||||
bool openFile(const std::string &filename);
|
||||
void recreateUIAssets();
|
||||
void shaderChanged();
|
||||
void gameChanging();
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "EmuApplication.hpp"
|
||||
#include "EmuConfig.hpp"
|
||||
|
||||
static const int playback_rates[] = { 96000, 48000, 44100 };
|
||||
static constexpr int playback_rates[] = { 96000, 48000, 44100 };
|
||||
|
||||
SoundPanel::SoundPanel(EmuApplication *app_)
|
||||
: app(app_)
|
||||
|
@ -74,9 +74,7 @@ SoundPanel::SoundPanel(EmuApplication *app_)
|
|||
});
|
||||
}
|
||||
|
||||
SoundPanel::~SoundPanel()
|
||||
{
|
||||
}
|
||||
SoundPanel::~SoundPanel() = default;
|
||||
|
||||
void SoundPanel::updateInputRate()
|
||||
{
|
||||
|
|
|
@ -27,11 +27,11 @@ int main(int argc, char *argv[])
|
|||
|
||||
QGuiApplication::setDesktopFileName("snes9x-gtk");
|
||||
|
||||
if (emu.qtapp->platformName() == "windows")
|
||||
if (QApplication::platformName() == "windows")
|
||||
{
|
||||
if (emu.qtapp->styleHints()->colorScheme() == Qt::ColorScheme::Dark)
|
||||
if (QApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark)
|
||||
{
|
||||
emu.qtapp->setStyle("fusion");
|
||||
QApplication::setStyle("fusion");
|
||||
|
||||
const QColor darkGray(53, 53, 53);
|
||||
const QColor gray(128, 128, 128);
|
||||
|
@ -59,11 +59,11 @@ int main(int argc, char *argv[])
|
|||
darkPalette.setColor(QPalette::Disabled, QPalette::WindowText, gray);
|
||||
darkPalette.setColor(QPalette::Disabled, QPalette::Text, gray);
|
||||
darkPalette.setColor(QPalette::Disabled, QPalette::Light, darkGray);
|
||||
emu.qtapp->setPalette(darkPalette);
|
||||
QApplication::setPalette(darkPalette);
|
||||
}
|
||||
else
|
||||
{
|
||||
emu.qtapp->setStyle("windowsvista");
|
||||
QApplication::setStyle("windowsvista");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue