lay base for a window with no menubar

This commit is contained in:
Arisotura 2024-10-27 02:07:33 +02:00
parent 881a740cab
commit b2ae4c7dc5
4 changed files with 478 additions and 437 deletions

View File

@ -76,11 +76,15 @@ void EmuThread::attachWindow(MainWindow* window)
connect(this, SIGNAL(windowEmuStop()), window, SLOT(onEmuStop()));
connect(this, SIGNAL(windowEmuPause(bool)), window, SLOT(onEmuPause(bool)));
connect(this, SIGNAL(windowEmuReset()), window, SLOT(onEmuReset()));
connect(this, SIGNAL(windowLimitFPSChange()), window->actLimitFramerate, SLOT(trigger()));
connect(this, SIGNAL(autoScreenSizingChange(int)), window->panel, SLOT(onAutoScreenSizingChanged(int)));
connect(this, SIGNAL(windowFullscreenToggle()), window, SLOT(onFullscreenToggled()));
connect(this, SIGNAL(swapScreensToggle()), window->actScreenSwap, SLOT(trigger()));
connect(this, SIGNAL(screenEmphasisToggle()), window, SLOT(onScreenEmphasisToggled()));
if (window->winHasMenu())
{
connect(this, SIGNAL(windowLimitFPSChange()), window->actLimitFramerate, SLOT(trigger()));
connect(this, SIGNAL(swapScreensToggle()), window->actScreenSwap, SLOT(trigger()));
}
}
void EmuThread::detachWindow(MainWindow* window)
@ -91,11 +95,15 @@ void EmuThread::detachWindow(MainWindow* window)
disconnect(this, SIGNAL(windowEmuStop()), window, SLOT(onEmuStop()));
disconnect(this, SIGNAL(windowEmuPause(bool)), window, SLOT(onEmuPause(bool)));
disconnect(this, SIGNAL(windowEmuReset()), window, SLOT(onEmuReset()));
disconnect(this, SIGNAL(windowLimitFPSChange()), window->actLimitFramerate, SLOT(trigger()));
disconnect(this, SIGNAL(autoScreenSizingChange(int)), window->panel, SLOT(onAutoScreenSizingChanged(int)));
disconnect(this, SIGNAL(windowFullscreenToggle()), window, SLOT(onFullscreenToggled()));
disconnect(this, SIGNAL(swapScreensToggle()), window->actScreenSwap, SLOT(trigger()));
disconnect(this, SIGNAL(screenEmphasisToggle()), window, SLOT(onScreenEmphasisToggled()));
if (window->winHasMenu())
{
disconnect(this, SIGNAL(windowLimitFPSChange()), window->actLimitFramerate, SLOT(trigger()));
disconnect(this, SIGNAL(swapScreensToggle()), window->actScreenSwap, SLOT(trigger()));
}
}
void EmuThread::run()

View File

