SourceTree.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #pragma once
  2. #include "SourceTreeItem.hpp"
  3. #include "SourceTreeModel.hpp"
  4. #include <QListView>
  5. #include <QStaticText>
  6. #include <QSvgRenderer>
  7. class SourceTree : public QListView {
  8. Q_OBJECT
  9. bool ignoreReorder = false;
  10. friend class SourceTreeModel;
  11. friend class SourceTreeItem;
  12. bool textPrepared = false;
  13. QStaticText textNoSources;
  14. QSvgRenderer iconNoSources;
  15. OBSData undoSceneData;
  16. bool iconsVisible = true;
  17. void UpdateNoSourcesMessage();
  18. void ResetWidgets();
  19. void UpdateWidget(const QModelIndex &idx, obs_sceneitem_t *item);
  20. void UpdateWidgets(bool force = false);
  21. inline SourceTreeModel *GetStm() const { return reinterpret_cast<SourceTreeModel *>(model()); }
  22. public:
  23. inline SourceTreeItem *GetItemWidget(int idx)
  24. {
  25. QWidget *widget = indexWidget(GetStm()->createIndex(idx, 0));
  26. return reinterpret_cast<SourceTreeItem *>(widget);
  27. }
  28. explicit SourceTree(QWidget *parent = nullptr);
  29. inline bool IgnoreReorder() const { return ignoreReorder; }
  30. inline void Clear() { GetStm()->Clear(); }
  31. inline void Add(obs_sceneitem_t *item) { GetStm()->Add(item); }
  32. inline OBSSceneItem Get(int idx) { return GetStm()->Get(idx); }
  33. inline QString GetNewGroupName() { return GetStm()->GetNewGroupName(); }
  34. void SelectItem(obs_sceneitem_t *sceneitem, bool select);
  35. bool MultipleBaseSelected() const;
  36. bool GroupsSelected() const;
  37. bool GroupedItemsSelected() const;
  38. void UpdateIcons();
  39. void SetIconsVisible(bool visible);
  40. public slots:
  41. inline void ReorderItems() { GetStm()->ReorderItems(); }
  42. inline void RefreshItems() { GetStm()->SceneChanged(); }
  43. void Remove(OBSSceneItem item, OBSScene scene);
  44. void GroupSelectedItems();
  45. void UngroupSelectedGroups();
  46. void AddGroup();
  47. bool Edit(int idx);
  48. void NewGroupEdit(int idx);
  49. protected:
  50. virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
  51. virtual void dropEvent(QDropEvent *event) override;
  52. virtual void paintEvent(QPaintEvent *event) override;
  53. virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override;
  54. };