Qt: Disable "New multiplayer window" when MAX_GBAS is reached.

Fixes #107.
This commit is contained in:
waddlesplash 2017-05-16 14:54:57 -04:00 committed by Vicki Pfau
parent d7aa0eaf54
commit ea93b029c9
3 changed files with 12 additions and 3 deletions

View File

@ -118,6 +118,9 @@ Window* GBAApp::newWindow() {
int windowId = m_multiplayer.attached(); int windowId = m_multiplayer.attached();
connect(w, &Window::destroyed, [this, w]() { connect(w, &Window::destroyed, [this, w]() {
m_windows.removeAll(w); m_windows.removeAll(w);
for (Window* w : m_windows) {
w->updateMultiplayerStatus(m_windows.count() < MAX_GBAS);
}
}); });
m_windows.append(w); m_windows.append(w);
w->setAttribute(Qt::WA_DeleteOnClose); w->setAttribute(Qt::WA_DeleteOnClose);
@ -125,6 +128,9 @@ Window* GBAApp::newWindow() {
w->show(); w->show();
w->controller()->setMultiplayerController(&m_multiplayer); w->controller()->setMultiplayerController(&m_multiplayer);
w->multiplayerChanged(); w->multiplayerChanged();
for (Window* w : m_windows) {
w->updateMultiplayerStatus(m_windows.count() < MAX_GBAS);
}
return w; return w;
} }

View File

@ -1024,11 +1024,11 @@ void Window::setupMenu(QMenuBar* menubar) {
#endif #endif
fileMenu->addSeparator(); fileMenu->addSeparator();
QAction* multiWindow = new QAction(tr("New multiplayer window"), fileMenu); m_multiWindow = new QAction(tr("New multiplayer window"), fileMenu);
connect(multiWindow, &QAction::triggered, [this]() { connect(m_multiWindow, &QAction::triggered, [this]() {
GBAApp::app()->newWindow(); GBAApp::app()->newWindow();
}); });
addControlledAction(fileMenu, multiWindow, "multiWindow"); addControlledAction(fileMenu, m_multiWindow, "multiWindow");
#ifndef Q_OS_MAC #ifndef Q_OS_MAC
fileMenu->addSeparator(); fileMenu->addSeparator();

View File

@ -50,6 +50,8 @@ public:
void resizeFrame(const QSize& size); void resizeFrame(const QSize& size);
void updateMultiplayerStatus(bool canOpenAnother) { m_multiWindow->setEnabled(canOpenAnother); }
signals: signals:
void startDrawing(mCoreThread*); void startDrawing(mCoreThread*);
void shutdown(); void shutdown();
@ -160,6 +162,7 @@ private:
#ifdef M_CORE_GBA #ifdef M_CORE_GBA
QList<QAction*> m_gbaActions; QList<QAction*> m_gbaActions;
#endif #endif
QAction* m_multiWindow;
QMap<int, QAction*> m_frameSizes; QMap<int, QAction*> m_frameSizes;
LogController m_log; LogController m_log;
LogView* m_logView; LogView* m_logView;