From 0df30ff22e50aa301791fc72f106ab15ce385a6a Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 18 Feb 2019 15:40:04 +0100 Subject: [PATCH] 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 .../widgets/richtext/textedit/textedit.cpp | 70 +++++++++++++++--- examples/widgets/richtext/textedit/textedit.h | 2 + .../widgets/richtext/textedit/textedit.qrc | 4 + 7 files changed, 64 insertions(+), 12 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 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 0000000000000000000000000000000000000000..a072d7fb5cf6f50faee3024265d421423eebd2fd GIT binary patch literal 1167 zcmZvbe=ys37{|X^qB2^SolQ;MX1(ol({W{5HtJX7N2tssL)BCfq)3oNqC`TpMV+&C zSgSibv!nESw41hwpV1%$(I6@s5+Z0435obI`=XR0ZR5q&5S+;P(B@;LBvNglAfis)1uag79NX zKr{tQN~X}RW#a)Fjpj@srjZk`W#XMl*(tRuFFUa4Q&SO+KuN~~K}1pp-T|ANkw8i( zBs!oINkj)+Dn0{W(ePyp06_Y~FW~~fmjBhrn=O!YCS*O6a@pq2;X8pup)>xsK0UAa z2u4I+0TUPucI3gPn)|=m*xG(zZM~&8fcA9g)n6miPlrW+k4%I1Y;^X#myf4kKx#Jq z#rRy8P~zz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4%-MiA? zzt-Z&;O)ua?8@Tr%H#3N`R%w=`r@z0zz`?@A$;-{o&d<@*)z;S6*x1_I-QC{f z=jiF_>gww2>+tgP^Yrxe_4W4o`uh6&{Qdp@{{H^{2kVo$0002aNklG&tA*5LgfR=B*eUQbm&`F*xHh()`#G?bZ%2;GXi%w0Pgn^UVt+$d{W;Mp2ZL zcswS{awHTAN|GdHU-?-y1IE-yblzdn2>=GqX=9+T|8(g!1Ah+JTb+9Ru~z^9002ov JPDHLkV1k{Ct#JSV literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..a072d7fb5cf6f50faee3024265d421423eebd2fd GIT binary patch literal 1167 zcmZvbe=ys37{|X^qB2^SolQ;MX1(ol({W{5HtJX7N2tssL)BCfq)3oNqC`TpMV+&C zSgSibv!nESw41hwpV1%$(I6@s5+Z0435obI`=XR0ZR5q&5S+;P(B@;LBvNglAfis)1uag79NX zKr{tQN~X}RW#a)Fjpj@srjZk`W#XMl*(tRuFFUa4Q&SO+KuN~~K}1pp-T|ANkw8i( zBs!oINkj)+Dn0{W(ePyp06_Y~FW~~fmjBhrn=O!YCS*O6a@pq2;X8pup)>xsK0UAa z2u4I+0TUPucI3gPn)|=m*xG(zZM~&8fcA9g)n6miPlrW+k4%I1Y;^X#myf4kKx#Jq z#rRy8P~zzycmajx2qn+^c^u&aCMvdXTIzK%*e5V_U}nh=jqwk`fXTi3#`ZDspjaLr z6OW5aq86}U&dCSF@=?*;utdR|S9DJ;G=1}oHQR~AoTN-TfmQ&LZs9^wCXJB8NTajTa|^}G8wnZI)EowpQGA_N z077DZaW<4w$zt5hVwF(Xcc{hX3+r0dwvkd)26~=Ul}gPAr}1T* zV{+}-vTjkWU*6owV%{bfmQadHUrb0kg>N{brJm`fzS)(5*GlfZa!C4iSh_K?q#luN z@?{#nTstaLkIJ>*D&go4bdnx3{lfSR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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); - break; - case QTextListFormat::ListLowerAlpha: - comboStyle->setCurrentIndex(5); - break; - case QTextListFormat::ListUpperAlpha: comboStyle->setCurrentIndex(6); break; - case QTextListFormat::ListLowerRoman: + case QTextListFormat::ListLowerAlpha: comboStyle->setCurrentIndex(7); break; - case QTextListFormat::ListUpperRoman: + case QTextListFormat::ListUpperAlpha: comboStyle->setCurrentIndex(8); break; + case QTextListFormat::ListLowerRoman: + comboStyle->setCurrentIndex(9); + break; + case QTextListFormat::ListUpperRoman: + 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