File indexing completed on 2023-05-30 11:30:49
0001 /** 0002 * Copyright (C) 2002-2004 Scott Wheeler <wheeler@kde.org> 0003 * 0004 * This program is free software; you can redistribute it and/or modify it under 0005 * the terms of the GNU General Public License as published by the Free Software 0006 * Foundation; either version 2 of the License, or (at your option) any later 0007 * version. 0008 * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. 0012 * 0013 * You should have received a copy of the GNU General Public License along with 0014 * this program. If not, see <http://www.gnu.org/licenses/>. 0015 */ 0016 0017 #ifndef PLAYLISTBOX_H 0018 #define PLAYLISTBOX_H 0019 0020 #include "playlistcollection.h" 0021 0022 #include <QHash> 0023 #include <QVector> 0024 #include <QTreeWidget> 0025 0026 class Playlist; 0027 class PlaylistItem; 0028 class ViewMode; 0029 0030 class QMenu; 0031 0032 typedef QVector<Playlist *> PlaylistList; 0033 0034 /** 0035 * This is the play list selection box that is by default on the left side of 0036 * JuK's main widget (PlaylistSplitter). 0037 */ 0038 0039 class PlaylistBox final : public QTreeWidget, public PlaylistCollection 0040 { 0041 Q_OBJECT 0042 0043 public: 0044 class Item; 0045 typedef QVector<Item *> ItemList; 0046 0047 friend class Item; 0048 0049 PlaylistBox(PlayerManager *player, QWidget *parent, QStackedWidget *playlistStack); 0050 virtual ~PlaylistBox(); 0051 0052 virtual void raise(Playlist *playlist) override; 0053 virtual void duplicate() override; 0054 virtual void remove() override; 0055 0056 // Called after files loaded to pickup any new files that might be present 0057 // in managed directories. 0058 virtual void scanFolders() override; 0059 0060 virtual bool requestPlaybackFor(const FileHandle &file) override; 0061 0062 /** 0063 * For view modes that have dynamic playlists, this freezes them from 0064 * removing playlists. 0065 */ 0066 virtual void setDynamicListsFrozen(bool frozen) override; 0067 0068 Item *dropItem() const { return m_dropItem; } 0069 0070 void setupPlaylist(Playlist *playlist, const QString &iconName, Item *parentItem = nullptr); 0071 0072 public slots: 0073 void paste(); 0074 void clear() {} 0075 0076 void slotFreezePlaylists(); 0077 void slotUnfreezePlaylists(); 0078 void slotPlaylistDataChanged(); 0079 void slotSetHistoryPlaylistEnabled(bool enable); 0080 0081 protected: 0082 virtual void setupPlaylist(Playlist *playlist, const QString &iconName) override; 0083 virtual void removePlaylist(Playlist *playlist) override; 0084 virtual Qt::DropActions supportedDropActions() const override; 0085 virtual bool dropMimeData(QTreeWidgetItem *, int, const QMimeData *, Qt::DropAction) override; 0086 virtual QStringList mimeTypes() const override; 0087 0088 signals: 0089 void signalPlaylistDestroyed(Playlist *); 0090 void signalMoveFocusAway(); // Handles keyboard scrolling up out of playlist 0091 void startupComplete(); ///< Emitted after playlists are loaded. 0092 void signalPlayFile(const FileHandle &file); 0093 0094 private: 0095 void readConfig(); 0096 void saveConfig(); 0097 0098 virtual void mousePressEvent(QMouseEvent *e) override; 0099 virtual void mouseReleaseEvent(QMouseEvent *e) override; 0100 virtual void keyPressEvent(QKeyEvent *e) override; 0101 virtual void keyReleaseEvent(QKeyEvent *e) override; 0102 0103 // selectedItems already used for something different 0104 0105 ItemList selectedBoxItems(); 0106 void setSingleItem(QTreeWidgetItem *item); 0107 0108 void setupItem(Item *item); 0109 void setupUpcomingPlaylist(); 0110 int viewModeIndex() const { return m_viewModeIndex; } 0111 ViewMode *viewMode() const { return m_viewModes[m_viewModeIndex]; } 0112 void dragMoveEvent(QDragMoveEvent *event) override; 0113 void dragLeaveEvent(QDragLeaveEvent *event) override; 0114 0115 private slots: 0116 /** 0117 * Catches QListBox::currentChanged(QListBoxItem *), does a cast and then re-emits 0118 * the signal as currentChanged(Item *). 0119 */ 0120 void slotPlaylistChanged(); 0121 void slotDoubleClicked(QTreeWidgetItem *); 0122 void slotShowContextMenu(const QPoint &point); 0123 void slotSetViewMode(int index); 0124 void slotSavePlaylists(); 0125 void slotShowDropTarget(); 0126 0127 void slotPlaylistItemsDropped(Playlist *p); 0128 0129 void slotAddItem(const QString &tag, unsigned column); 0130 void slotRemoveItem(const QString &tag, unsigned column); 0131 0132 // Used to load the playlists after GUI setup. 0133 void slotLoadCachedPlaylists(); 0134 0135 private: 0136 QHash<Playlist *, Item *> m_playlistDict; 0137 QTimer *m_showTimer = nullptr; 0138 QTimer *m_savePlaylistTimer = nullptr; 0139 Item *m_dropItem = nullptr; 0140 QMenu *m_contextMenu = nullptr; 0141 QVector<ViewMode *> m_viewModes; 0142 int m_viewModeIndex = 0; 0143 bool m_hasSelection = false; 0144 bool m_doingMultiSelect = false; 0145 }; 0146 0147 class PlaylistBox::Item final : public QObject, public QTreeWidgetItem 0148 { 0149 friend class PlaylistBox; 0150 friend class PlaylistSplitter; 0151 friend class ViewMode; 0152 friend class CompactViewMode; 0153 friend class TreeViewMode; 0154 0155 Q_OBJECT 0156 0157 // moc won't let me create private QObject subclasses and Qt won't let me 0158 // make the destructor protected, so here's the closest hack that will 0159 // compile. 0160 0161 public: 0162 virtual ~Item(); 0163 0164 protected: 0165 using QTreeWidgetItem::text; 0166 0167 Item(PlaylistBox *listBox, const QString &icon, const QString &text, Playlist *l = nullptr); 0168 Item(Item *parent, const QString &icon, const QString &text, Playlist *l = nullptr); 0169 0170 Playlist *playlist() const { return m_playlist; } 0171 PlaylistBox *listView() const { return static_cast<PlaylistBox *>(QTreeWidgetItem::treeWidget()); } 0172 QString iconName() const { return m_iconName; } 0173 QString text() const { return QTreeWidgetItem::text(0); } 0174 void setSortedFirst(bool first = true) { m_sortedFirst = first; } 0175 0176 virtual void setup(); 0177 0178 static Item *collectionItem() { return m_collectionItem; } 0179 0180 // Used to post a timer in PlaylistBox to save playlists. 0181 void playlistItemDataChanged(); 0182 0183 0184 protected slots: 0185 void slotSetName(const QString &name); 0186 0187 private: 0188 // setup() was already taken. 0189 void init(); 0190 QString sortTextFor(const QString &name) const; 0191 0192 Playlist *m_playlist; 0193 QString m_iconName; 0194 bool m_sortedFirst; 0195 0196 static Item *m_collectionItem; 0197 }; 0198 0199 #endif 0200 0201 // vim: set et sw=4 tw=0 sta: