1 /* ============================================================
2 * QuiteRSS is a open-source cross-platform RSS/Atom news feeds reader
3 * Copyright (C) 2011-2020 QuiteRSS Team <quiterssteam@gmail.com>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 * ============================================================ */
18 #ifndef FEEDSVIEW_H
19 #define FEEDSVIEW_H
20 
21 #ifdef HAVE_QT5
22 #include <QtWidgets>
23 #else
24 #include <QtGui>
25 #endif
26 #include <feedsmodel.h>
27 
28 class FeedsView : public QTreeView
29 {
30   Q_OBJECT
31 public:
32   explicit FeedsView(QWidget * parent = 0);
33   int selectId_;
34   bool selectIdEn_;
35   bool autocollapseFolder_;
36 
37   void setSourceModel(FeedsModel *sourceModel);
38   void refresh();
39   void setColumnHidden(const QString& column, bool hide);
40   int columnIndex(const QString& fieldName) const;
41   bool isFolder(const QModelIndex &index) const;
42   QModelIndex indexNextUnread(const QModelIndex &indexCur, int nextCondition = 0);
43   QModelIndex firstFeedInFolder(const QModelIndex &indexFolder);
44   QModelIndex lastFeedInFolder(const QModelIndex &indexFolder);
45   QModelIndex indexPrevious(const QModelIndex &indexCur, bool isParent = false);
46   QModelIndex indexNext(const QModelIndex &indexCur, bool isParent = false);
47   QModelIndex lastFolderInFolder(const QModelIndex &indexFolder);
48   QModelIndex indexPreviousFolder(const QModelIndex &indexCur);
49   QModelIndex firstFolderInFolder(const QModelIndex &indexFolder);
50   QModelIndex indexNextFolder(const QModelIndex &indexCur, bool isParent = false);
51 
52 public slots:
53   void restoreExpanded();
54   void expandAll();
55   void collapseAll();
56   QPersistentModelIndex selectIndex();
57   void updateCurrentIndex(const QModelIndex &index);
58 
59 signals:
60   void signalDoubleClicked();
61   void signalMiddleClicked();
62   void pressKeyUp();
63   void pressKeyDown();
64   void pressKeyHome();
65   void pressKeyEnd();
66   void pressKeyPageUp();
67   void pressKeyPageDown();
68   void signalDropped(const QModelIndex &where, int how);
69 
70 protected:
71   virtual void mousePressEvent(QMouseEvent*);
72   virtual void mouseReleaseEvent(QMouseEvent*event);
73   virtual void mouseMoveEvent(QMouseEvent*);
74   virtual void mouseDoubleClickEvent(QMouseEvent*);
75   virtual void keyPressEvent(QKeyEvent*);
76   virtual void currentChanged(const QModelIndex &current,
77                               const QModelIndex &previous);
78   void dragEnterEvent(QDragEnterEvent *event);
79   void dragLeaveEvent(QDragLeaveEvent *event);
80   void dragMoveEvent(QDragMoveEvent *event);
81   void dropEvent(QDropEvent *event);
82   void paintEvent(QPaintEvent *event);
83 
84 private slots:
85   void slotExpanded(const QModelIndex&index);
86   void slotCollapsed(const QModelIndex&index);
87 
88 private:
89   FeedsModel *sourceModel_;
90   QPoint dragPos_;
91   QPoint dragStartPos_;
92   QList<int> expandedList;
93   int expandedOldId_;
94   QModelIndex indexClicked_;
95 
96   void handleDrop(QDropEvent *e);
97   bool shouldAutoScroll(const QPoint &pos) const;
98 
99 };
100 
101 #endif // FEEDSVIEW_H
102