qt-wrappers.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 <memory>
  21. #include <vector>
  22. #define QT_UTF8(str) QString::fromUtf8(str)
  23. #define QT_TO_UTF8(str) str.toUtf8().constData()
  24. class QDataStream;
  25. class QWidget;
  26. class QLayout;
  27. class QString;
  28. struct gs_window;
  29. class OBSMessageBox {
  30. public:
  31. static QMessageBox::StandardButton question(
  32. QWidget *parent,
  33. const QString &title,
  34. const QString &text,
  35. QMessageBox::StandardButtons buttons = QMessageBox::StandardButtons( QMessageBox::Yes | QMessageBox::No ),
  36. QMessageBox::StandardButton defaultButton = QMessageBox::NoButton);
  37. static void information(
  38. QWidget *parent,
  39. const QString &title,
  40. const QString &text);
  41. };
  42. void OBSErrorBox(QWidget *parent, const char *msg, ...);
  43. void QTToGSWindow(WId windowId, gs_window &gswindow);
  44. uint32_t TranslateQtKeyboardEventModifiers(Qt::KeyboardModifiers mods);
  45. QDataStream &operator<<(QDataStream &out,
  46. const std::vector<std::shared_ptr<OBSSignal>> &signal_vec);
  47. QDataStream &operator>>(QDataStream &in,
  48. std::vector<std::shared_ptr<OBSSignal>> &signal_vec);
  49. QDataStream &operator<<(QDataStream &out, const OBSScene &scene);
  50. QDataStream &operator>>(QDataStream &in, OBSScene &scene);
  51. QDataStream &operator<<(QDataStream &out, const OBSSceneItem &si);
  52. QDataStream &operator>>(QDataStream &in, OBSSceneItem &si);
  53. class SignalBlocker {
  54. QWidget *widget;
  55. bool blocked;
  56. public:
  57. inline explicit SignalBlocker(QWidget *widget_) : widget(widget_)
  58. {
  59. blocked = widget->blockSignals(true);
  60. }
  61. inline ~SignalBlocker()
  62. {
  63. widget->blockSignals(blocked);
  64. }
  65. };
  66. void DeleteLayout(QLayout *layout);
  67. static inline Qt::ConnectionType WaitConnection()
  68. {
  69. return QThread::currentThread() == qApp->thread()
  70. ? Qt::DirectConnection
  71. : Qt::BlockingQueuedConnection;
  72. }