File indexing completed on 2024-04-28 05:49:36
0001 /* 0002 SPDX-FileCopyrightText: 2021 Waqar Ahmed <waqar.17a@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 #pragma once 0007 0008 #include <QLineEdit> 0009 #include <QMenu> 0010 #include <QPointer> 0011 #include <QSortFilterProxyModel> 0012 #include <QStyledItemDelegate> 0013 #include <QTreeView> 0014 0015 #include "kateprivate_export.h" 0016 0017 class QAbstractItemModel; 0018 class QStyledItemDelegate; 0019 0020 namespace KTextEditor 0021 { 0022 class MainWindow; 0023 } 0024 0025 class KATE_PRIVATE_EXPORT HUDStyleDelegate : public QStyledItemDelegate 0026 { 0027 Q_OBJECT 0028 public: 0029 using QStyledItemDelegate::QStyledItemDelegate; 0030 0031 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; 0032 0033 public: 0034 void setFilterString(const QString &text) 0035 { 0036 m_filterString = text; 0037 } 0038 0039 void setDisplayRole(int role) 0040 { 0041 m_displayRole = role; 0042 } 0043 0044 protected: 0045 QString m_filterString; 0046 int m_displayRole = Qt::DisplayRole; 0047 }; 0048 0049 class KATE_PRIVATE_EXPORT HUDDialog : public QMenu 0050 { 0051 Q_OBJECT 0052 public: 0053 HUDDialog(QWidget *parent, QWidget *mainWindow); 0054 ~HUDDialog(); 0055 0056 enum FilterType { Contains, Fuzzy, ScoredFuzzy }; 0057 0058 void setStringList(const QStringList &); 0059 0060 void setModel(QAbstractItemModel *, FilterType, int filterKeyCol = 0, int filterRole = Qt::DisplayRole, int scoreRole = -1); 0061 0062 void setFilteringEnabled(bool enabled); 0063 0064 protected: 0065 bool eventFilter(QObject *obj, QEvent *event) override; 0066 void updateViewGeometry(); 0067 void clearLineEdit(); 0068 void setDelegate(HUDStyleDelegate *); 0069 void reselectFirst(); 0070 0071 protected Q_SLOTS: 0072 virtual void slotReturnPressed(const QModelIndex &index); 0073 0074 protected: 0075 QTreeView m_treeView; 0076 QLineEdit m_lineEdit; 0077 0078 private: 0079 QPointer<QWidget> m_mainWindow; 0080 QPointer<QAbstractItemModel> m_model; 0081 QPointer<QSortFilterProxyModel> m_proxy; 0082 HUDStyleDelegate *m_delegate = nullptr; 0083 0084 Q_SIGNALS: 0085 void itemExecuted(const QModelIndex &index); 0086 };