1 /***************************************************************************
2 * Copyright (C) 2005-2018 by the Quassel Project *
3 * devel@quassel-irc.org *
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. *
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. *
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 ***************************************************************************/
23 #include "uisupport-export.h"
29 # include <KTextWidgets/KTextEdit>
30 # define MultiLineEditParent KTextEdit
33 # define MultiLineEditParent QTextEdit
36 #if defined HAVE_SONNET && !defined HAVE_KDE
37 # include <QContextMenuEvent>
38 # include <Sonnet/Highlighter>
39 # include <Sonnet/SpellCheckDecorator>
42 class UISUPPORT_EXPORT MultiLineEdit : public MultiLineEditParent
52 MultiLineEdit(QWidget *parent = nullptr);
55 void setCustomFont(const QFont &); // should be used instead setFont(), so we can set our size correctly
57 // Compatibility methods with the rest of the classes which still expect this to be a QLineEdit
58 inline QString text() const { return toPlainText(); }
59 inline QString html() const { return toHtml(); }
60 inline int cursorPosition() const { return textCursor().position(); }
61 inline void insert(const QString &newText) { insertPlainText(newText); }
62 inline void backspace() { keyPressEvent(new QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier)); }
63 inline bool hasSelectedText() const { return textCursor().hasSelection(); }
65 inline bool isSingleLine() const { return _singleLine; }
66 inline bool pasteProtectionEnabled() const { return _pasteProtectionEnabled; }
68 QSize sizeHint() const override;
69 QSize minimumSizeHint() const override;
71 inline QString mircColorFromRGB(QString rgbColor) const { return _mircColorMap.key(rgbColor); }
72 inline QString rgbColorFromMirc(QString mircColor) const { return _mircColorMap[mircColor]; }
73 inline QMap<QString, QString> mircColorMap() const { return _mircColorMap; }
75 inline QStringList history() const { return _history; }
76 inline QHash<int, QString> tempHistory() const { return _tempHistory; }
77 inline qint32 idx() const { return _idx; }
78 inline bool emacsMode() const { return _emacsMode; }
80 void addCompletionSpace();
83 void setMode(Mode mode);
84 void setMinHeight(int numLines);
85 void setMaxHeight(int numLines);
86 void setEmacsMode(bool enable = true);
87 void setScrollBarsEnabled(bool enable = true);
88 void setPasteProtectionEnabled(bool enable = true, QWidget *msgBoxParent = nullptr);
89 void setLineWrapEnabled(bool enable = false);
91 inline void setHistory(QStringList history) { _history = history; }
92 inline void setTempHistory(QHash<int, QString> tempHistory) { _tempHistory = tempHistory; }
93 inline void setIdx(qint32 idx) { _idx = idx; }
96 void textEntered(const QString &text);
100 bool event(QEvent *e) override;
101 void keyPressEvent(QKeyEvent *event) override;
102 void resizeEvent(QResizeEvent *event) override;
104 #if defined HAVE_SONNET && !defined HAVE_KDE
105 void contextMenuEvent(QContextMenuEvent *event) override;
109 void on_returnPressed();
110 void on_returnPressed(QString text);
111 void on_textChanged();
112 void on_documentHeightChanged(qreal height);
114 bool addToHistory(const QString &text, bool temporary = false);
115 void historyMoveForward();
116 void historyMoveBack();
118 QString convertRichtextToMircCodes();
119 QString convertMircCodesToHtml(const QString &text);
120 bool mircCodesChanged(QTextCursor &cursor, QTextCursor &peekcursor);
124 void showHistoryEntry();
125 void updateScrollBars();
126 void updateSizeHint();
129 QStringList _history;
130 QHash<int, QString> _tempHistory;
136 bool _scrollBarsEnabled;
137 bool _pasteProtectionEnabled;
139 int _completionSpace;
142 qreal _lastDocumentHeight;
144 QMap<QString, QString> _mircColorMap;
146 #if defined HAVE_SONNET && !defined HAVE_KDE
147 // This member function is provided by KTextEdit
148 Sonnet::Highlighter *highlighter() const;
151 void setSpellCheckEnabled(bool enabled);
154 Sonnet::SpellCheckDecorator *_spellCheckDecorator{nullptr};