author | sheepluva |
Thu, 24 Nov 2011 19:15:29 +0100 | |
changeset 6418 | f1a3c3aab5b4 |
parent 6205 | 7764cbe4ddd7 |
child 6616 | f77bb02b669f |
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 |
/** |
6170 | 21 |
* @file |
6168 | 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 |
|
6187 | 28 |
#include <QMap> |
29 |
#include <QString> |
|
6147 | 30 |
#include <QStringList> |
31 |
||
32 |
#include <QEvent> |
|
6187 | 33 |
#include <QKeyEvent> |
34 |
||
6147 | 35 |
#include <QRegExp> |
36 |
||
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
|
37 |
#include "HistoryLineEdit.h" |
6147 | 38 |
|
39 |
/** |
|
6200 | 40 |
* @brief {@link HistoryLineEdit} that features auto-completion with TAB key |
6162 | 41 |
* and clear with ESC key. |
6150
1d98752c1fba
frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents:
6149
diff
changeset
|
42 |
* |
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
|
43 |
* 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
|
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 |
* <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
|
46 |
* 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
|
47 |
* </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
|
48 |
* |
6147 | 49 |
* @author sheepluva |
50 |
* @since 0.9.17 |
|
51 |
*/ |
|
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
|
52 |
class SmartLineEdit : public HistoryLineEdit |
6147 | 53 |
{ |
54 |
Q_OBJECT |
|
55 |
||
56 |
public: |
|
57 |
/** |
|
6161 | 58 |
* @brief Class constructor. |
6150
1d98752c1fba
frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents:
6149
diff
changeset
|
59 |
* @param parent parent QWidget. |
1d98752c1fba
frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents:
6149
diff
changeset
|
60 |
* @param maxHistorySize maximum amount of history entries kept. |
6147 | 61 |
*/ |
6150
1d98752c1fba
frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents:
6149
diff
changeset
|
62 |
SmartLineEdit(QWidget * parent = 0, int maxHistorySize = 64); |
6147 | 63 |
|
64 |
/** |
|
6187 | 65 |
* @brief Class destructor. |
66 |
*/ |
|
67 |
~SmartLineEdit(); |
|
68 |
||
69 |
/** |
|
6161 | 70 |
* @brief Adds commands to the auto-completion feature. |
6147 | 71 |
* @param commands list of commands to be added. |
72 |
*/ |
|
73 |
void addCommands(const QStringList & commands); |
|
74 |
||
75 |
/** |
|
6161 | 76 |
* @brief Adds a single nickname to the auto-completion feature. |
6147 | 77 |
* @param nickname name to be added. |
78 |
*/ |
|
79 |
void addNickname(const QString & nickname); |
|
80 |
||
81 |
/** |
|
6161 | 82 |
* @brief Removes commands from the auto-completion feature. |
6147 | 83 |
* @param commands list of commands to be removed. |
84 |
*/ |
|
85 |
void removeCommands(const QStringList & commands); |
|
86 |
||
87 |
/** |
|
6161 | 88 |
* @brief Removes a single nickname from the auto-completion feature. |
6147 | 89 |
* @param nickname name to be removed. |
90 |
*/ |
|
91 |
void removeNickname(const QString & nickname); |
|
92 |
||
6149 | 93 |
/** |
6161 | 94 |
* @brief Forget all keywords and input history. |
6149 | 95 |
*/ |
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
|
96 |
void reset(); |
6150
1d98752c1fba
frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents:
6149
diff
changeset
|
97 |
|
1d98752c1fba
frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents:
6149
diff
changeset
|
98 |
|
6147 | 99 |
protected: |
100 |
/** |
|
6161 | 101 |
* @brief Overrides method of parent class. |
6147 | 102 |
* Forward pressed TAB to parent class' method (for focus handling etc) |
103 |
* only if line is empty. |
|
6161 | 104 |
* |
6163 | 105 |
* @param event the event. |
6147 | 106 |
* @return returns true if the event was recognized. |
107 |
*/ |
|
108 |
virtual bool event(QEvent * event); |
|
109 |
||
110 |
/** |
|
6161 | 111 |
* @brief Overrides method of parent class. |
6147 | 112 |
* Autocompletes if TAB is reported as pressed key in the key event, |
113 |
* ESC leads to the contents being cleared. |
|
6161 | 114 |
* |
115 |
* Other keys are forwarded to parent method. |
|
116 |
* |
|
6147 | 117 |
* @param event the key event. |
118 |
*/ |
|
119 |
virtual void keyPressEvent(QKeyEvent * event); |
|
120 |
||
121 |
||
122 |
private: |
|
6162 | 123 |
QRegExp m_whitespace; ///< regexp that matches a whitespace |
6147 | 124 |
|
6162 | 125 |
QStringList * m_cmds; ///< list of recognized commands |
126 |
QStringList * m_nicks; ///< list of recognized nicknames |
|
6188
e48280142001
doxygen seems to get confused if a ///< line is followed by a /// line
sheepluva
parents:
6187
diff
changeset
|
127 |
|
e48280142001
doxygen seems to get confused if a ///< line is followed by a /// line
sheepluva
parents:
6187
diff
changeset
|
128 |
/// recognized nicknames, sorted case-insensitive |
6187 | 129 |
QMap<QString, QString> * m_sorted_nicks; |
6147 | 130 |
|
131 |
// these variables contain information about the last replacement |
|
132 |
// they get reset whenever cursor is moved or text is changed |
|
133 |
||
6162 | 134 |
QString m_beforeMatch; ///< the string that was just matched |
135 |
bool m_hasJustMatched; ///< whether this widget just did an auto-completion |
|
136 |
QString m_prefix; ///< prefix of the text replacement this widget just did |
|
137 |
QString m_postfix; ///< postfix of the text replacement this widget just did |
|
6147 | 138 |
|
139 |
/** |
|
6162 | 140 |
* @brief Autocompletes the contents based on the known commands and/or names. |
6147 | 141 |
*/ |
142 |
void autoComplete(); |
|
143 |
||
144 |
||
145 |
private slots: |
|
6149 | 146 |
/** |
6162 | 147 |
* @brief Resets the information about the last match and text replacement. |
6149 | 148 |
*/ |
149 |
void resetAutoCompletionStatus(); |
|
6147 | 150 |
}; |
151 |
||
152 |
||
153 |
||
6153
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6151
diff
changeset
|
154 |
#endif // HEDGEWARS_SMARTLINEEDIT_H |