QGIS API Documentation 3.41.0-Master (57ec4277f5e)
Loading...
Searching...
No Matches
qgsrichtexteditor.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** Copyright (C) 2013 Jiří Procházka (Hobrasoft)
4** Contact: http://www.hobrasoft.cz/
5**
6** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
7** Contact: http://www.qt-project.org/legal
8**
9** This library is free software; you can redistribute it and/or
10** modify it under the terms of the GNU Lesser General Public
11** License as published by the Free Software Foundation; either
12** version 2.1 of the License, or (at your option) any later version.
13**
14** $QT_BEGIN_LICENSE:LGPL$
15** GNU Lesser General Public License Usage
16** This file is under the terms of the GNU Lesser General Public License
17** version 2.1 as published by the Free Software Foundation and appearing
18** in the file LICENSE.LGPL included in the packaging of this file.
19** Please review the following information to ensure the
20** GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Digia gives you certain additional
24** rights. These rights are described in the Digia Qt LGPL Exception
25** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
26**
27** $QT_END_LICENSE$
28**
29****************************************************************************/
30
31#ifndef QGSRICHTEXTEDITOR_H
32#define QGSRICHTEXTEDITOR_H
33
34#include "qgis_gui.h"
35#include "qgis_sip.h"
36#include "ui_qgsrichtexteditorbase.h"
37#include <QPointer>
38
39class QImage;
40class QComboBox;
41class QgsColorButton;
43
44/*
45 * Originally ported from https://github.com/Anchakor/MRichTextEditor, courtesy of Hobrasoft.
46 */
47
58class GUI_EXPORT QgsRichTextEditor : public QWidget, protected Ui::QgsRichTextEditorBase
59{
60 Q_OBJECT
61 public:
67 enum class Mode
68 {
69 QTextDocument,
71 PlainText,
72 };
73 Q_ENUM( Mode )
74
75
78 QgsRichTextEditor( QWidget *parent = nullptr );
79
87 Mode mode() const { return mMode; }
88
96 void setMode( Mode mode );
97
103 QString toPlainText() const;
104
110 QString toHtml() const;
111
117 QTextEdit *textEdit() { return mTextEdit; }
118
122 QTextDocument *document() { return mTextEdit->document(); }
123
129 QTextCursor textCursor() const { return mTextEdit->textCursor(); }
130
136 void setTextCursor( const QTextCursor &cursor ) { mTextEdit->setTextCursor( cursor ); }
137
138 public slots:
139
145 void setText( const QString &text );
146
150 void clearSource();
151
152 signals:
153
160
161 protected:
162 void focusInEvent( QFocusEvent *event ) override;
163
164 private slots:
165 void setPlainText( const QString &text ) { mTextEdit->setPlainText( text ); }
166 void setHtml( const QString &text ) { mTextEdit->setHtml( text ); }
167 void textRemoveFormat();
168 void textRemoveAllFormat();
169 void textBold();
170 void textUnderline();
171 void textStrikeout();
172 void textItalic();
173 void textSize( const QString &p );
174 void textLink( bool checked );
175 void textStyle( int index );
176 void textFgColor();
177 void textBgColor();
178 void listBullet( bool checked );
179 void listOrdered( bool checked );
180 void slotCurrentCharFormatChanged( const QTextCharFormat &format );
181 void slotCursorPositionChanged();
182 void slotClipboardDataChanged();
183 void increaseIndentation();
184 void decreaseIndentation();
185 void insertImage();
186 void editSource( bool enabled );
187
188 private:
189 void mergeFormatOnWordOrSelection( const QTextCharFormat &format );
190 void fontChanged( const QFont &f );
191 void fgColorChanged( const QColor &c );
192 void bgColorChanged( const QColor &c );
193 void list( bool checked, QTextListFormat::Style style );
194 void indent( int delta );
195
196 Mode mMode = Mode::QTextDocument;
197
198 int mFontSizeH1 = 18;
199 int mFontSizeH2 = 16;
200 int mFontSizeH3 = 14;
201 int mFontSizeH4 = 12;
202
203 enum ParagraphItems
204 {
205 ParagraphStandard = 0,
206 ParagraphHeading1,
207 ParagraphHeading2,
208 ParagraphHeading3,
209 ParagraphHeading4,
210 ParagraphMonospace
211 };
212
213 QComboBox *mParagraphStyleCombo = nullptr;
214 QComboBox *mFontSizeCombo = nullptr;
215
216 QgsColorButton *mForeColorButton = nullptr;
217 QgsColorButton *mBackColorButton = nullptr;
218 QgsCodeEditorHTML *mSourceEdit = nullptr;
219
220 QPointer<QTextList> mLastBlockList;
221 QString mMonospaceFontFamily;
222};
223
224
225#endif // QGSRICHTEXTEDITOR_H
A HTML editor based on QScintilla2.
A cross platform button subclass for selecting colors.
A widget for editing rich text documents, with support for user controlled formatting of text and ins...
QTextCursor textCursor() const
Returns a reference to the text cursor.
Mode mode() const
Returns the widget's mode, which defines which formatting options are exposed in the widget.
void setTextCursor(const QTextCursor &cursor)
Sets the current text cursor.
void textChanged()
Emitted when the text contents are changed.
QTextEdit * textEdit()
Returns the widget's QTextEditor control.
QTextDocument * document()
Returns a reference to the QTextDocument shown in the widget.
Handles rendering text using rich formatting options, including drop shadows, buffers and background ...
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c