diff --git a/UI/qt-wrappers.cpp b/UI/qt-wrappers.cpp index 5ab41a9e5..8abfe17be 100644 --- a/UI/qt-wrappers.cpp +++ b/UI/qt-wrappers.cpp @@ -16,6 +16,8 @@ ******************************************************************************/ #include "qt-wrappers.hpp" +#include "obs-app.hpp" + #include #include #include @@ -42,6 +44,50 @@ void OBSErrorBox(QWidget *parent, const char *msg, ...) va_end(args); } +QMessageBox::StandardButton OBSMessageBox::question( + QWidget *parent, + const QString &title, + const QString &text, + QMessageBox::StandardButtons buttons, + QMessageBox::StandardButton defaultButton) +{ + QMessageBox mb(QMessageBox::Question, + title, text, buttons, + parent); + mb.setDefaultButton(defaultButton); +#define translate_button(x) \ + if (buttons & QMessageBox::x) \ + mb.setButtonText(QMessageBox::x, QTStr(#x)); + translate_button(Ok); + translate_button(Open); + translate_button(Save); + translate_button(Cancel); + translate_button(Close); + translate_button(Discard); + translate_button(Apply); + translate_button(Reset); + translate_button(Yes); + translate_button(No); + translate_button(No); + translate_button(Abort); + translate_button(Retry); + translate_button(Ignore); +#undef translate_button + return (QMessageBox::StandardButton)mb.exec(); +} + +void OBSMessageBox::information( + QWidget *parent, + const QString &title, + const QString &text) +{ + QMessageBox mb(QMessageBox::Information, + title, text, QMessageBox::Ok, + parent); + mb.setButtonText(QMessageBox::Ok, QTStr("OK")); + mb.exec(); +} + void QTToGSWindow(WId windowId, gs_window &gswindow) { #ifdef _WIN32 diff --git a/UI/qt-wrappers.hpp b/UI/qt-wrappers.hpp index aec516ebb..7899387bf 100644 --- a/UI/qt-wrappers.hpp +++ b/UI/qt-wrappers.hpp @@ -17,6 +17,7 @@ #pragma once +#include #include #include @@ -29,8 +30,23 @@ class QDataStream; class QWidget; class QLayout; +class QString; struct gs_window; +class OBSMessageBox { +public: + static QMessageBox::StandardButton question( + QWidget *parent, + const QString &title, + const QString &text, + QMessageBox::StandardButtons buttons = QMessageBox::StandardButtons( QMessageBox::Yes | QMessageBox::No ), + QMessageBox::StandardButton defaultButton = QMessageBox::NoButton); + static void information( + QWidget *parent, + const QString &title, + const QString &text); +}; + void OBSErrorBox(QWidget *parent, const char *msg, ...); void QTToGSWindow(WId windowId, gs_window &gswindow);