summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/widgets/richtext/textedit/images/mac/checkbox-checked.pngbin0 -> 1167 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/checkbox.pngbin0 -> 779 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/checkbox-checked.pngbin0 -> 1167 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/checkbox.pngbin0 -> 779 bytes
-rw-r--r--examples/widgets/richtext/textedit/textedit.cpp64
-rw-r--r--examples/widgets/richtext/textedit/textedit.h2
-rw-r--r--examples/widgets/richtext/textedit/textedit.qrc4
7 files changed, 61 insertions, 9 deletions
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
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/checkbox-checked.png
Binary files 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
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/checkbox.png
Binary files 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
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/checkbox-checked.png
Binary files 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
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/checkbox.png
Binary files 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 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource prefix="/">
<file>images/logo32.png</file>
+ <file>images/mac/checkbox.png</file>
+ <file>images/mac/checkbox-checked.png</file>
<file>images/mac/editcopy.png</file>
<file>images/mac/editcut.png</file>
<file>images/mac/editpaste.png</file>
@@ -20,6 +22,8 @@
<file>images/mac/textunder.png</file>
<file>images/mac/zoomin.png</file>
<file>images/mac/zoomout.png</file>
+ <file>images/win/checkbox.png</file>
+ <file>images/win/checkbox-checked.png</file>
<file>images/win/editcopy.png</file>
<file>images/win/editcut.png</file>
<file>images/win/editpaste.png</file>