1 /*
2     SPDX-FileCopyrightText: 2009 Joris Guisson <joris.guisson@gmail.com>
3     SPDX-License-Identifier: GPL-2.0-or-later
4 */
5 
6 #ifndef PLAYLISTWIDGET_H
7 #define PLAYLISTWIDGET_H
8 
9 #include <QCheckBox>
10 #include <QComboBox>
11 #include <QLabel>
12 #include <QMenu>
13 #include <QToolBar>
14 #include <QTreeView>
15 
16 #include <KSharedConfig>
17 
18 #include "mediafile.h"
19 
20 class QSortFilterProxyModel;
21 
22 namespace kt
23 {
24 class PlayList;
25 class MediaPlayer;
26 class MediaFileCollection;
27 
28 class PlayListWidget : public QWidget
29 {
30     Q_OBJECT
31 public:
32     PlayListWidget(MediaFileCollection *collection, MediaPlayer *player, QWidget *parent);
33     ~PlayListWidget() override;
34 
35     /// Get the play list
playList()36     PlayList *playList()
37     {
38         return play_list;
39     }
40 
41     /// Get the current selected item
42     QModelIndex selectedItem() const;
43 
44     void saveState(KSharedConfigPtr cfg);
45     void loadState(KSharedConfigPtr cfg);
46 
47     /// Get the next item to play, if idx is invalid return the first playable item
48     QModelIndex next(const QModelIndex &idx, bool random) const;
49 
50     /// Get the file of a given index
51     QString fileForIndex(const QModelIndex &index) const;
52 
53     /// Get the index of a file
54     QModelIndex indexForFile(const QString &file) const;
55 
56     /// Is random mode activated ?
randomOrder()57     bool randomOrder() const
58     {
59         return random_mode->isChecked();
60     }
61 
62 public Q_SLOTS:
63     QModelIndex play();
64     void addMedia();
65     void clearPlayList();
66 
67 private Q_SLOTS:
68     void onSelectionChanged(const QItemSelection &s, const QItemSelection &d);
69     void doubleClicked(const QModelIndex &index);
70     void showContextMenu(QPoint pos);
71     void removeFiles();
72     void onItemsDropped();
73 
74 Q_SIGNALS:
75     void fileSelected(const MediaFileRef &file);
76     void doubleClicked(const MediaFileRef &file);
77     void randomModeActivated(bool random);
78     void enableNext(bool on);
79 
80 private:
81     QModelIndex next(const QModelIndex &idx) const;
82     QModelIndex randomNext(const QModelIndex &idx) const;
83 
84 private:
85     MediaPlayer *player;
86     PlayList *play_list;
87     QToolBar *tool_bar;
88     QTreeView *view;
89     QCheckBox *random_mode;
90 
91     QMenu *menu;
92     QSortFilterProxyModel *proxy_model;
93     MediaFileCollection *collection;
94 };
95 }
96 
97 #endif // PLAYLISTWIDGET_H
98