QTfrontend/ui/widget/SmartLineEdit.h
changeset 6161 98486efeb0b7
parent 6160 863d3edf5690
child 6162 437116977d43
equal deleted inserted replaced
6160:863d3edf5690 6161:98486efeb0b7
    45 {
    45 {
    46  Q_OBJECT
    46  Q_OBJECT
    47 
    47 
    48 public:
    48 public:
    49     /**
    49     /**
    50     * Class constructor.
    50     * @brief Class constructor.
    51     * @param parent parent QWidget.
    51     * @param parent parent QWidget.
    52     * @param maxHistorySize maximum amount of history entries kept.
    52     * @param maxHistorySize maximum amount of history entries kept.
    53     */
    53     */
    54     SmartLineEdit(QWidget * parent = 0, int maxHistorySize = 64);
    54     SmartLineEdit(QWidget * parent = 0, int maxHistorySize = 64);
    55 
    55 
    56     /**
    56     /**
    57      * Adds commands to the auto-completion feature.
    57      * @brief Adds commands to the auto-completion feature.
    58      * @param commands list of commands to be added.
    58      * @param commands list of commands to be added.
    59      */
    59      */
    60     void addCommands(const QStringList & commands);
    60     void addCommands(const QStringList & commands);
    61 
    61 
    62     /**
    62     /**
    63      * Adds a single nickname to the auto-completion feature.
    63      * @brief Adds a single nickname to the auto-completion feature.
    64      * @param nickname name to be added.
    64      * @param nickname name to be added.
    65      */
    65      */
    66     void addNickname(const QString & nickname);
    66     void addNickname(const QString & nickname);
    67 
    67 
    68     /**
    68     /**
    69      * Removes commands from the auto-completion feature.
    69      * @brief Removes commands from the auto-completion feature.
    70      * @param commands list of commands to be removed.
    70      * @param commands list of commands to be removed.
    71      */
    71      */
    72     void removeCommands(const QStringList & commands);
    72     void removeCommands(const QStringList & commands);
    73 
    73 
    74     /**
    74     /**
    75      * Removes a single nickname from the auto-completion feature.
    75      * @brief Removes a single nickname from the auto-completion feature.
    76      * @param nickname name to be removed.
    76      * @param nickname name to be removed.
    77      */
    77      */
    78     void removeNickname(const QString & nickname);
    78     void removeNickname(const QString & nickname);
    79 
    79 
    80     /**
    80     /**
    81      * Forget all keywords and input history.
    81      * @brief Forget all keywords and input history.
    82      */
    82      */
    83     void reset();
    83     void reset();
    84 
    84 
    85 
    85 
    86 protected:
    86 protected:
    87     /**
    87     /**
    88      * Overrides method of parent class.
    88      * @brief Overrides method of parent class.
    89      * Forward pressed TAB to parent class' method (for focus handling etc)
    89      * Forward pressed TAB to parent class' method (for focus handling etc)
    90      * only if line is empty.
    90      * only if line is empty.
       
    91      * 
    91      * @param event the key event.
    92      * @param event the key event.
    92      * @return returns true if the event was recognized.
    93      * @return returns true if the event was recognized.
    93      */
    94      */
    94     virtual bool event(QEvent * event);
    95     virtual bool event(QEvent * event);
    95 
    96 
    96     /**
    97     /**
    97      * Overrides method of parent class.
    98      * @brief Overrides method of parent class.
    98      * Autocompletes if TAB is reported as pressed key in the key event,
    99      * Autocompletes if TAB is reported as pressed key in the key event,
    99      * ESC leads to the contents being cleared.
   100      * ESC leads to the contents being cleared.
   100      * otherwise keys are forwarded to parent method.
   101      * 
       
   102      * Other keys are forwarded to parent method.
       
   103      *
   101      * @param event the key event.
   104      * @param event the key event.
   102      */
   105      */
   103     virtual void keyPressEvent(QKeyEvent * event);
   106     virtual void keyPressEvent(QKeyEvent * event);
   104 
   107 
   105 
   108 
   106 private:
   109 private:
   107     QRegExp m_whitespace; // regexp that matches a whitespace
   110     QRegExp m_whitespace; /// regexp that matches a whitespace
   108 
   111 
   109     QStringList * m_cmds;  // list of recognized commands
   112     QStringList * m_cmds;  /// list of recognized commands
   110     QStringList * m_nicks; // list of recognized nicknames
   113     QStringList * m_nicks; /// list of recognized nicknames
   111 
   114 
   112     // these variables contain information about the last replacement
   115     // these variables contain information about the last replacement
   113     // they get reset whenever cursor is moved or text is changed
   116     // they get reset whenever cursor is moved or text is changed
   114 
   117 
   115     QString m_beforeMatch; // the string that was just matched
   118     QString m_beforeMatch; /// the string that was just matched
   116     bool m_hasJustMatched; // whether this widget just did an auto-completion
   119     bool m_hasJustMatched; /// whether this widget just did an auto-completion
   117     QString m_prefix; // prefix of the text replacement this widget just did
   120     QString m_prefix; /// prefix of the text replacement this widget just did
   118     QString m_postfix; // postfix of the text replacement this widget just did
   121     QString m_postfix; /// postfix of the text replacement this widget just did
   119 
   122 
   120     QMutex m_keywordMutex; // make keyword QStringList action thread-safe
   123     QMutex m_keywordMutex; /// make keyword QStringList action thread-safe
   121 
   124 
   122     /**
   125     /**
   123      * Autocompletes the contents based on the known commands and/or names.
   126      * Autocompletes the contents based on the known commands and/or names.
   124      */
   127      */
   125     void autoComplete();
   128     void autoComplete();