1 /* 2 * Cantata 3 * 4 * Copyright (c) s2018 Craig Drummond <craig.p.drummond@gmail.com> 5 * 6 * ---- 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; see the file COPYING. If not, write to 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 * Boston, MA 02110-1301, USA. 22 */ 23 24 #ifndef CATEGORIZEDVIEW_H 25 #define CATEGORIZEDVIEW_H 26 27 #include "kcategorizedview/kcategorizedview.h" 28 #include "treeview.h" 29 30 class QIcon; 31 class QMenu; 32 class KCategorizedSortFilterProxyModel; 33 34 class CategorizedView : public KCategorizedView 35 { 36 Q_OBJECT 37 38 public: 39 CategorizedView(QWidget *parent=nullptr); 40 ~CategorizedView() override; 41 42 void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override; 43 bool haveSelectedItems() const; 44 bool haveUnSelectedItems() const; startDrag(Qt::DropActions supportedActions)45 void startDrag(Qt::DropActions supportedActions) override { TreeView::drag(supportedActions, this, selectedIndexes()); } 46 void mouseReleaseEvent(QMouseEvent *event) override; selectedIndexes()47 QModelIndexList selectedIndexes() const override { return selectedIndexes(true); } 48 QModelIndexList selectedIndexes(bool sorted) const; 49 void setModel(QAbstractItemModel *m) override; 50 void addDefaultAction(QAction *act); 51 void setBackgroundImage(const QIcon &icon); 52 void paintEvent(QPaintEvent *e) override; installFilter(QObject * f)53 void installFilter(QObject *f) { eventFilter=f; installEventFilter(f); } filter()54 QObject * filter() const { return eventFilter; } zoom()55 double zoom() const { return zoomLevel; } setZoom(double l)56 void setZoom(double l) { zoomLevel = l; } setInfoText(const QString & i)57 void setInfoText(const QString &i) { info=i; update(); } 58 void setRootIndex(const QModelIndex &idx) override; 59 QModelIndex rootIndex() const; indexAt(const QPoint & point)60 QModelIndex indexAt(const QPoint &point) const override { return indexAt(point, false); } 61 QModelIndex indexAt(const QPoint &point, bool ensureFromSource) const; 62 QModelIndex mapFromSource(const QModelIndex &idx) const; 63 void setPlain(bool plain); 64 65 private Q_SLOTS: 66 void correctSelection(); 67 void showCustomContextMenu(const QPoint &pos); 68 void checkDoubleClick(const QModelIndex &idx); 69 void checkClicked(const QModelIndex &idx); 70 void checkActivated(const QModelIndex &idx); 71 72 Q_SIGNALS: 73 bool itemsSelected(bool); 74 void itemDoubleClicked(const QModelIndex &idx); 75 void itemClicked(const QModelIndex &idx); 76 void itemActivated(const QModelIndex &idx); 77 78 private: 79 void rowsInserted(const QModelIndex &parent, int start, int end) override; 80 81 private: 82 QString info; 83 QObject *eventFilter; 84 QMenu *menu; 85 QPixmap bgnd; 86 double zoomLevel; 87 KCategorizedSortFilterProxyModel *proxy; 88 }; 89 90 #endif 91