-
Notifications
You must be signed in to change notification settings - Fork 8
/
HistoryLineEdit.H
123 lines (102 loc) · 3.02 KB
/
HistoryLineEdit.H
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2012-2015 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#pragma once
#include <QLineEdit>
/**
* \brief Line edit providing a history of entered text
*/
class HistoryLineEdit : public QLineEdit
{
Q_OBJECT
public:
explicit HistoryLineEdit(QWidget *parent = 0);
/**
* \brief Number of available lines
*/
int lineCount() const { return lines.size(); }
/**
* \brief Stored history
*/
QStringList history() const { return lines; }
/**
* \brief Overwrite the line history
*/
void setHistory(const QStringList& history);
/**
* \brief Sets the completer used on a per-word completion
*
* Unlike setCompleter(), this suggests completion at every entered word
*
* If \c completer is null it will remove the current completer
*/
void setWordCompleter(QCompleter* completer);
/**
* \brief Sets a prefix that is ignored by the word completer
*/
void setWordCompleterPrefix(const QString& prefix);
/**
* \brief Sets the minimum number of characters required to display the word completer
*/
void setWordCompleterMinChars(int min_chars);
/**
* \brief Sets the maximum number of suggestions that the completer should show.
*
* If more than this many suggestions are found the completer isn't shown
*/
void setWordCompleterMaxSuggestions(int max);
public slots:
/**
* \brief Executes the current line
*/
void execute();
signals:
/**
* \brief Emitted when some text is executed
*/
void lineExecuted(QString);
protected:
void keyPressEvent(QKeyEvent *) Q_DECL_OVERRIDE;
void wheelEvent(QWheelEvent *) Q_DECL_OVERRIDE;
void previous_line();
void next_line();
/**
* \brief Current word being edited (used to fire the completer)
*/
QString current_word() const;
private slots:
/**
* \brief Autocompletes the current word
*/
void autocomplete(const QString& completion);
private:
/**
* \brief Returns the index of the character starting the currently edited word
*/
int word_start() const;
int current_line;
QStringList lines;
QString unfinished;
QCompleter* completer;
QString completion_prefix;
int completion_minchars;
int completion_max;
};