mirror of https://github.com/mgba-emu/mgba.git
Qt: Refactor out duplicated named view setup
This commit is contained in:
parent
06e6e1a27d
commit
9877c1bf1e
|
@ -162,11 +162,6 @@ Window::Window(CoreManager* manager, ConfigController* config, int playerId, QWi
|
||||||
Window::~Window() {
|
Window::~Window() {
|
||||||
delete m_logView;
|
delete m_logView;
|
||||||
|
|
||||||
#ifdef USE_FFMPEG
|
|
||||||
delete m_videoView;
|
|
||||||
delete m_gifView;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USE_SQLITE3
|
#ifdef USE_SQLITE3
|
||||||
delete m_libraryView;
|
delete m_libraryView;
|
||||||
#endif
|
#endif
|
||||||
|
@ -492,7 +487,6 @@ std::function<void()> Window::openTView(A... arg) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename T, typename... A>
|
template <typename T, typename... A>
|
||||||
std::function<void()> Window::openControllerTView(A... arg) {
|
std::function<void()> Window::openControllerTView(A... arg) {
|
||||||
return [=]() {
|
return [=]() {
|
||||||
|
@ -501,30 +495,21 @@ std::function<void()> Window::openControllerTView(A... arg) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_FFMPEG
|
template <typename T, typename... A>
|
||||||
void Window::openVideoWindow() {
|
std::function<void()> Window::openNamedControllerTView(std::unique_ptr<T>* name, A... arg) {
|
||||||
if (!m_videoView) {
|
return [=]() {
|
||||||
m_videoView = new VideoView();
|
if (!*name) {
|
||||||
if (m_controller) {
|
*name = std::make_unique<T>(arg...);
|
||||||
m_videoView->setController(m_controller);
|
if (m_controller) {
|
||||||
|
(*name)->setController(m_controller);
|
||||||
|
}
|
||||||
|
connect(this, &Window::shutdown, name->get(), &QWidget::close);
|
||||||
}
|
}
|
||||||
connect(this, &Window::shutdown, m_videoView, &QWidget::close);
|
(*name)->show();
|
||||||
}
|
(*name)->setFocus(Qt::PopupFocusReason);
|
||||||
m_videoView->show();
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::openGIFWindow() {
|
|
||||||
if (!m_gifView) {
|
|
||||||
m_gifView = new GIFView();
|
|
||||||
if (m_controller) {
|
|
||||||
m_gifView->setController(m_controller);
|
|
||||||
}
|
|
||||||
connect(this, &Window::shutdown, m_gifView, &QWidget::close);
|
|
||||||
}
|
|
||||||
m_gifView->show();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USE_GDB_STUB
|
#ifdef USE_GDB_STUB
|
||||||
void Window::gdbOpen() {
|
void Window::gdbOpen() {
|
||||||
if (!m_gdbController) {
|
if (!m_gdbController) {
|
||||||
|
@ -1465,8 +1450,8 @@ void Window::setupMenu(QMenuBar* menubar) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_FFMPEG
|
#ifdef USE_FFMPEG
|
||||||
addGameAction(tr("Record A/V..."), "recordOutput", this, &Window::openVideoWindow, "av");
|
addGameAction(tr("Record A/V..."), "recordOutput", openNamedControllerTView<VideoView>(&m_videoView), "av");
|
||||||
addGameAction(tr("Record GIF/WebP/APNG..."), "recordGIF", this, &Window::openGIFWindow, "av");
|
addGameAction(tr("Record GIF/WebP/APNG..."), "recordGIF", openNamedControllerTView<GIFView>(&m_gifView), "av");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_actions.addSeparator("av");
|
m_actions.addSeparator("av");
|
||||||
|
@ -1490,16 +1475,7 @@ void Window::setupMenu(QMenuBar* menubar) {
|
||||||
m_overrideView->recheck();
|
m_overrideView->recheck();
|
||||||
}, "tools");
|
}, "tools");
|
||||||
|
|
||||||
m_actions.addAction(tr("Game Pak sensors..."), "sensorWindow", [this]() {
|
m_actions.addAction(tr("Game Pak sensors..."), "sensorWindow", openNamedControllerTView<SensorView>(&m_sensorView, &m_inputController), "tools");
|
||||||
if (!m_sensorView) {
|
|
||||||
m_sensorView = std::make_unique<SensorView>(&m_inputController);
|
|
||||||
if (m_controller) {
|
|
||||||
m_sensorView->setController(m_controller);
|
|
||||||
}
|
|
||||||
connect(this, &Window::shutdown, m_sensorView.get(), &QWidget::close);
|
|
||||||
}
|
|
||||||
m_sensorView->show();
|
|
||||||
}, "tools");
|
|
||||||
|
|
||||||
addGameAction(tr("&Cheats..."), "cheatsWindow", openControllerTView<CheatsView>(), "tools");
|
addGameAction(tr("&Cheats..."), "cheatsWindow", openControllerTView<CheatsView>(), "tools");
|
||||||
|
|
||||||
|
|
|
@ -105,11 +105,6 @@ public slots:
|
||||||
void consoleOpen();
|
void consoleOpen();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_FFMPEG
|
|
||||||
void openVideoWindow();
|
|
||||||
void openGIFWindow();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USE_GDB_STUB
|
#ifdef USE_GDB_STUB
|
||||||
void gdbOpen();
|
void gdbOpen();
|
||||||
#endif
|
#endif
|
||||||
|
@ -168,6 +163,7 @@ private:
|
||||||
|
|
||||||
template <typename T, typename... A> std::function<void()> openTView(A... arg);
|
template <typename T, typename... A> std::function<void()> openTView(A... arg);
|
||||||
template <typename T, typename... A> std::function<void()> openControllerTView(A... arg);
|
template <typename T, typename... A> std::function<void()> openControllerTView(A... arg);
|
||||||
|
template <typename T, typename... A> std::function<void()> openNamedControllerTView(std::unique_ptr<T>*, A... arg);
|
||||||
|
|
||||||
Action* addGameAction(const QString& visibleName, const QString& name, Action::Function action, const QString& menu = {}, const QKeySequence& = {});
|
Action* addGameAction(const QString& visibleName, const QString& name, Action::Function action, const QString& menu = {}, const QKeySequence& = {});
|
||||||
template<typename T, typename V> Action* addGameAction(const QString& visibleName, const QString& name, T* obj, V (T::*action)(), const QString& menu = {}, const QKeySequence& = {});
|
template<typename T, typename V> Action* addGameAction(const QString& visibleName, const QString& name, T* obj, V (T::*action)(), const QString& menu = {}, const QKeySequence& = {});
|
||||||
|
@ -231,8 +227,8 @@ private:
|
||||||
FrameView* m_frameView = nullptr;
|
FrameView* m_frameView = nullptr;
|
||||||
|
|
||||||
#ifdef USE_FFMPEG
|
#ifdef USE_FFMPEG
|
||||||
VideoView* m_videoView = nullptr;
|
std::unique_ptr<VideoView> m_videoView;
|
||||||
GIFView* m_gifView = nullptr;
|
std::unique_ptr<GIFView> m_gifView;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_GDB_STUB
|
#ifdef USE_GDB_STUB
|
||||||
|
|
Loading…
Reference in New Issue