File indexing completed on 2024-04-21 04:54:12
0001 /* 0002 SPDX-FileCopyrightText: 2011 Koos Vriezen <koos.vriezen@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only 0005 */ 0006 0007 #ifndef KMPLAYER_PLAYMODEL_H 0008 #define KMPLAYER_PLAYMODEL_H 0009 0010 #include "config-kmplayer.h" 0011 0012 #include <QAbstractItemModel> 0013 #include <QModelIndex> 0014 #include <QPixmap> 0015 0016 #include "kmplayerplaylist.h" 0017 0018 class QPixmap; 0019 class KIconLoader; 0020 struct TreeUpdate; 0021 0022 namespace KMPlayer { 0023 0024 class PlayModel; 0025 class TopPlayItem; 0026 0027 /* 0028 * An item in the playlist 0029 */ 0030 class PlayItem 0031 { 0032 public: 0033 PlayItem (Node *e, PlayItem *parent) 0034 : item_flags (Qt::ItemIsEnabled | Qt::ItemIsSelectable), 0035 node (e), parent_item (parent) 0036 {} 0037 PlayItem (Attribute *a, PlayItem *pa) 0038 : item_flags (Qt::ItemIsEnabled | Qt::ItemIsSelectable), 0039 attribute (a), parent_item (pa) 0040 {} 0041 virtual ~PlayItem () { deleteChildren (); } 0042 0043 void deleteChildren () { qDeleteAll (child_items); child_items.clear (); } 0044 void appendChild (PlayItem *child) { child_items.append (child); } 0045 PlayItem *child (unsigned i) { 0046 return i < (unsigned) child_items.size() ? child_items.at (i) : NULL; 0047 } 0048 int childCount () const { return child_items.count(); } 0049 int row () const { 0050 return parent_item->child_items.indexOf (const_cast <PlayItem*>( this)); 0051 } 0052 PlayItem *parent () { return parent_item; } 0053 TopPlayItem *rootItem () KMPLAYERCOMMON_EXPORT; 0054 0055 QString title; 0056 Qt::ItemFlags item_flags; 0057 0058 NodePtrW node; 0059 AttributePtrW attribute; 0060 0061 QList<PlayItem*> child_items; 0062 PlayItem *parent_item; 0063 }; 0064 0065 class TopPlayItem : public PlayItem 0066 { 0067 public: 0068 TopPlayItem (PlayModel *m, int _id, Node *e, int flags) 0069 : PlayItem (e, nullptr), 0070 model (m), 0071 id (_id), 0072 root_flags (flags), 0073 show_all_nodes (false), 0074 have_dark_nodes (false) 0075 {} 0076 Qt::ItemFlags itemFlags () KMPLAYERCOMMON_EXPORT; 0077 void add (); 0078 void remove (); 0079 QPixmap icon; 0080 QString source; 0081 PlayModel *model; 0082 int id; 0083 int root_flags; 0084 bool show_all_nodes; 0085 bool have_dark_nodes; 0086 }; 0087 0088 class KMPLAYERCOMMON_EXPORT PlayModel : public QAbstractItemModel 0089 { 0090 friend class TopPlayItem; 0091 0092 Q_OBJECT 0093 0094 public: 0095 enum { UrlRole = Qt::UserRole + 1 }; 0096 0097 enum Flags { 0098 AllowDrops = 0x01, AllowDrag = 0x02, 0099 InPlaceEdit = 0x04, TreeEdit = 0x08, 0100 Moveable = 0x10, Deleteable = 0x20 0101 }; 0102 0103 PlayModel(QObject *parent, KIconLoader *); 0104 ~PlayModel() override; 0105 0106 QVariant data (const QModelIndex &index, int role) const override KMPLAYERCOMMON_NO_EXPORT; 0107 bool setData (const QModelIndex&, const QVariant& v, int role) override KMPLAYERCOMMON_NO_EXPORT; 0108 Qt::ItemFlags flags (const QModelIndex &index) const override KMPLAYERCOMMON_NO_EXPORT; 0109 QVariant headerData (int section, Qt::Orientation orientation, 0110 int role = Qt::DisplayRole) const override KMPLAYERCOMMON_NO_EXPORT; 0111 QModelIndex index (int row, int column, 0112 const QModelIndex &parent = QModelIndex()) const override KMPLAYERCOMMON_NO_EXPORT; 0113 QModelIndex parent (const QModelIndex &index) const override KMPLAYERCOMMON_NO_EXPORT; 0114 bool hasChildren (const QModelIndex& parent = QModelIndex ()) const override KMPLAYERCOMMON_NO_EXPORT; 0115 int rowCount (const QModelIndex &parent = QModelIndex()) const override KMPLAYERCOMMON_NO_EXPORT; 0116 int columnCount (const QModelIndex &parent = QModelIndex()) const override KMPLAYERCOMMON_NO_EXPORT; 0117 0118 PlayItem *rootItem () const KMPLAYERCOMMON_NO_EXPORT { return root_item; } 0119 QModelIndex indexFromItem (PlayItem *item) const KMPLAYERCOMMON_NO_EXPORT; 0120 PlayItem *itemFromIndex (const QModelIndex& index) const KMPLAYERCOMMON_NO_EXPORT; 0121 0122 int addTree (NodePtr r, const QString &src, const QString &ico, int flgs); 0123 PlayItem *updateTree (TopPlayItem *ritem, NodePtr active); 0124 Q_SIGNALS: 0125 void updating (const QModelIndex&); 0126 void updated (const QModelIndex&, const QModelIndex&, bool sel, bool exp); 0127 0128 public Q_SLOTS: 0129 void updateTree (int id, NodePtr root, NodePtr active, bool sel, bool open); 0130 0131 private Q_SLOTS: 0132 void updateTrees() KMPLAYERCOMMON_NO_EXPORT; 0133 0134 private: 0135 PlayItem *populate (Node *e, Node *focus, 0136 TopPlayItem *root, PlayItem *item, 0137 PlayItem **curitem) KMPLAYERCOMMON_NO_EXPORT; 0138 SharedPtr <TreeUpdate> tree_update; 0139 QPixmap auxiliary_pix; 0140 QPixmap config_pix; 0141 QPixmap folder_pix; 0142 QPixmap img_pix; 0143 QPixmap info_pix; 0144 QPixmap menu_pix; 0145 QPixmap unknown_pix; 0146 QPixmap url_pix; 0147 QPixmap video_pix; 0148 PlayItem *root_item; 0149 int last_id; 0150 }; 0151 0152 } 0153 0154 #endif 0155