author | sheepluva |
Wed, 19 Oct 2011 16:10:18 +0200 | |
changeset 6151 | 9fd5b70acb1a |
parent 6150 | 1d98752c1fba |
child 6153 | 3881126e06e8 |
permissions | -rw-r--r-- |
6147 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
3 |
* Copyright (c) 2006-2007 Igor Ulyanov <iulyanov@gmail.com> |
|
4 |
* Copyright (c) 2007-2011 Andrey Korotaev <unC0Rr@gmail.com> |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or modify |
|
7 |
* it under the terms of the GNU General Public License as published by |
|
8 |
* the Free Software Foundation; version 2 of the License |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
18 |
*/ |
|
19 |
||
6151
9fd5b70acb1a
give the room name edit box a history of previous room. however I hate that box from the bottom of my heart, it shall dieeeee... later...
sheepluva
parents:
6150
diff
changeset
|
20 |
#ifndef HEDGEWARS_SMARTLINEEDIT |
9fd5b70acb1a
give the room name edit box a history of previous room. however I hate that box from the bottom of my heart, it shall dieeeee... later...
sheepluva
parents:
6150
diff
changeset
|
21 |
#define HEDGEWARS_SMARTLINEEDIT |
6147 | 22 |
|
23 |
#include <QStringList> |
|
24 |
||
25 |
#include <QEvent> |
|
26 |
#include <QRegExp> |
|
27 |
||
6151
9fd5b70acb1a
give the room name edit box a history of previous room. however I hate that box from the bottom of my heart, it shall dieeeee... later...
sheepluva
parents:
6150
diff
changeset
|
28 |
#include "HistoryLineEdit.h" |
6147 | 29 |
|
30 |
/** |
|
6151
9fd5b70acb1a
give the room name edit box a history of previous room. however I hate that box from the bottom of my heart, it shall dieeeee... later...
sheepluva
parents:
6150
diff
changeset
|
31 |
* A {@link HistoryLineEdit} that additionally features: |
6150
1d98752c1fba
frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents:
6149
diff
changeset
|
32 |
* + Auto-completion for word under cursor when the TAB key is pressed. |
1d98752c1fba
frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents:
6149
diff
changeset
|
33 |
* + ESC key clears text. |
1d98752c1fba
frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents:
6149
diff
changeset
|
34 |
* |
1d98752c1fba
frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents:
6149
diff
changeset
|
35 |
* Note: |
1d98752c1fba
frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents:
6149
diff
changeset
|
36 |
* * A Keyword can either be a command (if first word) or |
1d98752c1fba
frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents:
6149
diff
changeset
|
37 |
* a nickname (completed regardless of position in text). |
6151
9fd5b70acb1a
give the room name edit box a history of previous room. however I hate that box from the bottom of my heart, it shall dieeeee... later...
sheepluva
parents:
6150
diff
changeset
|
38 |
* * Public methods for accessing keywords are thread-safe. |
6147 | 39 |
* @author sheepluva |
40 |
* @since 0.9.17 |
|
41 |
*/ |
|
6151
9fd5b70acb1a
give the room name edit box a history of previous room. however I hate that box from the bottom of my heart, it shall dieeeee... later...
sheepluva
parents:
6150
diff
changeset
|
42 |
class SmartLineEdit : public HistoryLineEdit |
6147 | 43 |
{ |
44 |
Q_OBJECT |
|
45 |
||
46 |
public: |
|
47 |
/** |
|
48 |
* Class constructor. |
|
6150
1d98752c1fba
frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents:
6149
diff
changeset
|
49 |
* @param parent parent QWidget. |
1d98752c1fba
frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents:
6149
diff
changeset
|
50 |
* @param maxHistorySize maximum amount of history entries kept. |
6147 | 51 |
*/ |
6150
1d98752c1fba
frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents:
6149
diff
changeset
|
52 |
SmartLineEdit(QWidget * parent = 0, int maxHistorySize = 64); |
6147 | 53 |
|
54 |
/** |
|
55 |
* Adds commands to the auto-completion feature. |
|
56 |
* @param commands list of commands to be added. |
|
57 |
*/ |
|
58 |
void addCommands(const QStringList & commands); |
|
59 |
||
60 |
/** |
|
61 |
* Adds a single nickname to the auto-completion feature. |
|
62 |
* @param nickname name to be added. |
|
63 |
*/ |
|
64 |
void addNickname(const QString & nickname); |
|
65 |
||
66 |
/** |
|
67 |
* Removes commands from the auto-completion feature. |
|
68 |
* @param commands list of commands to be removed. |
|
69 |
*/ |
|
70 |
void removeCommands(const QStringList & commands); |
|
71 |
||
72 |
/** |
|
73 |
* Removes a single nickname from the auto-completion feature. |
|
74 |
* @param nickname name to be removed. |
|
75 |
*/ |
|
76 |
void removeNickname(const QString & nickname); |
|
77 |
||
6149 | 78 |
/** |
79 |
* Forget all keywords and input history. |
|
80 |
*/ |
|
6151
9fd5b70acb1a
give the room name edit box a history of previous room. however I hate that box from the bottom of my heart, it shall dieeeee... later...
sheepluva
parents:
6150
diff
changeset
|
81 |
void reset(); |
6150
1d98752c1fba
frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents:
6149
diff
changeset
|
82 |
|
1d98752c1fba
frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents:
6149
diff
changeset
|
83 |
|
6147 | 84 |
protected: |
85 |
/** |
|
86 |
* Overrides method of parent class. |
|
87 |
* Forward pressed TAB to parent class' method (for focus handling etc) |
|
88 |
* only if line is empty. |
|
89 |
* @param event the key event. |
|
90 |
* @return returns true if the event was recognized. |
|
91 |
*/ |
|
92 |
virtual bool event(QEvent * event); |
|
93 |
||
94 |
/** |
|
95 |
* Overrides method of parent class. |
|
96 |
* Autocompletes if TAB is reported as pressed key in the key event, |
|
97 |
* ESC leads to the contents being cleared. |
|
6151
9fd5b70acb1a
give the room name edit box a history of previous room. however I hate that box from the bottom of my heart, it shall dieeeee... later...
sheepluva
parents:
6150
diff
changeset
|
98 |
* otherwise keys are forwarded to parent method. |
6147 | 99 |
* @param event the key event. |
100 |
*/ |
|
101 |
virtual void keyPressEvent(QKeyEvent * event); |
|
102 |
||
103 |
||
104 |
private: |
|
105 |
QRegExp m_whitespace; // regexp that matches a whitespace |
|
106 |
||
107 |
QStringList * m_cmds; // list of recognized commands |
|
108 |
QStringList * m_nicks; // list of recognized nicknames |
|
109 |
||
110 |
// these variables contain information about the last replacement |
|
111 |
// they get reset whenever cursor is moved or text is changed |
|
112 |
||
113 |
QString m_beforeMatch; // the string that was just matched |
|
114 |
bool m_hasJustMatched; // whether this widget just did an auto-completion |
|
115 |
QString m_prefix; // prefix of the text replacement this widget just did |
|
116 |
QString m_postfix; // postfix of the text replacement this widget just did |
|
117 |
||
6150
1d98752c1fba
frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents:
6149
diff
changeset
|
118 |
QMutex m_keywordMutex; // make keyword QStringList action thread-safe |
6147 | 119 |
|
120 |
/** |
|
6149 | 121 |
* Autocompletes the contents based on the known commands and/or names. |
6147 | 122 |
*/ |
123 |
void autoComplete(); |
|
124 |
||
125 |
||
126 |
private slots: |
|
6149 | 127 |
/** |
128 |
* Resets the information about the last match and text replacement. |
|
129 |
*/ |
|
130 |
void resetAutoCompletionStatus(); |
|
6147 | 131 |
}; |
132 |
||
133 |
||
134 |
||
6151
9fd5b70acb1a
give the room name edit box a history of previous room. however I hate that box from the bottom of my heart, it shall dieeeee... later...
sheepluva
parents:
6150
diff
changeset
|
135 |
#endif // HEDGEWARS_SMARTLINEEDIT |