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_
29 # include <KDE/KTextEdit>
35 class MultiLineEdit : public
50 MultiLineEdit(QWidget *parent = 0);
53 void setCustomFont(const QFont &); // should be used instead setFont(), so we can set our size correctly
55 // Compatibility methods with the rest of the classes which still expect this to be a QLineEdit
56 inline QString text() const { return toPlainText(); }
57 inline QString html() const { return toHtml(); }
58 inline int cursorPosition() const { return textCursor().position(); }
59 inline void insert(const QString &newText) { insertPlainText(newText); }
60 inline void backspace() { keyPressEvent(new QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier)); }
61 inline bool hasSelectedText() const { return textCursor().hasSelection(); }
63 inline bool isSingleLine() const { return _singleLine; }
64 inline bool pasteProtectionEnabled() const { return _pasteProtectionEnabled; }
66 virtual QSize sizeHint() const;
67 virtual QSize minimumSizeHint() const;
69 inline QString mircColorFromRGB(QString rgbColor) const { return _mircColorMap.key(rgbColor); }
70 inline QString rgbColorFromMirc(QString mircColor) const { return _mircColorMap[mircColor]; }
71 inline QMap<QString, QString> mircColorMap() const { return _mircColorMap; }
73 inline QStringList history() const { return _history; }
74 inline QHash<int, QString> tempHistory() const { return _tempHistory; }
75 inline qint32 idx() const { return _idx; }
78 void setMode(Mode mode);
79 void setMinHeight(int numLines);
80 void setMaxHeight(int numLines);
81 void setScrollBarsEnabled(bool enable = true);
82 void setSpellCheckEnabled(bool enable = true);
83 void setPasteProtectionEnabled(bool enable = true, QWidget *msgBoxParent = 0);
85 // Note: Enabling wrap will make isSingleLine() not work correctly, so only use this if minHeight() > 1!
86 void setWordWrapEnabled(bool enable = true);
88 inline void setHistory(QStringList history) { _history = history; }
89 inline void setTempHistory(QHash<int, QString> tempHistory) { _tempHistory = tempHistory; }
90 inline void setIdx(qint32 idx) { _idx = idx; }
93 void textEntered(const QString &text);
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;
126 qreal _lastDocumentHeight;
128 QMap<QString, QString> _mircColorMap;
131 void showHistoryEntry();
132 void updateScrollBars();
133 void updateSizeHint();