| 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 CODECOMPLETIONLISTVIEW_H | 
|---|
| 18 | #define CODECOMPLETIONLISTVIEW_H | 
|---|
| 19 |  | 
|---|
| 20 | #include <QListView> | 
|---|
| 21 | #include <QKeyEvent> | 
|---|
| 22 | #include <QStyledItemDelegate> | 
|---|
| 23 | #include "../parser/parserutils.h" | 
|---|
| 24 | using KeyPressedCallback = std::function<bool (QKeyEvent *)>; | 
|---|
| 25 | using InputMethodCallback = std::function<bool (QInputMethodEvent*)>; | 
|---|
| 26 |  | 
|---|
| 27 | class CodeCompletionListView: public QListView { | 
|---|
| 28 | Q_OBJECT | 
|---|
| 29 | public: | 
|---|
| 30 | explicit CodeCompletionListView(QWidget *parent = nullptr); | 
|---|
| 31 |  | 
|---|
| 32 | // QWidget interface | 
|---|
| 33 | const KeyPressedCallback &keypressedCallback() const; | 
|---|
| 34 | void setKeypressedCallback(const KeyPressedCallback &newKeypressedCallback); | 
|---|
| 35 |  | 
|---|
| 36 | const InputMethodCallback &inputMethodCallback() const; | 
|---|
| 37 | void setInputMethodCallback(const InputMethodCallback &newInputMethodCallback); | 
|---|
| 38 |  | 
|---|
| 39 | protected: | 
|---|
| 40 | void keyPressEvent(QKeyEvent *event) override; | 
|---|
| 41 | private: | 
|---|
| 42 | KeyPressedCallback mKeypressedCallback; | 
|---|
| 43 |  | 
|---|
| 44 | // QWidget interface | 
|---|
| 45 | protected: | 
|---|
| 46 | void focusInEvent(QFocusEvent *event) override; | 
|---|
| 47 |  | 
|---|
| 48 | // QWidget interface | 
|---|
| 49 | protected: | 
|---|
| 50 | void mouseDoubleClickEvent(QMouseEvent *event) override; | 
|---|
| 51 | }; | 
|---|
| 52 |  | 
|---|
| 53 |  | 
|---|
| 54 | #endif // CODECOMPLETIONLISTVIEW_H | 
|---|
| 55 |  | 
|---|