QGIS API Documentation 3.99.0-Master (26c88405ac0)
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 "ui_qgsrichtexteditorbase.h"
35
36#include "qgis_gui.h"
37#include "qgis_sip.h"
38
39#include <QPointer>
40
41class QImage;
42class QComboBox;
43class QgsColorButton;
45
46/*
47 * Originally ported from https://github.com/Anchakor/MRichTextEditor, courtesy of Hobrasoft.
48 */
49
60class GUI_EXPORT QgsRichTextEditor : public QWidget, protected Ui::QgsRichTextEditorBase
61{
62 Q_OBJECT
63 public:
64
70 enum class Mode
71 {
72 QTextDocument,
74 PlainText,
75 };
76 Q_ENUM( Mode )
77
78
81 QgsRichTextEditor( QWidget *parent = nullptr );
82
90 Mode mode() const { return mMode; }
91
99 void setMode( Mode mode );
100
106 QString toPlainText() const;
107
113 QString toHtml() const;
114
120 QTextEdit *textEdit() { return mTextEdit; }
121
125 QTextDocument *document() { return mTextEdit->document(); }
126
132 QTextCursor textCursor() const { return mTextEdit->textCursor(); }
133
139 void setTextCursor( const QTextCursor &cursor ) { mTextEdit->setTextCursor( cursor ); }
140
141 public slots:
142
148 void setText( const QString &text );
149
153 void clearSource();
154
155 signals:
156
163
164 protected:
165 void focusInEvent( QFocusEvent *event ) override;
166
167 private slots:
168 void textRemoveFormat();
169 void textRemoveAllFormat();
170 void textBold();
171 void textUnderline();
172 void textStrikeout();
173 void textItalic();
174 void textSize( const QString &p );
175 void textLink( bool checked );
176 void textStyle( int index );
177 void textFgColor();
178 void textBgColor();
179 void listBullet( bool checked );
180 void listOrdered( bool checked );
181 void slotCurrentCharFormatChanged( const QTextCharFormat &format );
182 void slotCursorPositionChanged();
183 void slotClipboardDataChanged();
184 void increaseIndentation();
185 void decreaseIndentation();
186 void insertImage();
187 void editSource( bool enabled );
188
189 private:
190 void mergeFormatOnWordOrSelection( const QTextCharFormat &format );
191 void fontChanged( const QFont &f );
192 void fgColorChanged( const QColor &c );
193 void bgColorChanged( const QColor &c );
194 void list( bool checked, QTextListFormat::Style style );
195 void indent( int delta );
196
198
199 int mFontSizeH1 = 18;
200 int mFontSizeH2 = 16;
201 int mFontSizeH3 = 14;
202 int mFontSizeH4 = 12;
203
204 enum ParagraphItems
205 {
206 ParagraphStandard = 0,
207 ParagraphHeading1,
208 ParagraphHeading2,
209 ParagraphHeading3,
210 ParagraphHeading4,
211 ParagraphMonospace
212 };
213
214 QComboBox *mParagraphStyleCombo = nullptr;
215 QComboBox *mFontSizeCombo = nullptr;
216
217 QgsColorButton *mForeColorButton = nullptr;
218 QgsColorButton *mBackColorButton = nullptr;
219 QgsCodeEditorHTML *mSourceEdit = nullptr;
220
221 QPointer<QTextList> mLastBlockList;
222 QString mMonospaceFontFamily;
223};
224
225
226#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.
QgsRichTextEditor(QWidget *parent=nullptr)
Constructor for QgsRichTextEditor, with the specified parent widget.
Mode mode() const
Returns the widget's mode, which defines which formatting options are exposed in the widget.
@ QTextDocument
Default mode, exposes the Qt supported HTML/CSS subset.
void setTextCursor(const QTextCursor &cursor)
Sets the current text cursor.
void textChanged()
Emitted when the text contents are changed.
void focusInEvent(QFocusEvent *event) override
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