1 /***************************************************************************
2 * Copyright (C) 2005-2010 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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 {
47 MultiLineEdit(QWidget *parent = 0);
50 void setCustomFont(const QFont &); // should be used instead setFont(), so we can set our size correctly
52 // Compatibility methods with the rest of the classes which still expect this to be a QLineEdit
53 inline QString text() const { return toPlainText(); }
54 inline QString html() const { return toHtml(); }
55 inline int cursorPosition() const { return textCursor().position(); }
56 inline void insert(const QString &newText) { insertPlainText(newText); }
57 inline void backspace() { keyPressEvent(new QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier)); }
58 inline bool hasSelectedText() const { return textCursor().hasSelection(); }
60 inline bool isSingleLine() const { return _singleLine; }
61 inline bool pasteProtectionEnabled() const { return _pasteProtectionEnabled; }
63 virtual QSize sizeHint() const;
64 virtual QSize minimumSizeHint() const;
66 inline QString mircColorFromRGB(QString rgbColor) const { return _mircColorMap.key(rgbColor); }
67 inline QString rgbColorFromMirc(QString mircColor) const { return _mircColorMap[mircColor]; }
68 inline QMap<QString, QString> mircColorMap() const { return _mircColorMap; }
70 inline QStringList history() const { return _history; }
71 inline QHash<int, QString> tempHistory() const { return _tempHistory; }
72 inline qint32 idx() const { return _idx; }
73 inline bool emacsMode() const { return _emacsMode; }
76 void setMode(Mode mode);
77 void setMinHeight(int numLines);
78 void setMaxHeight(int numLines);
79 void setEmacsMode(bool enable = true);
80 void setScrollBarsEnabled(bool enable = true);
81 void setSpellCheckEnabled(bool enable = true);
82 void setPasteProtectionEnabled(bool enable = true, QWidget *msgBoxParent = 0);
84 // Note: Enabling wrap will make isSingleLine() not work correctly, so only use this if minHeight() > 1!
85 void setWordWrapEnabled(bool enable = true);
87 inline void setHistory(QStringList history) { _history = history; }
88 inline void setTempHistory(QHash<int, QString> tempHistory) { _tempHistory = tempHistory; }
89 inline void setIdx(qint32 idx) { _idx = idx; }
92 void textEntered(const QString &text);
96 virtual bool event(QEvent *e);
97 virtual void keyPressEvent(QKeyEvent * event);
98 virtual void resizeEvent(QResizeEvent *event);
101 void on_returnPressed();
102 void on_returnPressed(const QString &text);
103 void on_textChanged();
104 void on_documentHeightChanged(qreal height);
106 bool addToHistory(const QString &text, bool temporary = false);
107 void historyMoveForward();
108 void historyMoveBack();
110 QString convertRichtextToMircCodes();
111 QString convertMircCodesToHtml(const QString &text);
112 bool mircCodesChanged(QTextCursor &cursor, QTextCursor &peekcursor);
115 QStringList _history;
116 QHash<int, QString> _tempHistory;
122 bool _scrollBarsEnabled;
123 bool _pasteProtectionEnabled;
127 qreal _lastDocumentHeight;
129 QMap<QString, QString> _mircColorMap;
132 void showHistoryEntry();
133 void updateScrollBars();
134 void updateSizeHint();