1 /*
2     SPDX-License-Identifier: GPL-2.0-or-later
3 
4     SPDX-FileCopyrightText: 2002 Dario Abatianni <eisfuchs@tigress.com>
5 */
6 
7 #ifndef IRCINPUT_H
8 #define IRCINPUT_H
9 
10 #include <KTextEdit>
11 
12 class KCompletionBox;
13 
14 /**
15  * The line input widget with chat enhanced functions
16  */
17 class IRCInput : public KTextEdit
18 {
19     Q_OBJECT
20 
21     public:
22         explicit IRCInput(QWidget* parent);
23         ~IRCInput() override;
24 
25         void setCompletionMode(char mode);
26         char getCompletionMode() const;
27         void setOldCursorPosition(int pos);
28         int getOldCursorPosition() const;
lastCompletion()29         QString lastCompletion() const { return m_lastCompletion; }
30         void doInlineAutoreplace();
31 
32         QSize sizeHint() const override;
33         QSize minimumSizeHint() const override;
34 
35         bool event(QEvent* e) override;
36 
37         void createHighlighter() override;
38 
39     Q_SIGNALS:
40         void nickCompletion();
41         void endCompletion();                     // tell channel that completion phase is over
42         void textPasted(const QString& text);
43         void submit();
44         void envelopeCommand();
45 
46     public Q_SLOTS:
47         void paste(bool useSelection);
48         void showCompletionList(const QStringList& nicks);
49         void setText(const QString& text, bool preserveContents = false);
50         void setLastCompletion(const QString& completion);
setOverwriteMode(bool)51         virtual void setOverwriteMode(bool) { }
52         virtual void updateAppearance();
53 
54     protected:
55         bool eventFilter(QObject *object,QEvent *event) override;
56 
57         void insertFromMimeData(const QMimeData *source) override;
58         void keyPressEvent(QKeyEvent* e) override;
59         void wheelEvent(QWheelEvent* e) override;
60         void showEvent(QShowEvent* e) override;
61         void hideEvent(QHideEvent* e) override;
62         void resizeEvent(QResizeEvent* e) override;
63 
64     private:
65         void addHistory(const QString& text);
66         bool checkPaste(QString& text);
67 
68     private Q_SLOTS:
69         void getHistory(bool up);
70         void insertCompletion(const QString& nick);
71         void disableSpellChecking();
72         void setSpellChecking(bool set);
73 
74         void maybeResize();
75 
76     private:
77         QStringList historyList;
78         int lineNum;
79         int oldPos;
80         char completionMode;
81         KCompletionBox* completionBox;
82         QString m_lastCompletion;
83         bool m_multiRow;
84         int m_qtBoxPadding; //see comment in constructor
85 
86         QTimer* m_disableSpellCheckTimer;
87 
88         Q_DISABLE_COPY(IRCInput)
89 };
90 
91 #endif
92