├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── cmake ├── ProjectConfig.cmake.in └── version.h.in ├── data └── locale │ ├── en-US.ini │ ├── pt-BR.ini │ └── ru-RU.ini ├── forms ├── scene_tree_view.ui └── scene_tree_view_frame.ui ├── images └── obs_scene_tree_view_example.png └── obs_scene_tree_view ├── obs_scene_tree_view.cpp ├── obs_scene_tree_view.h ├── stv_item_model.cpp ├── stv_item_model.h ├── stv_item_view.cpp └── stv_item_view.h /.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /build_win 3 | CMakeLists.txt.user* 4 | 5 | # ---> CMake 6 | CMakeCache.txt 7 | CMakeFiles 8 | CMakeScripts 9 | Makefile 10 | cmake_install.cmake 11 | install_manifest.txt 12 | 13 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(PROJECT_NAME "obs_scene_tree_view") 2 | set(HEADER_DIRECTORY "obs_scene_tree_view") 3 | 4 | set(NAMESPACE_NAME "${PROJECT_NAME}") 5 | 6 | set(LIBRARY_NAME "${PROJECT_NAME}") 7 | set(EXECUTABLE_NAME "${PROJECT_NAME}Exec") 8 | set(TEST_NAME "${PROJECT_NAME}Tests") 9 | 10 | set(LIB_EXPORT_NAME "${LIBRARY_NAME}Targets") 11 | set(LIB_CONFIG_NAME "${LIBRARY_NAME}Config") 12 | set(LIB_VERSION_NAME "${LIB_CONFIG_NAME}Version") 13 | 14 | cmake_minimum_required(VERSION 3.20) 15 | project("${PROJECT_NAME}" VERSION 0.1.5) 16 | 17 | if(NOT DEFINED BUILD_IN_OBS) 18 | set(BUILD_IN_OBS OFF) 19 | endif() 20 | 21 | find_package(Qt6 REQUIRED COMPONENTS Widgets) 22 | 23 | if(NOT ${BUILD_IN_OBS}) 24 | set(CMAKE_CXX_STANDARD 20) 25 | 26 | find_package(libobs REQUIRED) 27 | find_package(obs-frontend-api REQUIRED) 28 | 29 | if(NOT DEFINED LIBOBS_PLUGIN_DESTINATION) 30 | set(LIBOBS_PLUGIN_DESTINATION "lib/obs-plugins") 31 | endif() 32 | 33 | if(NOT DEFINED LIBOBS_PLUGIN_DATA_DESTINATION) 34 | set(LIBOBS_PLUGIN_DATA_DESTINATION "share/obs/obs-plugins") 35 | endif() 36 | 37 | set(OBS_PLUGIN_LIB_DIR "${LIBOBS_PLUGIN_DESTINATION}" CACHE PATH "Path to obs plugins (relative to CMAKE_INSTALL_PREFIX)") 38 | set(OBS_PLUGIN_DATA_DIR "${LIBOBS_PLUGIN_DATA_DESTINATION}" CACHE PATH "Path to scene tree view data dir (relative to CMAKE_INSTALL_PREFIX)") 39 | 40 | if(WIN32) 41 | message(WARNING "Building ${PROJECT_NAME} outside of OBS is currently not supported") 42 | endif() 43 | endif() 44 | 45 | if(NOT TARGET OBS::obs-frontend-api) 46 | add_library(OBS::obs-frontend-api ALIAS obs-frontend-api) 47 | endif() 48 | 49 | set(LIB_SRC_FILES 50 | obs_scene_tree_view/obs_scene_tree_view.cpp 51 | obs_scene_tree_view/stv_item_model.cpp 52 | obs_scene_tree_view/stv_item_view.cpp 53 | ) 54 | 55 | 56 | ########################################## 57 | ## Version 58 | configure_file(cmake/version.h.in "${CMAKE_CURRENT_BINARY_DIR}/include/${HEADER_DIRECTORY}/version.h" @ONLY) 59 | 60 | 61 | ########################################## 62 | ## Qt6 UI 63 | set(CMAKE_AUTOUIC_SEARCH_PATHS ${CMAKE_AUTOUIC_SEARCH_PATHS} "${CMAKE_CURRENT_SOURCE_DIR}/forms") 64 | set(CMAKE_AUTOUIC ON) 65 | set(CMAKE_AUTOMOC ON) 66 | 67 | 68 | ########################################## 69 | ## Library 70 | add_library(${LIBRARY_NAME} SHARED ${LIB_SRC_FILES} ${VT_UI_HEADERS}) 71 | add_library("${NAMESPACE_NAME}::${LIBRARY_NAME}" ALIAS ${LIBRARY_NAME}) 72 | target_compile_options(${LIBRARY_NAME} PUBLIC $<$,$>:-Wall -Wextra>) 73 | 74 | set_target_properties(${LIBRARY_NAME} PROPERTIES PREFIX "") 75 | 76 | target_include_directories(${LIBRARY_NAME} 77 | PUBLIC 78 | "$" 79 | "$" 80 | "$" 81 | 82 | PRIVATE 83 | ) 84 | 85 | target_link_libraries(${LIBRARY_NAME} 86 | PUBLIC 87 | OBS::libobs 88 | OBS::obs-frontend-api 89 | Qt6::Widgets 90 | 91 | PRIVATE 92 | ) 93 | 94 | 95 | ########################################## 96 | ## Install files 97 | if(${BUILD_IN_OBS}) 98 | install_obs_plugin_with_data(${LIBRARY_NAME} data) 99 | else() 100 | install(TARGETS ${LIBRARY_NAME} 101 | EXPORT ${LIB_EXPORT_NAME} 102 | LIBRARY DESTINATION "${OBS_PLUGIN_LIB_DIR}" 103 | ARCHIVE DESTINATION "${OBS_PLUGIN_LIB_DIR}") 104 | 105 | install(DIRECTORY "data/locale" 106 | DESTINATION "${OBS_PLUGIN_DATA_DIR}/${PROJECT_NAME}") 107 | endif() 108 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Scene Tree Folder plugin for OBS Studio 2 | 3 | Plugin for OBS that adds a scene tree folder dock 4 | 5 | ![Screenshot](images/obs_scene_tree_view_example.png) 6 | 7 | ## Build 8 | 9 | ### Linux 10 | 11 | - Ensure that `obs-studio` and `qt5-base` are installed 12 | - Arch Linux: `sudo pacman -S obs-studio qt5-base` 13 | - Download repository 14 | - Execute inside the repository directory: 15 | ```bash 16 | mkdir build 17 | cd build 18 | cmake .. 19 | make 20 | sudo make install 21 | ``` 22 | 23 | ### Windows 24 | 25 | - Setup OBS Studio build environment (see https://obsproject.com/wiki/Install-Instructions) 26 | - Download this repository into `UI/frontend-plugins/obs_scene_tree_view` 27 | - Add the following to `UI/frontend-plugins/CMakeLists.txt`: 28 | ```cmake 29 | set(BUILD_IN_OBS ON) 30 | add_subdirectory(obs_scene_tree_view) 31 | ``` 32 | - Build and install OBS Studio 33 | 34 | 35 | ## Installation 36 | 37 | ### Linux 38 | 39 | #### Arch Linux 40 | 41 | Available via the `obs-scene-tree-view-git` AUR package: 42 | 43 | ```bash 44 | pikaur -S obs-scene-tree-view-git 45 | ``` 46 | 47 | ### Windows 48 | 49 | Visit [Releases](https://github.com/DigitOtter/obs_scene_tree_view/releases) and follow the installation instructions for the newest version. 50 | 51 | ## Todos 52 | 53 | - [ ] Undo/Redo scene rename does not update SceneTree 54 | - [ ] Add Fullscreen Viewport Projector option to scene context menu 55 | 56 | -------------------------------------------------------------------------------- /cmake/ProjectConfig.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | include(${CMAKE_CURRENT_LIST_DIR}/@LIB_EXPORT_NAME@.cmake) 4 | 5 | -------------------------------------------------------------------------------- /cmake/version.h.in: -------------------------------------------------------------------------------- 1 | #ifndef VERSION_H 2 | #define VERSION_H 3 | 4 | #define PROJECT_VERSION "@PROJECT_VERSION@" 5 | #define PROJECT_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ 6 | #define PROJECT_VERSION_MINOR @PROJECT_VERSION_MINOR@ 7 | #define PROJECT_VERSION_PATCH @PROJECT_VERSION_PATCH@ 8 | 9 | #define PROJECT_DATA_FOLDER "@PROJECT_NAME@" 10 | 11 | #endif // VERSION_H 12 | -------------------------------------------------------------------------------- /data/locale/en-US.ini: -------------------------------------------------------------------------------- 1 | SceneTreeView.DefaultFolderName="Folder %1" 2 | SceneTreeView.Title="SceneTree" 3 | SceneTreeView.Add="Add" 4 | SceneTreeView.Remove="Remove" 5 | SceneTreeView.AddScene="Add Scene" 6 | SceneTreeView.AddFolder="Add Folder" 7 | SceneTreeView.ToggleFolderIcons="Toggle Folder Icons" 8 | SceneTreeView.ToggleSceneIcons="Toggle Scene Icons" 9 | -------------------------------------------------------------------------------- /data/locale/pt-BR.ini: -------------------------------------------------------------------------------- 1 | SceneTreeView.DefaultFolderName="Pasta %1" 2 | SceneTreeView.Title="SceneTree" 3 | SceneTreeView.Add="Adicionar" 4 | SceneTreeView.Remove="Remover" 5 | SceneTreeView.AddScene="Adicionar Cena" 6 | SceneTreeView.AddFolder="Adicionar Pasta" 7 | SceneTreeView.ToggleFolderIcons="Alternar Ícones de Pasta" 8 | SceneTreeView.ToggleSceneIcons="Alternar Ícones de Cena" 9 | -------------------------------------------------------------------------------- /data/locale/ru-RU.ini: -------------------------------------------------------------------------------- 1 | SceneTreeView.DefaultFolderName="Папка %1" 2 | SceneTreeView.Title="SceneTree" 3 | SceneTreeView.Add="Добавить" 4 | SceneTreeView.Remove="Удалить" 5 | SceneTreeView.AddScene="Добавить сцену" 6 | SceneTreeView.AddFolder="Добавить папку" 7 | SceneTreeView.ToggleFolderIcons="Отображать иконки папок" 8 | SceneTreeView.ToggleSceneIcons="Отображать иконки сцен" 9 | -------------------------------------------------------------------------------- /forms/scene_tree_view.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | STVDock 4 | 5 | 6 | 7 | 0 8 | 0 9 | 532 10 | 263 11 | 12 | 13 | 14 | show-decoration-selected: 1 15 | 16 | 17 | true 18 | 19 | 20 | SceneTreeView.Title 21 | 22 | 23 | 24 | 25 | 0 26 | 27 | 28 | 0 29 | 30 | 31 | 0 32 | 33 | 34 | 0 35 | 36 | 37 | 38 | 39 | QFrame::StyledPanel 40 | 41 | 42 | QFrame::Raised 43 | 44 | 45 | 46 | 0 47 | 48 | 49 | 0 50 | 51 | 52 | 0 53 | 54 | 55 | 0 56 | 57 | 58 | 0 59 | 60 | 61 | 62 | 63 | Qt::CustomContextMenu 64 | 65 | 66 | QAbstractItemView::InternalMove 67 | 68 | 69 | Qt::TargetMoveAction 70 | 71 | 72 | QAbstractItemView::SelectItems 73 | 74 | 75 | true 76 | 77 | 78 | true 79 | 80 | 81 | 82 | 83 | 84 | 85 | true 86 | 87 | 88 | 89 | 1 90 | 91 | 92 | 4 93 | 94 | 95 | 4 96 | 97 | 98 | 4 99 | 100 | 101 | 4 102 | 103 | 104 | 105 | 106 | SceneTreeView.Add 107 | 108 | 109 | true 110 | 111 | 112 | addIconSmall 113 | 114 | 115 | 116 | 117 | 118 | 119 | SceneTreeView.Remove 120 | 121 | 122 | true 123 | 124 | 125 | removeIconSmall 126 | 127 | 128 | 129 | 130 | 131 | 132 | QFrame::Plain 133 | 134 | 135 | Qt::Vertical 136 | 137 | 138 | 139 | 140 | 141 | 142 | SceneTreeView.AddFolder 143 | 144 | 145 | true 146 | 147 | 148 | 149 | 150 | 151 | 152 | Qt::Horizontal 153 | 154 | 155 | 156 | 40 157 | 20 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | StvItemView 174 | QTreeView 175 |
obs_scene_tree_view/stv_item_view.h
176 |
177 |
178 | 179 | 180 |
181 | -------------------------------------------------------------------------------- /forms/scene_tree_view_frame.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | STVFrame 4 | 5 | 6 | 7 | 0 8 | 0 9 | 492 10 | 267 11 | 12 | 13 | 14 | Frame 15 | 16 | 17 | 18 | 19 | 20 | QFrame::StyledPanel 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | SourceTreeView.Add 30 | 31 | 32 | 33 | 34 | 35 | 36 | SourceTreeView.Remove 37 | 38 | 39 | 40 | 41 | 42 | 43 | Qt::Horizontal 44 | 45 | 46 | 47 | 40 48 | 20 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | SourceTreeView.Config 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /images/obs_scene_tree_view_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DigitOtter/obs_scene_tree_view/212385dfd46fb18f38dbdcd3beef84dc5e168458/images/obs_scene_tree_view_example.png -------------------------------------------------------------------------------- /obs_scene_tree_view/obs_scene_tree_view.cpp: -------------------------------------------------------------------------------- 1 | #include "obs_scene_tree_view/obs_scene_tree_view.h" 2 | 3 | #include "obs_scene_tree_view/version.h" 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | 18 | OBS_DECLARE_MODULE(); 19 | OBS_MODULE_AUTHOR("DigitOtter"); 20 | OBS_MODULE_USE_DEFAULT_LOCALE(PROJECT_DATA_FOLDER, "en-US"); 21 | 22 | MODULE_EXPORT const char *obs_module_description(void) 23 | { 24 | return obs_module_text("Description"); 25 | } 26 | 27 | MODULE_EXPORT const char *obs_module_name(void) 28 | { 29 | return obs_module_text("SceneTreeView"); 30 | } 31 | 32 | bool obs_module_load() 33 | { 34 | blog(LOG_INFO, "[%s] loaded version %s", obs_module_name(), PROJECT_VERSION); 35 | 36 | BPtr stv_config_path = obs_module_config_path(""); 37 | if(!os_mkdir(stv_config_path)) 38 | blog(LOG_WARNING, "[%s] failed to create config dir '%s'", obs_module_name(), stv_config_path.Get()); 39 | 40 | QMainWindow *main_window = reinterpret_cast(obs_frontend_get_main_window()); 41 | obs_frontend_push_ui_translation(obs_module_get_string); 42 | obs_frontend_add_dock(new ObsSceneTreeView(main_window)); 43 | obs_frontend_pop_ui_translation(); 44 | 45 | return true; 46 | } 47 | 48 | MODULE_EXPORT void obs_module_unload() 49 | {} 50 | 51 | #define QT_UTF8(str) QString::fromUtf8(str) 52 | #define QT_TO_UTF8(str) str.toUtf8().constData() 53 | 54 | 55 | ObsSceneTreeView::ObsSceneTreeView(QMainWindow *main_window) 56 | : QDockWidget(dynamic_cast(main_window)), 57 | _add_scene_act(main_window->findChild("actionAddScene")), 58 | _remove_scene_act(main_window->findChild("actionRemoveScene")), 59 | _toggle_toolbars_scene_act(main_window->findChild("toggleListboxToolbars")) 60 | { 61 | config_t *const global_config = obs_frontend_get_global_config(); 62 | config_set_default_bool(global_config, "SceneTreeView", "ShowSceneIcons", false); 63 | config_set_default_bool(global_config, "SceneTreeView", "ShowFolderIcons", false); 64 | 65 | assert(this->_add_scene_act); 66 | assert(this->_remove_scene_act); 67 | 68 | this->_stv_dock.setupUi(this); 69 | this->hide(); 70 | 71 | this->_stv_dock.stvTree->SetItemModel(&this->_scene_tree_items); 72 | this->_stv_dock.stvTree->setDefaultDropAction(Qt::DropAction::MoveAction); 73 | 74 | const bool show_icons = config_get_bool(global_config, "BasicWindow", "ShowListboxToolbars"); 75 | this->on_toggleListboxToolbars(show_icons); 76 | 77 | // Add callback to obs scene list change event 78 | obs_frontend_add_event_callback(&ObsSceneTreeView::obs_frontend_event_cb, this); 79 | obs_frontend_add_save_callback(&ObsSceneTreeView::obs_frontend_save_cb, this); 80 | 81 | QObject::connect(this->_stv_dock.stvAdd, &QToolButton::released, this->_add_scene_act, &QAction::trigger); 82 | 83 | QObject::connect(this->_stv_dock.stvTree->itemDelegate(), SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)), 84 | this, SLOT(on_SceneNameEdited(QWidget*))); 85 | //main_window, SLOT(SceneNameEdited(QWidget*,QAbstractItemDelegate::EndEditHint))); 86 | 87 | QObject::connect(this->_toggle_toolbars_scene_act, &QAction::triggered, this, &ObsSceneTreeView::on_toggleListboxToolbars); 88 | 89 | this->_stv_dock.stvTree->setModel(&(this->_scene_tree_items)); 90 | } 91 | 92 | ObsSceneTreeView::~ObsSceneTreeView() 93 | { 94 | // Remove frontend cb 95 | obs_frontend_remove_save_callback(&ObsSceneTreeView::obs_frontend_save_cb, this); 96 | obs_frontend_remove_event_callback(&ObsSceneTreeView::obs_frontend_event_cb, this); 97 | } 98 | 99 | void ObsSceneTreeView::SaveSceneTree(const char *scene_collection) 100 | { 101 | if(!scene_collection) 102 | return; 103 | 104 | BPtr stv_config_file_path = obs_module_config_path(SCENE_TREE_CONFIG_FILE.data()); 105 | 106 | OBSDataAutoRelease stv_data = obs_data_create_from_json_file(stv_config_file_path); 107 | if(!stv_data) 108 | stv_data = obs_data_create(); 109 | 110 | this->_scene_tree_items.SaveSceneTree(stv_data, scene_collection, this->_stv_dock.stvTree); 111 | 112 | if(!obs_data_save_json(stv_data, stv_config_file_path)) 113 | blog(LOG_WARNING, "[%s] Failed to save scene tree in '%s'", obs_module_name(), stv_config_file_path.Get()); 114 | } 115 | 116 | void ObsSceneTreeView::LoadSceneTree(const char *scene_collection) 117 | { 118 | assert(scene_collection); 119 | 120 | BPtr stv_config_file_path = obs_module_config_path(SCENE_TREE_CONFIG_FILE.data()); 121 | 122 | OBSDataAutoRelease stv_data = obs_data_create_from_json_file(stv_config_file_path); 123 | this->_scene_tree_items.LoadSceneTree(stv_data, scene_collection, this->_stv_dock.stvTree); 124 | } 125 | 126 | void ObsSceneTreeView::UpdateTreeView() 127 | { 128 | obs_frontend_source_list scene_list = {}; 129 | obs_frontend_get_scenes(&scene_list); 130 | 131 | this->_scene_tree_items.UpdateTree(scene_list, this->_stv_dock.stvTree->currentIndex()); 132 | 133 | obs_frontend_source_list_free(&scene_list); 134 | 135 | this->SaveSceneTree(this->_scene_collection_name); 136 | } 137 | 138 | void ObsSceneTreeView::on_toggleListboxToolbars(bool visible) 139 | { 140 | this->_stv_dock.listbox->setVisible(visible); 141 | } 142 | 143 | void ObsSceneTreeView::on_stvAddFolder_clicked() 144 | { 145 | int row; 146 | QStandardItem *selected = this->_scene_tree_items.itemFromIndex(this->_stv_dock.stvTree->currentIndex()); 147 | if(!selected) 148 | { 149 | selected = this->_scene_tree_items.invisibleRootItem(); 150 | row = selected->rowCount(); 151 | } 152 | else 153 | { 154 | if(selected->type() == StvItemModel::FOLDER) 155 | row = selected->rowCount(); 156 | else 157 | { 158 | row = selected->row()+1; 159 | 160 | selected = this->_scene_tree_items.GetParentOrRoot(selected->index()); 161 | } 162 | } 163 | 164 | // Get unique new folder name 165 | QString format{obs_module_text("SceneTreeView.DefaultFolderName")}; 166 | int i = 0; 167 | QString new_folder_name = format.arg(i); 168 | OBSSourceAutoRelease source = nullptr; 169 | while(!this->_scene_tree_items.CheckFolderNameUniqueness(new_folder_name, selected)) 170 | { 171 | new_folder_name = format.arg(++i); 172 | } 173 | 174 | StvFolderItem *pItem = new StvFolderItem(new_folder_name); 175 | selected->insertRow(row, pItem); 176 | 177 | this->SaveSceneTree(this->_scene_collection_name); 178 | } 179 | 180 | void ObsSceneTreeView::on_stvRemove_released() 181 | { 182 | QStandardItem *selected = this->_scene_tree_items.itemFromIndex(this->_stv_dock.stvTree->currentIndex()); 183 | if(selected) 184 | { 185 | assert(selected->type() == StvItemModel::FOLDER || selected->type() == StvItemModel::SCENE); 186 | if(selected->type() == StvItemModel::SCENE) 187 | QMetaObject::invokeMethod(this->_remove_scene_act, "triggered"); 188 | else 189 | this->RemoveFolder(selected); 190 | } 191 | } 192 | 193 | void ObsSceneTreeView::on_stvTree_customContextMenuRequested(const QPoint &pos) 194 | { 195 | QStandardItem *item = this->_scene_tree_items.itemFromIndex(this->_stv_dock.stvTree->indexAt(pos)); 196 | 197 | QMainWindow *main_window = reinterpret_cast(obs_frontend_get_main_window()); 198 | 199 | QMenu popup(this); 200 | // QMenu order(QTStr("Basic.MainMenu.Edit.Order"), this); 201 | 202 | popup.addAction(obs_module_text("SceneTreeView.AddScene"), 203 | main_window, SLOT(on_actionAddScene_triggered())); 204 | 205 | popup.addAction(obs_module_text("SceneTreeView.AddFolder"), 206 | this, SLOT(on_stvAddFolder_clicked())); 207 | 208 | if(item) 209 | { 210 | if(item->type() == StvItemModel::SCENE) 211 | { 212 | QAction *copyFilters = new QAction(QTStr("Copy.Filters"), this); 213 | copyFilters->setEnabled(false); 214 | connect(copyFilters, SIGNAL(triggered()), 215 | main_window, SLOT(SceneCopyFilters())); 216 | QAction *pasteFilters = new QAction(QTStr("Paste.Filters"), this); 217 | // pasteFilters->setEnabled( 218 | // !obs_weak_source_expired(copyFiltersSource)); // Cannot use (we can't check copyFiltersSource, as it's a private member of OBSBasic) 219 | connect(pasteFilters, SIGNAL(triggered()), 220 | main_window, SLOT(ScenePasteFilters())); 221 | 222 | popup.addSeparator(); 223 | popup.addAction(QTStr("Duplicate"), 224 | main_window, SLOT(DuplicateSelectedScene())); 225 | popup.addAction(copyFilters); 226 | popup.addAction(pasteFilters); 227 | popup.addSeparator(); 228 | QAction *rename = popup.addAction(QTStr("Rename")); 229 | QObject::connect(rename, SIGNAL(triggered()), this->_stv_dock.stvTree, SLOT(EditSelectedItem())); 230 | popup.addAction(QTStr("Remove"), 231 | main_window, SLOT(RemoveSelectedScene())); 232 | popup.addSeparator(); 233 | 234 | // order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveUp"), 235 | // main_window, SLOT(on_actionSceneUp_triggered())); 236 | // order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveDown"), 237 | // this, SLOT(on_actionSceneDown_triggered())); 238 | // order.addSeparator(); 239 | 240 | // order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveToTop"), 241 | // this, SLOT(MoveSceneToTop())); 242 | // order.addAction(QTStr("Basic.MainMenu.Edit.Order.MoveToBottom"), 243 | // this, SLOT(MoveSceneToBottom())); 244 | // popup.addMenu(&order); 245 | 246 | // popup.addSeparator(); 247 | 248 | // delete sceneProjectorMenu; 249 | // sceneProjectorMenu = new QMenu(QTStr("SceneProjector")); 250 | // AddProjectorMenuMonitors(sceneProjectorMenu, this, 251 | // SLOT(OpenSceneProjector())); 252 | // popup.addMenu(sceneProjectorMenu); 253 | 254 | QAction *sceneWindow = popup.addAction(QTStr("SceneWindow"), 255 | main_window, SLOT(OpenSceneWindow())); 256 | 257 | popup.addAction(sceneWindow); 258 | popup.addAction(QTStr("Screenshot.Scene"), 259 | main_window, SLOT(ScreenshotScene())); 260 | popup.addSeparator(); 261 | popup.addAction(QTStr("Filters"), 262 | main_window, SLOT(OpenSceneFilters())); 263 | 264 | popup.addSeparator(); 265 | 266 | this->_per_scene_transition_menu.reset(CreatePerSceneTransitionMenu(main_window)); 267 | popup.addMenu(this->_per_scene_transition_menu.get()); 268 | 269 | /* ---------------------- */ 270 | 271 | QAction *multiviewAction = popup.addAction(QTStr("ShowInMultiview")); 272 | 273 | OBSSourceAutoRelease source = this->_scene_tree_items.GetCurrentScene(); 274 | OBSDataAutoRelease data = obs_source_get_private_settings(source); 275 | 276 | obs_data_set_default_bool(data, "show_in_multiview", true); 277 | bool show = obs_data_get_bool(data, "show_in_multiview"); 278 | 279 | multiviewAction->setCheckable(true); 280 | multiviewAction->setChecked(show); 281 | 282 | auto showInMultiview = [main_window](OBSData data) { 283 | bool show = 284 | obs_data_get_bool(data, "show_in_multiview"); 285 | obs_data_set_bool(data, "show_in_multiview", !show); 286 | // Workaround because OBSProjector::UpdateMultiviewProjectors() isn't available to modules 287 | QMetaObject::invokeMethod(main_window, "ScenesReordered"); 288 | }; 289 | 290 | connect(multiviewAction, &QAction::triggered, 291 | std::bind(showInMultiview, data.Get())); 292 | 293 | copyFilters->setEnabled(obs_source_filter_count(source) > 0); 294 | } 295 | 296 | popup.addSeparator(); 297 | 298 | // Enable/disable scene or folder icon 299 | const auto toggleName = item->type() == StvItemModel::SCENE ? obs_module_text("SceneTreeView.ToggleSceneIcons") : 300 | obs_module_text("SceneTreeView.ToggleFolderIcons"); 301 | 302 | QAction *toggleIconAction = popup.addAction(toggleName); 303 | toggleIconAction->setCheckable(true); 304 | 305 | const auto configName = item->type() == StvItemModel::SCENE ? "ShowSceneIcons" : "ShowFolderIcons"; 306 | const bool showIcon = config_get_bool(obs_frontend_get_global_config(), "SceneTreeView", configName); 307 | 308 | toggleIconAction->setChecked(showIcon); 309 | 310 | auto toggleIcon = [this, showIcon, configName, item]() { 311 | config_set_bool(obs_frontend_get_global_config(), "SceneTreeView", configName, !showIcon); 312 | this->_scene_tree_items.SetIconVisibility(!showIcon, (StvItemModel::QITEM_TYPE)item->type()); 313 | }; 314 | 315 | connect(toggleIconAction, &QAction::triggered, toggleIcon); 316 | } 317 | 318 | // popup.addSeparator(); 319 | 320 | // bool grid = ui->scenes->GetGridMode(); 321 | 322 | // QAction *gridAction = new QAction(grid ? QTStr("Basic.Main.ListMode") 323 | // : QTStr("Basic.Main.GridMode"), 324 | // this); 325 | // connect(gridAction, SIGNAL(triggered()), this, 326 | // SLOT(GridActionClicked())); 327 | // popup.addAction(gridAction); 328 | 329 | popup.exec(QCursor::pos()); 330 | } 331 | 332 | void ObsSceneTreeView::on_SceneNameEdited(QWidget *editor) 333 | { 334 | QStandardItem *selected = this->_scene_tree_items.itemFromIndex(this->_stv_dock.stvTree->currentIndex()); 335 | if(selected->type() == StvItemModel::SCENE) 336 | { 337 | QMainWindow *main_window = reinterpret_cast(obs_frontend_get_main_window()); 338 | QMetaObject::invokeMethod(main_window, "SceneNameEdited", Q_ARG(QWidget*, editor)); 339 | } 340 | else 341 | { 342 | QLineEdit *edit = qobject_cast(editor); 343 | std::string text = QT_TO_UTF8(edit->text().trimmed()); 344 | 345 | selected->setText(this->_scene_tree_items.CreateUniqueFolderName(selected, 346 | this->_scene_tree_items.GetParentOrRoot(selected->index()))); 347 | } 348 | } 349 | 350 | void ObsSceneTreeView::SelectCurrentScene() 351 | { 352 | QStandardItem *item = this->_scene_tree_items.GetCurrentSceneItem(); 353 | if(item && item->index() != this->_stv_dock.stvTree->currentIndex()) 354 | QMetaObject::invokeMethod(this->_stv_dock.stvTree, "setCurrentIndex", Q_ARG(QModelIndex, item->index())); 355 | } 356 | 357 | void ObsSceneTreeView::RemoveFolder(QStandardItem *folder) 358 | { 359 | int row = 0; 360 | int row_count = folder->rowCount(); 361 | while(row < row_count) 362 | { 363 | QStandardItem *item = folder->child(row); 364 | assert(item->type() == StvItemModel::FOLDER || item->type() == StvItemModel::SCENE); 365 | 366 | if(item->type() == StvItemModel::SCENE) 367 | { 368 | // Keep source reference to prevent race conditions on deletion via "triggered action" 369 | obs_weak_source_t *weak = item->data(StvItemModel::OBS_SCENE).value().ptr; 370 | OBSSourceAutoRelease source = OBSGetStrongRef(weak); 371 | 372 | this->_scene_tree_items.SetSelectedScene(item, obs_frontend_preview_program_mode_active()); 373 | QMetaObject::invokeMethod(this->_remove_scene_act, "triggered"); 374 | } 375 | else 376 | this->RemoveFolder(item); 377 | 378 | // Check if item was deleted. If not, move to next row 379 | if(row_count == folder->rowCount()) 380 | ++row; 381 | 382 | row_count = folder->rowCount(); 383 | } 384 | 385 | // Remove folder if empty 386 | if(folder->rowCount() == 0) 387 | this->_scene_tree_items.GetParentOrRoot(folder->index())->removeRow(folder->row()); 388 | } 389 | 390 | Q_DECLARE_METATYPE(OBSSource); 391 | 392 | static inline OBSSource GetTransitionComboItem(QComboBox *combo, int idx) 393 | { 394 | return combo->itemData(idx).value(); 395 | } 396 | 397 | QMenu *ObsSceneTreeView::CreatePerSceneTransitionMenu(QMainWindow *main_window) 398 | { 399 | OBSSourceAutoRelease scene = this->_scene_tree_items.GetCurrentScene(); 400 | QMenu *menu = new QMenu(QTStr("TransitionOverride")); 401 | QAction *action; 402 | 403 | OBSDataAutoRelease data = obs_source_get_private_settings(scene); 404 | 405 | obs_data_set_default_int(data, "transition_duration", 300); 406 | 407 | const char *curTransition = obs_data_get_string(data, "transition"); 408 | int curDuration = (int)obs_data_get_int(data, "transition_duration"); 409 | 410 | QSpinBox *duration = new QSpinBox(menu); 411 | duration->setMinimum(50); 412 | duration->setSuffix(" ms"); 413 | duration->setMaximum(20000); 414 | duration->setSingleStep(50); 415 | duration->setValue(curDuration); 416 | 417 | // Workaround to get the transitions menu from the main menu 418 | QComboBox *combo = main_window->findChild("transitions"); 419 | assert(combo); 420 | 421 | auto setTransition = [this, combo](QAction *action) { 422 | int idx = action->property("transition_index").toInt(); 423 | OBSSourceAutoRelease scene = this->_scene_tree_items.GetCurrentScene(); 424 | OBSDataAutoRelease data = 425 | obs_source_get_private_settings(scene); 426 | 427 | if (idx == -1) { 428 | obs_data_set_string(data, "transition", ""); 429 | return; 430 | } 431 | 432 | OBSSource tr = GetTransitionComboItem(combo, idx); 433 | 434 | if (tr) 435 | { 436 | const char *name = obs_source_get_name(tr); 437 | obs_data_set_string(data, "transition", name); 438 | } 439 | }; 440 | 441 | auto setDuration = [this](int duration) { 442 | OBSSourceAutoRelease scene = this->_scene_tree_items.GetCurrentScene(); 443 | OBSDataAutoRelease data = 444 | obs_source_get_private_settings(scene); 445 | 446 | obs_data_set_int(data, "transition_duration", duration); 447 | }; 448 | 449 | connect(duration, (void (QSpinBox::*)(int)) & QSpinBox::valueChanged, setDuration); 450 | 451 | std::string none = "None"; 452 | for (int i = -1; i < combo->count(); i++) 453 | { 454 | const char *name = ""; 455 | 456 | if (i >= 0) 457 | { 458 | OBSSource tr; 459 | tr = GetTransitionComboItem(combo, i); 460 | if (!tr) 461 | continue; 462 | name = obs_source_get_name(tr); 463 | } 464 | 465 | bool match = (name && strcmp(name, curTransition) == 0); 466 | 467 | if (!name || !*name) 468 | name = none.c_str(); 469 | 470 | action = menu->addAction(QT_UTF8(name)); 471 | action->setProperty("transition_index", i); 472 | action->setCheckable(true); 473 | action->setChecked(match); 474 | 475 | connect(action, &QAction::triggered, 476 | std::bind(setTransition, action)); 477 | } 478 | 479 | QWidgetAction *durationAction = new QWidgetAction(menu); 480 | durationAction->setDefaultWidget(duration); 481 | 482 | menu->addSeparator(); 483 | menu->addAction(durationAction); 484 | return menu; 485 | } 486 | 487 | void ObsSceneTreeView::ObsFrontendEvent(enum obs_frontend_event event) 488 | { 489 | // Update our tree view when scene list was changed 490 | if(event == OBS_FRONTEND_EVENT_FINISHED_LOADING) 491 | { 492 | this->_scene_collection_name = obs_frontend_get_current_scene_collection(); 493 | 494 | // Load saved scene locations, then add any missing items that weren't saved 495 | this->LoadSceneTree(this->_scene_collection_name); 496 | this->UpdateTreeView(); 497 | 498 | this->SelectCurrentScene(); 499 | 500 | // We're updating the icons here to allow the main_window to load themes first 501 | // Set icons, force style sheet recalculation. Taken from obs source code, qt-wrappers.cpp, setThemeID() 502 | QMainWindow *main_window = reinterpret_cast(obs_frontend_get_main_window()); 503 | this->_stv_dock.stvAdd->setIcon(this->_add_scene_act->icon()); 504 | this->_stv_dock.stvRemove->setIcon(this->_remove_scene_act->icon()); 505 | this->_stv_dock.stvAddFolder->setIcon(main_window->property("groupIcon").value()); 506 | 507 | QString qss = this->styleSheet(); 508 | this->setStyleSheet("/* */"); 509 | this->setStyleSheet(qss); 510 | } 511 | else if(event == OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED) 512 | this->UpdateTreeView(); 513 | else if(event == OBS_FRONTEND_EVENT_SCENE_CHANGED || event == OBS_FRONTEND_EVENT_PREVIEW_SCENE_CHANGED) 514 | this->SelectCurrentScene(); 515 | else if(event == OBS_FRONTEND_EVENT_SCENE_COLLECTION_CLEANUP) 516 | { 517 | this->_scene_tree_items.CleanupSceneTree(); 518 | this->_scene_collection_name = nullptr; 519 | } 520 | else if(event == OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGING) 521 | this->SaveSceneTree(this->_scene_collection_name); 522 | else if(event == OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGED) 523 | { 524 | this->_scene_collection_name = obs_frontend_get_current_scene_collection(); 525 | this->LoadSceneTree(this->_scene_collection_name); 526 | this->UpdateTreeView(); 527 | } 528 | else if(event == OBS_FRONTEND_EVENT_SCENE_COLLECTION_RENAMED) 529 | { 530 | // TODO: Delete old scene tree from json file 531 | 532 | this->_scene_collection_name = obs_frontend_get_current_scene_collection(); 533 | this->SaveSceneTree(this->_scene_collection_name); 534 | 535 | this->UpdateTreeView(); 536 | } 537 | } 538 | 539 | void ObsSceneTreeView::ObsFrontendSave(obs_data_t */*save_data*/, bool saving) 540 | { 541 | if(saving) 542 | this->SaveSceneTree(this->_scene_collection_name); 543 | } 544 | -------------------------------------------------------------------------------- /obs_scene_tree_view/obs_scene_tree_view.h: -------------------------------------------------------------------------------- 1 | #ifndef OBS_SCENE_TREE_VIEW_H 2 | #define OBS_SCENE_TREE_VIEW_H 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | #include "obs-data.h" 12 | #include "obs_scene_tree_view/stv_item_model.h" 13 | #include "ui_scene_tree_view.h" 14 | 15 | class ObsSceneTreeView 16 | : public QDockWidget 17 | { 18 | Q_OBJECT 19 | 20 | public: 21 | static constexpr std::string_view SCENE_TREE_CONFIG_FILE = "scene_tree.json"; 22 | 23 | ObsSceneTreeView(QMainWindow *main_window); 24 | virtual ~ObsSceneTreeView() override; 25 | 26 | void SaveSceneTree(const char *scene_collection); 27 | void LoadSceneTree(const char *scene_collection); 28 | 29 | protected slots: 30 | void UpdateTreeView(); 31 | 32 | void on_toggleListboxToolbars(bool visible); 33 | 34 | void on_stvAddFolder_clicked(); 35 | void on_stvRemove_released(); 36 | 37 | // Copied from OBS, OBSBasic::on_scenes_customContextMenuRequested() 38 | void on_stvTree_customContextMenuRequested(const QPoint &pos); 39 | 40 | void on_SceneNameEdited(QWidget *editor); 41 | 42 | private: 43 | QAction *_add_scene_act = nullptr; 44 | QAction *_remove_scene_act = nullptr; 45 | QAction *_toggle_toolbars_scene_act = nullptr; 46 | 47 | std::unique_ptr _per_scene_transition_menu; 48 | 49 | Ui::STVDock _stv_dock; 50 | 51 | StvItemModel _scene_tree_items; 52 | BPtr _scene_collection_name = nullptr; 53 | 54 | void SelectCurrentScene(); 55 | void RemoveFolder(QStandardItem *folder); 56 | 57 | // Copied from OBS, OBSBasic::CreatePerSceneTransitionMenu() 58 | QMenu *CreatePerSceneTransitionMenu(QMainWindow *main_window); 59 | 60 | inline static void obs_frontend_event_cb(enum obs_frontend_event event, void *private_data) 61 | { ((ObsSceneTreeView*)private_data)->ObsFrontendEvent(event); } 62 | 63 | inline static void obs_frontend_save_cb(obs_data_t *save_data, bool saving, void *private_data) 64 | { ((ObsSceneTreeView*)private_data)->ObsFrontendSave(save_data, saving); } 65 | 66 | void ObsFrontendEvent(enum obs_frontend_event event); 67 | void ObsFrontendSave(obs_data_t *save_data, bool saving); 68 | }; 69 | 70 | #endif //OBS_SCENE_TREE_VIEW_H 71 | -------------------------------------------------------------------------------- /obs_scene_tree_view/stv_item_model.cpp: -------------------------------------------------------------------------------- 1 | #include "obs_scene_tree_view/stv_item_model.h" 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | StvFolderItem::StvFolderItem(const QString &text) 13 | : QStandardItem(text) 14 | { 15 | this->setDropEnabled(true); 16 | 17 | QMainWindow *main_window = reinterpret_cast(obs_frontend_get_main_window()); 18 | QIcon icon = config_get_bool(obs_frontend_get_global_config(), "SceneTreeView", "ShowFolderIcons") ? 19 | main_window->property("groupIcon").value() : 20 | QIcon(); 21 | this->setIcon(icon); 22 | } 23 | 24 | int StvFolderItem::type() const 25 | { return StvItemModel::FOLDER; } 26 | 27 | 28 | StvSceneItem::StvSceneItem(const QString &text, obs_weak_source_t *weak) 29 | : QStandardItem(text) 30 | { 31 | this->setDropEnabled(false); 32 | this->setData(QVariant::fromValue(obs_weak_source_ptr({weak})), StvItemModel::OBS_SCENE); 33 | 34 | QMainWindow *main_window = reinterpret_cast(obs_frontend_get_main_window()); 35 | QIcon icon = config_get_bool(obs_frontend_get_global_config(), "SceneTreeView", "ShowSceneIcons") ? 36 | main_window->property("sceneIcon").value() : 37 | QIcon(); 38 | this->setIcon(icon); 39 | } 40 | 41 | int StvSceneItem::type() const 42 | { return StvItemModel::SCENE; } 43 | 44 | 45 | StvItemModel::StvItemModel() 46 | {} 47 | 48 | StvItemModel::~StvItemModel() 49 | { 50 | // Remove scene refs 51 | for(auto &scene : this->_scenes_in_tree) 52 | { 53 | obs_weak_source_release(scene.first); 54 | } 55 | 56 | this->_scenes_in_tree.clear(); 57 | } 58 | 59 | QStringList StvItemModel::mimeTypes() const 60 | { 61 | return QStringList(MIME_TYPE.data()); 62 | } 63 | 64 | QMimeData *StvItemModel::mimeData(const QModelIndexList &indexes) const 65 | { 66 | QMimeData *mime = new QMimeData(); 67 | 68 | const int num_indexes = indexes.size(); 69 | 70 | QByteArray mime_dat; 71 | mime_dat.reserve(num_indexes*sizeof(mime_item_data_t)+sizeof(int)); 72 | mime_dat.append((const char*)&num_indexes, sizeof(int)); 73 | 74 | for(const auto &index : indexes) 75 | { 76 | mime_item_data_t item_mime_dat; 77 | 78 | const QStandardItem *item = this->itemFromIndex(index); 79 | 80 | assert(item->type() == FOLDER || item->type() == SCENE); 81 | item_mime_dat.Type = (QITEM_TYPE)item->type(); 82 | item_mime_dat.Data = item_mime_dat.Type == QITEM_TYPE::FOLDER ? (void*)item : 83 | (void*)item->data(OBS_SCENE).value().ptr; 84 | 85 | mime_dat.append((const char*)&item_mime_dat, sizeof(mime_item_data_t)); 86 | } 87 | 88 | mime->setData(MIME_TYPE.data(), mime_dat); 89 | 90 | return mime; 91 | } 92 | 93 | bool StvItemModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) 94 | { 95 | Q_UNUSED(action); 96 | Q_UNUSED(column); 97 | 98 | QStandardItem *parent_item = this->itemFromIndex(parent); 99 | if(!parent_item) 100 | parent_item = this->invisibleRootItem(); 101 | else if(parent_item->type() == QITEM_TYPE::SCENE) 102 | return false; 103 | 104 | if(row < 0) 105 | row = 0; 106 | 107 | QByteArray qdat = data->data(MIME_TYPE.data()); 108 | assert(qdat.size() >= (int)sizeof(int)); 109 | 110 | const char *dat = qdat.constData(); 111 | 112 | const int num_indexes = *(int*)dat; 113 | dat += sizeof(int); 114 | 115 | for(int i = 0; i < num_indexes; ++i) 116 | { 117 | // Find item and move it 118 | const mime_item_data_t *item_data = (const mime_item_data_t*)dat; 119 | assert(item_data->Type == FOLDER || item_data->Type == SCENE); 120 | if(item_data->Type == SCENE) 121 | this->MoveSceneItem((obs_weak_source_t*)item_data->Data, row, parent_item); 122 | else 123 | this->MoveSceneFolder((QStandardItem*)item_data->Data, row, parent_item); 124 | 125 | dat += sizeof(obs_weak_source_ptr); 126 | } 127 | 128 | return true; 129 | } 130 | 131 | void StvItemModel::UpdateTree(obs_frontend_source_list &scene_list, const QModelIndex &selected_index) 132 | { 133 | this->UpdateSceneSize(); 134 | 135 | source_map_t new_scene_tree; 136 | 137 | for (size_t i = 0; i < scene_list.sources.num; i++) 138 | { 139 | obs_source_t *source = scene_list.sources.array[i]; 140 | assert(obs_scene_from_source(source) != nullptr); 141 | 142 | if(!this->IsManagedScene(source)) 143 | continue; 144 | 145 | source_map_t::iterator scene_it; 146 | 147 | // Check if scene already in tree 148 | obs_weak_source_t *weak = obs_source_get_weak_source(source); 149 | 150 | scene_it = this->_scenes_in_tree.find(weak); 151 | if(scene_it != this->_scenes_in_tree.end()) 152 | { 153 | // if already in tree, move to new set 154 | auto new_scene_it = new_scene_tree.emplace(scene_it->first, scene_it->second).first; 155 | this->_scenes_in_tree.erase(scene_it); 156 | scene_it = new_scene_it; 157 | 158 | obs_weak_source_release(weak); 159 | } 160 | else 161 | { 162 | // if not in tree, add it 163 | scene_it = new_scene_tree.emplace(weak, nullptr).first; 164 | } 165 | 166 | weak = nullptr; 167 | 168 | // Check that scene contains tree data 169 | obs_data_t *scene_dat = obs_source_get_private_settings(OBSGetStrongRef(scene_it->first).Get()); 170 | 171 | if(!scene_it->second) 172 | { 173 | // Scene not yet in tree, add it at the correct position 174 | QStandardItem *selected = this->itemFromIndex(selected_index); 175 | QStandardItem *parent; 176 | if(selected) 177 | { 178 | assert(selected->type() == QITEM_TYPE::SCENE || selected->type() == QITEM_TYPE::FOLDER); 179 | 180 | if(selected->type() == QITEM_TYPE::FOLDER) 181 | parent = selected; 182 | else 183 | parent = this->GetParentOrRoot(selected->index()); 184 | } 185 | else 186 | { 187 | selected = this->invisibleRootItem(); 188 | parent = selected; 189 | } 190 | 191 | // Add new item to scene 192 | StvSceneItem *pItem = new StvSceneItem(obs_source_get_name(source), scene_it->first); 193 | 194 | const auto row = parent == selected ? 0 : selected->row(); 195 | parent->insertRow(row, pItem); 196 | 197 | scene_it->second = pItem; 198 | } 199 | else 200 | { 201 | // Update scene name 202 | scene_it->second->setText(obs_source_get_name(source)); 203 | } 204 | 205 | obs_data_release(scene_dat); 206 | scene_dat = nullptr; 207 | } 208 | 209 | // Erase all remaining elements in _scene_tree 210 | for(const auto &scene : this->_scenes_in_tree) 211 | { 212 | assert(scene.second); 213 | 214 | const int row = scene.second->row(); 215 | this->removeRow(row, this->parent(scene.second->index())); 216 | 217 | // Remove scene reference 218 | obs_weak_source_release(scene.first); 219 | } 220 | 221 | this->_scenes_in_tree = std::move(new_scene_tree); 222 | } 223 | 224 | bool StvItemModel::CheckFolderNameUniqueness(const QString &name, QStandardItem *parent, QStandardItem *item_to_skip) 225 | { 226 | const int row_count = parent->rowCount(); 227 | for(int i=0; ichild(i); 230 | if(item == item_to_skip) 231 | continue; 232 | 233 | if(item->type() == FOLDER && item->text() == name) 234 | return false; 235 | } 236 | 237 | return true; 238 | } 239 | 240 | void StvItemModel::SetSelectedScene(QStandardItem *item, bool set_preview_scene, bool force_set_scene) 241 | { 242 | obs_weak_source_t *weak = item->data(QDATA_ROLE::OBS_SCENE).value().ptr; 243 | OBSSourceAutoRelease source = OBSGetStrongRef(weak); 244 | if(source) 245 | { 246 | if(!set_preview_scene) 247 | { 248 | if(force_set_scene || OBSSourceAutoRelease(obs_frontend_get_current_scene()).Get() != source) 249 | obs_frontend_set_current_scene(source); 250 | } 251 | else if(force_set_scene || OBSSourceAutoRelease(obs_frontend_get_current_preview_scene()).Get() != source) 252 | obs_frontend_set_current_preview_scene(source); 253 | } 254 | } 255 | 256 | QStandardItem *StvItemModel::GetCurrentSceneItem() 257 | { 258 | // Change source to the selected one 259 | OBSSourceAutoRelease source = this->GetCurrentScene(); 260 | OBSWeakSource weak = OBSGetWeakRef(source); 261 | 262 | if(auto scene_it = this->_scenes_in_tree.find(weak); scene_it != this->_scenes_in_tree.end()) 263 | return scene_it->second; 264 | else 265 | { 266 | blog(LOG_WARNING, "[%s] Couldn't find current scene in Scene Tree View", obs_module_name()); 267 | return nullptr; 268 | } 269 | } 270 | 271 | OBSSourceAutoRelease StvItemModel::GetCurrentScene() 272 | { 273 | return obs_frontend_preview_program_mode_active() ? obs_frontend_get_current_preview_scene() : obs_frontend_get_current_scene(); 274 | } 275 | 276 | void StvItemModel::SaveSceneTree(obs_data_t *root_folder_data, const char *scene_collection, QTreeView *view) 277 | { 278 | OBSDataArrayAutoRelease folder_data = this->CreateFolderArray(*this->invisibleRootItem(), view); 279 | obs_data_set_array(root_folder_data, scene_collection, folder_data); 280 | } 281 | 282 | void StvItemModel::LoadSceneTree(obs_data_t *root_folder_data, const char *scene_collection, QTreeView *view) 283 | { 284 | this->UpdateSceneSize(); 285 | 286 | QStandardItem *root_item = this->invisibleRootItem(); 287 | 288 | // Erase previous data 289 | this->CleanupSceneTree(); 290 | 291 | // Add loaded data 292 | OBSDataArrayAutoRelease folder_array = obs_data_get_array(root_folder_data, scene_collection); 293 | if(folder_array) 294 | { 295 | std::list expandable_folders; 296 | this->LoadFolderArray(folder_array, *root_item, expandable_folders); 297 | 298 | for(auto &item : expandable_folders) 299 | { 300 | view->setExpanded(item->index(), true); 301 | } 302 | } 303 | } 304 | 305 | void StvItemModel::CleanupSceneTree() 306 | { 307 | // Remove scene refs 308 | for(auto &scene : this->_scenes_in_tree) 309 | { 310 | obs_weak_source_release(scene.first); 311 | } 312 | 313 | this->_scenes_in_tree.clear(); 314 | 315 | QStandardItem *root_item = this->invisibleRootItem(); 316 | root_item->removeRows(0, root_item->rowCount()); 317 | } 318 | 319 | QStandardItem *StvItemModel::GetParentOrRoot(const QModelIndex &index) 320 | { 321 | QStandardItem *selected = this->itemFromIndex(this->parent(index)); 322 | if(!selected) 323 | selected = this->invisibleRootItem(); 324 | 325 | return selected; 326 | } 327 | 328 | QString StvItemModel::CreateUniqueFolderName(QStandardItem *folder_item, QStandardItem *parent) 329 | { 330 | // Check that name is unique 331 | QString folder_name = folder_item->text(); 332 | if(!this->CheckFolderNameUniqueness(folder_name, parent, folder_item)) 333 | { 334 | QString format = folder_name.replace(QRegularExpression("\\d+$"), "%1"); 335 | if(!format.endsWith("%1")) 336 | format += " %1"; 337 | 338 | size_t i = 0; 339 | QString name; 340 | do 341 | { 342 | name = format.arg(QString::number(++i)); 343 | } 344 | while(!this->CheckFolderNameUniqueness(name, parent, folder_item)); 345 | 346 | folder_name = name; 347 | } 348 | 349 | return folder_name; 350 | } 351 | 352 | void StvItemModel::SetIconVisibility(bool enable_visibility, QITEM_TYPE item_type) 353 | { 354 | if(item_type == SCENE) 355 | return this->SetSceneIconVisibility(enable_visibility); 356 | else 357 | return this->SetFolderIconVisibility(enable_visibility); 358 | } 359 | 360 | void StvItemModel::SetSceneIconVisibility(bool enable_visibility) 361 | { 362 | QMainWindow *main_window = reinterpret_cast(obs_frontend_get_main_window()); 363 | QIcon icon = enable_visibility ? main_window->property("sceneIcon").value() : QIcon(); 364 | 365 | return this->SetIcon(icon, SCENE, this->invisibleRootItem()); 366 | } 367 | 368 | void StvItemModel::SetFolderIconVisibility(bool enable_visibility) 369 | { 370 | QMainWindow *main_window = reinterpret_cast(obs_frontend_get_main_window()); 371 | QIcon icon = enable_visibility ? main_window->property("groupIcon").value() : QIcon(); 372 | 373 | return this->SetIcon(icon, FOLDER, this->invisibleRootItem()); 374 | } 375 | 376 | void StvItemModel::UpdateSceneSize() 377 | { 378 | this->_scene_size.cx = config_get_int(obs_frontend_get_profile_config(), "Video", "BaseCX"); 379 | this->_scene_size.cy = config_get_int(obs_frontend_get_profile_config(), "Video", "BaseCY"); 380 | } 381 | 382 | bool StvItemModel::IsManagedScene(obs_scene_t *scene) const 383 | { 384 | OBSSource source = obs_scene_get_source(scene); 385 | return this->IsManagedScene(source); 386 | } 387 | 388 | bool StvItemModel::IsManagedScene(obs_source_t *scene_source) const 389 | { 390 | OBSDataAutoRelease settings = obs_source_get_settings(scene_source); 391 | return obs_data_get_bool(settings, "custom_size") == false /*&& 392 | obs_data_get_bool(settings, "cx") == this->_scene_size.cx && 393 | obs_data_get_bool(settings, "cy") == this->_scene_size.cy*/; 394 | } 395 | 396 | void StvItemModel::MoveSceneItem(obs_weak_source_t *source, int row, QStandardItem *parent_item) 397 | { 398 | if(const auto scene_it = this->_scenes_in_tree.find(source); scene_it != this->_scenes_in_tree.end()) 399 | { 400 | assert(scene_it->second->type() == SCENE); 401 | 402 | blog(LOG_INFO, "[%s] Moving %s", obs_module_name(), scene_it->second->text().toStdString().c_str()); 403 | 404 | StvSceneItem *pItem = new StvSceneItem(scene_it->second->text(), scene_it->first); 405 | parent_item->insertRow(row, pItem); 406 | 407 | // Old item removed when returning true 408 | 409 | scene_it->second = pItem; 410 | } 411 | else 412 | blog(LOG_WARNING, "[%s] Couldn't find item to move in Scene Tree View", obs_module_name()); 413 | } 414 | 415 | void StvItemModel::MoveSceneFolder(QStandardItem *item, int row, QStandardItem *parent_item) 416 | { 417 | assert(item->type() == FOLDER); 418 | blog(LOG_INFO, "[%s] Moving %s", obs_module_name(), item->text().toStdString().c_str()); 419 | 420 | // Check that name is unique 421 | QString new_name = this->CreateUniqueFolderName(item, parent_item); 422 | 423 | StvFolderItem *new_item = new StvFolderItem(new_name); 424 | parent_item->insertRow(row, new_item); 425 | 426 | for(int sub_row = 0; sub_row < item->rowCount(); ++sub_row) 427 | { 428 | QStandardItem *sub_item = item->child(sub_row); 429 | 430 | assert(sub_item->type() == FOLDER || sub_item->type() == SCENE); 431 | 432 | if(sub_item->type() == FOLDER) 433 | this->MoveSceneFolder(sub_item, sub_row, new_item); 434 | else 435 | { 436 | obs_weak_source_t *weak = sub_item->data(OBS_SCENE).value().ptr; 437 | this->MoveSceneItem(weak, sub_row, new_item); 438 | } 439 | } 440 | } 441 | 442 | obs_data_array_t *StvItemModel::CreateFolderArray(QStandardItem &folder, QTreeView *view) 443 | { 444 | obs_data_array_t *folder_data = obs_data_array_create(); 445 | 446 | for(int i=0; i < folder.rowCount(); ++i) 447 | { 448 | QStandardItem *item = folder.child(i); 449 | assert(item->type() == FOLDER || item->type() == SCENE); 450 | 451 | OBSDataAutoRelease item_data = obs_data_create(); 452 | if(item->type() == FOLDER) 453 | { 454 | OBSDataArrayAutoRelease sub_folder_data = this->CreateFolderArray(*item, view); 455 | obs_data_set_array(item_data, SCENE_TREE_CONFIG_FOLDER_DATA.data(), sub_folder_data); 456 | obs_data_set_bool(item_data, SCENE_TREE_CONFIG_FOLDER_EXPANDED.data(), view->isExpanded(item->index())); 457 | obs_data_set_string(item_data, SCENE_TREE_CONFIG_ITEM_NAME_DATA.data(), item->text().toStdString().c_str()); 458 | } 459 | else 460 | { 461 | obs_weak_source_t *weak = item->data(QDATA_ROLE::OBS_SCENE).value().ptr; 462 | OBSSourceAutoRelease source = OBSGetStrongRef(weak); 463 | obs_data_set_string(item_data, SCENE_TREE_CONFIG_ITEM_NAME_DATA.data(), obs_source_get_name(source)); 464 | } 465 | 466 | obs_data_array_push_back(folder_data, item_data); 467 | } 468 | 469 | return folder_data; 470 | } 471 | 472 | void StvItemModel::LoadFolderArray(obs_data_array_t *folder_data, QStandardItem &folder, std::list &expandable_folders) 473 | { 474 | const size_t item_count = obs_data_array_count(folder_data); 475 | for(size_t i=0; i < item_count; ++i) 476 | { 477 | OBSDataAutoRelease item_data = obs_data_array_item(folder_data, i); 478 | 479 | const char *item_name = obs_data_get_string(item_data, SCENE_TREE_CONFIG_ITEM_NAME_DATA.data()); 480 | OBSDataArrayAutoRelease folder_data = obs_data_get_array(item_data, SCENE_TREE_CONFIG_FOLDER_DATA.data()); 481 | 482 | // Check if this is folder or scene item (only folders have folder_data) 483 | if(!folder_data) 484 | { 485 | // Add scene to folder, skip if scene doesn't exist anymore 486 | OBSSceneAutoRelease scene = obs_get_scene_by_name(item_name); 487 | if(!scene || !this->IsManagedScene(scene)) 488 | continue; 489 | 490 | { 491 | OBSSource source = obs_scene_get_source(scene); 492 | OBSWeakSource weak = obs_source_get_weak_source(source); 493 | 494 | // Skip if scene already in treeview 495 | // (see issue https://github.com/DigitOtter/obs_scene_tree_view/issues/19) 496 | if(this->_scenes_in_tree.find(weak) != this->_scenes_in_tree.end()) 497 | { 498 | obs_weak_source_release(weak); 499 | continue; 500 | } 501 | 502 | StvSceneItem *new_scene_item = new StvSceneItem(item_name, weak); 503 | folder.appendRow(new_scene_item); 504 | 505 | this->_scenes_in_tree.emplace(weak, new_scene_item); 506 | } 507 | } 508 | else 509 | { 510 | StvFolderItem *new_folder_item = new StvFolderItem(item_name); 511 | this->LoadFolderArray(folder_data, *new_folder_item, expandable_folders); 512 | 513 | folder.appendRow(new_folder_item); 514 | 515 | // Check if folder should be expanded. 516 | // The folders are expanded after the tree is completely created to prevent new inserts from closing the folders again 517 | if(obs_data_get_bool(item_data, SCENE_TREE_CONFIG_FOLDER_EXPANDED.data())) 518 | expandable_folders.push_back(new_folder_item); 519 | } 520 | } 521 | } 522 | 523 | void StvItemModel::SetIcon(const QIcon &icon, QITEM_TYPE item_type, QStandardItem *item) 524 | { 525 | if(!item) 526 | return; 527 | 528 | for(int i=0; i < item->rowCount(); ++i) 529 | { 530 | QStandardItem *child = item->child(i); 531 | if(child->type() == item_type) 532 | child->setIcon(icon); 533 | 534 | if(child->type() == FOLDER) 535 | this->SetIcon(icon, item_type, child); 536 | } 537 | } 538 | -------------------------------------------------------------------------------- /obs_scene_tree_view/stv_item_model.h: -------------------------------------------------------------------------------- 1 | #ifndef STV_ITEM_MODEL_H 2 | #define STV_ITEM_MODEL_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | 15 | struct obs_weak_source_ptr 16 | { 17 | obs_weak_source_t *ptr; 18 | }; 19 | 20 | Q_DECLARE_METATYPE(obs_weak_source_ptr); 21 | 22 | class StvFolderItem 23 | : public QStandardItem 24 | { 25 | public: 26 | StvFolderItem(const QString &text); 27 | virtual ~StvFolderItem() override = default; 28 | int type() const override; 29 | }; 30 | 31 | class StvSceneItem 32 | : public QStandardItem 33 | { 34 | public: 35 | StvSceneItem(const QString &text, obs_weak_source_t *weak); 36 | virtual ~StvSceneItem() override = default; 37 | int type() const override; 38 | }; 39 | 40 | 41 | class StvItemModel 42 | : public QStandardItemModel 43 | { 44 | Q_OBJECT 45 | 46 | struct SCENE_SIZE_T 47 | { 48 | uint32_t cx, cy; 49 | }; 50 | 51 | static constexpr std::string_view MIME_TYPE = "application/x-stvindexlist"; 52 | static constexpr std::string_view SCENE_TREE_CONFIG_FOLDER_DATA = "folder"; 53 | static constexpr std::string_view SCENE_TREE_CONFIG_FOLDER_EXPANDED = "is_expanded"; 54 | static constexpr std::string_view SCENE_TREE_CONFIG_ITEM_NAME_DATA = "name"; 55 | 56 | public: 57 | enum QDATA_ROLE 58 | { OBS_SCENE = Qt::UserRole }; 59 | 60 | enum QITEM_TYPE 61 | { FOLDER = QStandardItem::UserType+1, SCENE }; 62 | 63 | StvItemModel(); 64 | virtual ~StvItemModel() override; 65 | 66 | QStringList mimeTypes() const override; 67 | QMimeData *mimeData(const QModelIndexList &indexes) const override; 68 | bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; 69 | 70 | void UpdateTree(obs_frontend_source_list &scene_list, const QModelIndex &selected_index); 71 | 72 | bool CheckFolderNameUniqueness(const QString &name, QStandardItem *parent, QStandardItem *item_to_skip = nullptr); 73 | 74 | void SetSelectedScene(QStandardItem *item, bool set_preview_scene, bool force_set_scene = false); 75 | QStandardItem *GetCurrentSceneItem(); 76 | OBSSourceAutoRelease GetCurrentScene(); 77 | 78 | void SaveSceneTree(obs_data_t *root_folder_data, const char *scene_collection, QTreeView *view); 79 | void LoadSceneTree(obs_data_t *root_folder_data, const char *scene_collection, QTreeView *view); 80 | void CleanupSceneTree(); 81 | 82 | QStandardItem *GetParentOrRoot(const QModelIndex &index); 83 | 84 | QString CreateUniqueFolderName(QStandardItem *folder_item, QStandardItem *parent); 85 | 86 | void SetIconVisibility(bool enable_visibility, QITEM_TYPE item_type); 87 | void SetSceneIconVisibility(bool enable_visibility); 88 | void SetFolderIconVisibility(bool enable_visibility); 89 | 90 | void UpdateSceneSize(); 91 | bool IsManagedScene(obs_scene_t *scene) const; 92 | bool IsManagedScene(obs_source_t *scene_source) const; 93 | 94 | private: 95 | struct mime_item_data_t 96 | { 97 | QITEM_TYPE Type; 98 | void *Data; // Either QStandardItem* (if Type == FOLDER) or obs_weak_source_t* (if Type == SCENE) 99 | }; 100 | 101 | struct SceneComp 102 | { 103 | bool operator() (obs_weak_source_t *x, obs_weak_source_t *y) const 104 | { return OBSGetStrongRef(x).Get() < OBSGetStrongRef(y).Get(); } 105 | }; 106 | using source_map_t = std::map; 107 | 108 | source_map_t _scenes_in_tree; 109 | 110 | SCENE_SIZE_T _scene_size; 111 | 112 | void MoveSceneItem(obs_weak_source_t *source, int row, QStandardItem *parent_item); 113 | void MoveSceneFolder(QStandardItem *item, int row, QStandardItem *parent_item); 114 | 115 | obs_data_array_t *CreateFolderArray(QStandardItem &folder, QTreeView *view); 116 | void LoadFolderArray(obs_data_array_t *folder_data, QStandardItem &folder, std::list &expandable_folders); 117 | 118 | void SetIcon(const QIcon &icon, QITEM_TYPE item_type, QStandardItem *item); 119 | }; 120 | 121 | // Use OBS locale for translation 122 | inline QString QTStr(const char *text, QMainWindow *main_window = reinterpret_cast(obs_frontend_get_main_window())) 123 | { 124 | return main_window->tr(text); 125 | } 126 | 127 | #endif // STV_ITEM_MODEL_H 128 | -------------------------------------------------------------------------------- /obs_scene_tree_view/stv_item_view.cpp: -------------------------------------------------------------------------------- 1 | #include "obs_scene_tree_view/stv_item_view.h" 2 | 3 | #include 4 | #include 5 | 6 | 7 | StvItemView::StvItemView(QWidget *parent) 8 | : QTreeView(parent) 9 | {} 10 | 11 | void StvItemView::SetItemModel(StvItemModel *model) 12 | { 13 | this->_model = model; 14 | } 15 | 16 | void StvItemView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) 17 | { 18 | this->QTreeView::selectionChanged(selected, deselected); 19 | 20 | if(selected.indexes().size() == 0) 21 | return; 22 | 23 | assert(selected.indexes().size() == 1); 24 | QStandardItem *item = this->_model->itemFromIndex(selected.indexes().front()); 25 | if(item->type() == StvItemModel::SCENE) 26 | this->_model->SetSelectedScene(item, obs_frontend_preview_program_mode_active()); 27 | } 28 | 29 | void StvItemView::EditSelectedItem() 30 | { 31 | this->edit(this->currentIndex()); 32 | } 33 | 34 | void StvItemView::mouseDoubleClickEvent(QMouseEvent *event) 35 | { 36 | if(obs_frontend_preview_enabled()) 37 | { 38 | // If preview mode enabled, check whether the option to transition output scenes on double-click is active 39 | const bool transition_enabled = config_get_bool(obs_frontend_get_global_config(), 40 | "BasicWindow", "TransitionOnDoubleClick"); 41 | 42 | if(transition_enabled) 43 | { 44 | QStandardItem *item = this->_model->itemFromIndex(this->indexAt(event->pos())); 45 | if(item && item->type() == StvItemModel::SCENE) 46 | { 47 | this->_model->SetSelectedScene(item, false, true); 48 | return; 49 | } 50 | } 51 | } 52 | 53 | // If TransitionOnDoubleClick is disabled or a folder is selected, perform a normal edit on double click 54 | return QTreeView::mouseDoubleClickEvent(event); 55 | } 56 | -------------------------------------------------------------------------------- /obs_scene_tree_view/stv_item_view.h: -------------------------------------------------------------------------------- 1 | #ifndef STV_ITEM_VIEW_H 2 | #define STV_ITEM_VIEW_H 3 | 4 | #include 5 | 6 | #include "obs_scene_tree_view/stv_item_model.h" 7 | 8 | class StvItemView 9 | : public QTreeView 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | StvItemView(QWidget *parent = nullptr); 15 | ~StvItemView() override = default; 16 | 17 | void SetItemModel(StvItemModel *model); 18 | 19 | protected slots: 20 | void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override; 21 | //bool edit(const QModelIndex &index, EditTrigger trigger, QEvent *event) override; 22 | 23 | void EditSelectedItem(); 24 | 25 | void mouseDoubleClickEvent(QMouseEvent *event) override; 26 | 27 | private: 28 | StvItemModel *_model = nullptr; 29 | }; 30 | 31 | #endif //STV_ITEM_VIEW_H 32 | --------------------------------------------------------------------------------