qt-wrappers.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 QComboBox;
  27. class QWidget;
  28. class QLayout;
  29. class QString;
  30. struct gs_window;
  31. class OBSMessageBox {
  32. public:
  33. static QMessageBox::StandardButton
  34. question(QWidget *parent, const QString &title, const QString &text,
  35. QMessageBox::StandardButtons buttons =
  36. QMessageBox::StandardButtons(QMessageBox::Yes |
  37. QMessageBox::No),
  38. QMessageBox::StandardButton defaultButton =
  39. QMessageBox::NoButton);
  40. static void information(QWidget *parent, const QString &title,
  41. const QString &text);
  42. static void warning(QWidget *parent, const QString &title,
  43. const QString &text, bool enableRichText = false);
  44. static void critical(QWidget *parent, const QString &title,
  45. const QString &text);
  46. };
  47. void OBSErrorBox(QWidget *parent, const char *msg, ...);
  48. void QTToGSWindow(WId windowId, gs_window &gswindow);
  49. uint32_t TranslateQtKeyboardEventModifiers(Qt::KeyboardModifiers mods);
  50. QDataStream &
  51. operator<<(QDataStream &out,
  52. const std::vector<std::shared_ptr<OBSSignal>> &signal_vec);
  53. QDataStream &operator>>(QDataStream &in,
  54. std::vector<std::shared_ptr<OBSSignal>> &signal_vec);
  55. QDataStream &operator<<(QDataStream &out, const OBSScene &scene);
  56. QDataStream &operator>>(QDataStream &in, OBSScene &scene);
  57. QDataStream &operator<<(QDataStream &out, const OBSSceneItem &si);
  58. QDataStream &operator>>(QDataStream &in, OBSSceneItem &si);
  59. QThread *CreateQThread(std::function<void()> func);
  60. void ExecuteFuncSafeBlock(std::function<void()> func);
  61. void ExecuteFuncSafeBlockMsgBox(std::function<void()> func,
  62. const QString &title, const QString &text);
  63. /* allows executing without message boxes if starting up, otherwise with a
  64. * message box */
  65. void EnableThreadedMessageBoxes(bool enable);
  66. void ExecThreadedWithoutBlocking(std::function<void()> func,
  67. const QString &title, const QString &text);
  68. class SignalBlocker {
  69. QWidget *widget;
  70. bool blocked;
  71. public:
  72. inline explicit SignalBlocker(QWidget *widget_) : widget(widget_)
  73. {
  74. blocked = widget->blockSignals(true);
  75. }
  76. inline ~SignalBlocker() { widget->blockSignals(blocked); }
  77. };
  78. void DeleteLayout(QLayout *layout);
  79. static inline Qt::ConnectionType WaitConnection()
  80. {
  81. return QThread::currentThread() == qApp->thread()
  82. ? Qt::DirectConnection
  83. : Qt::BlockingQueuedConnection;
  84. }
  85. bool LineEditCanceled(QEvent *event);
  86. bool LineEditChanged(QEvent *event);
  87. void SetComboItemEnabled(QComboBox *c, int idx, bool enabled);
  88. void setThemeID(QWidget *widget, const QString &themeID);
  89. QString SelectDirectory(QWidget *parent, QString title, QString path);
  90. QString SaveFile(QWidget *parent, QString title, QString path,
  91. QString extensions);
  92. QString OpenFile(QWidget *parent, QString title, QString path,
  93. QString extensions);
  94. QStringList OpenFiles(QWidget *parent, QString title, QString path,
  95. QString extensions);