1 /***************************************************************************
2 * Copyright (C) 2005-2016 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 ***************************************************************************/
21 #ifndef MULTILINEEDIT_H_
22 #define MULTILINEEDIT_H_
28 # include <KDE/KTextEdit>
29 # define MultiLineEditParent KTextEdit
30 #elif defined HAVE_KF5
31 # include <KTextWidgets/KTextEdit>
32 # define MultiLineEditParent KTextEdit
35 # define MultiLineEditParent QTextEdit
38 class MultiLineEdit : public MultiLineEditParent
48 MultiLineEdit(QWidget *parent = 0);
51 void setCustomFont(const QFont &); // should be used instead setFont(), so we can set our size correctly
53 // Compatibility methods with the rest of the classes which still expect this to be a QLineEdit
54 inline QString text() const { return toPlainText(); }
55 inline QString html() const { return toHtml(); }
56 inline int cursorPosition() const { return textCursor().position(); }
57 inline void insert(const QString &newText) { insertPlainText(newText); }
58 inline void backspace() { keyPressEvent(new QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier)); }
59 inline bool hasSelectedText() const { return textCursor().hasSelection(); }
61 inline bool isSingleLine() const { return _singleLine; }
62 inline bool pasteProtectionEnabled() const { return _pasteProtectionEnabled; }
64 QSize sizeHint() const override;
65 QSize minimumSizeHint() const override;
67 inline QString mircColorFromRGB(QString rgbColor) const { return _mircColorMap.key(rgbColor); }
68 inline QString rgbColorFromMirc(QString mircColor) const { return _mircColorMap[mircColor]; }
69 inline QMap<QString, QString> mircColorMap() const { return _mircColorMap; }
71 inline QStringList history() const { return _history; }
72 inline QHash<int, QString> tempHistory() const { return _tempHistory; }
73 inline qint32 idx() const { return _idx; }
74 inline bool emacsMode() const { return _emacsMode; }
76 void addCompletionSpace();
77 #if defined HAVE_KF5 || defined HAVE_KDE4
78 void createHighlighter() override;
82 void setMode(Mode mode);
83 void setMinHeight(int numLines);
84 void setMaxHeight(int numLines);
85 void setEmacsMode(bool enable = true);
86 void setScrollBarsEnabled(bool enable = true);
87 void setSpellCheckEnabled(bool enable = true);
88 void setPasteProtectionEnabled(bool enable = true, QWidget *msgBoxParent = 0);
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;
105 void on_returnPressed();
106 void on_returnPressed(QString text);
107 void on_textChanged();
108 void on_documentHeightChanged(qreal height);
110 bool addToHistory(const QString &text, bool temporary = false);
111 void historyMoveForward();
112 void historyMoveBack();
114 QString convertRichtextToMircCodes();
115 QString convertMircCodesToHtml(const QString &text);
116 bool mircCodesChanged(QTextCursor &cursor, QTextCursor &peekcursor);
119 QStringList _history;
120 QHash<int, QString> _tempHistory;
126 bool _scrollBarsEnabled;
127 bool _pasteProtectionEnabled;
129 int _completionSpace;
132 qreal _lastDocumentHeight;
134 QMap<QString, QString> _mircColorMap;
137 void showHistoryEntry();
138 void updateScrollBars();
139 void updateSizeHint();