QTfrontend/ui/widget/SmartLineEdit.h
changeset 6616 f77bb02b669f
parent 6205 7764cbe4ddd7
child 6700 e04da46ee43c
equal deleted inserted replaced
6615:65602f1ef0f8 6616:f77bb02b669f
    43  * Notes:
    43  * Notes:
    44  * <ul>
    44  * <ul>
    45  *   <li>A Keyword can either be a command (if first word) or
    45  *   <li>A Keyword can either be a command (if first word) or
    46  *       a nickname (completed regardless of position in text).</li>
    46  *       a nickname (completed regardless of position in text).</li>
    47  * </ul>
    47  * </ul>
    48  * 
    48  *
    49  * @author sheepluva
    49  * @author sheepluva
    50  * @since 0.9.17
    50  * @since 0.9.17
    51  */
    51  */
    52 class SmartLineEdit : public HistoryLineEdit
    52 class SmartLineEdit : public HistoryLineEdit
    53 {
    53 {
    54  Q_OBJECT
    54         Q_OBJECT
    55 
    55 
    56 public:
    56     public:
    57     /**
    57         /**
    58     * @brief Class constructor.
    58         * @brief Class constructor.
    59     * @param parent parent QWidget.
    59         * @param parent parent QWidget.
    60     * @param maxHistorySize maximum amount of history entries kept.
    60         * @param maxHistorySize maximum amount of history entries kept.
    61     */
    61         */
    62     SmartLineEdit(QWidget * parent = 0, int maxHistorySize = 64);
    62         SmartLineEdit(QWidget * parent = 0, int maxHistorySize = 64);
    63 
    63 
    64     /**
    64         /**
    65     * @brief Class destructor.
    65         * @brief Class destructor.
    66     */
    66         */
    67     ~SmartLineEdit();
    67         ~SmartLineEdit();
    68 
    68 
    69     /**
    69         /**
    70      * @brief Adds commands to the auto-completion feature.
    70          * @brief Adds commands to the auto-completion feature.
    71      * @param commands list of commands to be added.
    71          * @param commands list of commands to be added.
    72      */
    72          */
    73     void addCommands(const QStringList & commands);
    73         void addCommands(const QStringList & commands);
    74 
    74 
    75     /**
    75         /**
    76      * @brief Adds a single nickname to the auto-completion feature.
    76          * @brief Adds a single nickname to the auto-completion feature.
    77      * @param nickname name to be added.
    77          * @param nickname name to be added.
    78      */
    78          */
    79     void addNickname(const QString & nickname);
    79         void addNickname(const QString & nickname);
    80 
    80 
    81     /**
    81         /**
    82      * @brief Removes commands from the auto-completion feature.
    82          * @brief Removes commands from the auto-completion feature.
    83      * @param commands list of commands to be removed.
    83          * @param commands list of commands to be removed.
    84      */
    84          */
    85     void removeCommands(const QStringList & commands);
    85         void removeCommands(const QStringList & commands);
    86 
    86 
    87     /**
    87         /**
    88      * @brief Removes a single nickname from the auto-completion feature.
    88          * @brief Removes a single nickname from the auto-completion feature.
    89      * @param nickname name to be removed.
    89          * @param nickname name to be removed.
    90      */
    90          */
    91     void removeNickname(const QString & nickname);
    91         void removeNickname(const QString & nickname);
    92 
    92 
    93     /**
    93         /**
    94      * @brief Forget all keywords and input history.
    94          * @brief Forget all keywords and input history.
    95      */
    95          */
    96     void reset();
    96         void reset();
    97 
    97 
    98 
    98 
    99 protected:
    99     protected:
   100     /**
   100         /**
   101      * @brief Overrides method of parent class.
   101          * @brief Overrides method of parent class.
   102      * Forward pressed TAB to parent class' method (for focus handling etc)
   102          * Forward pressed TAB to parent class' method (for focus handling etc)
   103      * only if line is empty.
   103          * only if line is empty.
   104      * 
   104          *
   105      * @param event the event.
   105          * @param event the event.
   106      * @return returns true if the event was recognized.
   106          * @return returns true if the event was recognized.
   107      */
   107          */
   108     virtual bool event(QEvent * event);
   108         virtual bool event(QEvent * event);
   109 
   109 
   110     /**
   110         /**
   111      * @brief Overrides method of parent class.
   111          * @brief Overrides method of parent class.
   112      * Autocompletes if TAB is reported as pressed key in the key event,
   112          * Autocompletes if TAB is reported as pressed key in the key event,
   113      * ESC leads to the contents being cleared.
   113          * ESC leads to the contents being cleared.
   114      * 
   114          *
   115      * Other keys are forwarded to parent method.
   115          * Other keys are forwarded to parent method.
   116      *
   116          *
   117      * @param event the key event.
   117          * @param event the key event.
   118      */
   118          */
   119     virtual void keyPressEvent(QKeyEvent * event);
   119         virtual void keyPressEvent(QKeyEvent * event);
   120 
   120 
   121 
   121 
   122 private:
   122     private:
   123     QRegExp m_whitespace; ///< regexp that matches a whitespace
   123         QRegExp m_whitespace; ///< regexp that matches a whitespace
   124 
   124 
   125     QStringList * m_cmds;  ///< list of recognized commands
   125         QStringList * m_cmds;  ///< list of recognized commands
   126     QStringList * m_nicks; ///< list of recognized nicknames
   126         QStringList * m_nicks; ///< list of recognized nicknames
   127 
   127 
   128     /// recognized nicknames, sorted case-insensitive
   128         /// recognized nicknames, sorted case-insensitive
   129     QMap<QString, QString> * m_sorted_nicks;
   129         QMap<QString, QString> * m_sorted_nicks;
   130 
   130 
   131     // these variables contain information about the last replacement
   131         // these variables contain information about the last replacement
   132     // they get reset whenever cursor is moved or text is changed
   132         // they get reset whenever cursor is moved or text is changed
   133 
   133 
   134     QString m_beforeMatch; ///< the string that was just matched
   134         QString m_beforeMatch; ///< the string that was just matched
   135     bool m_hasJustMatched; ///< whether this widget just did an auto-completion
   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
   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
   137         QString m_postfix; ///< postfix of the text replacement this widget just did
   138 
   138 
   139     /**
   139         /**
   140      * @brief Autocompletes the contents based on the known commands and/or names.
   140          * @brief Autocompletes the contents based on the known commands and/or names.
   141      */
   141          */
   142     void autoComplete();
   142         void autoComplete();
   143 
   143 
   144 
   144 
   145 private slots:
   145     private slots:
   146     /**
   146         /**
   147      * @brief Resets the information about the last match and text replacement.
   147          * @brief Resets the information about the last match and text replacement.
   148      */
   148          */
   149     void resetAutoCompletionStatus();
   149         void resetAutoCompletionStatus();
   150 };
   150 };
   151 
   151 
   152 
   152 
   153 
   153 
   154 #endif // HEDGEWARS_SMARTLINEEDIT_H
   154 #endif // HEDGEWARS_SMARTLINEEDIT_H