1 /* 2 * Strawberry Music Player 3 * This file was part of Clementine. 4 * Copyright 2010, David Sansome <me@davidsansome.com> 5 * Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net> 6 * 7 * Strawberry is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * Strawberry is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with Strawberry. If not, see <http://www.gnu.org/licenses/>. 19 * 20 */ 21 22 #ifndef AUTOEXPANDINGTREEVIEW_H 23 #define AUTOEXPANDINGTREEVIEW_H 24 25 #include "config.h" 26 27 #include <QtGlobal> 28 #include <QObject> 29 #include <QString> 30 #include <QTreeView> 31 32 class QMimeData; 33 class QWidget; 34 class QModelIndex; 35 class QKeyEvent; 36 class QMouseEvent; 37 38 class AutoExpandingTreeView : public QTreeView { 39 Q_OBJECT 40 41 public: 42 explicit AutoExpandingTreeView(QWidget *parent = nullptr); 43 44 static const int kRowsToShow; 45 SetAutoOpen(bool v)46 void SetAutoOpen(bool v) { auto_open_ = v; } SetExpandOnReset(bool v)47 void SetExpandOnReset(bool v) { expand_on_reset_ = v; } SetAddOnDoubleClick(bool v)48 void SetAddOnDoubleClick(bool v) { add_on_double_click_ = v; } 49 50 public slots: 51 void RecursivelyExpandSlot(const QModelIndex &idx); 52 void UpAndFocus(); 53 void DownAndFocus(); 54 55 signals: 56 void AddToPlaylistSignal(QMimeData *data); 57 void FocusOnFilterSignal(QKeyEvent *event); 58 59 protected: 60 // QAbstractItemView 61 void reset() override; 62 63 // QWidget 64 void mousePressEvent(QMouseEvent *event) override; 65 void mouseDoubleClickEvent(QMouseEvent *event) override; 66 void keyPressEvent(QKeyEvent *event) override; 67 CanRecursivelyExpand(const QModelIndex & idx)68 virtual bool CanRecursivelyExpand(const QModelIndex &idx) const { Q_UNUSED(idx); return true; } 69 70 private slots: 71 void ItemExpanded(const QModelIndex &idx); 72 void ItemClicked(const QModelIndex &idx); 73 void ItemDoubleClicked(const QModelIndex &idx); 74 75 private: 76 bool RecursivelyExpand(const QModelIndex &idx, int *count); 77 78 private: 79 bool auto_open_; 80 bool expand_on_reset_; 81 bool add_on_double_click_; 82 bool ignore_next_click_; 83 }; 84 85 #endif // AUTOEXPANDINGTREEVIEW_H 86