From 9f1c442d35a634c1d85da70e6b32052734785cd1 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Mon, 20 Jan 2020 23:18:46 -0800 Subject: [PATCH] UI: Add option to toggle source icons to View menu --- UI/data/locale/en-US.ini | 1 + UI/forms/OBSBasic.ui | 16 +++++++++++++-- UI/obs-app.cpp | 2 ++ UI/source-tree.cpp | 42 ++++++++++++++++++++++++++-------------- UI/source-tree.hpp | 3 +++ UI/window-basic-main.cpp | 12 ++++++++++++ UI/window-basic-main.hpp | 1 + 7 files changed, 61 insertions(+), 16 deletions(-) diff --git a/UI/data/locale/en-US.ini b/UI/data/locale/en-US.ini index 7db1f3f72..20088c886 100644 --- a/UI/data/locale/en-US.ini +++ b/UI/data/locale/en-US.ini @@ -591,6 +591,7 @@ Basic.MainMenu.View.Docks.LockUI="Lock UI" Basic.MainMenu.View.Docks.CustomBrowserDocks="Custom Browser Docks..." Basic.MainMenu.View.Toolbars.Listboxes="&Listboxes" Basic.MainMenu.View.SceneTransitions="S&cene Transitions" +Basic.MainMenu.View.SourceIcons="Source &Icons" Basic.MainMenu.View.StatusBar="&Status Bar" Basic.MainMenu.View.Fullscreen.Interface="Fullscreen Interface" diff --git a/UI/forms/OBSBasic.ui b/UI/forms/OBSBasic.ui index e6ea7ed62..606584c5c 100644 --- a/UI/forms/OBSBasic.ui +++ b/UI/forms/OBSBasic.ui @@ -188,7 +188,7 @@ 0 0 1079 - 22 + 21 @@ -393,6 +393,7 @@ + @@ -728,7 +729,7 @@ 0 0 - 64 + 80 16 @@ -1788,6 +1789,17 @@ Basic.MainMenu.Help.About + + + true + + + true + + + Basic.MainMenu.View.SourceIcons + + diff --git a/UI/obs-app.cpp b/UI/obs-app.cpp index 6da08dd1c..7568849ad 100644 --- a/UI/obs-app.cpp +++ b/UI/obs-app.cpp @@ -424,6 +424,8 @@ bool OBSApp::InitGlobalConfigDefaults() "ShowListboxToolbars", true); config_set_default_bool(globalConfig, "BasicWindow", "ShowStatusBar", true); + config_set_default_bool(globalConfig, "BasicWindow", "ShowSourceIcons", + true); config_set_default_bool(globalConfig, "BasicWindow", "StudioModeLabels", true); diff --git a/UI/source-tree.cpp b/UI/source-tree.cpp index ec57b34c7..fa21620d4 100644 --- a/UI/source-tree.cpp +++ b/UI/source-tree.cpp @@ -59,21 +59,25 @@ SourceTreeItem::SourceTreeItem(SourceTree *tree_, OBSSceneItem sceneitem_) OBSBasic *main = reinterpret_cast(App()->GetMainWindow()); const char *id = obs_source_get_id(source); - QIcon icon; - if (strcmp(id, "scene") == 0) - icon = main->GetSceneIcon(); - else if (strcmp(id, "group") == 0) - icon = main->GetGroupIcon(); - else - icon = main->GetSourceIcon(id); + QLabel *iconLabel = nullptr; + if (tree->iconsVisible) { + QIcon icon; - QPixmap pixmap = icon.pixmap(QSize(16, 16)); + if (strcmp(id, "scene") == 0) + icon = main->GetSceneIcon(); + else if (strcmp(id, "group") == 0) + icon = main->GetGroupIcon(); + else + icon = main->GetSourceIcon(id); - QLabel *iconLabel = new QLabel(); - iconLabel->setPixmap(pixmap); - iconLabel->setFixedSize(16, 16); - iconLabel->setStyleSheet("background: none"); + QPixmap pixmap = icon.pixmap(QSize(16, 16)); + + iconLabel = new QLabel(); + iconLabel->setPixmap(pixmap); + iconLabel->setFixedSize(16, 16); + iconLabel->setStyleSheet("background: none"); + } vis = new VisibilityCheckBox(); vis->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); @@ -100,8 +104,10 @@ SourceTreeItem::SourceTreeItem(SourceTree *tree_, OBSSceneItem sceneitem_) boxLayout = new QHBoxLayout(); boxLayout->setContentsMargins(0, 0, 0, 0); - boxLayout->addWidget(iconLabel); - boxLayout->addSpacing(2); + if (iconLabel) { + boxLayout->addWidget(iconLabel); + boxLayout->addSpacing(2); + } boxLayout->addWidget(label); boxLayout->addWidget(vis); boxLayout->addSpacing(1); @@ -972,6 +978,14 @@ void SourceTree::UpdateIcons() stm->SceneChanged(); } +void SourceTree::SetIconsVisible(bool visible) +{ + SourceTreeModel *stm = GetStm(); + + iconsVisible = visible; + stm->SceneChanged(); +} + void SourceTree::ResetWidgets() { OBSScene scene = GetCurrentScene(); diff --git a/UI/source-tree.hpp b/UI/source-tree.hpp index e9a26f33b..00c0d58da 100644 --- a/UI/source-tree.hpp +++ b/UI/source-tree.hpp @@ -144,6 +144,8 @@ class SourceTree : public QListView { QStaticText textNoSources; QSvgRenderer iconNoSources; + bool iconsVisible = true; + void UpdateNoSourcesMessage(); void ResetWidgets(); @@ -178,6 +180,7 @@ public: bool GroupedItemsSelected() const; void UpdateIcons(); + void SetIconsVisible(bool visible); public slots: inline void ReorderItems() { GetStm()->ReorderItems(); } diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index ae3c7bad5..2ca68322c 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -1647,6 +1647,10 @@ void OBSBasic::OBSInit() SET_VISIBILITY("ShowStatusBar", toggleStatusBar); #undef SET_VISIBILITY + bool sourceIconsVisible = config_get_bool( + GetGlobalConfig(), "BasicWindow", "ShowSourceIcons"); + ui->toggleSourceIcons->setChecked(sourceIconsVisible); + { ProfileScope("OBSBasic::Load"); disableSaving--; @@ -6801,6 +6805,14 @@ void OBSBasic::on_toggleStatusBar_toggled(bool visible) visible); } +void OBSBasic::on_toggleSourceIcons_toggled(bool visible) +{ + ui->sources->SetIconsVisible(visible); + + config_set_bool(App()->GlobalConfig(), "BasicWindow", "ShowSourceIcons", + visible); +} + void OBSBasic::on_actionLockPreview_triggered() { ui->preview->ToggleLocked(); diff --git a/UI/window-basic-main.hpp b/UI/window-basic-main.hpp index 9d95f4fa0..481244faa 100644 --- a/UI/window-basic-main.hpp +++ b/UI/window-basic-main.hpp @@ -893,6 +893,7 @@ private slots: void on_toggleListboxToolbars_toggled(bool visible); void on_toggleStatusBar_toggled(bool visible); + void on_toggleSourceIcons_toggled(bool visible); void on_transitions_currentIndexChanged(int index); void on_transitionAdd_clicked();