Qt: Clean up named view initialization and fix raising
This commit is contained in:
parent
939c8f0487
commit
9bbf6b3173
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
using namespace QGBA;
|
using namespace QGBA;
|
||||||
|
|
||||||
GIFView::GIFView(QWidget* parent)
|
GIFView::GIFView(std::shared_ptr<CoreController> controller, QWidget* parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
{
|
{
|
||||||
m_ui.setupUi(this);
|
m_ui.setupUi(this);
|
||||||
@ -31,6 +31,8 @@ GIFView::GIFView(QWidget* parent)
|
|||||||
|
|
||||||
FFmpegEncoderInit(&m_encoder);
|
FFmpegEncoderInit(&m_encoder);
|
||||||
FFmpegEncoderSetAudio(&m_encoder, nullptr, 0);
|
FFmpegEncoderSetAudio(&m_encoder, nullptr, 0);
|
||||||
|
|
||||||
|
setController(controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
GIFView::~GIFView() {
|
GIFView::~GIFView() {
|
||||||
|
@ -23,7 +23,7 @@ class GIFView : public QWidget {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GIFView(QWidget* parent = nullptr);
|
GIFView(std::shared_ptr<CoreController> controller, QWidget* parent = nullptr);
|
||||||
virtual ~GIFView();
|
virtual ~GIFView();
|
||||||
|
|
||||||
mAVStream* getStream() { return &m_encoder.d; }
|
mAVStream* getStream() { return &m_encoder.d; }
|
||||||
|
@ -47,7 +47,7 @@ bool VideoView::Preset::compatible(const Preset& other) const {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
VideoView::VideoView(QWidget* parent)
|
VideoView::VideoView(std::shared_ptr<CoreController> controller, QWidget* parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
{
|
{
|
||||||
m_ui.setupUi(this);
|
m_ui.setupUi(this);
|
||||||
@ -133,6 +133,8 @@ VideoView::VideoView(QWidget* parent)
|
|||||||
|
|
||||||
m_ui.presetYoutube->setChecked(true); // Use the Youtube preset by default
|
m_ui.presetYoutube->setChecked(true); // Use the Youtube preset by default
|
||||||
showAdvanced(false);
|
showAdvanced(false);
|
||||||
|
|
||||||
|
setController(controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoView::updatePresets() {
|
void VideoView::updatePresets() {
|
||||||
|
@ -26,7 +26,7 @@ class VideoView : public QWidget {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
VideoView(QWidget* parent = nullptr);
|
VideoView(std::shared_ptr<CoreController> controller, QWidget* parent = nullptr);
|
||||||
virtual ~VideoView();
|
virtual ~VideoView();
|
||||||
|
|
||||||
mAVStream* getStream() { return &m_encoder.d; }
|
mAVStream* getStream() { return &m_encoder.d; }
|
||||||
|
@ -580,29 +580,35 @@ std::function<void()> Window::openControllerTView(A... arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename... A>
|
template <typename T, typename... A>
|
||||||
std::function<void()> Window::openNamedTView(std::unique_ptr<T>* name, A... arg) {
|
std::function<void()> Window::openNamedTView(QPointer<T>* name, bool keepalive, A... arg) {
|
||||||
return [=]() {
|
return [=]() {
|
||||||
if (!*name) {
|
if (!*name) {
|
||||||
*name = std::make_unique<T>(arg...);
|
*name = new T(arg...);
|
||||||
connect(this, &Window::shutdown, name->get(), &QWidget::close);
|
connect(this, &Window::shutdown, name->get(), &QWidget::close);
|
||||||
|
if (!keepalive) {
|
||||||
|
(*name)->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(*name)->show();
|
(*name)->show();
|
||||||
(*name)->setFocus(Qt::PopupFocusReason);
|
(*name)->activateWindow();
|
||||||
|
(*name)->raise();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename... A>
|
template <typename T, typename... A>
|
||||||
std::function<void()> Window::openNamedControllerTView(std::unique_ptr<T>* name, A... arg) {
|
std::function<void()> Window::openNamedControllerTView(QPointer<T>* name, bool keepalive, A... arg) {
|
||||||
return [=]() {
|
return [=]() {
|
||||||
if (!*name) {
|
if (!*name) {
|
||||||
*name = std::make_unique<T>(arg...);
|
*name = new T(m_controller, arg...);
|
||||||
if (m_controller) {
|
connect(m_controller.get(), &CoreController::stopping, name->get(), &QWidget::close);
|
||||||
(*name)->setController(m_controller);
|
|
||||||
}
|
|
||||||
connect(this, &Window::shutdown, name->get(), &QWidget::close);
|
connect(this, &Window::shutdown, name->get(), &QWidget::close);
|
||||||
|
if (!keepalive) {
|
||||||
|
(*name)->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(*name)->show();
|
(*name)->show();
|
||||||
(*name)->setFocus(Qt::PopupFocusReason);
|
(*name)->activateWindow();
|
||||||
|
(*name)->raise();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1414,7 +1420,7 @@ void Window::setupMenu(QMenuBar* menubar) {
|
|||||||
m_multiWindow = m_actions.addAction(tr("New multiplayer window"), "multiWindow", GBAApp::app(), &GBAApp::newWindow, "file");
|
m_multiWindow = m_actions.addAction(tr("New multiplayer window"), "multiWindow", GBAApp::app(), &GBAApp::newWindow, "file");
|
||||||
|
|
||||||
#ifdef M_CORE_GBA
|
#ifdef M_CORE_GBA
|
||||||
auto dolphin = m_actions.addAction(tr("Connect to Dolphin..."), "connectDolphin", openNamedTView<DolphinConnector>(&m_dolphinView, this), "file");
|
auto dolphin = m_actions.addAction(tr("Connect to Dolphin..."), "connectDolphin", openNamedTView<DolphinConnector>(&m_dolphinView, true, this), "file");
|
||||||
m_platformActions.insert(mPLATFORM_GBA, dolphin);
|
m_platformActions.insert(mPLATFORM_GBA, dolphin);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1695,8 +1701,8 @@ void Window::setupMenu(QMenuBar* menubar) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_FFMPEG
|
#ifdef USE_FFMPEG
|
||||||
addGameAction(tr("Record A/V..."), "recordOutput", openNamedControllerTView<VideoView>(&m_videoView), "av");
|
addGameAction(tr("Record A/V..."), "recordOutput", openNamedControllerTView<VideoView>(&m_videoView, true), "av");
|
||||||
addGameAction(tr("Record GIF/WebP/APNG..."), "recordGIF", openNamedControllerTView<GIFView>(&m_gifView), "av");
|
addGameAction(tr("Record GIF/WebP/APNG..."), "recordGIF", openNamedControllerTView<GIFView>(&m_gifView, true), "av");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_actions.addSeparator("av");
|
m_actions.addSeparator("av");
|
||||||
@ -1710,17 +1716,29 @@ void Window::setupMenu(QMenuBar* menubar) {
|
|||||||
|
|
||||||
m_actions.addAction(tr("Game &overrides..."), "overrideWindow", [this]() {
|
m_actions.addAction(tr("Game &overrides..."), "overrideWindow", [this]() {
|
||||||
if (!m_overrideView) {
|
if (!m_overrideView) {
|
||||||
m_overrideView = std::make_unique<OverrideView>(m_config);
|
m_overrideView = new OverrideView(m_config);
|
||||||
if (m_controller) {
|
if (m_controller) {
|
||||||
m_overrideView->setController(m_controller);
|
m_overrideView->setController(m_controller);
|
||||||
}
|
}
|
||||||
connect(this, &Window::shutdown, m_overrideView.get(), &QWidget::close);
|
connect(this, &Window::shutdown, m_overrideView.get(), &QWidget::close);
|
||||||
}
|
}
|
||||||
m_overrideView->show();
|
m_overrideView->show();
|
||||||
m_overrideView->recheck();
|
m_overrideView->activateWindow();
|
||||||
|
m_overrideView->raise();
|
||||||
}, "tools");
|
}, "tools");
|
||||||
|
|
||||||
m_actions.addAction(tr("Game Pak sensors..."), "sensorWindow", openNamedControllerTView<SensorView>(&m_sensorView, &m_inputController), "tools");
|
m_actions.addAction(tr("Game Pak sensors..."), "sensorWindow", [this]() {
|
||||||
|
if (!m_sensorView) {
|
||||||
|
m_sensorView = new SensorView(&m_inputController);
|
||||||
|
if (m_controller) {
|
||||||
|
m_sensorView->setController(m_controller);
|
||||||
|
}
|
||||||
|
connect(this, &Window::shutdown, m_sensorView.get(), &QWidget::close);
|
||||||
|
}
|
||||||
|
m_sensorView->show();
|
||||||
|
m_sensorView->activateWindow();
|
||||||
|
m_sensorView->raise();
|
||||||
|
}, "tools");
|
||||||
|
|
||||||
addGameAction(tr("&Cheats..."), "cheatsWindow", openControllerTView<CheatsView>(), "tools");
|
addGameAction(tr("&Cheats..."), "cheatsWindow", openControllerTView<CheatsView>(), "tools");
|
||||||
#ifdef ENABLE_SCRIPTING
|
#ifdef ENABLE_SCRIPTING
|
||||||
@ -1750,16 +1768,7 @@ void Window::setupMenu(QMenuBar* menubar) {
|
|||||||
addGameAction(tr("View &sprites..."), "spriteWindow", openControllerTView<ObjView>(), "stateViews");
|
addGameAction(tr("View &sprites..."), "spriteWindow", openControllerTView<ObjView>(), "stateViews");
|
||||||
addGameAction(tr("View &tiles..."), "tileWindow", openControllerTView<TileView>(), "stateViews");
|
addGameAction(tr("View &tiles..."), "tileWindow", openControllerTView<TileView>(), "stateViews");
|
||||||
addGameAction(tr("View &map..."), "mapWindow", openControllerTView<MapView>(), "stateViews");
|
addGameAction(tr("View &map..."), "mapWindow", openControllerTView<MapView>(), "stateViews");
|
||||||
|
addGameAction(tr("&Frame inspector..."), "frameWindow", openNamedControllerTView<FrameView>(&m_frameView, false), "stateViews");
|
||||||
addGameAction(tr("&Frame inspector..."), "frameWindow", [this]() {
|
|
||||||
if (!m_frameView) {
|
|
||||||
m_frameView = new FrameView(m_controller);
|
|
||||||
connect(this, &Window::shutdown, m_frameView, &QWidget::close);
|
|
||||||
m_frameView->setAttribute(Qt::WA_DeleteOnClose);
|
|
||||||
}
|
|
||||||
m_frameView->show();
|
|
||||||
}, "stateViews");
|
|
||||||
|
|
||||||
addGameAction(tr("View memory..."), "memoryView", openControllerTView<MemoryView>(), "stateViews");
|
addGameAction(tr("View memory..."), "memoryView", openControllerTView<MemoryView>(), "stateViews");
|
||||||
addGameAction(tr("Search memory..."), "memorySearch", openControllerTView<MemorySearch>(), "stateViews");
|
addGameAction(tr("Search memory..."), "memorySearch", openControllerTView<MemorySearch>(), "stateViews");
|
||||||
addGameAction(tr("View &I/O registers..."), "ioViewer", openControllerTView<IOViewer>(), "stateViews");
|
addGameAction(tr("View &I/O registers..."), "ioViewer", openControllerTView<IOViewer>(), "stateViews");
|
||||||
|
@ -177,8 +177,8 @@ 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()> openNamedTView(std::unique_ptr<T>*, A... arg);
|
template <typename T, typename... A> std::function<void()> openNamedTView(QPointer<T>*, bool keepalive, A... arg);
|
||||||
template <typename T, typename... A> std::function<void()> openNamedControllerTView(std::unique_ptr<T>*, A... arg);
|
template <typename T, typename... A> std::function<void()> openNamedControllerTView(QPointer<T>*, bool keepalive, A... arg);
|
||||||
|
|
||||||
std::shared_ptr<Action> addGameAction(const QString& visibleName, const QString& name, Action::Function action, const QString& menu = {}, const QKeySequence& = {});
|
std::shared_ptr<Action> addGameAction(const QString& visibleName, const QString& name, Action::Function action, const QString& menu = {}, const QKeySequence& = {});
|
||||||
template<typename T, typename V> std::shared_ptr<Action> addGameAction(const QString& visibleName, const QString& name, T* obj, V (T::*action)(), const QString& menu = {}, const QKeySequence& = {});
|
template<typename T, typename V> std::shared_ptr<Action> addGameAction(const QString& visibleName, const QString& name, T* obj, V (T::*action)(), const QString& menu = {}, const QKeySequence& = {});
|
||||||
@ -241,14 +241,14 @@ private:
|
|||||||
bool m_multiActive = true;
|
bool m_multiActive = true;
|
||||||
int m_playerId;
|
int m_playerId;
|
||||||
|
|
||||||
std::unique_ptr<OverrideView> m_overrideView;
|
QPointer<OverrideView> m_overrideView;
|
||||||
std::unique_ptr<SensorView> m_sensorView;
|
QPointer<SensorView> m_sensorView;
|
||||||
std::unique_ptr<DolphinConnector> m_dolphinView;
|
QPointer<DolphinConnector> m_dolphinView;
|
||||||
QPointer<FrameView> m_frameView;
|
QPointer<FrameView> m_frameView;
|
||||||
|
|
||||||
#ifdef USE_FFMPEG
|
#ifdef USE_FFMPEG
|
||||||
std::unique_ptr<VideoView> m_videoView;
|
QPointer<VideoView> m_videoView;
|
||||||
std::unique_ptr<GIFView> m_gifView;
|
QPointer<GIFView> m_gifView;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_GDB_STUB
|
#ifdef ENABLE_GDB_STUB
|
||||||
|
Loading…
x
Reference in New Issue
Block a user