Communi  3.7.0
A cross-platform IRC framework written with Qt
irccompleter.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2008-2020 The Communi Project
3
4 You may use this file under the terms of BSD license as follows:
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8 * Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 * Neither the name of the copyright holder nor the names of its
14 contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
28
29#ifndef IRCCOMPLETER_H
30#define IRCCOMPLETER_H
31
32#include <IrcGlobal>
33#include <QtCore/qobject.h>
34#include <QtCore/qstring.h>
35#include <QtCore/qmetatype.h>
36
37IRC_BEGIN_NAMESPACE
38
39class IrcBuffer;
41class IrcCompleterPrivate;
42
43class IRC_UTIL_EXPORT IrcCompleter : public QObject
44{
45 Q_OBJECT
46 Q_PROPERTY(QString suffix READ suffix WRITE setSuffix NOTIFY suffixChanged)
47 Q_PROPERTY(IrcBuffer* buffer READ buffer WRITE setBuffer NOTIFY bufferChanged)
48 Q_PROPERTY(IrcCommandParser* parser READ parser WRITE setParser NOTIFY parserChanged)
49 Q_ENUMS(Direction)
50
51public:
52 explicit IrcCompleter(QObject* parent = nullptr);
53 ~IrcCompleter() override;
54
55 enum Direction {
56 Forward,
57 Backward
58 };
59
60 QString suffix() const;
61 IrcBuffer* buffer() const;
62 IrcCommandParser* parser() const;
63
64public Q_SLOTS:
65 void setSuffix(const QString& suffix);
66 void setBuffer(IrcBuffer* buffer);
67 void setParser(IrcCommandParser* parser);
68
69 void complete(const QString& text, int cursor, Direction direction = Forward);
70 void reset();
71
72Q_SIGNALS:
73 void suffixChanged(const QString& suffix);
74 void bufferChanged(IrcBuffer* buffer);
75 void parserChanged(IrcCommandParser* parser);
76
77 void completed(const QString& text, int cursor);
78
79private:
80 QScopedPointer<IrcCompleterPrivate> d_ptr;
81 Q_DECLARE_PRIVATE(IrcCompleter)
82 Q_DISABLE_COPY(IrcCompleter)
83};
84
85IRC_END_NAMESPACE
86
87Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcCompleter*))
88Q_DECLARE_METATYPE(IRC_PREPEND_NAMESPACE(IrcCompleter::Direction))
89
90#endif // IRCCOMPLETER_H
Keeps track of buffer status.
Definition: ircbuffer.h:50
Parses commands from user input.
Definition: irccommandparser.h:43
Provides command and name completion.
Definition: irccompleter.h:44
void completed(const QString &text, int cursor)