File indexing completed on 2024-05-19 04:49:53
0001 /**************************************************************************************** 0002 * Copyright (c) 2008 Soren Harward <stharward@gmail.com> * 0003 * Copyright (c) 2009 Téo Mrnjavac <teo@kde.org> * 0004 * Copyright (c) 2009 Oleksandr Khayrullin <saniokh@gmail.com> * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify it under * 0007 * the terms of the GNU General Public License as published by the Free Software * 0008 * Foundation; either version 2 of the License, or (at your option) version 3 or * 0009 * any later version accepted by the membership of KDE e.V. (or its successor approved * 0010 * by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of * 0011 * version 3 of the license. * 0012 * * 0013 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0014 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0015 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0016 * * 0017 * You should have received a copy of the GNU General Public License along with * 0018 * this program. If not, see <http://www.gnu.org/licenses/>. * 0019 ****************************************************************************************/ 0020 0021 #ifndef PRETTYLISTVIEW_H 0022 #define PRETTYLISTVIEW_H 0023 0024 #include "PrettyItemDelegate.h" 0025 #include "playlist/proxymodels/GroupingProxy.h" 0026 #include "playlist/view/PlaylistViewCommon.h" 0027 0028 #include <QListView> 0029 #include <QModelIndex> 0030 #include <QPersistentModelIndex> 0031 #include <QRect> 0032 0033 #include <QAction> 0034 #include <QDateTime> 0035 #include <QTimer> 0036 0037 class PopupDropper; 0038 class QContextMenuEvent; 0039 class QDragLeaveEvent; 0040 class QDragMoveEvent; 0041 class QDropEvent; 0042 class QKeyEvent; 0043 class QMouseEvent; 0044 class QPaintEvent; 0045 class QTimer; 0046 0047 namespace Playlist 0048 { 0049 class PrettyListView : public QListView, public ViewCommon 0050 { 0051 Q_OBJECT 0052 0053 public: 0054 explicit PrettyListView( QWidget* parent = nullptr ); 0055 ~PrettyListView() override; 0056 0057 protected: 0058 int verticalOffset() const override; 0059 0060 Q_SIGNALS: 0061 void found(); 0062 void notFound(); 0063 0064 // these slots are used by the ContextMenu 0065 public Q_SLOTS: 0066 void editTrackInformation(); 0067 void playFirstSelected(); 0068 void dequeueSelection(); 0069 void queueSelection(); 0070 0071 /* Switch queue state for selected rows in playlist */ 0072 void switchQueueState(); 0073 0074 void removeSelection(); 0075 void stopAfterTrack(); 0076 void scrollToActiveTrack(); 0077 void selectSource(); 0078 0079 void downOneTrack(); 0080 void upOneTrack(); 0081 0082 // Workaround for BUG 222961 and BUG 229240: see implementation for more comments. 0083 void setCurrentIndex( const QModelIndex &index ); 0084 void selectionModel_setCurrentIndex( const QModelIndex &index, QItemSelectionModel::SelectionFlags command ); // Never call selectionModel()->setCurrentIndex() directly! 0085 0086 void find( const QString & searchTerm, int fields, bool filter ); 0087 void findNext( const QString & searchTerm, int fields ); 0088 void findPrevious( const QString & searchTerm, int fields ); 0089 void clearSearchTerm(); 0090 void showOnlyMatches( bool onlyMatches ); 0091 void findInSource(); 0092 0093 protected: 0094 void showEvent( QShowEvent* ) override; 0095 void contextMenuEvent( QContextMenuEvent* ) override; 0096 void dragEnterEvent( QDragEnterEvent *event ) override; 0097 void dragLeaveEvent( QDragLeaveEvent* ) override; 0098 void dragMoveEvent( QDragMoveEvent* ) override; 0099 void dropEvent( QDropEvent* ) override; 0100 void keyPressEvent( QKeyEvent* ) override; 0101 void mousePressEvent( QMouseEvent* ) override; 0102 void mouseReleaseEvent( QMouseEvent* ) override; 0103 0104 /** Draws a "drop here" text if empty */ 0105 void paintEvent( QPaintEvent* ) override; 0106 0107 void startDrag( Qt::DropActions supportedActions ) override; 0108 bool edit( const QModelIndex &index, EditTrigger trigger, QEvent *event ) override; 0109 0110 protected Q_SLOTS: 0111 void newPalette( const QPalette & palette ); 0112 0113 private Q_SLOTS: 0114 void slotPlaylistActiveTrackChanged(); 0115 void bottomModelRowsInserted( const QModelIndex& parent, int start, int end ); 0116 void bottomModelRowsInsertedScroll(); 0117 void moveTrackSelection( int offset ); 0118 0119 void slotSelectionChanged(); 0120 void trackActivated( const QModelIndex& ); 0121 void updateProxyTimeout(); 0122 void fixInvisible(); // Workaround for BUG 184714; see implementation for more comments. 0123 void redrawActive(); 0124 void playlistLayoutChanged(); 0125 0126 private: 0127 bool mouseEventInHeader( const QMouseEvent* ) const; 0128 QItemSelectionModel::SelectionFlags headerPressSelectionCommand( const QModelIndex&, const QMouseEvent* ) const; 0129 QItemSelectionModel::SelectionFlags headerReleaseSelectionCommand( const QModelIndex&, const QMouseEvent* ) const; 0130 0131 void startProxyUpdateTimeout(); 0132 0133 QRect m_dropIndicator; 0134 QPersistentModelIndex m_headerPressIndex; 0135 bool m_mousePressInHeader; 0136 0137 bool m_skipAutoScroll; 0138 bool m_firstScrollToActiveTrack; 0139 quint64 m_rowsInsertedScrollItem; 0140 0141 QString m_searchTerm; 0142 int m_fields; 0143 bool m_filter; 0144 0145 bool m_showOnlyMatches; 0146 0147 QTimer *m_proxyUpdateTimer; 0148 PopupDropper *m_pd; 0149 0150 PrettyItemDelegate * m_prettyDelegate; 0151 0152 QTimer *m_animationTimer; 0153 QDateTime m_lastTimeSelectionChanged; // we want to prevent a click to change the selection and open the editor (BR 220818) 0154 0155 public: 0156 QList<int> selectedRows() const; 0157 }; 0158 } 0159 #endif