1 | /* |
2 | * Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com) |
3 | * |
4 | * This program is free software: you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by |
6 | * the Free Software Foundation, either version 3 of the License, or |
7 | * (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
16 | */ |
17 | #ifndef CODECOMPLETIONPOPUP_H |
18 | #define |
19 | |
20 | #include <QListView> |
21 | #include <QWidget> |
22 | #include "parser/cppparser.h" |
23 | #include "codecompletionlistview.h" |
24 | |
25 | class ColorSchemeItem; |
26 | class CodeCompletionListModel : public QAbstractListModel { |
27 | Q_OBJECT |
28 | public: |
29 | explicit CodeCompletionListModel(const StatementList* statements,QObject *parent = nullptr); |
30 | int rowCount(const QModelIndex &parent) const override; |
31 | QVariant data(const QModelIndex &index, int role) const override; |
32 | PStatement statement(const QModelIndex &index) const; |
33 | QPixmap statementIcon(const QModelIndex &index) const; |
34 | void notifyUpdated(); |
35 | |
36 | private: |
37 | const StatementList* mStatements; |
38 | }; |
39 | |
40 | class CodeCompletionListItemDelegate: public QStyledItemDelegate { |
41 | Q_OBJECT |
42 | public: |
43 | CodeCompletionListItemDelegate(CodeCompletionListModel *model=nullptr, QWidget *parent = nullptr); |
44 | |
45 | |
46 | // QAbstractItemDelegate interface |
47 | public: |
48 | void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; |
49 | CodeCompletionListModel *model() const; |
50 | void setModel(CodeCompletionListModel *newModel); |
51 | |
52 | const QColor &normalColor() const; |
53 | void setNormalColor(const QColor &newNormalColor); |
54 | |
55 | const QColor &matchedColor() const; |
56 | void setMatchedColor(const QColor &newMatchedColor); |
57 | |
58 | const QFont &font() const; |
59 | void setFont(const QFont &newFont); |
60 | |
61 | private: |
62 | CodeCompletionListModel *mModel; |
63 | QColor mNormalColor; |
64 | QColor mMatchedColor; |
65 | QFont mFont; |
66 | }; |
67 | |
68 | class : public QWidget |
69 | { |
70 | Q_OBJECT |
71 | |
72 | public: |
73 | explicit (QWidget *parent = nullptr); |
74 | (); |
75 | |
76 | void (const KeyPressedCallback &newKeypressedCallback); |
77 | void (const QString& preWord, |
78 | const QStringList & ownerExpression, |
79 | const QString& memberOperator, |
80 | const QStringList& memberExpression, |
81 | const QString& filename, |
82 | int line, |
83 | const QSet<QString>& customKeywords); |
84 | bool (const QString& memberPhrase, bool autoHideOnSingleResult); |
85 | |
86 | PStatement (); |
87 | |
88 | const PCppParser &() const; |
89 | void (const PCppParser &newParser); |
90 | |
91 | int () const; |
92 | void (int newShowCount); |
93 | |
94 | bool () const; |
95 | void (bool newOnlyGlobals); |
96 | |
97 | bool () const; |
98 | void (bool newRecordUsage); |
99 | |
100 | bool () const; |
101 | void (bool newShowKeywords); |
102 | |
103 | bool () const; |
104 | void (bool newShowCodeIns); |
105 | |
106 | bool () const; |
107 | void (bool newIgnoreCase); |
108 | |
109 | bool () const; |
110 | void (bool newSortByScope); |
111 | |
112 | bool () const; |
113 | void (bool newUseCppKeyword); |
114 | |
115 | bool () const; |
116 | void (bool newHideSymbolsStartWithUnderline); |
117 | bool () const; |
118 | void (bool newHideSymbolsStartWithTwoUnderline); |
119 | |
120 | const PStatement &() const; |
121 | void (const PStatement &newCurrentStatement); |
122 | const std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > >& () const; |
123 | void (const std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > &newColors); |
124 | const QString &() const; |
125 | const QList<PCodeSnippet> &() const; |
126 | void (const QList<PCodeSnippet> &newCodeSnippets); |
127 | private: |
128 | void (PStatement scopeStatement, const QString& fileName, |
129 | int line); |
130 | void (PStatement statement, const QString& fileName, int line); |
131 | void (const QString& member); |
132 | void ( |
133 | const QStringList& ownerExpression, |
134 | const QString& memberOperator, |
135 | const QStringList& memberExpression, |
136 | const QString& fileName, |
137 | int line, |
138 | const QSet<QString>& customKeywords); |
139 | void (const QString& preWord); |
140 | void (const QString& keyword); |
141 | bool (const QString& fileName); |
142 | private: |
143 | CodeCompletionListView * ; |
144 | CodeCompletionListModel* ; |
145 | QList<PCodeSnippet> ; //(Code template list) |
146 | //QList<PStatement> mCodeInsStatements; //temporary (user code template) statements created when show code suggestion |
147 | StatementList ; |
148 | StatementList ; |
149 | QSet<QString> ; |
150 | QSet<QString> ; |
151 | QSet<QString> ; |
152 | QString ; |
153 | QString ; |
154 | QMutex ; |
155 | std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > ; |
156 | CodeCompletionListItemDelegate* ; |
157 | |
158 | PCppParser ; |
159 | PStatement ; |
160 | int ; |
161 | bool ; |
162 | bool ; |
163 | bool ; |
164 | bool ; |
165 | bool ; |
166 | bool ; |
167 | bool ; |
168 | bool ; |
169 | bool ; |
170 | |
171 | // QWidget interface |
172 | protected: |
173 | void (QShowEvent *event) override; |
174 | void (QHideEvent *event) override; |
175 | |
176 | // QObject interface |
177 | public: |
178 | bool (QEvent *event) override; |
179 | const QString &() const; |
180 | |
181 | }; |
182 | |
183 | #endif // CODECOMPLETIONPOPUP_H |
184 | |