modernize: Use nullptr
[quassel.git] / src / uisupport / tabcompleter.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 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 <QPointer>
26 #include <QString>
27 #include <QMap>
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         UserTab = 0x01,
42         ChannelTab = 0x02
43     };
44
45     explicit TabCompleter(MultiLineEdit *inputLine_);
46
47     void reset();
48     void complete();
49
50     virtual bool eventFilter(QObject *obj, QEvent *event);
51
52 public slots:
53     void onTabCompletionKey();
54
55 private:
56
57     struct CompletionKey {
58         inline CompletionKey(const QString &n) { contents = n; }
59         bool operator<(const CompletionKey &other) const;
60         QString contents;
61     };
62
63     QPointer<MultiLineEdit> _lineEdit;
64     bool _enabled;
65     QString _nickSuffix;
66
67     static const Network *_currentNetwork;
68     static BufferId _currentBufferId;
69     static QString _currentBufferName;
70     static Type _completionType;
71
72     QMap<CompletionKey, QString> _completionMap;
73     // QStringList completionTemplates;
74
75     QMap<CompletionKey, QString>::Iterator _nextCompletion;
76     int _lastCompletionLength;
77
78     void buildCompletionList();
79 };