qt-wrappers.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #pragma once
  15. #include <QApplication>
  16. #include <QMessageBox>
  17. #include <QWidget>
  18. #include <QThread>
  19. #include <obs.hpp>
  20. #include <functional>
  21. #include <memory>
  22. #include <vector>
  23. #define QT_UTF8(str) QString::fromUtf8(str)
  24. #define QT_TO_UTF8(str) str.toUtf8().constData()
  25. class QDataStream;
  26. class QWidget;
  27. class QLayout;
  28. class QString;
  29. struct gs_window;
  30. class OBSMessageBox {
  31. public:
  32. static QMessageBox::StandardButton question(
  33. QWidget *parent,
  34. const QString &title,
  35. const QString &text,
  36. QMessageBox::StandardButtons buttons = QMessageBox::StandardButtons( QMessageBox::Yes | QMessageBox::No ),
  37. QMessageBox::StandardButton defaultButton = QMessageBox::NoButton);
  38. static void information(
  39. QWidget *parent,
  40. const QString &title,
  41. const QString &text);
  42. static void warning(
  43. QWidget *parent,
  44. const QString &title,
  45. const QString &text,
  46. bool enableRichText = false);
  47. static void critical(
  48. QWidget *parent,
  49. const QString &title,
  50. const QString &text);
  51. };
  52. void OBSErrorBox(QWidget *parent, const char *msg, ...);
  53. void QTToGSWindow(WId windowId, gs_window &gswindow);
  54. uint32_t TranslateQtKeyboardEventModifiers(Qt::KeyboardModifiers mods);
  55. QDataStream &operator<<(QDataStream &out,
  56. const std::vector<std::shared_ptr<OBSSignal>> &signal_vec);
  57. QDataStream &operator>>(QDataStream &in,
  58. std::vector<std::shared_ptr<OBSSignal>> &signal_vec);
  59. QDataStream &operator<<(QDataStream &out, const OBSScene &scene);
  60. QDataStream &operator>>(QDataStream &in, OBSScene &scene);
  61. QDataStream &operator<<(QDataStream &out, const OBSSceneItem &si);
  62. QDataStream &operator>>(QDataStream &in, OBSSceneItem &si);
  63. QThread *CreateQThread(std::function<void()> func);
  64. void ExecuteFuncSafeBlock(std::function<void()> func);
  65. void ExecuteFuncSafeBlockMsgBox(
  66. std::function<void()> func,
  67. const QString &title,
  68. const QString &text);
  69. /* allows executing without message boxes if starting up, otherwise with a
  70. * message box */
  71. void EnableThreadedMessageBoxes(bool enable);
  72. void ExecThreadedWithoutBlocking(
  73. std::function<void()> func,
  74. const QString &title,
  75. const QString &text);
  76. class SignalBlocker {
  77. QWidget *widget;
  78. bool blocked;
  79. public:
  80. inline explicit SignalBlocker(QWidget *widget_) : widget(widget_)
  81. {
  82. blocked = widget->blockSignals(true);
  83. }
  84. inline ~SignalBlocker()
  85. {
  86. widget->blockSignals(blocked);
  87. }
  88. };
  89. void DeleteLayout(QLayout *layout);
  90. static inline Qt::ConnectionType WaitConnection()
  91. {
  92. return QThread::currentThread() == qApp->thread()
  93. ? Qt::DirectConnection
  94. : Qt::BlockingQueuedConnection;
  95. }