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 CATEGORIESTREEWIDGET_H 19 #define CATEGORIESTREEWIDGET_H 20 21 #include <QtGui> 22 #ifdef HAVE_QT5 23 #include <QtWidgets> 24 #else 25 #include <QtGui> 26 #endif 27 28 class CategoriesTreeWidget : public QTreeWidget 29 { 30 Q_OBJECT 31 public: 32 explicit CategoriesTreeWidget(QWidget *parent = 0); 33 34 enum Items {UnreadItem, StarredItem, DeletedItem, LabelsItem}; 35 enum LabelRole {ImageRole = Qt::UserRole+1, NumRole, colorBgRole, colorTextRole}; 36 getLabelListItems()37 QList<QTreeWidgetItem *> getLabelListItems() const { 38 QList<QTreeWidgetItem *> items; 39 for (int i = 0; i < topLevelItem(LabelsItem)->childCount(); ++i) { 40 items.append(topLevelItem(LabelsItem)->child(i)); 41 } 42 return items; 43 } getLabelItem(int id)44 QTreeWidgetItem* getLabelItem(int id) const { 45 for (int i = 0; i < topLevelItem(LabelsItem)->childCount(); ++i) { 46 QTreeWidgetItem *item = topLevelItem(LabelsItem)->child(i); 47 if (item->text(2).toInt() == id) 48 return item; 49 } 50 return 0; 51 } labelsCount()52 int labelsCount() const { 53 return topLevelItem(LabelsItem)->childCount(); 54 } 55 56 signals: 57 void signalMiddleClicked(); 58 void signalClearDeleted(); 59 void signalMarkRead(QTreeWidgetItem *item); 60 // void pressKeyUp(); 61 // void pressKeyDown(); 62 63 protected: 64 virtual void mousePressEvent(QMouseEvent*); 65 // virtual void keyPressEvent(QKeyEvent*); 66 67 private slots: 68 void showContextMenuCategory(const QPoint &pos); 69 void openCategoryNewTab(); 70 71 void slotMarkRead(); 72 73 private: 74 QTreeWidgetItem *itemClicked_; 75 76 }; 77 78 #endif // CATEGORIESTREEWIDGET_H 79