qt-wrappers.hpp 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /******************************************************************************
  2. Copyright (C) 2023 by Lain 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 <QWindow>
  19. #include <QThread>
  20. #include <obs.hpp>
  21. #include <functional>
  22. #include <memory>
  23. #include <vector>
  24. #define QT_UTF8(str) QString::fromUtf8(str, -1)
  25. #define QT_TO_UTF8(str) str.toUtf8().constData()
  26. #define MAX_LABEL_LENGTH 80
  27. class QDataStream;
  28. class QComboBox;
  29. class QWidget;
  30. class QLayout;
  31. class QString;
  32. class QLabel;
  33. class QToolBar;
  34. class OBSMessageBox : QObject {
  35. Q_OBJECT
  36. public:
  37. static QMessageBox::StandardButton question(
  38. QWidget *parent, const QString &title, const QString &text,
  39. QMessageBox::StandardButtons buttons = QMessageBox::StandardButtons(QMessageBox::Yes | QMessageBox::No),
  40. QMessageBox::StandardButton defaultButton = QMessageBox::NoButton);
  41. static void information(QWidget *parent, const QString &title, const QString &text);
  42. static void warning(QWidget *parent, const QString &title, const QString &text, bool enableRichText = false);
  43. static void critical(QWidget *parent, const QString &title, const QString &text);
  44. };
  45. void OBSErrorBox(QWidget *parent, const char *msg, ...);
  46. uint32_t TranslateQtKeyboardEventModifiers(Qt::KeyboardModifiers mods);
  47. QDataStream &operator<<(QDataStream &out, const std::vector<std::shared_ptr<OBSSignal>> &signal_vec);
  48. QDataStream &operator>>(QDataStream &in, 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 OBSSource &source);
  52. QDataStream &operator>>(QDataStream &in, OBSSource &source);
  53. QThread *CreateQThread(std::function<void()> func);
  54. void ExecuteFuncSafeBlock(std::function<void()> func);
  55. void ExecuteFuncSafeBlockMsgBox(std::function<void()> func, const QString &title, const QString &text);
  56. /* allows executing without message boxes if starting up, otherwise with a
  57. * message box */
  58. void EnableThreadedMessageBoxes(bool enable);
  59. void ExecThreadedWithoutBlocking(std::function<void()> func, const QString &title, const QString &text);
  60. void DeleteLayout(QLayout *layout);
  61. static inline Qt::ConnectionType WaitConnection()
  62. {
  63. return QThread::currentThread() == qApp->thread() ? Qt::DirectConnection : Qt::BlockingQueuedConnection;
  64. }
  65. bool LineEditCanceled(QEvent *event);
  66. bool LineEditChanged(QEvent *event);
  67. void SetComboItemEnabled(QComboBox *c, int idx, bool enabled);
  68. void setClasses(QWidget *widget, const QString &newClasses);
  69. QString SelectDirectory(QWidget *parent, QString title, QString path);
  70. QString SaveFile(QWidget *parent, QString title, QString path, QString extensions);
  71. QString OpenFile(QWidget *parent, QString title, QString path, QString extensions);
  72. QStringList OpenFiles(QWidget *parent, QString title, QString path, QString extensions);
  73. void TruncateLabel(QLabel *label, QString newText, int length = MAX_LABEL_LENGTH);
  74. void RefreshToolBarStyling(QToolBar *toolBar);