| 1 | // For license of this file, see <project-root-folder>/LICENSE.md. |
| 2 | |
| 3 | #ifndef FEEDSVIEW_H |
| 4 | #define FEEDSVIEW_H |
| 5 | |
| 6 | #include "core/feedsmodel.h" |
| 7 | #include "gui/reusable/basetreeview.h" |
| 8 | #include "gui/toolbars/feedstoolbar.h" |
| 9 | |
| 10 | #include <QStyledItemDelegate> |
| 11 | #include <QTimer> |
| 12 | |
| 13 | class FeedsProxyModel; |
| 14 | class Feed; |
| 15 | class Category; |
| 16 | |
| 17 | class RSSGUARD_DLLSPEC FeedsView : public BaseTreeView { |
| 18 | Q_OBJECT |
| 19 | |
| 20 | public: |
| 21 | explicit FeedsView(QWidget* parent = nullptr); |
| 22 | virtual ~FeedsView(); |
| 23 | |
| 24 | FeedsProxyModel* model() const; |
| 25 | FeedsModel* sourceModel() const; |
| 26 | |
| 27 | void reloadFontSettings(); |
| 28 | |
| 29 | void setSortingEnabled(bool enable); |
| 30 | |
| 31 | // Returns list of selected/all feeds. |
| 32 | // NOTE: This is recursive method which returns all descendants. |
| 33 | QList<Feed*> selectedFeeds(bool recursive) const; |
| 34 | |
| 35 | // Returns selected item. If multiple items are selected, returns |
| 36 | // the one of them which is also "current". If none of them is |
| 37 | // "current", returns firs item of selected ones. |
| 38 | RootItem* selectedItem() const; |
| 39 | QList<RootItem*> selectedItems() const; |
| 40 | |
| 41 | // Saves/loads expand states of all nodes (feeds/categories) of the list to/from settings. |
| 42 | void saveAllExpandStates(); |
| 43 | void loadAllExpandStates(); |
| 44 | |
| 45 | QByteArray saveHeaderState() const; |
| 46 | void restoreHeaderState(const QByteArray& dta); |
| 47 | |
| 48 | public slots: |
| 49 | void copyUrlOfSelectedFeeds() const; |
| 50 | void sortByColumn(int column, Qt::SortOrder order); |
| 51 | |
| 52 | void addFeedIntoSelectedAccount(); |
| 53 | void addCategoryIntoSelectedAccount(); |
| 54 | void expandCollapseCurrentItem(bool recursive); |
| 55 | |
| 56 | // Feed updating. |
| 57 | void updateSelectedItems(); |
| 58 | |
| 59 | // Feed read/unread manipulators. |
| 60 | void markSelectedItemRead(); |
| 61 | void markSelectedItemUnread(); |
| 62 | void markAllItemsRead(); |
| 63 | |
| 64 | // Feed clearers. |
| 65 | void clearSelectedItems(); |
| 66 | void clearAllItems(); |
| 67 | void purgeSelectedFeeds(); |
| 68 | |
| 69 | // Base manipulators. |
| 70 | void editItems(const QList<RootItem*>& items); |
| 71 | void editSelectedItems(); |
| 72 | void editChildFeeds(); |
| 73 | void editRecursiveFeeds(); |
| 74 | void deleteSelectedItem(); |
| 75 | |
| 76 | // Sort order manipulations. |
| 77 | void moveSelectedItemUp(); |
| 78 | void moveSelectedItemTop(); |
| 79 | void moveSelectedItemBottom(); |
| 80 | void moveSelectedItemDown(); |
| 81 | void rearrangeCategoriesOfSelectedItem(); |
| 82 | void rearrangeFeedsOfSelectedItem(); |
| 83 | |
| 84 | // Selects next/previous item (feed/category) in the list. |
| 85 | void selectNextItem(); |
| 86 | void selectPreviousItem(); |
| 87 | void selectNextUnreadItem(); |
| 88 | |
| 89 | // Switches visibility of the widget. |
| 90 | void switchVisibility(); |
| 91 | |
| 92 | void changeFilter(FeedsProxyModel::FeedListFilter filter); |
| 93 | void filterItems(SearchLineEdit::SearchMode mode, |
| 94 | Qt::CaseSensitivity sensitivity, |
| 95 | int custom_criteria, |
| 96 | const QString& phrase); |
| 97 | void toggleFeedSortingMode(bool sort_alphabetically); |
| 98 | |
| 99 | signals: |
| 100 | void itemSelected(RootItem* item); |
| 101 | void requestViewNextUnreadMessage(); |
| 102 | |
| 103 | protected: |
| 104 | void drawBranches(QPainter* painter, const QRect& rect, const QModelIndex& index) const; |
| 105 | void focusInEvent(QFocusEvent* event); |
| 106 | void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected); |
| 107 | void keyPressEvent(QKeyEvent* event); |
| 108 | void contextMenuEvent(QContextMenuEvent* event); |
| 109 | void mouseDoubleClickEvent(QMouseEvent* event); |
| 110 | |
| 111 | private slots: |
| 112 | void onIndexExpanded(const QModelIndex& idx); |
| 113 | void onIndexCollapsed(const QModelIndex& idx); |
| 114 | |
| 115 | void reloadDelayedExpansions(); |
| 116 | void reloadItemExpandState(const QModelIndex& source_idx); |
| 117 | void markSelectedItemReadStatus(RootItem::ReadStatus read); |
| 118 | void markAllItemsReadStatus(RootItem::ReadStatus read); |
| 119 | |
| 120 | void saveSortState(int column, Qt::SortOrder order); |
| 121 | void validateItemAfterDragDrop(const QModelIndex& source_index); |
| 122 | void onItemExpandRequested(const QList<RootItem*>& items, bool exp); |
| 123 | void onItemExpandStateSaveRequested(RootItem* item); |
| 124 | |
| 125 | private: |
| 126 | QModelIndex nextPreviousUnreadItem(const QModelIndex& default_row); |
| 127 | QModelIndex nextUnreadItem(const QModelIndex& default_row); |
| 128 | |
| 129 | // Initializes context menus. |
| 130 | QMenu* initializeContextMenuBin(RootItem* clicked_item); |
| 131 | QMenu* initializeContextMenuService(RootItem* clicked_item); |
| 132 | QMenu* initializeContextMenuCategories(RootItem* clicked_item); |
| 133 | QMenu* initializeContextMenuFeeds(RootItem* clicked_item); |
| 134 | QMenu* initializeContextMenuImportant(RootItem* clicked_item); |
| 135 | QMenu* initializeContextMenuEmptySpace(); |
| 136 | QMenu* initializeContextMenuOtherItem(RootItem* clicked_item); |
| 137 | QMenu* initializeContextMenuLabel(RootItem* clicked_item); |
| 138 | QMenu* initializeContextMenuProbe(RootItem* clicked_item); |
| 139 | |
| 140 | void setupAppearance(); |
| 141 | void saveExpandStates(RootItem* item); |
| 142 | |
| 143 | QMenu* m_contextMenuService; |
| 144 | QMenu* m_contextMenuBin; |
| 145 | QMenu* m_contextMenuCategories; |
| 146 | QMenu* m_contextMenuFeeds; |
| 147 | QMenu* m_contextMenuImportant; |
| 148 | QMenu* m_contextMenuEmptySpace; |
| 149 | QMenu* m_contextMenuOtherItems; |
| 150 | QMenu* m_contextMenuLabel; |
| 151 | QMenu* m_contextMenuProbe; |
| 152 | FeedsModel* m_sourceModel; |
| 153 | FeedsProxyModel* m_proxyModel; |
| 154 | bool m_dontSaveExpandState; |
| 155 | QList<QPair<QModelIndex, bool>> m_delayedItemExpansions; |
| 156 | QTimer m_expansionDelayer; |
| 157 | |
| 158 | // QTreeView interface |
| 159 | protected: |
| 160 | virtual void drawRow(QPainter* painter, const QStyleOptionViewItem& options, const QModelIndex& index) const; |
| 161 | }; |
| 162 | |
| 163 | inline FeedsProxyModel* FeedsView::model() const { |
| 164 | return m_proxyModel; |
| 165 | } |
| 166 | |
| 167 | inline FeedsModel* FeedsView::sourceModel() const { |
| 168 | return m_sourceModel; |
| 169 | } |
| 170 | |
| 171 | #endif // FEEDSVIEW_H |