File indexing completed on 2024-12-01 05:16:30
0001 /** 0002 * SPDX-FileCopyrightText: (C) 2003 by Sébastien Laoût <slaout@linux62.org> 0003 * SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef BASKETLISTVIEW_H 0007 #define BASKETLISTVIEW_H 0008 0009 #include <QStyledItemDelegate> 0010 #include <QTreeWidget> 0011 #include <QtCore/QTimer> 0012 0013 class QPixmap; 0014 class QResizeEvent; 0015 class QDragEnterEvent; 0016 class QDropEvent; 0017 class QDragMoveEvent; 0018 class QFocusEvent; 0019 class QDragLeaveEvent; 0020 0021 class BasketScene; 0022 0023 class BasketListViewItem : public QTreeWidgetItem 0024 { 0025 public: 0026 /// CONSTRUCTOR AND DESTRUCTOR: 0027 BasketListViewItem(QTreeWidget *parent, BasketScene *basket); 0028 BasketListViewItem(QTreeWidgetItem *parent, BasketScene *basket); 0029 BasketListViewItem(QTreeWidget *parent, QTreeWidgetItem *after, BasketScene *basket); 0030 BasketListViewItem(QTreeWidgetItem *parent, QTreeWidgetItem *after, BasketScene *basket); 0031 ~BasketListViewItem() override; 0032 0033 BasketScene *basket() 0034 { 0035 return m_basket; 0036 } 0037 void setup(); 0038 BasketListViewItem *lastChild(); 0039 QStringList childNamesTree(int deep = 0); 0040 void moveChildsBaskets(); 0041 void ensureVisible(); 0042 bool isShown(); 0043 bool isCurrentBasket(); 0044 bool isUnderDrag(); 0045 QString escapedName(const QString &string); 0046 0047 bool haveChildsLoading(); 0048 bool haveHiddenChildsLoading(); 0049 bool haveChildsLocked(); 0050 bool haveHiddenChildsLocked(); 0051 int countChildsFound(); 0052 int countHiddenChildsFound(); 0053 0054 void setUnderDrag(bool); 0055 bool isAbbreviated(); 0056 void setAbbreviated(bool b); 0057 0058 private: 0059 BasketScene *m_basket; 0060 int m_width; 0061 bool m_isUnderDrag; 0062 bool m_isAbbreviated; 0063 }; 0064 0065 Q_DECLARE_METATYPE(BasketListViewItem *); 0066 0067 class BasketTreeListView : public QTreeWidget 0068 { 0069 Q_OBJECT 0070 public: 0071 explicit BasketTreeListView(QWidget *parent = nullptr); 0072 void dragEnterEvent(QDragEnterEvent *event) override; 0073 void removeExpands(); 0074 void dragLeaveEvent(QDragLeaveEvent *event) override; 0075 void dragMoveEvent(QDragMoveEvent *event) override; 0076 void dropEvent(QDropEvent *event) override; 0077 void resizeEvent(QResizeEvent *event) override; 0078 void contextMenuEvent(QContextMenuEvent *event) override; 0079 Qt::DropActions supportedDropActions() const override; 0080 0081 /*! Retrieve a basket from the tree 0082 * @see BasketListViewItem::basket() */ 0083 BasketListViewItem *getBasketInTree(const QModelIndex &index) const; 0084 0085 static QString TREE_ITEM_MIME_STRING; 0086 0087 protected: 0088 QStringList mimeTypes() const override; 0089 QMimeData *mimeData(const QList<QTreeWidgetItem *> items) const override; 0090 bool event(QEvent *e) override; 0091 void mousePressEvent(QMouseEvent *event) override; 0092 void mouseMoveEvent(QMouseEvent *event) override; 0093 void focusInEvent(QFocusEvent *) override; 0094 0095 private: 0096 QTimer m_autoOpenTimer; 0097 QTreeWidgetItem *m_autoOpenItem; 0098 Q_SIGNALS: 0099 void contextMenuRequested(const QPoint &); 0100 private Q_SLOTS: 0101 void autoOpen(); 0102 0103 private: 0104 void setItemUnderDrag(BasketListViewItem *item); 0105 BasketListViewItem *m_itemUnderDrag; 0106 QPoint m_dragStartPosition; 0107 }; 0108 0109 /** @class FoundCountIcon 0110 * Custom-drawn "little numbers" shown on Filter all */ 0111 class FoundCountIcon : public QStyledItemDelegate 0112 { 0113 public: 0114 FoundCountIcon(BasketTreeListView *basketTree, QObject *parent = nullptr) 0115 : QStyledItemDelegate(parent) 0116 , m_basketTree(basketTree) 0117 { 0118 } 0119 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; 0120 0121 private: 0122 QPixmap circledTextPixmap(const QString &text, int height, const QFont &font, const QColor &color) const; 0123 0124 //! @returns Rect-with-number, or null pixmap if nothing was found / basket is loading 0125 QPixmap foundCountPixmap(bool isLoading, int countFound, bool childrenAreLoading, int countChildsFound, const QFont &font, int height) const; 0126 0127 BasketTreeListView *m_basketTree; 0128 }; 0129 0130 #endif // BASKETLISTVIEW_H