PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/quassel-0.7.3/src/uisupport/multilineedit.h

#
C Header | 137 lines | 90 code | 26 blank | 21 comment | 0 complexity | 55bab454595b94e76dc32c367a9ed227 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0
  1. /***************************************************************************
  2. * Copyright (C) 2005-2010 by the Quassel Project *
  3. * devel@quassel-irc.org *
  4. * *
  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. *
  9. * *
  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. *
  14. * *
  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. ***************************************************************************/
  20. #ifndef MULTILINEEDIT_H_
  21. #define MULTILINEEDIT_H_
  22. #include <QKeyEvent>
  23. #include <QHash>
  24. #ifdef HAVE_KDE
  25. # include <KDE/KTextEdit>
  26. # define MultiLineEditParent KTextEdit
  27. #else
  28. # include <QTextEdit>
  29. # define MultiLineEditParent QTextEdit
  30. #endif
  31. class QKeyEvent;
  32. class TabCompleter;
  33. class MultiLineEdit : public MultiLineEditParent {
  34. Q_OBJECT
  35. public:
  36. enum Mode {
  37. SingleLine,
  38. MultiLine
  39. };
  40. MultiLineEdit(QWidget *parent = 0);
  41. ~MultiLineEdit();
  42. void setCustomFont(const QFont &); // should be used instead setFont(), so we can set our size correctly
  43. // Compatibility methods with the rest of the classes which still expect this to be a QLineEdit
  44. inline QString text() const { return toPlainText(); }
  45. inline QString html() const { return toHtml(); }
  46. inline int cursorPosition() const { return textCursor().position(); }
  47. inline void insert(const QString &newText) { insertPlainText(newText); }
  48. inline void backspace() { keyPressEvent(new QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier)); }
  49. inline bool hasSelectedText() const { return textCursor().hasSelection(); }
  50. inline bool isSingleLine() const { return _singleLine; }
  51. inline bool pasteProtectionEnabled() const { return _pasteProtectionEnabled; }
  52. virtual QSize sizeHint() const;
  53. virtual QSize minimumSizeHint() const;
  54. inline QString mircColorFromRGB(QString rgbColor) const { return _mircColorMap.key(rgbColor); }
  55. inline QString rgbColorFromMirc(QString mircColor) const { return _mircColorMap[mircColor]; }
  56. inline QMap<QString, QString> mircColorMap() const { return _mircColorMap; }
  57. inline QStringList history() const { return _history; }
  58. inline QHash<int, QString> tempHistory() const { return _tempHistory; }
  59. inline qint32 idx() const { return _idx; }
  60. inline bool emacsMode() const { return _emacsMode; }
  61. public slots:
  62. void setMode(Mode mode);
  63. void setMinHeight(int numLines);
  64. void setMaxHeight(int numLines);
  65. void setEmacsMode(bool enable = true);
  66. void setScrollBarsEnabled(bool enable = true);
  67. void setSpellCheckEnabled(bool enable = true);
  68. void setPasteProtectionEnabled(bool enable = true, QWidget *msgBoxParent = 0);
  69. // Note: Enabling wrap will make isSingleLine() not work correctly, so only use this if minHeight() > 1!
  70. void setWordWrapEnabled(bool enable = true);
  71. inline void setHistory(QStringList history) { _history = history; }
  72. inline void setTempHistory(QHash<int, QString> tempHistory) { _tempHistory = tempHistory; }
  73. inline void setIdx(qint32 idx) { _idx = idx; }
  74. signals:
  75. void textEntered(const QString &text);
  76. void noTextEntered();
  77. protected:
  78. virtual bool event(QEvent *e);
  79. virtual void keyPressEvent(QKeyEvent * event);
  80. virtual void resizeEvent(QResizeEvent *event);
  81. private slots:
  82. void on_returnPressed();
  83. void on_returnPressed(const QString &text);
  84. void on_textChanged();
  85. void on_documentHeightChanged(qreal height);
  86. bool addToHistory(const QString &text, bool temporary = false);
  87. void historyMoveForward();
  88. void historyMoveBack();
  89. QString convertRichtextToMircCodes();
  90. QString convertMircCodesToHtml(const QString &text);
  91. bool mircCodesChanged(QTextCursor &cursor, QTextCursor &peekcursor);
  92. private:
  93. QStringList _history;
  94. QHash<int, QString> _tempHistory;
  95. qint32 _idx;
  96. Mode _mode;
  97. bool _singleLine;
  98. int _minHeight;
  99. int _maxHeight;
  100. bool _scrollBarsEnabled;
  101. bool _pasteProtectionEnabled;
  102. bool _emacsMode;
  103. QSize _sizeHint;
  104. qreal _lastDocumentHeight;
  105. QMap<QString, QString> _mircColorMap;
  106. void reset();
  107. void showHistoryEntry();
  108. void updateScrollBars();
  109. void updateSizeHint();
  110. };
  111. #endif