1 /* This file is part of Clementine. 2 Copyright 2010, David Sansome <me@davidsansome.com> 3 4 Clementine is free software: you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation, either version 3 of the License, or 7 (at your option) any later version. 8 9 Clementine is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with Clementine. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #ifndef PLAYLISTTABBAR_H 19 #define PLAYLISTTABBAR_H 20 21 #include <QBasicTimer> 22 #include <QIcon> 23 #include <QTabBar> 24 25 class PlaylistManager; 26 class RenameTabLineEdit; 27 28 class QMenu; 29 30 class PlaylistTabBar : public QTabBar { 31 Q_OBJECT 32 33 public: 34 PlaylistTabBar(QWidget* parent = nullptr); 35 36 static const int kDragHoverTimeout = 500; 37 static const char* kSettingsGroup; 38 39 void SetActions(QAction* new_playlist, QAction* load_playlist); 40 void SetManager(PlaylistManager* manager); 41 42 // We use IDs to refer to tabs so the tabs can be moved around (and their 43 // indexes change). 44 int index_of(int id) const; 45 int current_id() const; 46 int id_of(int index) const; 47 48 // Utility functions that use IDs rather than indexes 49 void set_current_id(int id); 50 void set_icon_by_id(int id, const QIcon& icon); 51 void set_text_by_id(int id, const QString& text); 52 53 void RemoveTab(int id); 54 void InsertTab(int id, int index, const QString& text, bool favorite); 55 56 signals: 57 void CurrentIdChanged(int id); 58 void Rename(int id, const QString& name); 59 void Close(int id); 60 void Save(int id); 61 void PlaylistOrderChanged(const QList<int>& ids); 62 void PlaylistFavorited(int id, bool favorite); 63 64 protected: 65 void contextMenuEvent(QContextMenuEvent* e); 66 void mouseReleaseEvent(QMouseEvent* e); 67 void mouseDoubleClickEvent(QMouseEvent* e); 68 void dragEnterEvent(QDragEnterEvent* e); 69 void dragMoveEvent(QDragMoveEvent* e); 70 void dragLeaveEvent(QDragLeaveEvent* e); 71 void dropEvent(QDropEvent* e); 72 void timerEvent(QTimerEvent* e); 73 bool event(QEvent* e); 74 75 private slots: 76 void CurrentIndexChanged(int index); 77 void Rename(); 78 void RenameInline(); 79 void HideEditor(); 80 void Close(); 81 void CloseFromTabIndex(int index); 82 // Used when playlist's favorite flag isn't changed from the favorite widget 83 // (e.g. from the playlistlistcontainer): will update the favorite widget 84 void PlaylistFavoritedSlot(int id, bool favorite); 85 // Used to signal that the playlist manager is done starting up 86 void PlaylistManagerInitialized(); 87 void TabMoved(); 88 void Save(); 89 90 private: 91 PlaylistManager* manager_; 92 93 QMenu* menu_; 94 int menu_index_; 95 QAction* new_; 96 QAction* rename_; 97 QAction* close_; 98 QAction* save_; 99 100 QBasicTimer drag_hover_timer_; 101 int drag_hover_tab_; 102 103 bool suppress_current_changed_; 104 bool initialized_; 105 106 // Editor for inline renaming 107 RenameTabLineEdit* rename_editor_; 108 }; 109 110 #endif // PLAYLISTTABBAR_H 111