QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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 
39 class QImage;
40 class QComboBox;
41 class QgsColorButton;
42 class QgsCodeEditorHTML;
43 
44 /*
45  * Originally ported from https://github.com/Anchakor/MRichTextEditor, courtesy of Hobrasoft.
46  */
47 
58 class GUI_EXPORT QgsRichTextEditor : public QWidget, protected Ui::QgsRichTextEditorBase
59 {
60  Q_OBJECT
61  public:
62 
66  QgsRichTextEditor( QWidget *parent = nullptr );
67 
73  QString toPlainText() const;
74 
80  QString toHtml() const;
81 
85  QTextDocument *document() { return mTextEdit->document(); }
86 
92  QTextCursor textCursor() const { return mTextEdit->textCursor(); }
93 
99  void setTextCursor( const QTextCursor &cursor ) { mTextEdit->setTextCursor( cursor ); }
100 
101  public slots:
102 
108  void setText( const QString &text );
109 
113  void clearSource();
114 
115  protected:
116  void focusInEvent( QFocusEvent *event ) override;
117 
118  private slots:
119  void setPlainText( const QString &text ) { mTextEdit->setPlainText( text ); }
120  void setHtml( const QString &text ) { mTextEdit->setHtml( text ); }
121  void textRemoveFormat();
122  void textRemoveAllFormat();
123  void textBold();
124  void textUnderline();
125  void textStrikeout();
126  void textItalic();
127  void textSize( const QString &p );
128  void textLink( bool checked );
129  void textStyle( int index );
130  void textFgColor();
131  void textBgColor();
132  void listBullet( bool checked );
133  void listOrdered( bool checked );
134  void slotCurrentCharFormatChanged( const QTextCharFormat &format );
135  void slotCursorPositionChanged();
136  void slotClipboardDataChanged();
137  void increaseIndentation();
138  void decreaseIndentation();
139  void insertImage();
140  void editSource( bool enabled );
141 
142  private:
143  void mergeFormatOnWordOrSelection( const QTextCharFormat &format );
144  void fontChanged( const QFont &f );
145  void fgColorChanged( const QColor &c );
146  void bgColorChanged( const QColor &c );
147  void list( bool checked, QTextListFormat::Style style );
148  void indent( int delta );
149 
150  int mFontSizeH1 = 18;
151  int mFontSizeH2 = 16;
152  int mFontSizeH3 = 14;
153  int mFontSizeH4 = 12;
154 
155  enum ParagraphItems
156  {
157  ParagraphStandard = 0,
158  ParagraphHeading1,
159  ParagraphHeading2,
160  ParagraphHeading3,
161  ParagraphHeading4,
162  ParagraphMonospace
163  };
164 
165  QComboBox *mParagraphStyleCombo = nullptr;
166  QComboBox *mFontSizeCombo = nullptr;
167 
168  QgsColorButton *mForeColorButton = nullptr;
169  QgsColorButton *mBackColorButton = nullptr;
170  QgsCodeEditorHTML *mSourceEdit = nullptr;
171 
172  QPointer<QTextList> mLastBlockList;
173  QString mMonospaceFontFamily;
174 };
175 
176 
177 
178 #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.
QTextDocument * document()
Returns a reference to the QTextDocument shown in the widget.
void setTextCursor(const QTextCursor &cursor)
Sets the current text cursor.
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