qt-wrappers.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. #include "qt-wrappers.hpp"
  15. #include <graphics/graphics.h>
  16. #include <QWidget>
  17. #include <QMessageBox>
  18. #include <QDataStream>
  19. #if !defined(_WIN32) && !defined(__APPLE__)
  20. #include <QX11Info>
  21. #endif
  22. static inline void OBSErrorBoxva(QWidget *parent, const char *msg, va_list args)
  23. {
  24. char full_message[4096];
  25. vsnprintf(full_message, 4095, msg, args);
  26. QMessageBox::critical(parent, "Error", full_message);
  27. }
  28. void OBSErrorBox(QWidget *parent, const char *msg, ...)
  29. {
  30. va_list args;
  31. va_start(args, msg);
  32. OBSErrorBoxva(parent, msg, args);
  33. va_end(args);
  34. }
  35. void QTToGSWindow(WId windowId, gs_window &gswindow)
  36. {
  37. #ifdef _WIN32
  38. gswindow.hwnd = (HWND)windowId;
  39. #elif __APPLE__
  40. gswindow.view = (id)windowId;
  41. #else
  42. gswindow.id = windowId;
  43. gswindow.display = QX11Info::display();
  44. #endif
  45. }
  46. uint32_t TranslateQtKeyboardEventModifiers(Qt::KeyboardModifiers mods)
  47. {
  48. int obsModifiers = INTERACT_NONE;
  49. if (mods.testFlag(Qt::ShiftModifier))
  50. obsModifiers |= INTERACT_SHIFT_KEY;
  51. if (mods.testFlag(Qt::AltModifier))
  52. obsModifiers |= INTERACT_ALT_KEY;
  53. #ifdef __APPLE__
  54. // Mac: Meta = Control, Control = Command
  55. if (mods.testFlag(Qt::ControlModifier))
  56. obsModifiers |= INTERACT_COMMAND_KEY;
  57. if (mods.testFlag(Qt::MetaModifier))
  58. obsModifiers |= INTERACT_CONTROL_KEY;
  59. #else
  60. // Handle windows key? Can a browser even trap that key?
  61. if (mods.testFlag(Qt::ControlModifier))
  62. obsModifiers |= INTERACT_CONTROL_KEY;
  63. if (mods.testFlag(Qt::MetaModifier))
  64. obsModifiers |= INTERACT_COMMAND_KEY;
  65. #endif
  66. return obsModifiers;
  67. }
  68. QDataStream &operator<<(QDataStream &out,
  69. const std::vector<std::shared_ptr<OBSSignal>> &)
  70. {
  71. return out;
  72. }
  73. QDataStream &operator>>(QDataStream &in,
  74. std::vector<std::shared_ptr<OBSSignal>> &)
  75. {
  76. return in;
  77. }
  78. QDataStream &operator<<(QDataStream &out, const OBSScene &scene)
  79. {
  80. return out << QString(obs_source_get_name(obs_scene_get_source(scene)));
  81. }
  82. QDataStream &operator>>(QDataStream &in, OBSScene &scene)
  83. {
  84. QString sceneName;
  85. in >> sceneName;
  86. obs_source_t *source = obs_get_source_by_name(QT_TO_UTF8(sceneName));
  87. scene = obs_scene_from_source(source);
  88. return in;
  89. }
  90. QDataStream &operator<<(QDataStream &out, const OBSSceneItem &si)
  91. {
  92. obs_scene_t *scene = obs_sceneitem_get_scene(si);
  93. obs_source_t *source = obs_sceneitem_get_source(si);
  94. return out << QString(obs_source_get_name(obs_scene_get_source(scene)))
  95. << QString(obs_source_get_name(source));
  96. }
  97. QDataStream &operator>>(QDataStream &in, OBSSceneItem &si)
  98. {
  99. QString sceneName;
  100. QString sourceName;
  101. in >> sceneName >> sourceName;
  102. obs_source_t *sceneSource =
  103. obs_get_source_by_name(QT_TO_UTF8(sceneName));
  104. obs_scene_t *scene = obs_scene_from_source(sceneSource);
  105. si = obs_scene_find_source(scene, QT_TO_UTF8(sourceName));
  106. obs_source_release(sceneSource);
  107. return in;
  108. }