1 /*************************************************************************** 2 * Copyright (C) 2005-2020 by the Quassel Project * 3 * devel@quassel-irc.org * 4 * * 5 * This program is free software; you can redistribute it and/or modify * 6 * it under the terms of the GNU General Public License as published by * 7 * the Free Software Foundation; either version 2 of the License, or * 8 * (at your option) version 3. * 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 * 17 * Free Software Foundation, Inc., * 18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 19 ***************************************************************************/ 20 21 #pragma once 22 23 #include "uisupport-export.h" 24 25 #include <QMap> 26 #include <QPointer> 27 #include <QString> 28 29 #include "types.h" 30 31 class MultiLineEdit; 32 class IrcUser; 33 class Network; 34 35 class UISUPPORT_EXPORT TabCompleter : public QObject 36 { 37 Q_OBJECT 38 39 public: 40 enum Type 41 { 42 UserTab = 0x01, 43 ChannelTab = 0x02 44 }; 45 46 explicit TabCompleter(MultiLineEdit* inputLine_); 47 48 void reset(); 49 void complete(); 50 51 bool eventFilter(QObject* obj, QEvent* event) override; 52 53 public slots: 54 void onTabCompletionKey(); 55 56 private: 57 struct CompletionKey 58 { CompletionKeyCompletionKey59 inline CompletionKey(const QString& n) { contents = n; } 60 bool operator<(const CompletionKey& other) const; 61 QString contents; 62 }; 63 64 QPointer<MultiLineEdit> _lineEdit; 65 bool _enabled; 66 QString _nickSuffix; 67 68 static const Network* _currentNetwork; 69 static BufferId _currentBufferId; 70 static QString _currentBufferName; 71 static Type _completionType; 72 73 QMap<CompletionKey, QString> _completionMap; 74 // QStringList completionTemplates; 75 76 QMap<CompletionKey, QString>::Iterator _nextCompletion; 77 int _lastCompletionLength; 78 79 void buildCompletionList(); 80 }; 81