File indexing completed on 2021-12-21 13:28:03

0001 /**
0002  * Copyright (C) 2003-2004 Scott Wheeler <wheeler@kde.org>
0003  * Copyright (C) 2007 Michael Pyne <mpyne@kde.org>
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 JUK_VIEWMODE_H
0019 #define JUK_VIEWMODE_H
0020 
0021 #include <QObject>
0022 #include <QStringList>
0023 #include <QMap>
0024 
0025 #include "playlistbox.h"
0026 
0027 class QPainter;
0028 class QColorGroup;
0029 
0030 
0031 class ViewMode : public QObject
0032 {
0033     Q_OBJECT
0034 
0035 public:
0036     explicit ViewMode(PlaylistBox *b);
0037     virtual ~ViewMode();
0038 
0039     virtual QString name() const;
0040     virtual void setShown(bool shown);
0041 
0042     /*virtual void paintCell(PlaylistBox::Item *item,
0043                            QPainter *painter,
0044                            const QColorGroup &colorGroup,
0045                            int column, int width, int align);*/
0046 
0047     virtual bool eventFilter(QObject *watched, QEvent *e) override;
0048     void queueRefresh() { m_needsRefresh = true; }
0049 
0050     virtual void setupItem(PlaylistBox::Item *item) const;
0051 
0052     virtual void setupDynamicPlaylists() {}
0053 
0054     /**
0055      * If the view mode has dynamic lists, this function is used to temporarily
0056      * freeze them to prevent them from deleting dynamic elements.
0057      */
0058     virtual void setDynamicListsFrozen(bool /* frozen */) {}
0059 
0060     /**
0061      * Used for dynamic view modes.  This function will be called when \p items
0062      * are added to \p column (even if the view mode hasn't been shown yet).
0063      */
0064     virtual void addItems(const QStringList &items, unsigned column)
0065     {
0066         Q_UNUSED(items);
0067         Q_UNUSED(column);
0068     }
0069 
0070     /**
0071      * Used for dynamic view modes.  This function will be called when \p item
0072      * is removed from \p column (even if the view mode hasn't been shown yet).
0073      */
0074     virtual void removeItem(const QString &item, unsigned column)
0075     {
0076         Q_UNUSED(item);
0077         Q_UNUSED(column);
0078     }
0079 
0080 protected:
0081     PlaylistBox *playlistBox() const { return m_playlistBox; }
0082     bool visible() const { return m_visible; }
0083     void setVisible(bool v) { m_visible = v; }
0084     void updateIcons();
0085     static void paintDropIndicator(QPainter *painter, int width, int height);
0086 
0087 private:
0088     PlaylistBox *m_playlistBox;
0089     bool m_visible;
0090     bool m_needsRefresh;
0091     QMap<PlaylistBox::Item *, QStringList> m_lines;
0092     static const int border = 4;
0093 };
0094 
0095 ////////////////////////////////////////////////////////////////////////////////
0096 
0097 class CompactViewMode : public ViewMode
0098 {
0099     Q_OBJECT
0100 
0101 public:
0102     explicit CompactViewMode(PlaylistBox *b);
0103     virtual ~CompactViewMode();
0104 
0105     virtual QString name() const override;
0106     virtual void setShown(bool shown) override;
0107 
0108     virtual void setupItem(PlaylistBox::Item *item) const override
0109     {
0110         item->setup();
0111     }
0112 };
0113 
0114 ////////////////////////////////////////////////////////////////////////////////
0115 
0116 class TreeViewItemPlaylist;
0117 
0118 class TreeViewMode final : public CompactViewMode
0119 {
0120     Q_OBJECT
0121 
0122 public:
0123     explicit TreeViewMode(PlaylistBox *l);
0124     virtual ~TreeViewMode();
0125 
0126     virtual QString name() const override;
0127     virtual void setShown(bool shown) override;
0128     virtual void setupDynamicPlaylists() override;
0129     virtual void setDynamicListsFrozen(bool frozen) override;
0130 
0131     virtual void removeItem(const QString &item, unsigned column) override;
0132     virtual void addItems(const QStringList &items, unsigned column) override;
0133 
0134 signals:
0135     void signalPlaylistDestroyed(Playlist*);
0136 
0137 private:
0138     QMap<QString, PlaylistBox::Item*> m_searchCategories;
0139     QMap<QString, TreeViewItemPlaylist*> m_treeViewItems;
0140     QStringList m_pendingItemsToRemove;
0141     bool m_dynamicListsFrozen;
0142     bool m_setup;
0143 };
0144 
0145 #endif
0146 
0147 // vim: set et sw=4 tw=0 sta: