From deae75ae093d11714dd2f05a40dcfcdb6bb8e10e Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 18 Dec 2017 11:28:33 +0100 Subject: TextEdit example: add Markdown as a supported format Also use QT_CONFIG to disable features gracefully if Qt is configured without them. Change-Id: I38e92bf5fd70f77fc4d5158769d590619be8905f Reviewed-by: Gatis Paeglis --- examples/widgets/richtext/textedit/example.md | 96 +++++++++++++++++++++++++ examples/widgets/richtext/textedit/textedit.cpp | 33 +++++++-- 2 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 examples/widgets/richtext/textedit/example.md (limited to 'examples/widgets/richtext') diff --git a/examples/widgets/richtext/textedit/example.md b/examples/widgets/richtext/textedit/example.md new file mode 100644 index 0000000000..70aeaf7649 --- /dev/null +++ b/examples/widgets/richtext/textedit/example.md @@ -0,0 +1,96 @@ +# QTextEdit + +The QTextEdit widget is an advanced editor that supports formatted rich text. +It can be used to display HTML and other rich document formats. Internally, +QTextEdit uses the QTextDocument class to describe both the high-level +structure of each document and the low-level formatting of paragraphs. + +If you are viewing this document in the textedit example, you can edit this +document to explore Qt's rich text editing features. We have included some +comments in each of the following sections to encourage you to experiment. + +## Font and Paragraph Styles + +QTextEdit supports **bold**, *italic*, & ~~strikethrough~~ font styles, and +can display multicolored text. Font families such as Times New Roman and `Courier` +can also be used directly. *If you place the cursor in a region of styled text, +the controls in the tool bars will change to reflect the current style.* + +Paragraphs can be formatted so that the text is left-aligned, right-aligned, +centered, or fully justified. + +*Try changing the alignment of some text and resize the editor to see how the +text layout changes.* + +## Lists + +Different kinds of lists can be included in rich text documents. Standard +bullet lists can be nested, using different symbols for each level of the list: + +- Disc symbols are typically used for top-level list items. + * Circle symbols can be used to distinguish between items in lower-level + lists. + + Square symbols provide a reasonable alternative to discs and circles. + +Ordered lists can be created that can be used for tables of contents. Different +characters can be used to enumerate items, and we can use both Roman and Arabic +numerals in the same list structure: + +1. Introduction +2. Qt Tools + 1) Qt Assistant + 2) Qt Designer + 1. Form Editor + 2. Component Architecture + 3) Qt Linguist + +The list will automatically be renumbered if you add or remove items. *Try +adding new sections to the above list or removing existing item to see the +numbers change.* + +## Images + +Inline images are treated like ordinary ranges of characters in the text +editor, so they flow with the surrounding text. Images can also be selected in +the same way as text, making it easy to cut, copy, and paste them. + +![logo](images/logo32.png "logo") *Try to select this image by clicking and +dragging over it with the mouse, or use the text cursor to select it by holding +down Shift and using the arrow keys. You can then cut or copy it, and paste it +into different parts of this document.* + +## Tables + +QTextEdit can arrange and format tables, supporting features such as row and +column spans, text formatting within cells, and size constraints for columns. + +| | Development Tools | Programming Techniques | Graphical User Interfaces | +| ------------: | ----------------- | ---------------------- | ------------------------- | +| 9:00 - 11:00 | Introduction to Qt ||| +| 11:00 - 13:00 | Using qmake | Object-oriented Programming | Layouts in Qt | +| 13:00 - 15:00 | Qt Designer Tutorial | Extreme Programming | Writing Custom Styles | +| 15:00 - 17:00 | Qt Linguist and Internationalization |   |   | + +*Try adding text to the cells in the table and experiment with the alignment of +the paragraphs.* + +## Hyperlinks + +QTextEdit is designed to support hyperlinks between documents, and this feature +is used extensively in +[Qt Assistant](http://doc.qt.io/qt-5/qtassistant-index.html). Hyperlinks are +automatically created when an HTML file is imported into an editor. Since the +rich text framework supports hyperlinks natively, they can also be created +programatically. + +## Undo and Redo + +Full support for undo and redo operations is built into QTextEdit and the +underlying rich text framework. Operations on a document can be packaged +together to make editing a more comfortable experience for the user. + +*Try making changes to this document and press `Ctrl+Z` to undo them. You can +always recover the original contents of the document.* + diff --git a/examples/widgets/richtext/textedit/textedit.cpp b/examples/widgets/richtext/textedit/textedit.cpp index 3ad9f48b67..7b8c242cfc 100644 --- a/examples/widgets/richtext/textedit/textedit.cpp +++ b/examples/widgets/richtext/textedit/textedit.cpp @@ -71,6 +71,7 @@ #include #include #include +#include #if defined(QT_PRINTSUPPORT_LIB) #include #if QT_CONFIG(printer) @@ -395,11 +396,18 @@ bool TextEdit::load(const QString &f) QByteArray data = file.readAll(); QTextCodec *codec = Qt::codecForHtml(data); QString str = codec->toUnicode(data); + QUrl baseUrl = (f.front() == QLatin1Char(':') ? QUrl(f) : QUrl::fromLocalFile(f)).adjusted(QUrl::RemoveFilename); + textEdit->document()->setBaseUrl(baseUrl); if (Qt::mightBeRichText(str)) { textEdit->setHtml(str); } else { - str = QString::fromLocal8Bit(data); - textEdit->setPlainText(str); +#if QT_CONFIG(textmarkdownreader) + QMimeDatabase db; + if (db.mimeTypeForFileNameAndData(f, data).name() == QLatin1String("text/markdown")) + textEdit->setMarkdown(str); + else +#endif + textEdit->setPlainText(QString::fromLocal8Bit(data)); } setCurrentFileName(f); @@ -451,7 +459,15 @@ void TextEdit::fileOpen() QFileDialog fileDialog(this, tr("Open File...")); fileDialog.setAcceptMode(QFileDialog::AcceptOpen); fileDialog.setFileMode(QFileDialog::ExistingFile); - fileDialog.setMimeTypeFilters(QStringList() << "text/html" << "text/plain"); + fileDialog.setMimeTypeFilters(QStringList() +#if QT_CONFIG(texthtmlparser) + << "text/html" +#endif +#if QT_CONFIG(textmarkdownreader) + + << "text/markdown" +#endif + << "text/plain"); if (fileDialog.exec() != QDialog::Accepted) return; const QString fn = fileDialog.selectedFiles().first(); @@ -485,9 +501,18 @@ bool TextEdit::fileSaveAs() QFileDialog fileDialog(this, tr("Save as...")); fileDialog.setAcceptMode(QFileDialog::AcceptSave); QStringList mimeTypes; - mimeTypes << "application/vnd.oasis.opendocument.text" << "text/html" << "text/plain"; + mimeTypes << "text/plain" +#if QT_CONFIG(textodfwriter) + << "application/vnd.oasis.opendocument.text" +#endif +#if QT_CONFIG(textmarkdownwriter) + << "text/markdown" +#endif + << "text/html"; fileDialog.setMimeTypeFilters(mimeTypes); +#if QT_CONFIG(textodfwriter) fileDialog.setDefaultSuffix("odt"); +#endif if (fileDialog.exec() != QDialog::Accepted) return false; const QString fn = fileDialog.selectedFiles().first(); -- cgit v1.2.3 From 75256d62d2462103180b368aa79b933acf71f444 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Wed, 6 Feb 2019 17:10:42 +0100 Subject: Render markdown task lists (checkboxes instead of bullets) in QTextEdit Checkboxes are right-aligned with any bullets that are in the same QTextList so that there is enough space to make them larger than bullets. But hopefully mixing bullets and checkboxes will be a rarely-used feature. Change-Id: I28e274d1f7883aa093df29eb4988e99641e87a71 Reviewed-by: Gatis Paeglis --- examples/widgets/richtext/textedit/example.md | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'examples/widgets/richtext') diff --git a/examples/widgets/richtext/textedit/example.md b/examples/widgets/richtext/textedit/example.md index 70aeaf7649..a16a9197b4 100644 --- a/examples/widgets/richtext/textedit/example.md +++ b/examples/widgets/richtext/textedit/example.md @@ -50,6 +50,12 @@ The list will automatically be renumbered if you add or remove items. *Try adding new sections to the above list or removing existing item to see the numbers change.* +Task lists can be used to track progress on projects: + +- [ ] This is not yet done +- This is just a bullet point +- [x] This is done + ## Images Inline images are treated like ordinary ranges of characters in the text -- cgit v1.2.3 From 0df30ff22e50aa301791fc72f106ab15ce385a6a Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 18 Feb 2019 15:40:04 +0100 Subject: Add task list checkbox manipulation features to the TextEdit example Change-Id: I5f0b8cb94d1af609ec531f9765d58be65b1129a3 Reviewed-by: Gatis Paeglis --- .../textedit/images/mac/checkbox-checked.png | Bin 0 -> 1167 bytes .../richtext/textedit/images/mac/checkbox.png | Bin 0 -> 779 bytes .../textedit/images/win/checkbox-checked.png | Bin 0 -> 1167 bytes .../richtext/textedit/images/win/checkbox.png | Bin 0 -> 779 bytes examples/widgets/richtext/textedit/textedit.cpp | 64 ++++++++++++++++++--- examples/widgets/richtext/textedit/textedit.h | 2 + examples/widgets/richtext/textedit/textedit.qrc | 4 ++ 7 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 examples/widgets/richtext/textedit/images/mac/checkbox-checked.png create mode 100644 examples/widgets/richtext/textedit/images/mac/checkbox.png create mode 100644 examples/widgets/richtext/textedit/images/win/checkbox-checked.png create mode 100644 examples/widgets/richtext/textedit/images/win/checkbox.png (limited to 'examples/widgets/richtext') diff --git a/examples/widgets/richtext/textedit/images/mac/checkbox-checked.png b/examples/widgets/richtext/textedit/images/mac/checkbox-checked.png new file mode 100644 index 0000000000..a072d7fb5c Binary files /dev/null and b/examples/widgets/richtext/textedit/images/mac/checkbox-checked.png differ diff --git a/examples/widgets/richtext/textedit/images/mac/checkbox.png b/examples/widgets/richtext/textedit/images/mac/checkbox.png new file mode 100644 index 0000000000..4064909712 Binary files /dev/null and b/examples/widgets/richtext/textedit/images/mac/checkbox.png differ diff --git a/examples/widgets/richtext/textedit/images/win/checkbox-checked.png b/examples/widgets/richtext/textedit/images/win/checkbox-checked.png new file mode 100644 index 0000000000..a072d7fb5c Binary files /dev/null and b/examples/widgets/richtext/textedit/images/win/checkbox-checked.png differ diff --git a/examples/widgets/richtext/textedit/images/win/checkbox.png b/examples/widgets/richtext/textedit/images/win/checkbox.png new file mode 100644 index 0000000000..4064909712 Binary files /dev/null and b/examples/widgets/richtext/textedit/images/win/checkbox.png differ diff --git a/examples/widgets/richtext/textedit/textedit.cpp b/examples/widgets/richtext/textedit/textedit.cpp index 7b8c242cfc..683e441fce 100644 --- a/examples/widgets/richtext/textedit/textedit.cpp +++ b/examples/widgets/richtext/textedit/textedit.cpp @@ -343,6 +343,15 @@ void TextEdit::setupTextActions() actionTextColor = menu->addAction(pix, tr("&Color..."), this, &TextEdit::textColor); tb->addAction(actionTextColor); + menu->addSeparator(); + + const QIcon checkboxIcon = QIcon::fromTheme("status-checkbox-checked", QIcon(rsrcPath + "/checkbox-checked.png")); + actionToggleCheckState = menu->addAction(checkboxIcon, tr("Chec&ked"), this, &TextEdit::setChecked); + actionToggleCheckState->setShortcut(Qt::CTRL + Qt::Key_K); + actionToggleCheckState->setCheckable(true); + actionToggleCheckState->setPriority(QAction::LowPriority); + tb->addAction(actionToggleCheckState); + tb = addToolBar(tr("Format Actions")); tb->setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea); addToolBarBreak(Qt::TopToolBarArea); @@ -354,6 +363,8 @@ void TextEdit::setupTextActions() comboStyle->addItem("Bullet List (Disc)"); comboStyle->addItem("Bullet List (Circle)"); comboStyle->addItem("Bullet List (Square)"); + comboStyle->addItem("Task List (Unchecked)"); + comboStyle->addItem("Task List (Checked)"); comboStyle->addItem("Ordered List (Decimal)"); comboStyle->addItem("Ordered List (Alpha lower)"); comboStyle->addItem("Ordered List (Alpha upper)"); @@ -617,6 +628,7 @@ void TextEdit::textStyle(int styleIndex) { QTextCursor cursor = textEdit->textCursor(); QTextListFormat::Style style = QTextListFormat::ListStyleUndefined; + QTextBlockFormat::MarkerType marker = QTextBlockFormat::NoMarker; switch (styleIndex) { case 1: @@ -629,18 +641,32 @@ void TextEdit::textStyle(int styleIndex) style = QTextListFormat::ListSquare; break; case 4: - style = QTextListFormat::ListDecimal; + if (cursor.currentList()) + style = cursor.currentList()->format().style(); + else + style = QTextListFormat::ListDisc; + marker = QTextBlockFormat::Unchecked; break; case 5: - style = QTextListFormat::ListLowerAlpha; + if (cursor.currentList()) + style = cursor.currentList()->format().style(); + else + style = QTextListFormat::ListDisc; + marker = QTextBlockFormat::Checked; break; case 6: - style = QTextListFormat::ListUpperAlpha; + style = QTextListFormat::ListDecimal; break; case 7: - style = QTextListFormat::ListLowerRoman; + style = QTextListFormat::ListLowerAlpha; break; case 8: + style = QTextListFormat::ListUpperAlpha; + break; + case 9: + style = QTextListFormat::ListLowerRoman; + break; + case 10: style = QTextListFormat::ListUpperRoman; break; default: @@ -665,6 +691,8 @@ void TextEdit::textStyle(int styleIndex) cursor.mergeCharFormat(fmt); textEdit->mergeCurrentCharFormat(fmt); } else { + blockFmt.setMarker(marker); + cursor.setBlockFormat(blockFmt); QTextListFormat listFmt; if (cursor.currentList()) { listFmt = cursor.currentList()->format(); @@ -703,6 +731,11 @@ void TextEdit::textAlign(QAction *a) textEdit->setAlignment(Qt::AlignJustify); } +void TextEdit::setChecked(bool checked) +{ + textStyle(checked ? 5 : 4); +} + void TextEdit::currentCharFormatChanged(const QTextCharFormat &format) { fontChanged(format.font()); @@ -725,24 +758,37 @@ void TextEdit::cursorPositionChanged() comboStyle->setCurrentIndex(3); break; case QTextListFormat::ListDecimal: - comboStyle->setCurrentIndex(4); + comboStyle->setCurrentIndex(6); break; case QTextListFormat::ListLowerAlpha: - comboStyle->setCurrentIndex(5); + comboStyle->setCurrentIndex(7); break; case QTextListFormat::ListUpperAlpha: - comboStyle->setCurrentIndex(6); + comboStyle->setCurrentIndex(8); break; case QTextListFormat::ListLowerRoman: - comboStyle->setCurrentIndex(7); + comboStyle->setCurrentIndex(9); break; case QTextListFormat::ListUpperRoman: - comboStyle->setCurrentIndex(8); + comboStyle->setCurrentIndex(10); break; default: comboStyle->setCurrentIndex(-1); break; } + switch (textEdit->textCursor().block().blockFormat().marker()) { + case QTextBlockFormat::NoMarker: + actionToggleCheckState->setChecked(false); + break; + case QTextBlockFormat::Unchecked: + comboStyle->setCurrentIndex(4); + actionToggleCheckState->setChecked(false); + break; + case QTextBlockFormat::Checked: + comboStyle->setCurrentIndex(5); + actionToggleCheckState->setChecked(true); + break; + } } else { int headingLevel = textEdit->textCursor().blockFormat().headingLevel(); comboStyle->setCurrentIndex(headingLevel ? headingLevel + 8 : 0); diff --git a/examples/widgets/richtext/textedit/textedit.h b/examples/widgets/richtext/textedit/textedit.h index ae0b13a4cc..c253548a4f 100644 --- a/examples/widgets/richtext/textedit/textedit.h +++ b/examples/widgets/richtext/textedit/textedit.h @@ -96,6 +96,7 @@ private slots: void textStyle(int styleIndex); void textColor(); void textAlign(QAction *a); + void setChecked(bool checked); void currentCharFormatChanged(const QTextCharFormat &format); void cursorPositionChanged(); @@ -125,6 +126,7 @@ private: QAction *actionAlignCenter; QAction *actionAlignRight; QAction *actionAlignJustify; + QAction *actionToggleCheckState; QAction *actionUndo; QAction *actionRedo; #ifndef QT_NO_CLIPBOARD diff --git a/examples/widgets/richtext/textedit/textedit.qrc b/examples/widgets/richtext/textedit/textedit.qrc index 7d6efd7d67..8016a07ca0 100644 --- a/examples/widgets/richtext/textedit/textedit.qrc +++ b/examples/widgets/richtext/textedit/textedit.qrc @@ -1,6 +1,8 @@ images/logo32.png + images/mac/checkbox.png + images/mac/checkbox-checked.png images/mac/editcopy.png images/mac/editcut.png images/mac/editpaste.png @@ -20,6 +22,8 @@ images/mac/textunder.png images/mac/zoomin.png images/mac/zoomout.png + images/win/checkbox.png + images/win/checkbox-checked.png images/win/editcopy.png images/win/editcut.png images/win/editpaste.png -- cgit v1.2.3 From b922c97c9c65ce28f4ea18106f384adf1bbf605a Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Sat, 4 May 2019 08:48:41 +0200 Subject: TextEdit example: add indent/unindent feature It was not possible to interactively create the example text without this feature; and in general it's necessary to work with nested lists. But currently it does not deal with all possible changes of list nesting, because the API seems incomplete for that purpose. Task-number: QTBUG-75589 Change-Id: I3e29ca15a2e7c37300a0103ceb90670716472ffb Reviewed-by: Gatis Paeglis --- .../textedit/images/mac/format-indent-less.png | Bin 0 -> 1201 bytes .../textedit/images/mac/format-indent-more.png | Bin 0 -> 993 bytes .../textedit/images/win/format-indent-less.png | Bin 0 -> 1201 bytes .../textedit/images/win/format-indent-more.png | Bin 0 -> 993 bytes examples/widgets/richtext/textedit/textedit.cpp | 46 +++++++++++++++++++++ examples/widgets/richtext/textedit/textedit.h | 5 +++ examples/widgets/richtext/textedit/textedit.qrc | 4 ++ 7 files changed, 55 insertions(+) create mode 100644 examples/widgets/richtext/textedit/images/mac/format-indent-less.png create mode 100644 examples/widgets/richtext/textedit/images/mac/format-indent-more.png create mode 100644 examples/widgets/richtext/textedit/images/win/format-indent-less.png create mode 100644 examples/widgets/richtext/textedit/images/win/format-indent-more.png (limited to 'examples/widgets/richtext') diff --git a/examples/widgets/richtext/textedit/images/mac/format-indent-less.png b/examples/widgets/richtext/textedit/images/mac/format-indent-less.png new file mode 100644 index 0000000000..e38074e78b Binary files /dev/null and b/examples/widgets/richtext/textedit/images/mac/format-indent-less.png differ diff --git a/examples/widgets/richtext/textedit/images/mac/format-indent-more.png b/examples/widgets/richtext/textedit/images/mac/format-indent-more.png new file mode 100644 index 0000000000..1bdeabd354 Binary files /dev/null and b/examples/widgets/richtext/textedit/images/mac/format-indent-more.png differ diff --git a/examples/widgets/richtext/textedit/images/win/format-indent-less.png b/examples/widgets/richtext/textedit/images/win/format-indent-less.png new file mode 100644 index 0000000000..e38074e78b Binary files /dev/null and b/examples/widgets/richtext/textedit/images/win/format-indent-less.png differ diff --git a/examples/widgets/richtext/textedit/images/win/format-indent-more.png b/examples/widgets/richtext/textedit/images/win/format-indent-more.png new file mode 100644 index 0000000000..1bdeabd354 Binary files /dev/null and b/examples/widgets/richtext/textedit/images/win/format-indent-more.png differ diff --git a/examples/widgets/richtext/textedit/textedit.cpp b/examples/widgets/richtext/textedit/textedit.cpp index 683e441fce..ced77a62ce 100644 --- a/examples/widgets/richtext/textedit/textedit.cpp +++ b/examples/widgets/richtext/textedit/textedit.cpp @@ -317,6 +317,14 @@ void TextEdit::setupTextActions() actionAlignJustify->setShortcut(Qt::CTRL + Qt::Key_J); actionAlignJustify->setCheckable(true); actionAlignJustify->setPriority(QAction::LowPriority); + const QIcon indentMoreIcon = QIcon::fromTheme("format-indent-more", QIcon(rsrcPath + "/format-indent-more.png")); + actionIndentMore = menu->addAction(indentMoreIcon, tr("&Indent"), this, &TextEdit::indent); + actionIndentMore->setShortcut(Qt::CTRL + Qt::Key_BracketRight); + actionIndentMore->setPriority(QAction::LowPriority); + const QIcon indentLessIcon = QIcon::fromTheme("format-indent-less", QIcon(rsrcPath + "/format-indent-less.png")); + actionIndentLess = menu->addAction(indentLessIcon, tr("&Unindent"), this, &TextEdit::unindent); + actionIndentLess->setShortcut(Qt::CTRL + Qt::Key_BracketLeft); + actionIndentLess->setPriority(QAction::LowPriority); // Make sure the alignLeft is always left of the alignRight QActionGroup *alignGroup = new QActionGroup(this); @@ -335,6 +343,10 @@ void TextEdit::setupTextActions() tb->addActions(alignGroup->actions()); menu->addActions(alignGroup->actions()); + tb->addAction(actionIndentMore); + tb->addAction(actionIndentLess); + menu->addAction(actionIndentMore); + menu->addAction(actionIndentLess); menu->addSeparator(); @@ -736,6 +748,40 @@ void TextEdit::setChecked(bool checked) textStyle(checked ? 5 : 4); } +void TextEdit::indent() +{ + modifyIndentation(1); +} + +void TextEdit::unindent() +{ + modifyIndentation(-1); +} + +void TextEdit::modifyIndentation(int amount) +{ + QTextCursor cursor = textEdit->textCursor(); + cursor.beginEditBlock(); + if (cursor.currentList()) { + QTextListFormat listFmt = cursor.currentList()->format(); + // See whether the line above is the list we want to move this item into, + // or whether we need a new list. + QTextCursor above(cursor); + above.movePosition(QTextCursor::Up); + if (above.currentList() && listFmt.indent() + amount == above.currentList()->format().indent()) { + above.currentList()->add(cursor.block()); + } else { + listFmt.setIndent(listFmt.indent() + amount); + cursor.createList(listFmt); + } + } else { + QTextBlockFormat blockFmt = cursor.blockFormat(); + blockFmt.setIndent(blockFmt.indent() + amount); + cursor.setBlockFormat(blockFmt); + } + cursor.endEditBlock(); +} + void TextEdit::currentCharFormatChanged(const QTextCharFormat &format) { fontChanged(format.font()); diff --git a/examples/widgets/richtext/textedit/textedit.h b/examples/widgets/richtext/textedit/textedit.h index c253548a4f..9e50166c6f 100644 --- a/examples/widgets/richtext/textedit/textedit.h +++ b/examples/widgets/richtext/textedit/textedit.h @@ -97,6 +97,8 @@ private slots: void textColor(); void textAlign(QAction *a); void setChecked(bool checked); + void indent(); + void unindent(); void currentCharFormatChanged(const QTextCharFormat &format); void cursorPositionChanged(); @@ -111,6 +113,7 @@ private: void setupTextActions(); bool maybeSave(); void setCurrentFileName(const QString &fileName); + void modifyIndentation(int amount); void mergeFormatOnWordOrSelection(const QTextCharFormat &format); void fontChanged(const QFont &f); @@ -126,6 +129,8 @@ private: QAction *actionAlignCenter; QAction *actionAlignRight; QAction *actionAlignJustify; + QAction *actionIndentLess; + QAction *actionIndentMore; QAction *actionToggleCheckState; QAction *actionUndo; QAction *actionRedo; diff --git a/examples/widgets/richtext/textedit/textedit.qrc b/examples/widgets/richtext/textedit/textedit.qrc index 8016a07ca0..1641acc207 100644 --- a/examples/widgets/richtext/textedit/textedit.qrc +++ b/examples/widgets/richtext/textedit/textedit.qrc @@ -13,6 +13,8 @@ images/mac/fileopen.png images/mac/fileprint.png images/mac/filesave.png + images/mac/format-indent-less.png + images/mac/format-indent-more.png images/mac/textbold.png images/mac/textcenter.png images/mac/textitalic.png @@ -34,6 +36,8 @@ images/win/fileopen.png images/win/fileprint.png images/win/filesave.png + images/win/format-indent-less.png + images/win/format-indent-more.png images/win/textbold.png images/win/textcenter.png images/win/textitalic.png -- cgit v1.2.3 From 1b8a1e04efb4ea71803edf8c122db2837fe23af9 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 6 May 2019 17:03:45 +0200 Subject: Fix heading level in style combobox in TextEdit example Amends 0df30ff22e50aa301791fc72f106ab15ce385a6a: when adding the checked and unchecked styles to the combobox, it changed the offsets for the heading styles; so the combobox stopped changing to the correct index when clicking on a heading, and also changed the heading two sizes smaller than it should when attempting to select a different heading level. Change-Id: Ib3f61987c786e34f32a81bf7b3ebc5ca730f40df Reviewed-by: Gatis Paeglis --- examples/widgets/richtext/textedit/textedit.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'examples/widgets/richtext') diff --git a/examples/widgets/richtext/textedit/textedit.cpp b/examples/widgets/richtext/textedit/textedit.cpp index ced77a62ce..996bb8e0a4 100644 --- a/examples/widgets/richtext/textedit/textedit.cpp +++ b/examples/widgets/richtext/textedit/textedit.cpp @@ -691,7 +691,7 @@ void TextEdit::textStyle(int styleIndex) if (style == QTextListFormat::ListStyleUndefined) { blockFmt.setObjectIndex(-1); - int headingLevel = styleIndex >= 9 ? styleIndex - 9 + 1 : 0; // H1 to H6, or Standard + int headingLevel = styleIndex >= 11 ? styleIndex - 11 + 1 : 0; // H1 to H6, or Standard blockFmt.setHeadingLevel(headingLevel); cursor.setBlockFormat(blockFmt); @@ -837,7 +837,7 @@ void TextEdit::cursorPositionChanged() } } else { int headingLevel = textEdit->textCursor().blockFormat().headingLevel(); - comboStyle->setCurrentIndex(headingLevel ? headingLevel + 8 : 0); + comboStyle->setCurrentIndex(headingLevel ? headingLevel + 10 : 0); } } -- cgit v1.2.3