OBSBasicSourceSelect.hpp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /******************************************************************************
  2. Copyright (C) 2023 by Lain Bailey <[email protected]>
  3. Copyright (C) 2025 by Taylor Giampaolo <[email protected]>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. ******************************************************************************/
  15. #pragma once
  16. #include <OBSApp.hpp>
  17. #include "ui_OBSBasicSourceSelect.h"
  18. #include <components/FlowLayout.hpp>
  19. #include <components/SourceSelectButton.hpp>
  20. #include <utility/undo_stack.hpp>
  21. #include <widgets/OBSBasic.hpp>
  22. #include <QButtonGroup>
  23. #include <QDialog>
  24. constexpr int UNVERSIONED_ID_ROLE = Qt::UserRole + 1;
  25. constexpr int DEPRECATED_ROLE = Qt::UserRole + 2;
  26. class OBSBasicSourceSelect : public QDialog {
  27. Q_OBJECT
  28. private:
  29. std::unique_ptr<Ui::OBSBasicSourceSelect> ui;
  30. QString sourceTypeId;
  31. undo_stack &undo_s;
  32. QPointer<QButtonGroup> sourceButtons;
  33. std::vector<obs_source_t *> sources;
  34. std::vector<obs_source_t *> groups;
  35. QPointer<FlowLayout> existingFlowLayout = nullptr;
  36. void getSources();
  37. void updateExistingSources(int limit = 0);
  38. static bool enumSourcesCallback(void *data, obs_source_t *source);
  39. static bool enumGroupsCallback(void *data, obs_source_t *source);
  40. static void OBSSourceRemoved(void *data, calldata_t *calldata);
  41. static void OBSSourceAdded(void *data, calldata_t *calldata);
  42. void getSourceTypes();
  43. void setSelectedSourceType(QListWidgetItem *item);
  44. int lastSelectedIndex = -1;
  45. std::vector<SourceSelectButton *> selectedItems;
  46. void setSelectedSource(SourceSelectButton *button);
  47. void addSelectedItem(SourceSelectButton *button);
  48. void removeSelectedItem(SourceSelectButton *button);
  49. void clearSelectedItems();
  50. void createNewSource();
  51. void addExistingSource(QString name, bool visible);
  52. void checkSourceVisibility();
  53. signals:
  54. void sourcesUpdated();
  55. void selectedItemsChanged();
  56. public slots:
  57. void on_createNewSource_clicked(bool checked);
  58. void addSelectedSources();
  59. void sourceTypeSelected(QListWidgetItem *current, QListWidgetItem *previous);
  60. void sourceButtonToggled(QAbstractButton *button, bool checked);
  61. void sourceDropped(QString uuid);
  62. public:
  63. OBSBasicSourceSelect(OBSBasic *parent, undo_stack &undo_s);
  64. ~OBSBasicSourceSelect();
  65. OBSSource newSource;
  66. static void SourcePaste(SourceCopyInfo &info, bool duplicate);
  67. };