QGIS API Documentation 4.3.0-Master (0de80482b60)
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 QToolBar;
44class QgsColorButton;
46
47/*
48 * Originally ported from https://github.com/Anchakor/MRichTextEditor, courtesy of Hobrasoft.
49 */
50
61class GUI_EXPORT QgsRichTextEditor : public QWidget, private Ui::QgsRichTextEditorBase
62{
63 Q_OBJECT
64 public:
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
130 QToolBar *toolBar() { return mToolBar; }
131
135 QTextDocument *document() { return mTextEdit->document(); }
136
142 QTextCursor textCursor() const { return mTextEdit->textCursor(); }
143
149 void setTextCursor( const QTextCursor &cursor ) { mTextEdit->setTextCursor( cursor ); }
150
151 public slots:
152
158 void setText( const QString &text );
159
163 void clearSource();
164
165 signals:
166
173
174 protected:
175 void focusInEvent( QFocusEvent *event ) override;
176
177 private slots:
178 void textRemoveFormat();
179 void textRemoveAllFormat();
180 void textBold();
181 void textUnderline();
182 void textStrikeout();
183 void textItalic();
184 void textSize( const QString &p );
185 void textLink( bool checked );
186 void textStyle( int index );
187 void textFgColor();
188 void textBgColor();
189 void listBullet( bool checked );
190 void listOrdered( bool checked );
191 void slotCurrentCharFormatChanged( const QTextCharFormat &format );
192 void slotCursorPositionChanged();
193 void slotClipboardDataChanged();
194 void increaseIndentation();
195 void decreaseIndentation();
196 void insertImage();
197 void insertImageFromUrl();
198 void editSource( bool enabled );
199
200 private:
201 void mergeFormatOnWordOrSelection( const QTextCharFormat &format );
202 void fontChanged( const QFont &f );
203 void fgColorChanged( const QColor &c );
204 void bgColorChanged( const QColor &c );
205 void list( bool checked, QTextListFormat::Style style );
206 void indent( int delta );
207
209
210 int mFontSizeH1 = 18;
211 int mFontSizeH2 = 16;
212 int mFontSizeH3 = 14;
213 int mFontSizeH4 = 12;
214
215 enum ParagraphItems
216 {
217 ParagraphStandard = 0,
218 ParagraphHeading1,
219 ParagraphHeading2,
220 ParagraphHeading3,
221 ParagraphHeading4,
222 ParagraphMonospace
223 };
224
225 QComboBox *mParagraphStyleCombo = nullptr;
226 QComboBox *mFontSizeCombo = nullptr;
227
228 QgsColorButton *mForeColorButton = nullptr;
229 QgsColorButton *mBackColorButton = nullptr;
230 QgsCodeEditorHTML *mSourceEdit = nullptr;
231
232 QPointer<QTextList> mLastBlockList;
233 QString mMonospaceFontFamily;
234};
235
236
237#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.
QToolBar * toolBar()
Returns the widget's toolbar.
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