1 /**************************************************************************************** 2 * Copyright (c) 2008 Soren Harward <stharward@gmail.com> * 3 * Copyright (c) 2009 Téo Mrnjavac <teo@kde.org> * 4 * Copyright (c) 2009 Oleksandr Khayrullin <saniokh@gmail.com> * 5 * * 6 * This program is free software; you can redistribute it and/or modify it under * 7 * the terms of the GNU General Public License as published by the Free Software * 8 * Foundation; either version 2 of the License, or (at your option) version 3 or * 9 * any later version accepted by the membership of KDE e.V. (or its successor approved * 10 * by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of * 11 * version 3 of the license. * 12 * * 13 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 14 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 15 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 16 * * 17 * You should have received a copy of the GNU General Public License along with * 18 * this program. If not, see <http://www.gnu.org/licenses/>. * 19 ****************************************************************************************/ 20 21 #ifndef PRETTYLISTVIEW_H 22 #define PRETTYLISTVIEW_H 23 24 #include "PrettyItemDelegate.h" 25 #include "playlist/proxymodels/GroupingProxy.h" 26 #include "playlist/view/PlaylistViewCommon.h" 27 28 #include <QListView> 29 #include <QModelIndex> 30 #include <QPersistentModelIndex> 31 #include <QRect> 32 33 #include <QAction> 34 #include <QDateTime> 35 #include <QTimer> 36 37 class PopupDropper; 38 class QContextMenuEvent; 39 class QDragLeaveEvent; 40 class QDragMoveEvent; 41 class QDropEvent; 42 class QKeyEvent; 43 class QMouseEvent; 44 class QPaintEvent; 45 class QTimer; 46 47 namespace Playlist 48 { 49 class PrettyListView : public QListView, public ViewCommon 50 { 51 Q_OBJECT 52 53 public: 54 explicit PrettyListView( QWidget* parent = nullptr ); 55 ~PrettyListView() override; 56 57 protected: 58 int verticalOffset() const override; 59 60 Q_SIGNALS: 61 void found(); 62 void notFound(); 63 64 // these slots are used by the ContextMenu 65 public Q_SLOTS: 66 void editTrackInformation(); 67 void playFirstSelected(); 68 void dequeueSelection(); 69 void queueSelection(); 70 71 /* Switch queue state for selected rows in playlist */ 72 void switchQueueState(); 73 74 void removeSelection(); 75 void stopAfterTrack(); 76 void scrollToActiveTrack(); 77 void selectSource(); 78 79 void downOneTrack(); 80 void upOneTrack(); 81 82 // Workaround for BUG 222961 and BUG 229240: see implementation for more comments. 83 void setCurrentIndex( const QModelIndex &index ); 84 void selectionModel_setCurrentIndex( const QModelIndex &index, QItemSelectionModel::SelectionFlags command ); // Never call selectionModel()->setCurrentIndex() directly! 85 86 void find( const QString & searchTerm, int fields, bool filter ); 87 void findNext( const QString & searchTerm, int fields ); 88 void findPrevious( const QString & searchTerm, int fields ); 89 void clearSearchTerm(); 90 void showOnlyMatches( bool onlyMatches ); 91 void findInSource(); 92 93 protected: 94 void showEvent( QShowEvent* ) override; 95 void contextMenuEvent( QContextMenuEvent* ) override; 96 void dragEnterEvent( QDragEnterEvent *event ) override; 97 void dragLeaveEvent( QDragLeaveEvent* ) override; 98 void dragMoveEvent( QDragMoveEvent* ) override; 99 void dropEvent( QDropEvent* ) override; 100 void keyPressEvent( QKeyEvent* ) override; 101 void mousePressEvent( QMouseEvent* ) override; 102 void mouseReleaseEvent( QMouseEvent* ) override; 103 104 /** Draws a "drop here" text if empty */ 105 void paintEvent( QPaintEvent* ) override; 106 107 void startDrag( Qt::DropActions supportedActions ) override; 108 bool edit( const QModelIndex &index, EditTrigger trigger, QEvent *event ) override; 109 110 protected Q_SLOTS: 111 void newPalette( const QPalette & palette ); 112 113 private Q_SLOTS: 114 void slotPlaylistActiveTrackChanged(); 115 void bottomModelRowsInserted( const QModelIndex& parent, int start, int end ); 116 void bottomModelRowsInsertedScroll(); 117 void moveTrackSelection( int offset ); 118 119 void slotSelectionChanged(); 120 void trackActivated( const QModelIndex& ); 121 void updateProxyTimeout(); 122 void fixInvisible(); // Workaround for BUG 184714; see implementation for more comments. 123 void redrawActive(); 124 void playlistLayoutChanged(); 125 126 private: 127 bool mouseEventInHeader( const QMouseEvent* ) const; 128 QItemSelectionModel::SelectionFlags headerPressSelectionCommand( const QModelIndex&, const QMouseEvent* ) const; 129 QItemSelectionModel::SelectionFlags headerReleaseSelectionCommand( const QModelIndex&, const QMouseEvent* ) const; 130 131 void startProxyUpdateTimeout(); 132 133 QRect m_dropIndicator; 134 QPersistentModelIndex m_headerPressIndex; 135 bool m_mousePressInHeader; 136 137 bool m_skipAutoScroll; 138 bool m_firstScrollToActiveTrack; 139 quint64 m_rowsInsertedScrollItem; 140 141 QString m_searchTerm; 142 int m_fields; 143 bool m_filter; 144 145 bool m_showOnlyMatches; 146 147 QTimer *m_proxyUpdateTimer; 148 PopupDropper *m_pd; 149 150 PrettyItemDelegate * m_prettyDelegate; 151 152 QTimer *m_animationTimer; 153 QDateTime m_lastTimeSelectionChanged; // we want to prevent a click to change the selection and open the editor (BR 220818) 154 155 public: 156 QList<int> selectedRows() const; 157 }; 158 } 159 #endif 160