1 /***************************************************************************
2 * Copyright (C) 2005-2014 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
32 # 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 virtual QSize sizeHint() const;
65 virtual QSize minimumSizeHint() const;
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; }
77 void setMode(Mode mode);
78 void setMinHeight(int numLines);
79 void setMaxHeight(int numLines);
80 void setEmacsMode(bool enable = true);
81 void setScrollBarsEnabled(bool enable = true);
82 void setSpellCheckEnabled(bool enable = true);
83 void setPasteProtectionEnabled(bool enable = true, QWidget *msgBoxParent = 0);
84 void setLineWrapEnabled(bool enable = false);
86 inline void setHistory(QStringList history) { _history = history; }
87 inline void setTempHistory(QHash<int, QString> tempHistory) { _tempHistory = tempHistory; }
88 inline void setIdx(qint32 idx) { _idx = idx; }
91 void textEntered(const QString &text);
95 virtual bool event(QEvent *e);
96 virtual void keyPressEvent(QKeyEvent *event);
97 virtual void resizeEvent(QResizeEvent *event);
100 void on_returnPressed();
101 void on_returnPressed(const QString &text);
102 void on_textChanged();
103 void on_documentHeightChanged(qreal height);
105 bool addToHistory(const QString &text, bool temporary = false);
106 void historyMoveForward();
107 void historyMoveBack();
109 QString convertRichtextToMircCodes();
110 QString convertMircCodesToHtml(const QString &text);
111 bool mircCodesChanged(QTextCursor &cursor, QTextCursor &peekcursor);
114 QStringList _history;
115 QHash<int, QString> _tempHistory;
121 bool _scrollBarsEnabled;
122 bool _pasteProtectionEnabled;
126 qreal _lastDocumentHeight;
128 QMap<QString, QString> _mircColorMap;
131 void showHistoryEntry();
132 void updateScrollBars();
133 void updateSizeHint();