/* Copyright 2020-2021 Brad Parker Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #include #include #include #include #include "mainwindow.h" #ifdef Q_OS_UNIX #include static void signal_handler(int) { QApplication::quit(); } #endif int main(int argc, char *argv[]) { QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication app(argc, argv); app.setOrganizationName("reference_frontend"); app.setApplicationName("reference_frontend"); app.setApplicationVersion("1.0"); QSettings::setDefaultFormat(QSettings::IniFormat); QCommandLineParser parser; parser.setApplicationDescription("reference_frontend"); parser.addHelpOption(); parser.addVersionOption(); QCommandLineOption muteOption(QStringList() << "m" << "mute", QCoreApplication::translate("main", "Start with audio muted")); QCommandLineOption fsOption(QStringList() << "f" << "fullscreen", QCoreApplication::translate("main", "Start in fullscreen mode")); parser.addOption(fsOption); parser.addOption(muteOption); parser.addPositionalArgument("core", QCoreApplication::translate("main", "Core library to use")); parser.addPositionalArgument("rom", QCoreApplication::translate("main", "ROM file to use")); parser.process(app); QSurfaceFormat f; //f.setMajorVersion(4); //f.setMinorVersion(3); //f.setProfile(QSurfaceFormat::CoreProfile); //f.setOption(QSurfaceFormat::DebugContext); //f.setSwapInterval(0); QSurfaceFormat::setDefaultFormat(f); MainWindow w; w.setWindowTitle(app.applicationName()); if(parser.isSet(muteOption)) { w.setCoreMuted(true); } const QStringList args = parser.positionalArguments(); if(args.length() < 2) { std::cerr << "Please specify a core and a content file." << std::endl; return 1; }else{ w.setCorePath(args.at(0)); w.setROMPath(args.at(1)); } w.resize(640, 480); w.show(); if(parser.isSet(fsOption)) { w.setFullScreen(true); } #ifdef Q_OS_UNIX struct sigaction sigact; sigact.sa_handler = signal_handler; sigemptyset(&sigact.sa_mask); sigact.sa_flags = 0; sigaction(SIGINT, &sigact, (struct sigaction*)NULL); sigaction(SIGTERM, &sigact, (struct sigaction*)NULL); #endif return app.exec(); }