36 class QLineEdit; |
36 class QLineEdit; |
37 |
37 |
38 /** |
38 /** |
39 * @brief <code>QLineEdit</code> that features a history of previous contents, |
39 * @brief <code>QLineEdit</code> that features a history of previous contents, |
40 * re-selectable using the arrow keys. |
40 * re-selectable using the arrow keys. |
41 * |
41 * |
42 * @author sheepluva |
42 * @author sheepluva |
43 * @since 0.9.17 |
43 * @since 0.9.17 |
44 */ |
44 */ |
45 class HistoryLineEdit : public QLineEdit |
45 class HistoryLineEdit : public QLineEdit |
46 { |
46 { |
47 Q_OBJECT |
47 Q_OBJECT |
48 |
48 |
49 public: |
49 public: |
50 /** |
50 /** |
51 * @brief Class constructor. |
51 * @brief Class constructor. |
52 * @param parent parent QWidget. |
52 * @param parent parent QWidget. |
53 * @param maxHistorySize maximum amount of history entries kept. |
53 * @param maxHistorySize maximum amount of history entries kept. |
54 */ |
54 */ |
55 HistoryLineEdit(QWidget * parent = 0, int maxHistorySize = 64); |
55 HistoryLineEdit(QWidget * parent = 0, int maxHistorySize = 64); |
56 |
56 |
57 /** |
57 /** |
58 * @brief Class destructor. |
58 * @brief Class destructor. |
59 */ |
59 */ |
60 ~HistoryLineEdit(); |
60 ~HistoryLineEdit(); |
61 |
61 |
62 /** |
62 /** |
63 * @brief Appends current text to history (if not only whitespaces); |
63 * @brief Appends current text to history (if not only whitespaces); |
64 */ |
64 */ |
65 void rememberCurrentText(); |
65 void rememberCurrentText(); |
66 |
66 |
67 /** |
67 /** |
68 * @brief Forget all history. |
68 * @brief Forget all history. |
69 */ |
69 */ |
70 void reset(); |
70 void reset(); |
71 |
71 |
72 |
72 |
73 public slots: |
73 public slots: |
74 /** |
74 /** |
75 * @brief Clears the contents. |
75 * @brief Clears the contents. |
76 */ |
76 */ |
77 void clear(); |
77 void clear(); |
78 |
78 |
79 |
79 |
80 protected: |
80 protected: |
81 /** |
81 /** |
82 * @brief Overrides method of parent class. |
82 * @brief Overrides method of parent class. |
83 * Arrow keys are used for navigating the history. |
83 * Arrow keys are used for navigating the history. |
84 * |
84 * |
85 * All other keys are forwarded to the parent's method. |
85 * All other keys are forwarded to the parent's method. |
86 * |
86 * |
87 * @param event the key event. |
87 * @param event the key event. |
88 */ |
88 */ |
89 virtual void keyPressEvent(QKeyEvent * event); |
89 virtual void keyPressEvent(QKeyEvent * event); |
90 |
90 |
91 |
91 |
92 private: |
92 private: |
93 int m_maxHistorySize; ///< the maximum allowed size for the history |
93 int m_maxHistorySize; ///< the maximum allowed size for the history |
94 int m_curHistEntryIdx; ///< the index of the displayed used entry |
94 int m_curHistEntryIdx; ///< the index of the displayed used entry |
95 |
95 |
96 QStringList * m_history; ///< history of previous inputs |
96 QStringList * m_history; ///< history of previous inputs |
97 |
97 |
98 /** |
98 /** |
99 * @brief Navigates content history in the desired direction. |
99 * @brief Navigates content history in the desired direction. |
100 * |
100 * |
101 * Note: no wrap-around on purpose (so that holding down/up will get the |
101 * Note: no wrap-around on purpose (so that holding down/up will get the |
102 * the user to the respective end rather than into an endless cycle :P) |
102 * the user to the respective end rather than into an endless cycle :P) |
103 * |
103 * |
104 * @param isGoingUp true: next older entry, false: next more recent entry. |
104 * @param isGoingUp true: next older entry, false: next more recent entry. |
105 */ |
105 */ |
106 void navigateHistory(bool isGoingUp); |
106 void navigateHistory(bool isGoingUp); |
107 }; |
107 }; |
108 |
108 |
109 |
109 |
110 |
110 |
111 #endif // HEDGEWARS_HISTORYLINEEDIT |
111 #endif // HEDGEWARS_HISTORYLINEEDIT |