author | sheepluva |
Fri, 21 Oct 2011 17:55:32 +0200 | |
changeset 6168 | 6f301dac12ff |
parent 6163 | fcb709d55413 |
child 6170 | 2b1748161278 |
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 |
||
6168 | 20 |
/** |
21 |
* @file SmartLineEdit.h |
|
22 |
* @brief SmartLineEdit class definition |
|
23 |
*/ |
|
24 |
||
6153
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6151
diff
changeset
|
25 |
#ifndef HEDGEWARS_SMARTLINEEDIT_H |
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6151
diff
changeset
|
26 |
#define HEDGEWARS_SMARTLINEEDIT_H |
6147 | 27 |
|
28 |
#include <QStringList> |
|
29 |
||
30 |
#include <QEvent> |
|
31 |
#include <QRegExp> |
|
32 |
||
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
|
33 |
#include "HistoryLineEdit.h" |
6147 | 34 |
|
35 |
/** |
|
6160
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6153
diff
changeset
|
36 |
* @brief A {@link HistoryLineEdit} that features auto-completion with TAB key |
6162 | 37 |
* and clear with ESC key. |
6150
1d98752c1fba
frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents:
6149
diff
changeset
|
38 |
* |
6160
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6153
diff
changeset
|
39 |
* Notes: |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6153
diff
changeset
|
40 |
* <ul> |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6153
diff
changeset
|
41 |
* <li>A Keyword can either be a command (if first word) or |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6153
diff
changeset
|
42 |
* a nickname (completed regardless of position in text).</li> |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6153
diff
changeset
|
43 |
* <li>Public methods for accessing keywords are <b>thread-safe.</b></li> |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6153
diff
changeset
|
44 |
* </ul> |
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6153
diff
changeset
|
45 |
* |
6147 | 46 |
* @author sheepluva |
47 |
* @since 0.9.17 |
|
48 |
*/ |
|
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
|
49 |
class SmartLineEdit : public HistoryLineEdit |
6147 | 50 |
{ |
51 |
Q_OBJECT |
|
52 |
||
53 |
public: |
|
54 |
/** |
|
6161 | 55 |
* @brief Class constructor. |
6150
1d98752c1fba
frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents:
6149
diff
changeset
|
56 |
* @param parent parent QWidget. |
1d98752c1fba
frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents:
6149
diff
changeset
|
57 |
* @param maxHistorySize maximum amount of history entries kept. |
6147 | 58 |
*/ |
6150
1d98752c1fba
frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents:
6149
diff
changeset
|
59 |
SmartLineEdit(QWidget * parent = 0, int maxHistorySize = 64); |
6147 | 60 |
|
61 |
/** |
|
6161 | 62 |
* @brief Adds commands to the auto-completion feature. |
6147 | 63 |
* @param commands list of commands to be added. |
64 |
*/ |
|
65 |
void addCommands(const QStringList & commands); |
|
66 |
||
67 |
/** |
|
6161 | 68 |
* @brief Adds a single nickname to the auto-completion feature. |
6147 | 69 |
* @param nickname name to be added. |
70 |
*/ |
|
71 |
void addNickname(const QString & nickname); |
|
72 |
||
73 |
/** |
|
6161 | 74 |
* @brief Removes commands from the auto-completion feature. |
6147 | 75 |
* @param commands list of commands to be removed. |
76 |
*/ |
|
77 |
void removeCommands(const QStringList & commands); |
|
78 |
||
79 |
/** |
|
6161 | 80 |
* @brief Removes a single nickname from the auto-completion feature. |
6147 | 81 |
* @param nickname name to be removed. |
82 |
*/ |
|
83 |
void removeNickname(const QString & nickname); |
|
84 |
||
6149 | 85 |
/** |
6161 | 86 |
* @brief Forget all keywords and input history. |
6149 | 87 |
*/ |
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
|
88 |
void reset(); |
6150
1d98752c1fba
frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents:
6149
diff
changeset
|
89 |
|
1d98752c1fba
frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents:
6149
diff
changeset
|
90 |
|
6147 | 91 |
protected: |
92 |
/** |
|
6161 | 93 |
* @brief Overrides method of parent class. |
6147 | 94 |
* Forward pressed TAB to parent class' method (for focus handling etc) |
95 |
* only if line is empty. |
|
6161 | 96 |
* |
6163 | 97 |
* @param event the event. |
6147 | 98 |
* @return returns true if the event was recognized. |
99 |
*/ |
|
100 |
virtual bool event(QEvent * event); |
|
101 |
||
102 |
/** |
|
6161 | 103 |
* @brief Overrides method of parent class. |
6147 | 104 |
* Autocompletes if TAB is reported as pressed key in the key event, |
105 |
* ESC leads to the contents being cleared. |
|
6161 | 106 |
* |
107 |
* Other keys are forwarded to parent method. |
|
108 |
* |
|
6147 | 109 |
* @param event the key event. |
110 |
*/ |
|
111 |
virtual void keyPressEvent(QKeyEvent * event); |
|
112 |
||
113 |
||
114 |
private: |
|
6162 | 115 |
QRegExp m_whitespace; ///< regexp that matches a whitespace |
6147 | 116 |
|
6162 | 117 |
QStringList * m_cmds; ///< list of recognized commands |
118 |
QStringList * m_nicks; ///< list of recognized nicknames |
|
6147 | 119 |
|
120 |
// these variables contain information about the last replacement |
|
121 |
// they get reset whenever cursor is moved or text is changed |
|
122 |
||
6162 | 123 |
QString m_beforeMatch; ///< the string that was just matched |
124 |
bool m_hasJustMatched; ///< whether this widget just did an auto-completion |
|
125 |
QString m_prefix; ///< prefix of the text replacement this widget just did |
|
126 |
QString m_postfix; ///< postfix of the text replacement this widget just did |
|
6147 | 127 |
|
6162 | 128 |
QMutex m_keywordMutex; ///< make keyword QStringList action thread-safe |
6147 | 129 |
|
130 |
/** |
|
6162 | 131 |
* @brief Autocompletes the contents based on the known commands and/or names. |
6147 | 132 |
*/ |
133 |
void autoComplete(); |
|
134 |
||
135 |
||
136 |
private slots: |
|
6149 | 137 |
/** |
6162 | 138 |
* @brief Resets the information about the last match and text replacement. |
6149 | 139 |
*/ |
140 |
void resetAutoCompletionStatus(); |
|
6147 | 141 |
}; |
142 |
||
143 |
||
144 |
||
6153
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6151
diff
changeset
|
145 |
#endif // HEDGEWARS_SMARTLINEEDIT_H |