File indexing completed on 2024-05-05 04:47:27
0001 /**************************************************************************************** 0002 * Copyright (c) 2009 Nikolaj Hald Nielsen <nhn@kde.org> * 0003 * Copyright (c) 2011 Ralf Engels <ralf-engels@gmx.de> * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify it under * 0006 * the terms of the GNU General Public License as published by the Free Software * 0007 * Foundation; either version 2 of the License, or (at your option) any later * 0008 * version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0011 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0012 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License along with * 0015 * this program. If not, see <http://www.gnu.org/licenses/>. * 0016 ****************************************************************************************/ 0017 0018 #ifndef AMAROKBROWSERCATEGORYLIST_H 0019 #define AMAROKBROWSERCATEGORYLIST_H 0020 0021 #include "BrowserCategory.h" 0022 #include "BrowserCategoryListModel.h" 0023 #include "BrowserCategoryListSortFilterProxyModel.h" 0024 0025 #include <QMap> 0026 0027 namespace Amarok { 0028 class PrettyTreeView; 0029 } 0030 class SearchWidget; 0031 0032 class QStackedWidget; 0033 0034 /** 0035 * This is a browser category that can contain other sub-categories 0036 * The main (home/root) category is such a BrowserCategoryList 0037 * 0038 * @author Nikolaj Hald Nielsen <nhn@kde.org> 0039 */ 0040 class BrowserCategoryList : public BrowserCategory 0041 { 0042 Q_OBJECT 0043 0044 public: 0045 /** 0046 * Constructor 0047 * @param parent The parent widget. 0048 * @param name The name of this widget. 0049 * @param sort Whether to sort the list. 0050 */ 0051 explicit BrowserCategoryList( const QString& name, QWidget* parent = nullptr, bool sort = false ); 0052 0053 /** 0054 * Destructor. 0055 */ 0056 ~BrowserCategoryList() override; 0057 0058 /** 0059 * Get a map of the categories. 0060 * @return the map of categories. 0061 */ 0062 QMap<QString,BrowserCategory *> categories(); 0063 0064 BrowserCategory *activeCategory() const; 0065 0066 /** 0067 * Show a category. Hide any other active category if needed. 0068 */ 0069 void setActiveCategory( BrowserCategory *category ); 0070 0071 /** 0072 * Recursively navigate to a specific category. 0073 * @param target This is a / delimited string of category names. 0074 * This list will take the first category name, and if a child category with 0075 * this name exists, it will switch to it. If there are are more category names 0076 * in the target string, and the category activated is itself a category list, 0077 * it will strip the first category name and / from the targe string and pass 0078 * the rest to the navigate() method of the active category list. 0079 * 0080 * @return this method will navigate as far as the target makes sense. Any parts 0081 * of the target that does not match up with child categories will be returned 0082 * as this might be additional arguments that are usable elsewhere. 0083 */ 0084 QString navigate( const QString &target ); 0085 0086 0087 QString path(); 0088 0089 BrowserCategory *activeCategoryRecursive(); 0090 0091 Q_SIGNALS: 0092 void viewChanged(); 0093 0094 public Q_SLOTS: 0095 0096 /** 0097 * Add a category. 0098 * This category will take ownership of the new sub-category. 0099 * @param category The category to add. 0100 */ 0101 void addCategory( BrowserCategory *category ); 0102 0103 /** 0104 * Remove a named category from the list and delete it. 0105 * @param category The category to remove. 0106 */ 0107 void removeCategory( BrowserCategory *category ); 0108 0109 0110 /** 0111 * Slot called when the active category should be hidden the category selection list shown again. 0112 */ 0113 void home(); 0114 0115 /** 0116 * Slot called when the we need to move up one level. Forwarded to child lists as needed 0117 */ 0118 void back(); 0119 0120 void childViewChanged(); 0121 0122 private Q_SLOTS: 0123 /** Sets the current filter value and updates the content */ 0124 void setFilter( const QString &filter ) override; 0125 0126 private: 0127 0128 SearchWidget *m_searchWidget; 0129 QStackedWidget *m_widgetStack; 0130 Amarok::PrettyTreeView *m_categoryListView; 0131 0132 QMap<QString, BrowserCategory *> m_categories; 0133 0134 BrowserCategoryListModel *m_categoryListModel; 0135 BrowserCategoryListSortFilterProxyModel* m_proxyModel; 0136 0137 QString m_infoHtmlTemplate; 0138 0139 bool m_sorting; 0140 0141 private Q_SLOTS: 0142 /** 0143 * Slot called when an item in the list has been activated and the 0144 * corresponding category should be shown. 0145 * @param index The index that was activated 0146 */ 0147 void categoryActivated( const QModelIndex &index ); 0148 0149 void categoryEntered( const QModelIndex &index ); 0150 0151 QString css(); 0152 }; 0153 0154 0155 #endif