File indexing completed on 2024-04-28 05:38:09

0001 /*
0002 ** Copyright (C) 2013 Jiří Procházka (Hobrasoft)
0003 ** Contact: http://www.hobrasoft.cz/
0004 **
0005 ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
0006 ** Contact: http://www.qt-project.org/legal
0007 **
0008 ** $QT_BEGIN_LICENSE:LGPL$
0009 ** GNU Lesser General Public License Usage
0010 ** This file is under the terms of the GNU Lesser General Public License
0011 ** version 2.1 as published by the Free Software Foundation and appearing
0012 ** in the file LICENSE.LGPL included in the packaging of this file.
0013 ** Please review the following information to ensure the
0014 ** GNU Lesser General Public License version 2.1 requirements
0015 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
0016 **
0017 ** In addition, as a special exception, Digia gives you certain additional
0018 ** rights.  These rights are described in the Digia Qt LGPL Exception
0019 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
0020 **
0021 ** $QT_END_LICENSE$
0022 */
0023 
0024 #ifndef _MRICHTEXTEDIT_H_
0025 #define _MRICHTEXTEDIT_H_
0026 
0027 #include "rwidgets_global.h"
0028 #include <QPointer>
0029 #include <QWidget>
0030 #include <QTextListFormat>
0031 #include <QTextList>
0032 
0033 namespace Ui
0034 {
0035 class MRichTextEdit;
0036 }
0037 /**
0038  * @Brief A simple rich-text editor
0039  */
0040 class RWIDGET_EXPORT MRichTextEdit : public QWidget
0041 {
0042     Q_OBJECT
0043 public:
0044     MRichTextEdit(QWidget* parent= 0);
0045     ~MRichTextEdit();
0046 
0047     QString toPlainText() const;
0048     QString toHtml() const;
0049     QTextDocument* document();
0050     QTextCursor textCursor() const;
0051     void setTextCursor(const QTextCursor& cursor);
0052 
0053 public slots:
0054     void setText(const QString& text);
0055 
0056 protected slots:
0057     void setPlainText(const QString& text);
0058     void setHtml(const QString& text);
0059     void textRemoveFormat();
0060     void textRemoveAllFormat();
0061     void textBold();
0062     void textUnderline();
0063     void textStrikeout();
0064     void textItalic();
0065     void textSize(const QString& p);
0066     void textLink(bool checked);
0067     void textStyle(int index);
0068     void textFgColor();
0069     void textBgColor();
0070     void listBullet(bool checked);
0071     void listOrdered(bool checked);
0072     void slotCurrentCharFormatChanged(const QTextCharFormat& format);
0073     void slotCursorPositionChanged();
0074     void slotClipboardDataChanged();
0075     void increaseIndentation();
0076     void decreaseIndentation();
0077     void insertImage();
0078     void textSource();
0079 
0080 protected:
0081     void mergeFormatOnWordOrSelection(const QTextCharFormat& format);
0082     void fontChanged(const QFont& f);
0083     void fgColorChanged(const QColor& c);
0084     void bgColorChanged(const QColor& c);
0085     void list(bool checked, QTextListFormat::Style style);
0086     void indent(int delta);
0087     void focusInEvent(QFocusEvent* event);
0088 
0089     QStringList m_paragraphItems;
0090     int m_fontsize_h1;
0091     int m_fontsize_h2;
0092     int m_fontsize_h3;
0093     int m_fontsize_h4;
0094 
0095     enum ParagraphItems
0096     {
0097         ParagraphStandard= 0,
0098         ParagraphHeading1,
0099         ParagraphHeading2,
0100         ParagraphHeading3,
0101         ParagraphHeading4,
0102         ParagraphMonospace
0103     };
0104 
0105     QPointer<QTextList> m_lastBlockList;
0106     std::unique_ptr<Ui::MRichTextEdit> m_ui;
0107 };
0108 
0109 #endif