@ -271,9 +271,13 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
setStyleSheet("QMenuBar::item { padding: 4px 8px; }");
#endif
QMenuBar* menubar = new QMenuBar();
hasMenu = (!parent);
if (hasMenu)
{
QMenu* menu = menubar->addMenu("File");
QMenuBar * menubar = new QMenuBar();
{
QMenu * menu = menubar->addMenu("File");
actOpenROM = menu->addAction("Open ROM...");
connect(actOpenROM, &QAction::triggered, this, &MainWindow::onOpenFile);
@ -285,7 +289,7 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
recentMenu = menu->addMenu("Open recent");
Config::Array recentROMs = globalCfg.GetArray("RecentROM");
int numrecent = std::min(kMaxRecentROMs, (int)recentROMs.Size());
int numrecent = std::min(kMaxRecentROMs, (int) recentROMs.Size());
for (int i = 0; i < numrecent; ++i)
{
std::string item = recentROMs.GetString(i);
@ -318,8 +322,8 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
connect(actInsertGBACart, &QAction::triggered, this, &MainWindow::onInsertGBACart);
{
QMenu* submenu = menu->addMenu("Insert add-on cart");
QAction* act;
QMenu * submenu = menu->addMenu("Insert add-on cart");
QAction *act;
int addons[] = {GBAAddon_RAMExpansion, GBAAddon_RumblePak, -1};
for (int i = 0; addons[i] != -1; i++)
@ -343,12 +347,12 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
menu->addSeparator();
{
QMenu* submenu = menu->addMenu("Save state");
QMenu * submenu = menu->addMenu("Save state");
for (int i = 1; i < 9; i++)
{
actSaveState[i] = submenu->addAction(QString("%1").arg(i));
actSaveState[i]->setShortcut(QKeySequence(Qt::ShiftModifier | (Qt::Key_F1+i-1)));
actSaveState[i]->setShortcut(QKeySequence(Qt::ShiftModifier | (Qt::Key_F1 + i - 1)));
actSaveState[i]->setData(QVariant(i));
connect(actSaveState[i], &QAction::triggered, this, &MainWindow::onSaveState);
}
@ -359,12 +363,12 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
connect(actSaveState[0], &QAction::triggered, this, &MainWindow::onSaveState);
}
{
QMenu* submenu = menu->addMenu("Load state");
QMenu * submenu = menu->addMenu("Load state");
for (int i = 1; i < 9; i++)
{
actLoadState[i] = submenu->addAction(QString("%1").arg(i));
actLoadState[i]->setShortcut(QKeySequence(Qt::Key_F1+i-1));
actLoadState[i]->setShortcut(QKeySequence(Qt::Key_F1 + i - 1));
actLoadState[i]->setData(QVariant(i));
connect(actLoadState[i], &QAction::triggered, this, &MainWindow::onLoadState);
}
@ -381,7 +385,8 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
menu->addSeparator();
actOpenConfig = menu->addAction("Open melonDS directory");
connect(actOpenConfig, &QAction::triggered, this, [&]() {
connect(actOpenConfig, &QAction::triggered, this, [&]()
{
QDesktopServices::openUrl(QUrl::fromLocalFile(emuDirectory));
});
@ -392,7 +397,7 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
actQuit->setShortcut(QKeySequence(QKeySequence::StandardKey::Quit));
}
{
QMenu* menu = menubar->addMenu("System");
QMenu * menu = menubar->addMenu("System");
actPause = menu->addAction("Pause");
actPause->setCheckable(true);
@ -440,7 +445,7 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
{
menu->addSeparator();
QMenu* submenu = menu->addMenu("Multiplayer");
QMenu * submenu = menu->addMenu("Multiplayer");
actMPNewInstance = submenu->addAction("Launch new instance");
connect(actMPNewInstance, &QAction::triggered, this, &MainWindow::onMPNewInstance);
@ -466,26 +471,26 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
}
}
{
QMenu *menu = menubar->addMenu("View");
QMenu * menu = menubar->addMenu("View");
{
QMenu* submenu = menu->addMenu("Screen size");
QMenu * submenu = menu->addMenu("Screen size");
for (int i = 0; i < 4; i++)
{
int data = i+1;
int data = i + 1;
actScreenSize[i] = submenu->addAction(QString("%1x").arg(data));
actScreenSize[i]->setData(QVariant(data));
connect(actScreenSize[i], &QAction::triggered, this, &MainWindow::onChangeScreenSize);
}
}
{
QMenu* submenu = menu->addMenu("Screen rotation");
QMenu * submenu = menu->addMenu("Screen rotation");
grpScreenRotation = new QActionGroup(submenu);
for (int i = 0; i < screenRot_MAX; i++)
{
int data = i*90;
int data = i * 90;
actScreenRotation[i] = submenu->addAction(QString("%1°").arg(data));
actScreenRotation[i]->setActionGroup(grpScreenRotation);
actScreenRotation[i]->setData(QVariant(i));
@ -495,7 +500,7 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
connect(grpScreenRotation, &QActionGroup::triggered, this, &MainWindow::onChangeScreenRotation);
}
{
QMenu* submenu = menu->addMenu("Screen gap");
QMenu * submenu = menu->addMenu("Screen gap");
grpScreenGap = new QActionGroup(submenu);
const int screengap[] = {0, 1, 8, 64, 90, 128};
@ -512,10 +517,10 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
connect(grpScreenGap, &QActionGroup::triggered, this, &MainWindow::onChangeScreenGap);
}
{
QMenu* submenu = menu->addMenu("Screen layout");
QMenu * submenu = menu->addMenu("Screen layout");
grpScreenLayout = new QActionGroup(submenu);
const char* screenlayout[] = {"Natural", "Vertical", "Horizontal", "Hybrid"};
const char *screenlayout[] = {"Natural", "Vertical", "Horizontal", "Hybrid"};
for (int i = 0; i < screenLayout_MAX; i++)
{
@ -534,10 +539,11 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
connect(actScreenSwap, &QAction::triggered, this, &MainWindow::onChangeScreenSwap);
}
{
QMenu* submenu = menu->addMenu("Screen sizing");
QMenu * submenu = menu->addMenu("Screen sizing");
grpScreenSizing = new QActionGroup(submenu);
const char* screensizing[] = {"Even", "Emphasize top", "Emphasize bottom", "Auto", "Top only", "Bottom only"};
const char *screensizing[] = {"Even", "Emphasize top", "Emphasize bottom", "Auto", "Top only",
"Bottom only"};
for (int i = 0; i < screenSizing_MAX; i++)
{
@ -556,16 +562,16 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
connect(actIntegerScaling, &QAction::triggered, this, &MainWindow::onChangeIntegerScaling);
}
{
QMenu* submenu = menu->addMenu("Aspect ratio");
QMenu * submenu = menu->addMenu("Aspect ratio");
grpScreenAspectTop = new QActionGroup(submenu);
grpScreenAspectBot = new QActionGroup(submenu);
actScreenAspectTop = new QAction*[AspectRatiosNum];
actScreenAspectBot = new QAction*[AspectRatiosNum];
actScreenAspectTop = new QAction *[AspectRatiosNum];
actScreenAspectBot = new QAction *[AspectRatiosNum];
for (int i = 0; i < 2; i++)
{
QActionGroup* group = grpScreenAspectTop;
QAction** actions = actScreenAspectTop;
QActionGroup * group = grpScreenAspectTop;
QAction **actions = actScreenAspectTop;
if (i == 1)
{
@ -604,7 +610,7 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
connect(actShowOSD, &QAction::triggered, this, &MainWindow::onChangeShowOSD);
}
{
QMenu* menu = menubar->addMenu("Config");
QMenu * menu = menubar->addMenu("Config");
actEmuSettings = menu->addAction("Emu settings");
connect(actEmuSettings, &QAction::triggered, this, &MainWindow::onOpenEmuSettings);
@ -643,7 +649,7 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
connect(actPathSettings, &QAction::triggered, this, &MainWindow::onOpenPathSettings);
{
QMenu* submenu = menu->addMenu("Savestate settings");
QMenu * submenu = menu->addMenu("Savestate settings");
actSavestateSRAMReloc = submenu->addAction("Separate savefiles");
actSavestateSRAMReloc->setCheckable(true);
@ -661,9 +667,10 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
connect(actAudioSync, &QAction::triggered, this, &MainWindow::onChangeAudioSync);
}
{
QMenu* menu = menubar->addMenu("Help");
QMenu * menu = menubar->addMenu("Help");
actAbout = menu->addAction("About...");
connect(actAbout, &QAction::triggered, this, [&]{
connect(actAbout, &QAction::triggered, this, [&]
{
auto dialog = AboutDialog(this);
dialog.exec();
});
@ -673,6 +680,7 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
if (localCfg.GetString("Firmware.Username") == "Arisotura")
actMPNewInstance->setText("Fart");
}
#ifdef Q_OS_MAC
QPoint screenCenter = screen()->availableGeometry().center();
@ -695,13 +703,15 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
createScreenPanel();
if (hasMenu)
{
actEjectCart->setEnabled(false);
actEjectGBACart->setEnabled(false);
if (globalCfg.GetInt("Emu.ConsoleType") == 1)
{
actInsertGBACart->setEnabled(false);
for (auto act : actInsertGBAAddon)
for (auto act: actInsertGBAAddon)
act->setEnabled(false);
}
@ -777,6 +787,7 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
actPreferences->setEnabled(false);
#endif // __APPLE__
}
}
QObject::connect(qApp, &QApplication::applicationStateChanged, this, &MainWindow::onAppStateChanged);
onUpdateInterfaceSettings();
@ -786,8 +797,11 @@ MainWindow::MainWindow(int id, EmuInstance* inst, QWidget* parent) :
MainWindow::~MainWindow()
{
if (hasMenu)
{
delete[] actScreenAspectTop;
delete[] actScreenAspectBot;
}
}
void MainWindow::osdAddMessage(unsigned int color, const char* msg)
@ -834,6 +848,7 @@ void MainWindow::createScreenPanel()
}
setCentralWidget(panel);
if (hasMenu)
actScreenFiltering->setEnabled(hasOGL);
panel->osdSetEnabled(showOSD);
@ -1635,6 +1650,8 @@ void MainWindow::onNPTest()
void MainWindow::updateMPInterface(MPInterfaceType type)
{
if (!hasMenu) return;
// MP interface was changed, reflect it in the UI
bool enable = (type == MPInterface_Local);
@ -1995,24 +2012,28 @@ void MainWindow::onTitleUpdate(QString title)
setWindowTitle(title);
}
void ToggleFullscreen(MainWindow* mainWindow)
void MainWindow::toggleFullscreen()
{
if (!mainWindow->isFullScreen())
if (!isFullScreen())
{
mainWindow->showFullScreen();
mainWindow->menuBar()->setFixedHeight(0); // Don't use hide() as menubar actions stop working
showFullScreen();
if (hasMenu)
menuBar()->setFixedHeight(0); // Don't use hide() as menubar actions stop working
}
else
{
mainWindow->showNormal();
int menuBarHeight = mainWindow->menuBar()->sizeHint().height();
mainWindow->menuBar()->setFixedHeight(menuBarHeight);
showNormal();
if (hasMenu)
{
int menuBarHeight = menuBar()->sizeHint().height();
menuBar()->setFixedHeight(menuBarHeight);
}
}
}
void MainWindow::onFullscreenToggled()
{
ToggleFullscreen(this);
toggleFullscreen();
}
void MainWindow::onScreenEmphasisToggled()
@ -2033,6 +2054,8 @@ void MainWindow::onScreenEmphasisToggled()
void MainWindow::onEmuStart()
{
if (!hasMenu) return;
for (int i = 1; i < 9; i++)
{
actSaveState[i]->setEnabled(true);
@ -2056,6 +2079,8 @@ void MainWindow::onEmuStart()
void MainWindow::onEmuStop()
{
if (!hasMenu) return;
for (int i = 0; i < 9; i++)
{
actSaveState[i]->setEnabled(false);
@ -2076,11 +2101,15 @@ void MainWindow::onEmuStop()
void MainWindow::onEmuPause(bool pause)
{
if (!hasMenu) return;
actPause->setChecked(pause);
}
void MainWindow::onEmuReset()
{
if (!hasMenu) return;
actUndoStateLoad->setEnabled(false);
}

View File

@ -111,6 +111,10 @@ public:
EmuInstance* getEmuInstance() { return emuInstance; }
Config::Table& getWindowConfig() { return windowCfg; }
bool winHasMenu() { return hasMenu; }
void toggleFullscreen();
bool hasOpenGL() { return hasOGL; }
GL::Context* getOGLContext();
void initOpenGL();
@ -263,6 +267,8 @@ private:
public:
ScreenPanel* panel;
bool hasMenu;
QAction* actOpenROM;
QAction* actBootFirmware;
QAction* actCurrentCart;
@ -335,6 +341,4 @@ public:
QAction* actAbout;
};
void ToggleFullscreen(MainWindow* mainWindow);
#endif // WINDOW_H

View File

@ -364,7 +364,7 @@ int main(int argc, char** argv)
win->preloadROMs(dsfile, gbafile, options->boot);
if (options->fullscreen)
ToggleFullscreen(win);
win->toggleFullscreen();
}
int ret = melon.exec();