/* Copyright 2003 Rikard Björklind, Arsenij Vodjanov, Mikael Gransell This file is part of dc-qt. dc-qt is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. dc-qt is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with dc-qt; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __CHATEDIT_H__ #define __CHATEDIT_H__ #include #include #include class ChatEdit : public QLineEdit { Q_OBJECT public: ChatEdit( QWidget *parent=0, const char *name = 0 ); virtual ~ChatEdit(); public slots: void addCompletion( const QString &str ); void removeCompletion( const QString &str ); void moveCompletionToFront( const QString &str ); void clearCompletions(); signals: void messageStr(const QString &); protected: virtual void keyPressEvent ( QKeyEvent * e ); virtual void focusOutEvent ( QFocusEvent * e ); // // Completion strings are stored in alphanum-ordered table of vectors, // where strings that start with the same character are stored in the same vector. // // CIndexMap is used to map first character of a string to an index in the table. // // When a match is found, the matching completion is moved to index 0 in the string vector. // // Ex: // If we have 3 completions that start with letter 'a': "abba", "alpha", "arduis", // and have a QString "ardent", the following applies: // // completions[ cindex[ str.at(0) ] ][1] == QString("alpha") // typedef QValueVector StrVec; typedef QValueVector StrStrVec; typedef QMap CIndexMap; StrStrVec completions; CIndexMap cindex; unsigned int lastindex; // current number of top-level entries (different by first-character) // our tab counter int tabs; }; #endif