From 6b34d0435fecd33c5524e316a8813e776627057d Mon Sep 17 00:00:00 2001 From: Jim Broadus Date: Sun, 21 Mar 2021 23:19:19 -0700 Subject: [PATCH] settings: Add SettingsCategory class Add a new category class for settings. This will eventually allow category classes to maintain their own lists of subpages. --- src/CMakeLists.txt | 2 ++ src/ui/settingscategory.cpp | 25 +++++++++++++++++++++++++ src/ui/settingscategory.h | 33 +++++++++++++++++++++++++++++++++ src/ui/settingsdialog.cpp | 26 ++++++++++++-------------- src/ui/settingsdialog.h | 4 +++- 5 files changed, 75 insertions(+), 15 deletions(-) create mode 100644 src/ui/settingscategory.cpp create mode 100644 src/ui/settingscategory.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d893cf309..3e214d1bf 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -363,6 +363,7 @@ set(SOURCES ui/playbacksettingspage.cpp ui/qtsystemtrayicon.cpp ui/screensaver.cpp + ui/settingscategory.cpp ui/settingsdialog.cpp ui/settingspage.cpp ui/splash.cpp @@ -659,6 +660,7 @@ set(HEADERS ui/organiseerrordialog.h ui/playbacksettingspage.h ui/qtsystemtrayicon.h + ui/settingscategory.h ui/settingsdialog.h ui/settingspage.h ui/standarditemiconloader.h diff --git a/src/ui/settingscategory.cpp b/src/ui/settingscategory.cpp new file mode 100644 index 000000000..d25c96e65 --- /dev/null +++ b/src/ui/settingscategory.cpp @@ -0,0 +1,25 @@ +/* This file is part of Clementine. + Copyright 2021, Jim Broadus + + Clementine is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#include "settingscategory.h" + +SettingsCategory::SettingsCategory(const QString& name, SettingsDialog* dialog) + : dialog_(dialog) { + setText(0, name); + setData(0, SettingsDialog::Role_IsSeparator, true); + setFlags(Qt::ItemIsEnabled); +} diff --git a/src/ui/settingscategory.h b/src/ui/settingscategory.h new file mode 100644 index 000000000..d486a3ed7 --- /dev/null +++ b/src/ui/settingscategory.h @@ -0,0 +1,33 @@ +/* This file is part of Clementine. + Copyright 2021, Jim Broadus + + Clementine is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#ifndef SETTINGSCATEGORY_H +#define SETTINGSCATEGORY_H + +#include + +#include "settingsdialog.h" + +class SettingsCategory : public QTreeWidgetItem { + public: + SettingsCategory(const QString& name, SettingsDialog* dialog); + + protected: + SettingsDialog* dialog_; +}; + +#endif // SETTINGSCATEGORY_H diff --git a/src/ui/settingsdialog.cpp b/src/ui/settingsdialog.cpp index 6ebd93f9f..7c0d60e76 100644 --- a/src/ui/settingsdialog.cpp +++ b/src/ui/settingsdialog.cpp @@ -44,6 +44,7 @@ #include "notificationssettingspage.h" #include "playbacksettingspage.h" #include "playlist/playlistview.h" +#include "settingscategory.h" #include "songinfo/songinfosettingspage.h" #include "transcoder/transcodersettingspage.h" #include "ui_settingsdialog.h" @@ -134,8 +135,8 @@ SettingsDialog::SettingsDialog(Application* app, BackgroundStreams* streams, ui_->setupUi(this); ui_->list->setItemDelegate(new SettingsItemDelegate(this)); - QTreeWidgetItem* general = AddCategory(tr("General")); - + SettingsCategory* general = new SettingsCategory(tr("General"), this); + AddCategory(general); AddPage(Page_Playback, new PlaybackSettingsPage(this), general); AddPage(Page_Behaviour, new BehaviourSettingsPage(this), general); AddPage(Page_Library, new LibrarySettingsPage(this), general); @@ -153,7 +154,8 @@ SettingsDialog::SettingsDialog(Application* app, BackgroundStreams* streams, #endif // User interface - QTreeWidgetItem* iface = AddCategory(tr("User interface")); + SettingsCategory* iface = new SettingsCategory(tr("User interface"), this); + AddCategory(iface); AddPage(Page_GlobalShortcuts, new GlobalShortcutsSettingsPage(this), iface); AddPage(Page_GlobalSearch, new GlobalSearchSettingsPage(this), iface); AddPage(Page_Appearance, new AppearanceSettingsPage(this), iface); @@ -169,7 +171,9 @@ SettingsDialog::SettingsDialog(Application* app, BackgroundStreams* streams, AddPage(Page_InternetShow, new InternetShowSettingsPage(this), iface); // Internet providers - QTreeWidgetItem* providers = AddCategory(tr("Internet providers")); + SettingsCategory* providers = + new SettingsCategory(tr("Internet providers"), this); + AddCategory(providers); #ifdef HAVE_LIBLASTFM AddPage(Page_Lastfm, new LastFMSettingsPage(this), providers); @@ -228,16 +232,10 @@ SettingsDialog::SettingsDialog(Application* app, BackgroundStreams* streams, SettingsDialog::~SettingsDialog() { delete ui_; } -QTreeWidgetItem* SettingsDialog::AddCategory(const QString& name) { - QTreeWidgetItem* item = new QTreeWidgetItem; - item->setText(0, name); - item->setData(0, Role_IsSeparator, true); - item->setFlags(Qt::ItemIsEnabled); - - ui_->list->invisibleRootItem()->addChild(item); - item->setExpanded(true); - - return item; +void SettingsDialog::AddCategory(SettingsCategory* category) { + ui_->list->invisibleRootItem()->addChild(category); + // This must not be called before it's added to the parent. + category->setExpanded(true); } void SettingsDialog::AddPage(Page id, SettingsPage* page, diff --git a/src/ui/settingsdialog.h b/src/ui/settingsdialog.h index 6aa2e7b6f..8e1ffef34 100644 --- a/src/ui/settingsdialog.h +++ b/src/ui/settingsdialog.h @@ -49,6 +49,8 @@ class SettingsItemDelegate : public QStyledItemDelegate { const QModelIndex& index) const; }; +class SettingsCategory; + class SettingsDialog : public QDialog { Q_OBJECT @@ -131,7 +133,7 @@ class SettingsDialog : public QDialog { SettingsPage* page_; }; - QTreeWidgetItem* AddCategory(const QString& name); + void AddCategory(SettingsCategory* category); void AddPage(Page id, SettingsPage* page, QTreeWidgetItem* parent = nullptr); private: