summaryrefslogtreecommitdiffstats
path: root/examples/widgets/richtext
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/richtext')
-rw-r--r--examples/widgets/richtext/README11
-rw-r--r--examples/widgets/richtext/calendar/calendar.desktop11
-rw-r--r--examples/widgets/richtext/calendar/calendar.pro11
-rw-r--r--examples/widgets/richtext/calendar/main.cpp52
-rw-r--r--examples/widgets/richtext/calendar/mainwindow.cpp215
-rw-r--r--examples/widgets/richtext/calendar/mainwindow.h73
-rw-r--r--examples/widgets/richtext/orderform/detailsdialog.cpp156
-rw-r--r--examples/widgets/richtext/orderform/detailsdialog.h90
-rw-r--r--examples/widgets/richtext/orderform/main.cpp55
-rw-r--r--examples/widgets/richtext/orderform/mainwindow.cpp253
-rw-r--r--examples/widgets/richtext/orderform/mainwindow.h76
-rw-r--r--examples/widgets/richtext/orderform/orderform.desktop11
-rw-r--r--examples/widgets/richtext/orderform/orderform.pro14
-rw-r--r--examples/widgets/richtext/richtext.pro11
-rw-r--r--examples/widgets/richtext/syntaxhighlighter/highlighter.cpp147
-rw-r--r--examples/widgets/richtext/syntaxhighlighter/highlighter.h84
-rw-r--r--examples/widgets/richtext/syntaxhighlighter/main.cpp52
-rw-r--r--examples/widgets/richtext/syntaxhighlighter/mainwindow.cpp128
-rw-r--r--examples/widgets/richtext/syntaxhighlighter/mainwindow.h75
-rw-r--r--examples/widgets/richtext/syntaxhighlighter/syntaxhighlighter.desktop11
-rw-r--r--examples/widgets/richtext/syntaxhighlighter/syntaxhighlighter.pro20
-rw-r--r--examples/widgets/richtext/textedit/example.html79
-rw-r--r--examples/widgets/richtext/textedit/images/logo32.pngbin0 -> 1410 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/editcopy.pngbin0 -> 1468 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/editcut.pngbin0 -> 1512 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/editpaste.pngbin0 -> 1906 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/editredo.pngbin0 -> 1752 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/editundo.pngbin0 -> 1746 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/exportpdf.pngbin0 -> 1215 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/filenew.pngbin0 -> 1172 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/fileopen.pngbin0 -> 2168 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/fileprint.pngbin0 -> 2087 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/filesave.pngbin0 -> 1206 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/textbold.pngbin0 -> 1611 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/textcenter.pngbin0 -> 1404 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/textitalic.pngbin0 -> 1164 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/textjustify.pngbin0 -> 1257 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/textleft.pngbin0 -> 1235 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/textright.pngbin0 -> 1406 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/textunder.pngbin0 -> 1183 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/zoomin.pngbin0 -> 1696 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/mac/zoomout.pngbin0 -> 1662 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/editcopy.pngbin0 -> 1325 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/editcut.pngbin0 -> 1896 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/editpaste.pngbin0 -> 1482 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/editredo.pngbin0 -> 1787 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/editundo.pngbin0 -> 1768 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/exportpdf.pngbin0 -> 1059 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/filenew.pngbin0 -> 768 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/fileopen.pngbin0 -> 1662 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/fileprint.pngbin0 -> 1456 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/filesave.pngbin0 -> 1205 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/textbold.pngbin0 -> 1134 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/textcenter.pngbin0 -> 627 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/textitalic.pngbin0 -> 829 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/textjustify.pngbin0 -> 695 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/textleft.pngbin0 -> 673 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/textright.pngbin0 -> 677 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/textunder.pngbin0 -> 971 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/zoomin.pngbin0 -> 1208 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/zoomout.pngbin0 -> 1226 bytes
-rw-r--r--examples/widgets/richtext/textedit/main.cpp54
-rw-r--r--examples/widgets/richtext/textedit/textedit.cpp737
-rw-r--r--examples/widgets/richtext/textedit/textedit.h130
-rw-r--r--examples/widgets/richtext/textedit/textedit.pro23
-rw-r--r--examples/widgets/richtext/textedit/textedit.qdoc45
-rw-r--r--examples/widgets/richtext/textedit/textedit.qrc44
67 files changed, 2668 insertions, 0 deletions
diff --git a/examples/widgets/richtext/README b/examples/widgets/richtext/README
new file mode 100644
index 0000000000..647029b8a2
--- /dev/null
+++ b/examples/widgets/richtext/README
@@ -0,0 +1,11 @@
+Qt provides powerful document-oriented rich text engine that supports Unicode
+and right-to-left scripts. Documents can be manipulated using a cursor-based
+API, and their contents can be imported and exported as both HTML and in a
+custom XML format.
+
+Text is rendered using anti-aliased outline fonts to provide the best
+possible on-screen representation.
+
+
+Documentation for these examples can be found via the Examples
+link in the main Qt documentation.
diff --git a/examples/widgets/richtext/calendar/calendar.desktop b/examples/widgets/richtext/calendar/calendar.desktop
new file mode 100644
index 0000000000..41ba6dd95a
--- /dev/null
+++ b/examples/widgets/richtext/calendar/calendar.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Calendar
+Exec=/opt/usr/bin/calendar
+Icon=calendar
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/richtext/calendar/calendar.pro b/examples/widgets/richtext/calendar/calendar.pro
new file mode 100644
index 0000000000..3867a027cf
--- /dev/null
+++ b/examples/widgets/richtext/calendar/calendar.pro
@@ -0,0 +1,11 @@
+HEADERS = mainwindow.h
+SOURCES = main.cpp \
+ mainwindow.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/richtext/calendar
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS calendar.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/richtext/calendar
+INSTALLS += target sources
+
+QT += widgets
diff --git a/examples/widgets/richtext/calendar/main.cpp b/examples/widgets/richtext/calendar/main.cpp
new file mode 100644
index 0000000000..35b6b90c13
--- /dev/null
+++ b/examples/widgets/richtext/calendar/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.resize(640, 256);
+ window.show();
+ return app.exec();
+}
diff --git a/examples/widgets/richtext/calendar/mainwindow.cpp b/examples/widgets/richtext/calendar/mainwindow.cpp
new file mode 100644
index 0000000000..366ebff2a9
--- /dev/null
+++ b/examples/widgets/richtext/calendar/mainwindow.cpp
@@ -0,0 +1,215 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "mainwindow.h"
+
+//! [0]
+MainWindow::MainWindow()
+{
+ selectedDate = QDate::currentDate();
+ fontSize = 10;
+
+ QWidget *centralWidget = new QWidget;
+//! [0]
+
+//! [1]
+ QLabel *dateLabel = new QLabel(tr("Date:"));
+ QComboBox *monthCombo = new QComboBox;
+
+ for (int month = 1; month <= 12; ++month)
+ monthCombo->addItem(QDate::longMonthName(month));
+
+ QDateTimeEdit *yearEdit = new QDateTimeEdit;
+ yearEdit->setDisplayFormat("yyyy");
+ yearEdit->setDateRange(QDate(1753, 1, 1), QDate(8000, 1, 1));
+//! [1]
+
+ monthCombo->setCurrentIndex(selectedDate.month() - 1);
+ yearEdit->setDate(selectedDate);
+
+//! [2]
+ QLabel *fontSizeLabel = new QLabel(tr("Font size:"));
+ QSpinBox *fontSizeSpinBox = new QSpinBox;
+ fontSizeSpinBox->setRange(1, 64);
+
+ editor = new QTextBrowser;
+ insertCalendar();
+//! [2]
+
+//! [3]
+ connect(monthCombo, SIGNAL(activated(int)), this, SLOT(setMonth(int)));
+ connect(yearEdit, SIGNAL(dateChanged(QDate)), this, SLOT(setYear(QDate)));
+ connect(fontSizeSpinBox, SIGNAL(valueChanged(int)),
+ this, SLOT(setFontSize(int)));
+//! [3]
+
+ fontSizeSpinBox->setValue(10);
+
+//! [4]
+ QHBoxLayout *controlsLayout = new QHBoxLayout;
+ controlsLayout->addWidget(dateLabel);
+ controlsLayout->addWidget(monthCombo);
+ controlsLayout->addWidget(yearEdit);
+ controlsLayout->addSpacing(24);
+ controlsLayout->addWidget(fontSizeLabel);
+ controlsLayout->addWidget(fontSizeSpinBox);
+ controlsLayout->addStretch(1);
+
+ QVBoxLayout *centralLayout = new QVBoxLayout;
+ centralLayout->addLayout(controlsLayout);
+ centralLayout->addWidget(editor, 1);
+ centralWidget->setLayout(centralLayout);
+
+ setCentralWidget(centralWidget);
+//! [4]
+}
+
+//! [5]
+void MainWindow::insertCalendar()
+{
+ editor->clear();
+ QTextCursor cursor = editor->textCursor();
+ cursor.beginEditBlock();
+
+ QDate date(selectedDate.year(), selectedDate.month(), 1);
+//! [5]
+
+//! [6]
+ QTextTableFormat tableFormat;
+ tableFormat.setAlignment(Qt::AlignHCenter);
+ tableFormat.setBackground(QColor("#e0e0e0"));
+ tableFormat.setCellPadding(2);
+ tableFormat.setCellSpacing(4);
+//! [6] //! [7]
+ QVector<QTextLength> constraints;
+ constraints << QTextLength(QTextLength::PercentageLength, 14)
+ << QTextLength(QTextLength::PercentageLength, 14)
+ << QTextLength(QTextLength::PercentageLength, 14)
+ << QTextLength(QTextLength::PercentageLength, 14)
+ << QTextLength(QTextLength::PercentageLength, 14)
+ << QTextLength(QTextLength::PercentageLength, 14)
+ << QTextLength(QTextLength::PercentageLength, 14);
+ tableFormat.setColumnWidthConstraints(constraints);
+//! [7]
+
+//! [8]
+ QTextTable *table = cursor.insertTable(1, 7, tableFormat);
+//! [8]
+
+//! [9]
+ QTextFrame *frame = cursor.currentFrame();
+ QTextFrameFormat frameFormat = frame->frameFormat();
+ frameFormat.setBorder(1);
+ frame->setFrameFormat(frameFormat);
+//! [9]
+
+//! [10]
+ QTextCharFormat format = cursor.charFormat();
+ format.setFontPointSize(fontSize);
+
+ QTextCharFormat boldFormat = format;
+ boldFormat.setFontWeight(QFont::Bold);
+
+ QTextCharFormat highlightedFormat = boldFormat;
+ highlightedFormat.setBackground(Qt::yellow);
+//! [10]
+
+//! [11]
+ for (int weekDay = 1; weekDay <= 7; ++weekDay) {
+ QTextTableCell cell = table->cellAt(0, weekDay-1);
+//! [11] //! [12]
+ QTextCursor cellCursor = cell.firstCursorPosition();
+ cellCursor.insertText(QString("%1").arg(QDate::longDayName(weekDay)),
+ boldFormat);
+ }
+//! [12]
+
+//! [13]
+ table->insertRows(table->rows(), 1);
+//! [13]
+
+ while (date.month() == selectedDate.month()) {
+ int weekDay = date.dayOfWeek();
+ QTextTableCell cell = table->cellAt(table->rows()-1, weekDay-1);
+ QTextCursor cellCursor = cell.firstCursorPosition();
+
+ if (date == QDate::currentDate())
+ cellCursor.insertText(QString("%1").arg(date.day()), highlightedFormat);
+ else
+ cellCursor.insertText(QString("%1").arg(date.day()), format);
+
+ date = date.addDays(1);
+ if (weekDay == 7 && date.month() == selectedDate.month())
+ table->insertRows(table->rows(), 1);
+ }
+
+ cursor.endEditBlock();
+//! [14]
+ setWindowTitle(tr("Calendar for %1 %2"
+ ).arg(QDate::longMonthName(selectedDate.month())
+ ).arg(selectedDate.year()));
+}
+//! [14]
+
+//! [15]
+void MainWindow::setFontSize(int size)
+{
+ fontSize = size;
+ insertCalendar();
+}
+//! [15]
+
+//! [16]
+void MainWindow::setMonth(int month)
+{
+ selectedDate = QDate(selectedDate.year(), month + 1, selectedDate.day());
+ insertCalendar();
+}
+//! [16]
+
+//! [17]
+void MainWindow::setYear(QDate date)
+{
+ selectedDate = QDate(date.year(), selectedDate.month(), selectedDate.day());
+ insertCalendar();
+}
+//! [17]
diff --git a/examples/widgets/richtext/calendar/mainwindow.h b/examples/widgets/richtext/calendar/mainwindow.h
new file mode 100644
index 0000000000..665452b688
--- /dev/null
+++ b/examples/widgets/richtext/calendar/mainwindow.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QDate>
+#include <QMainWindow>
+
+QT_BEGIN_NAMESPACE
+class QTextBrowser;
+QT_END_NAMESPACE
+
+//! [0]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+
+public slots:
+ void setFontSize(int size);
+ void setMonth(int month);
+ void setYear(QDate date);
+
+private:
+ void insertCalendar();
+
+ int fontSize;
+ QDate selectedDate;
+ QTextBrowser *editor;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/richtext/orderform/detailsdialog.cpp b/examples/widgets/richtext/orderform/detailsdialog.cpp
new file mode 100644
index 0000000000..3dbdee58c7
--- /dev/null
+++ b/examples/widgets/richtext/orderform/detailsdialog.cpp
@@ -0,0 +1,156 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "detailsdialog.h"
+
+//! [0]
+DetailsDialog::DetailsDialog(const QString &title, QWidget *parent)
+ : QDialog(parent)
+{
+ nameLabel = new QLabel(tr("Name:"));
+ addressLabel = new QLabel(tr("Address:"));
+ addressLabel->setAlignment(Qt::AlignLeft | Qt::AlignTop);
+
+ nameEdit = new QLineEdit;
+ addressEdit = new QTextEdit;
+
+ offersCheckBox = new QCheckBox(tr("Send information about products and "
+ "special offers"));
+
+ setupItemsTable();
+
+ buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
+ | QDialogButtonBox::Cancel);
+
+ connect(buttonBox, SIGNAL(accepted()), this, SLOT(verify()));
+ connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+//! [0]
+
+//! [1]
+ QGridLayout *mainLayout = new QGridLayout;
+ mainLayout->addWidget(nameLabel, 0, 0);
+ mainLayout->addWidget(nameEdit, 0, 1);
+ mainLayout->addWidget(addressLabel, 1, 0);
+ mainLayout->addWidget(addressEdit, 1, 1);
+ mainLayout->addWidget(itemsTable, 0, 2, 2, 1);
+ mainLayout->addWidget(offersCheckBox, 2, 1, 1, 2);
+ mainLayout->addWidget(buttonBox, 3, 0, 1, 3);
+ setLayout(mainLayout);
+
+ setWindowTitle(title);
+}
+//! [1]
+
+//! [2]
+void DetailsDialog::setupItemsTable()
+{
+ items << tr("T-shirt") << tr("Badge") << tr("Reference book")
+ << tr("Coffee cup");
+
+ itemsTable = new QTableWidget(items.count(), 2);
+
+ for (int row = 0; row < items.count(); ++row) {
+ QTableWidgetItem *name = new QTableWidgetItem(items[row]);
+ name->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
+ itemsTable->setItem(row, 0, name);
+ QTableWidgetItem *quantity = new QTableWidgetItem("1");
+ itemsTable->setItem(row, 1, quantity);
+ }
+}
+//! [2]
+
+//! [3]
+QList<QPair<QString, int> > DetailsDialog::orderItems()
+{
+ QList<QPair<QString, int> > orderList;
+
+ for (int row = 0; row < items.count(); ++row) {
+ QPair<QString, int> item;
+ item.first = itemsTable->item(row, 0)->text();
+ int quantity = itemsTable->item(row, 1)->data(Qt::DisplayRole).toInt();
+ item.second = qMax(0, quantity);
+ orderList.append(item);
+ }
+
+ return orderList;
+}
+//! [3]
+
+//! [4]
+QString DetailsDialog::senderName() const
+{
+ return nameEdit->text();
+}
+//! [4]
+
+//! [5]
+QString DetailsDialog::senderAddress() const
+{
+ return addressEdit->toPlainText();
+}
+//! [5]
+
+//! [6]
+bool DetailsDialog::sendOffers()
+{
+ return offersCheckBox->isChecked();
+}
+//! [6]
+
+//! [7]
+void DetailsDialog::verify()
+{
+ if (!nameEdit->text().isEmpty() && !addressEdit->toPlainText().isEmpty()) {
+ accept();
+ return;
+ }
+
+ QMessageBox::StandardButton answer;
+ answer = QMessageBox::warning(this, tr("Incomplete Form"),
+ tr("The form does not contain all the necessary information.\n"
+ "Do you want to discard it?"),
+ QMessageBox::Yes | QMessageBox::No);
+
+ if (answer == QMessageBox::Yes)
+ reject();
+}
+//! [7]
diff --git a/examples/widgets/richtext/orderform/detailsdialog.h b/examples/widgets/richtext/orderform/detailsdialog.h
new file mode 100644
index 0000000000..ee964d082e
--- /dev/null
+++ b/examples/widgets/richtext/orderform/detailsdialog.h
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DETAILSDIALOG_H
+#define DETAILSDIALOG_H
+
+#include <QDialog>
+#include <QList>
+#include <QPair>
+#include <QString>
+
+QT_BEGIN_NAMESPACE
+class QCheckBox;
+class QDialogButtonBox;
+class QLabel;
+class QLineEdit;
+class QTableWidget;
+class QTextEdit;
+class QWidget;
+QT_END_NAMESPACE
+
+//! [0]
+class DetailsDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ DetailsDialog(const QString &title, QWidget *parent);
+
+public slots:
+ void verify();
+
+public:
+ QList<QPair<QString, int> > orderItems();
+ QString senderName() const;
+ QString senderAddress() const;
+ bool sendOffers();
+
+private:
+ void setupItemsTable();
+
+ QLabel *nameLabel;
+ QLabel *addressLabel;
+ QCheckBox *offersCheckBox;
+ QLineEdit *nameEdit;
+ QStringList items;
+ QTableWidget *itemsTable;
+ QTextEdit *addressEdit;
+ QDialogButtonBox *buttonBox;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/richtext/orderform/main.cpp b/examples/widgets/richtext/orderform/main.cpp
new file mode 100644
index 0000000000..fc14fbb625
--- /dev/null
+++ b/examples/widgets/richtext/orderform/main.cpp
@@ -0,0 +1,55 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "mainwindow.h"
+
+//! [0]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.resize(640, 480);
+ window.show();
+ window.createSample();
+ return app.exec();
+}
+//! [0]
diff --git a/examples/widgets/richtext/orderform/mainwindow.cpp b/examples/widgets/richtext/orderform/mainwindow.cpp
new file mode 100644
index 0000000000..44b3cb4f9a
--- /dev/null
+++ b/examples/widgets/richtext/orderform/mainwindow.cpp
@@ -0,0 +1,253 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+#ifndef QT_NO_PRINTER
+#include <QPrinter>
+#include <QPrintDialog>
+#endif
+
+#include "detailsdialog.h"
+#include "mainwindow.h"
+
+//! [0]
+MainWindow::MainWindow()
+{
+ QMenu *fileMenu = new QMenu(tr("&File"), this);
+ QAction *newAction = fileMenu->addAction(tr("&New..."));
+ newAction->setShortcuts(QKeySequence::New);
+ printAction = fileMenu->addAction(tr("&Print..."), this, SLOT(printFile()));
+ printAction->setShortcuts(QKeySequence::Print);
+ printAction->setEnabled(false);
+ QAction *quitAction = fileMenu->addAction(tr("E&xit"));
+ quitAction->setShortcuts(QKeySequence::Quit);
+ menuBar()->addMenu(fileMenu);
+
+ letters = new QTabWidget;
+
+ connect(newAction, SIGNAL(triggered()), this, SLOT(openDialog()));
+ connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));
+
+ setCentralWidget(letters);
+ setWindowTitle(tr("Order Form"));
+}
+//! [0]
+
+//! [1]
+void MainWindow::createLetter(const QString &name, const QString &address,
+ QList<QPair<QString,int> > orderItems,
+ bool sendOffers)
+{
+ QTextEdit *editor = new QTextEdit;
+ int tabIndex = letters->addTab(editor, name);
+ letters->setCurrentIndex(tabIndex);
+//! [1]
+
+//! [2]
+ QTextCursor cursor(editor->textCursor());
+ cursor.movePosition(QTextCursor::Start);
+//! [2] //! [3]
+ QTextFrame *topFrame = cursor.currentFrame();
+ QTextFrameFormat topFrameFormat = topFrame->frameFormat();
+ topFrameFormat.setPadding(16);
+ topFrame->setFrameFormat(topFrameFormat);
+
+ QTextCharFormat textFormat;
+ QTextCharFormat boldFormat;
+ boldFormat.setFontWeight(QFont::Bold);
+
+ QTextFrameFormat referenceFrameFormat;
+ referenceFrameFormat.setBorder(1);
+ referenceFrameFormat.setPadding(8);
+ referenceFrameFormat.setPosition(QTextFrameFormat::FloatRight);
+ referenceFrameFormat.setWidth(QTextLength(QTextLength::PercentageLength, 40));
+ cursor.insertFrame(referenceFrameFormat);
+
+ cursor.insertText("A company", boldFormat);
+ cursor.insertBlock();
+ cursor.insertText("321 City Street");
+ cursor.insertBlock();
+ cursor.insertText("Industry Park");
+ cursor.insertBlock();
+ cursor.insertText("Another country");
+//! [3]
+
+//! [4]
+ cursor.setPosition(topFrame->lastPosition());
+
+ cursor.insertText(name, textFormat);
+ QString line;
+ foreach (line, address.split("\n")) {
+ cursor.insertBlock();
+ cursor.insertText(line);
+ }
+//! [4] //! [5]
+ cursor.insertBlock();
+ cursor.insertBlock();
+
+ QDate date = QDate::currentDate();
+ cursor.insertText(tr("Date: %1").arg(date.toString("d MMMM yyyy")),
+ textFormat);
+ cursor.insertBlock();
+
+ QTextFrameFormat bodyFrameFormat;
+ bodyFrameFormat.setWidth(QTextLength(QTextLength::PercentageLength, 100));
+ cursor.insertFrame(bodyFrameFormat);
+//! [5]
+
+//! [6]
+ cursor.insertText(tr("I would like to place an order for the following "
+ "items:"), textFormat);
+ cursor.insertBlock();
+//! [6] //! [7]
+ cursor.insertBlock();
+//! [7]
+
+//! [8]
+ QTextTableFormat orderTableFormat;
+ orderTableFormat.setAlignment(Qt::AlignHCenter);
+ QTextTable *orderTable = cursor.insertTable(1, 2, orderTableFormat);
+
+ QTextFrameFormat orderFrameFormat = cursor.currentFrame()->frameFormat();
+ orderFrameFormat.setBorder(1);
+ cursor.currentFrame()->setFrameFormat(orderFrameFormat);
+//! [8]
+
+//! [9]
+ cursor = orderTable->cellAt(0, 0).firstCursorPosition();
+ cursor.insertText(tr("Product"), boldFormat);
+ cursor = orderTable->cellAt(0, 1).firstCursorPosition();
+ cursor.insertText(tr("Quantity"), boldFormat);
+//! [9]
+
+//! [10]
+ for (int i = 0; i < orderItems.count(); ++i) {
+ QPair<QString,int> item = orderItems[i];
+ int row = orderTable->rows();
+
+ orderTable->insertRows(row, 1);
+ cursor = orderTable->cellAt(row, 0).firstCursorPosition();
+ cursor.insertText(item.first, textFormat);
+ cursor = orderTable->cellAt(row, 1).firstCursorPosition();
+ cursor.insertText(QString("%1").arg(item.second), textFormat);
+ }
+//! [10]
+
+//! [11]
+ cursor.setPosition(topFrame->lastPosition());
+
+ cursor.insertBlock();
+//! [11] //! [12]
+ cursor.insertText(tr("Please update my records to take account of the "
+ "following privacy information:"));
+ cursor.insertBlock();
+//! [12]
+
+//! [13]
+ QTextTable *offersTable = cursor.insertTable(2, 2);
+
+ cursor = offersTable->cellAt(0, 1).firstCursorPosition();
+ cursor.insertText(tr("I want to receive more information about your "
+ "company's products and special offers."), textFormat);
+ cursor = offersTable->cellAt(1, 1).firstCursorPosition();
+ cursor.insertText(tr("I do not want to receive any promotional information "
+ "from your company."), textFormat);
+
+ if (sendOffers)
+ cursor = offersTable->cellAt(0, 0).firstCursorPosition();
+ else
+ cursor = offersTable->cellAt(1, 0).firstCursorPosition();
+
+ cursor.insertText("X", boldFormat);
+//! [13]
+
+//! [14]
+ cursor.setPosition(topFrame->lastPosition());
+ cursor.insertBlock();
+ cursor.insertText(tr("Sincerely,"), textFormat);
+ cursor.insertBlock();
+ cursor.insertBlock();
+ cursor.insertBlock();
+ cursor.insertText(name);
+
+ printAction->setEnabled(true);
+}
+//! [14]
+
+//! [15]
+void MainWindow::createSample()
+{
+ DetailsDialog dialog("Dialog with default values", this);
+ createLetter("Mr. Smith", "12 High Street\nSmall Town\nThis country",
+ dialog.orderItems(), true);
+}
+//! [15]
+
+//! [16]
+void MainWindow::openDialog()
+{
+ DetailsDialog dialog(tr("Enter Customer Details"), this);
+
+ if (dialog.exec() == QDialog::Accepted)
+ createLetter(dialog.senderName(), dialog.senderAddress(),
+ dialog.orderItems(), dialog.sendOffers());
+}
+//! [16]
+
+//! [17]
+void MainWindow::printFile()
+{
+#ifndef QT_NO_PRINTER
+ QTextEdit *editor = static_cast<QTextEdit*>(letters->currentWidget());
+//! [18]
+ QPrinter printer;
+
+ QPrintDialog *dialog = new QPrintDialog(&printer, this);
+ dialog->setWindowTitle(tr("Print Document"));
+ if (editor->textCursor().hasSelection())
+ dialog->addEnabledOption(QAbstractPrintDialog::PrintSelection);
+ if (dialog->exec() != QDialog::Accepted)
+ return;
+//! [18]
+
+ editor->print(&printer);
+#endif
+}
+//! [17]
diff --git a/examples/widgets/richtext/orderform/mainwindow.h b/examples/widgets/richtext/orderform/mainwindow.h
new file mode 100644
index 0000000000..e688f42a80
--- /dev/null
+++ b/examples/widgets/richtext/orderform/mainwindow.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QList>
+#include <QMainWindow>
+#include <QPair>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QTabWidget;
+QT_END_NAMESPACE
+
+//! [0]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+ void createSample();
+
+public slots:
+ void openDialog();
+ void printFile();
+
+private:
+ void createLetter(const QString &name, const QString &address,
+ QList<QPair<QString,int> > orderItems,
+ bool sendOffers);
+
+ QAction *printAction;
+ QTabWidget *letters;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/richtext/orderform/orderform.desktop b/examples/widgets/richtext/orderform/orderform.desktop
new file mode 100644
index 0000000000..4690cbc876
--- /dev/null
+++ b/examples/widgets/richtext/orderform/orderform.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Order Form
+Exec=/opt/usr/bin/orderform
+Icon=orderform
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/richtext/orderform/orderform.pro b/examples/widgets/richtext/orderform/orderform.pro
new file mode 100644
index 0000000000..4aefb99428
--- /dev/null
+++ b/examples/widgets/richtext/orderform/orderform.pro
@@ -0,0 +1,14 @@
+HEADERS = detailsdialog.h \
+ mainwindow.h
+SOURCES = detailsdialog.cpp \
+ main.cpp \
+ mainwindow.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/richtext/orderform
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS orderform.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/richtext/orderform
+INSTALLS += target sources
+
+QT += widgets
+!isEmpty(QT.printsupport.name): QT += printsupport
diff --git a/examples/widgets/richtext/richtext.pro b/examples/widgets/richtext/richtext.pro
new file mode 100644
index 0000000000..511edb9ea9
--- /dev/null
+++ b/examples/widgets/richtext/richtext.pro
@@ -0,0 +1,11 @@
+TEMPLATE = subdirs
+SUBDIRS = calendar \
+ orderform \
+ syntaxhighlighter \
+ textedit
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/richtext
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS richtext.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/richtext
+INSTALLS += target sources
diff --git a/examples/widgets/richtext/syntaxhighlighter/highlighter.cpp b/examples/widgets/richtext/syntaxhighlighter/highlighter.cpp
new file mode 100644
index 0000000000..826e132110
--- /dev/null
+++ b/examples/widgets/richtext/syntaxhighlighter/highlighter.cpp
@@ -0,0 +1,147 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "highlighter.h"
+
+//! [0]
+Highlighter::Highlighter(QTextDocument *parent)
+ : QSyntaxHighlighter(parent)
+{
+ HighlightingRule rule;
+
+ keywordFormat.setForeground(Qt::darkBlue);
+ keywordFormat.setFontWeight(QFont::Bold);
+ QStringList keywordPatterns;
+ keywordPatterns << "\\bchar\\b" << "\\bclass\\b" << "\\bconst\\b"
+ << "\\bdouble\\b" << "\\benum\\b" << "\\bexplicit\\b"
+ << "\\bfriend\\b" << "\\binline\\b" << "\\bint\\b"
+ << "\\blong\\b" << "\\bnamespace\\b" << "\\boperator\\b"
+ << "\\bprivate\\b" << "\\bprotected\\b" << "\\bpublic\\b"
+ << "\\bshort\\b" << "\\bsignals\\b" << "\\bsigned\\b"
+ << "\\bslots\\b" << "\\bstatic\\b" << "\\bstruct\\b"
+ << "\\btemplate\\b" << "\\btypedef\\b" << "\\btypename\\b"
+ << "\\bunion\\b" << "\\bunsigned\\b" << "\\bvirtual\\b"
+ << "\\bvoid\\b" << "\\bvolatile\\b";
+ foreach (const QString &pattern, keywordPatterns) {
+ rule.pattern = QRegExp(pattern);
+ rule.format = keywordFormat;
+ highlightingRules.append(rule);
+//! [0] //! [1]
+ }
+//! [1]
+
+//! [2]
+ classFormat.setFontWeight(QFont::Bold);
+ classFormat.setForeground(Qt::darkMagenta);
+ rule.pattern = QRegExp("\\bQ[A-Za-z]+\\b");
+ rule.format = classFormat;
+ highlightingRules.append(rule);
+//! [2]
+
+//! [3]
+ singleLineCommentFormat.setForeground(Qt::red);
+ rule.pattern = QRegExp("//[^\n]*");
+ rule.format = singleLineCommentFormat;
+ highlightingRules.append(rule);
+
+ multiLineCommentFormat.setForeground(Qt::red);
+//! [3]
+
+//! [4]
+ quotationFormat.setForeground(Qt::darkGreen);
+ rule.pattern = QRegExp("\".*\"");
+ rule.format = quotationFormat;
+ highlightingRules.append(rule);
+//! [4]
+
+//! [5]
+ functionFormat.setFontItalic(true);
+ functionFormat.setForeground(Qt::blue);
+ rule.pattern = QRegExp("\\b[A-Za-z0-9_]+(?=\\()");
+ rule.format = functionFormat;
+ highlightingRules.append(rule);
+//! [5]
+
+//! [6]
+ commentStartExpression = QRegExp("/\\*");
+ commentEndExpression = QRegExp("\\*/");
+}
+//! [6]
+
+//! [7]
+void Highlighter::highlightBlock(const QString &text)
+{
+ foreach (const HighlightingRule &rule, highlightingRules) {
+ QRegExp expression(rule.pattern);
+ int index = expression.indexIn(text);
+ while (index >= 0) {
+ int length = expression.matchedLength();
+ setFormat(index, length, rule.format);
+ index = expression.indexIn(text, index + length);
+ }
+ }
+//! [7] //! [8]
+ setCurrentBlockState(0);
+//! [8]
+
+//! [9]
+ int startIndex = 0;
+ if (previousBlockState() != 1)
+ startIndex = commentStartExpression.indexIn(text);
+
+//! [9] //! [10]
+ while (startIndex >= 0) {
+//! [10] //! [11]
+ int endIndex = commentEndExpression.indexIn(text, startIndex);
+ int commentLength;
+ if (endIndex == -1) {
+ setCurrentBlockState(1);
+ commentLength = text.length() - startIndex;
+ } else {
+ commentLength = endIndex - startIndex
+ + commentEndExpression.matchedLength();
+ }
+ setFormat(startIndex, commentLength, multiLineCommentFormat);
+ startIndex = commentStartExpression.indexIn(text, startIndex + commentLength);
+ }
+}
+//! [11]
diff --git a/examples/widgets/richtext/syntaxhighlighter/highlighter.h b/examples/widgets/richtext/syntaxhighlighter/highlighter.h
new file mode 100644
index 0000000000..3f75063f89
--- /dev/null
+++ b/examples/widgets/richtext/syntaxhighlighter/highlighter.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef HIGHLIGHTER_H
+#define HIGHLIGHTER_H
+
+#include <QSyntaxHighlighter>
+
+#include <QHash>
+#include <QTextCharFormat>
+
+QT_BEGIN_NAMESPACE
+class QTextDocument;
+QT_END_NAMESPACE
+
+//! [0]
+class Highlighter : public QSyntaxHighlighter
+{
+ Q_OBJECT
+
+public:
+ Highlighter(QTextDocument *parent = 0);
+
+protected:
+ void highlightBlock(const QString &text);
+
+private:
+ struct HighlightingRule
+ {
+ QRegExp pattern;
+ QTextCharFormat format;
+ };
+ QVector<HighlightingRule> highlightingRules;
+
+ QRegExp commentStartExpression;
+ QRegExp commentEndExpression;
+
+ QTextCharFormat keywordFormat;
+ QTextCharFormat classFormat;
+ QTextCharFormat singleLineCommentFormat;
+ QTextCharFormat multiLineCommentFormat;
+ QTextCharFormat quotationFormat;
+ QTextCharFormat functionFormat;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/richtext/syntaxhighlighter/main.cpp b/examples/widgets/richtext/syntaxhighlighter/main.cpp
new file mode 100644
index 0000000000..5c2f0f236d
--- /dev/null
+++ b/examples/widgets/richtext/syntaxhighlighter/main.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ MainWindow window;
+ window.resize(640, 512);
+ window.show();
+ return app.exec();
+}
diff --git a/examples/widgets/richtext/syntaxhighlighter/mainwindow.cpp b/examples/widgets/richtext/syntaxhighlighter/mainwindow.cpp
new file mode 100644
index 0000000000..ffb02ebb9b
--- /dev/null
+++ b/examples/widgets/richtext/syntaxhighlighter/mainwindow.cpp
@@ -0,0 +1,128 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+#include "mainwindow.h"
+
+//! [0]
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent)
+{
+ setupFileMenu();
+ setupHelpMenu();
+ setupEditor();
+
+ setCentralWidget(editor);
+ setWindowTitle(tr("Syntax Highlighter"));
+}
+//! [0]
+
+void MainWindow::about()
+{
+ QMessageBox::about(this, tr("About Syntax Highlighter"),
+ tr("<p>The <b>Syntax Highlighter</b> example shows how " \
+ "to perform simple syntax highlighting by subclassing " \
+ "the QSyntaxHighlighter class and describing " \
+ "highlighting rules using regular expressions.</p>"));
+}
+
+void MainWindow::newFile()
+{
+ editor->clear();
+}
+
+void MainWindow::openFile(const QString &path)
+{
+ QString fileName = path;
+
+ if (fileName.isNull())
+ fileName = QFileDialog::getOpenFileName(this,
+ tr("Open File"), "", "C++ Files (*.cpp *.h)");
+
+ if (!fileName.isEmpty()) {
+ QFile file(fileName);
+ if (file.open(QFile::ReadOnly | QFile::Text))
+ editor->setPlainText(file.readAll());
+ }
+}
+
+//! [1]
+void MainWindow::setupEditor()
+{
+ QFont font;
+ font.setFamily("Courier");
+ font.setFixedPitch(true);
+ font.setPointSize(10);
+
+ editor = new QTextEdit;
+ editor->setFont(font);
+
+ highlighter = new Highlighter(editor->document());
+
+ QFile file("mainwindow.h");
+ if (file.open(QFile::ReadOnly | QFile::Text))
+ editor->setPlainText(file.readAll());
+}
+//! [1]
+
+void MainWindow::setupFileMenu()
+{
+ QMenu *fileMenu = new QMenu(tr("&File"), this);
+ menuBar()->addMenu(fileMenu);
+
+ fileMenu->addAction(tr("&New"), this, SLOT(newFile()),
+ QKeySequence::New);
+
+ fileMenu->addAction(tr("&Open..."), this, SLOT(openFile()),
+ QKeySequence::Open);
+
+ fileMenu->addAction(tr("E&xit"), qApp, SLOT(quit()),
+ QKeySequence::Quit);
+}
+
+void MainWindow::setupHelpMenu()
+{
+ QMenu *helpMenu = new QMenu(tr("&Help"), this);
+ menuBar()->addMenu(helpMenu);
+
+ helpMenu->addAction(tr("&About"), this, SLOT(about()));
+ helpMenu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt()));
+}
diff --git a/examples/widgets/richtext/syntaxhighlighter/mainwindow.h b/examples/widgets/richtext/syntaxhighlighter/mainwindow.h
new file mode 100644
index 0000000000..082ea77ba4
--- /dev/null
+++ b/examples/widgets/richtext/syntaxhighlighter/mainwindow.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
+** the names of its contributors may be used to endorse or promote
+** products derived from this software without specific prior written
+** permission.
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+#include "highlighter.h"
+
+QT_BEGIN_NAMESPACE
+class QTextEdit;
+QT_END_NAMESPACE
+
+//! [0]
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ MainWindow(QWidget *parent = 0);
+
+public slots:
+ void about();
+ void newFile();
+ void openFile(const QString &path = QString());
+
+private:
+ void setupEditor();
+ void setupFileMenu();
+ void setupHelpMenu();
+
+ QTextEdit *editor;
+ Highlighter *highlighter;
+};
+//! [0]
+
+#endif
diff --git a/examples/widgets/richtext/syntaxhighlighter/syntaxhighlighter.desktop b/examples/widgets/richtext/syntaxhighlighter/syntaxhighlighter.desktop
new file mode 100644
index 0000000000..2e3c833f0e
--- /dev/null
+++ b/examples/widgets/richtext/syntaxhighlighter/syntaxhighlighter.desktop
@@ -0,0 +1,11 @@
+[Desktop Entry]
+Encoding=UTF-8
+Version=1.0
+Type=Application
+Terminal=false
+Name=Syntax Highlighter
+Exec=/opt/usr/bin/syntaxhighlighter
+Icon=syntaxhighlighter
+X-Window-Icon=
+X-HildonDesk-ShowInToolbar=true
+X-Osso-Type=application/x-executable
diff --git a/examples/widgets/richtext/syntaxhighlighter/syntaxhighlighter.pro b/examples/widgets/richtext/syntaxhighlighter/syntaxhighlighter.pro
new file mode 100644
index 0000000000..0f9b447a74
--- /dev/null
+++ b/examples/widgets/richtext/syntaxhighlighter/syntaxhighlighter.pro
@@ -0,0 +1,20 @@
+HEADERS = highlighter.h \
+ mainwindow.h
+SOURCES = highlighter.cpp \
+ mainwindow.cpp \
+ main.cpp
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/richtext/syntaxhighlighter
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS syntaxhighlighter.pro examples
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/richtext/syntaxhighlighter
+INSTALLS += target sources
+
+
+wince*: {
+ addFiles.files = main.cpp mainwindow.cpp
+ addFiles.path = .
+ DEPLOYMENT += addFiles
+}
+QT += widgets
+
diff --git a/examples/widgets/richtext/textedit/example.html b/examples/widgets/richtext/textedit/example.html
new file mode 100644
index 0000000000..cdc8d2a23d
--- /dev/null
+++ b/examples/widgets/richtext/textedit/example.html
@@ -0,0 +1,79 @@
+<html><head><meta name="qrichtext" content="1" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>QTextEdit Example</title><style type="text/css">
+p, li { white-space: pre-wrap; }
+</style></head><body style=" font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;">
+<p align="center" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:20pt; font-weight:600;">QTextEdit</span></p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:11pt;">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.</span></p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">If you are viewing this document in the <span style=" font-style:italic;">textedit</span> 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. </p>
+<p style=" margin-top:16px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:18pt; font-weight:600;"><span style=" font-size:16pt;">Font and Paragraph Styles</span></p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:11pt;">QTextEdit supports </span><span style=" font-size:11pt; font-weight:600;">bold</span><span style=" font-size:11pt;">, </span><span style=" font-size:11pt; font-style:italic;">italic</span><span style=" font-size:11pt;">, and </span><span style=" font-size:11pt; text-decoration: underline;">underlined</span><span style=" font-size:11pt;"> font styles, and can display </span><span style=" font-size:11pt; font-weight:600; color:#00007f;">multicolored</span><span style=" font-size:11pt;"> </span><span style=" font-size:11pt; font-weight:600; color:#aa0000;">text</span><span style=" font-size:11pt;">. Font families such as </span><span style=" font-family:'Times'; font-size:11pt; font-weight:600;">Times New Roman</span><span style=" font-size:11pt;"> and </span><span style=" font-family:'Courier'; font-size:11pt; font-weight:600;">Courier</span><span style=" font-size:11pt;"> can also be used directly. </span><span style=" font-size:11pt; font-style:italic;">If you place the cursor in a region of styled text, the controls in the tool bars will change to reflect the current style.</span></p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">Paragraphs can be formatted so that the text is left-aligned, right-aligned, centered, or fully justified.</p>
+<p align="center" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-style:italic;">Try changing the alignment of some text and resize the editor to see how the text layout changes.</span> </p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:16pt; font-weight:600;">Lists</span></p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:16pt; font-weight:600;"><span style=" font-size:11pt; font-weight:400;">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: </span></p>
+<ul style="-qt-list-indent: 1;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Disc symbols are typically used for top-level list items. </li></ul>
+<ul type=circle style="-qt-list-indent: 2;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Circle symbols can be used to distinguish between items in lower-level lists.</li></ul>
+<ul type=square style="-qt-list-indent: 3;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Square symbols provide a reasonable alternative to discs and circles. </li></ul>
+<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">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: </p>
+<ol style="-qt-list-indent: 1;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Introduction</li>
+<li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Qt Tools </li></ol>
+<ol type=a style="-qt-list-indent: 2;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Qt Assistant</li>
+<li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Qt Designer</li>
+<ol type=A style="-qt-list-indent: 3;"><li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Form Editor</li>
+<li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Component Architecture</li></ol>
+<li style=" font-size:11pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Qt Linguist</li></ol>
+<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">The list will automatically be renumbered if you add or remove items. <span style=" font-style:italic;">Try adding new sections to the above list or removing existing item to see the numbers change.</span> </p>
+<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p>
+<p style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-size:16pt; font-weight:600;">Images</span></p>
+<p style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:16pt; font-weight:600;"><span style=" font-size:11pt; font-weight:400;">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. </span></p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><img src=":/images/logo32.png" /><span style=" font-style:italic;"> 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.</span></p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-size:16pt; font-weight:600;">Tables</span></p>
+<p align="justify" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:16pt; font-weight:600;"><span style=" font-size:11pt; font-weight:400;">QTextEdit can arrange and format tables, supporting features such as row and column spans, text formatting within cells, and size constraints for columns. </span></p>
+<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p>
+<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p>
+<table border="1" align="center" width="90%" cellspacing="0" cellpadding="4">
+<tr>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"> </p></td>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Development Tools </span></p></td>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Programming Techniques </span></p></td>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Graphical User Interfaces </span></p></td></tr>
+<tr>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">9:00 - 11:00 </span></p></td>
+<td colspan="3">
+<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Introduction to <span style=" font-style:italic;">Qt </span></p></td></tr>
+<tr>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">11:00 - 13:00 </span></p></td>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Using <span style=" font-style:italic;">qmake</span> </p></td>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Object-oriented Programming </p></td>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Layouts in <span style=" font-style:italic;">Qt</span> </p></td></tr>
+<tr>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">13:00 - 15:00 </span></p></td>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-style:italic;">Qt Designer</span> Tutorial </p></td>
+<td rowspan="2">
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Extreme Programming </p></td>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Writing Custom Styles </p></td></tr>
+<tr>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">15:00 - 17:00 </span></p></td>
+<td>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-style:italic;">Qt Linguist</span> and Internationalization </p></td>
+<td></td></tr></table>
+<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"></p>
+<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt; font-style:italic;">Try adding text to the cells in the table and experiment with the alignment of the paragraphs.</p>
+<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-size:16pt; font-weight:600;">Hyperlinks</span></p>
+<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:11pt;">QTextEdit is designed to support hyperlinks between documents, and this feature is used extensively in </span><span style=" font-size:11pt; font-style:italic;">Qt Assistant</span><span style=" font-size:11pt;">. 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.</span></p>
+<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-size:16pt; font-weight:600;">Undo and Redo</span></p>
+<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;">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.</p>
+<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:11pt;"><span style=" font-style:italic;">Try making changes to this document and press Ctrl+Z to undo them. You can always recover the original contents of the document.</span> </p></body></html>
diff --git a/examples/widgets/richtext/textedit/images/logo32.png b/examples/widgets/richtext/textedit/images/logo32.png
new file mode 100644
index 0000000000..5f91e9873b
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/logo32.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/editcopy.png b/examples/widgets/richtext/textedit/images/mac/editcopy.png
new file mode 100644
index 0000000000..f551364464
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/editcopy.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/editcut.png b/examples/widgets/richtext/textedit/images/mac/editcut.png
new file mode 100644
index 0000000000..a784fd5709
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/editcut.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/editpaste.png b/examples/widgets/richtext/textedit/images/mac/editpaste.png
new file mode 100644
index 0000000000..64c0b2d6ab
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/editpaste.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/editredo.png b/examples/widgets/richtext/textedit/images/mac/editredo.png
new file mode 100644
index 0000000000..8875bf246c
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/editredo.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/editundo.png b/examples/widgets/richtext/textedit/images/mac/editundo.png
new file mode 100644
index 0000000000..a3bd5e0bf2
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/editundo.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/exportpdf.png b/examples/widgets/richtext/textedit/images/mac/exportpdf.png
new file mode 100644
index 0000000000..ebb44e6b88
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/exportpdf.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/filenew.png b/examples/widgets/richtext/textedit/images/mac/filenew.png
new file mode 100644
index 0000000000..d3882c7b3f
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/filenew.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/fileopen.png b/examples/widgets/richtext/textedit/images/mac/fileopen.png
new file mode 100644
index 0000000000..fc06c5ec63
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/fileopen.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/fileprint.png b/examples/widgets/richtext/textedit/images/mac/fileprint.png
new file mode 100644
index 0000000000..10ca56c82a
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/fileprint.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/filesave.png b/examples/widgets/richtext/textedit/images/mac/filesave.png
new file mode 100644
index 0000000000..b41ecf5319
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/filesave.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/textbold.png b/examples/widgets/richtext/textedit/images/mac/textbold.png
new file mode 100644
index 0000000000..38400bd1f6
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/textbold.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/textcenter.png b/examples/widgets/richtext/textedit/images/mac/textcenter.png
new file mode 100644
index 0000000000..2ef5b2ee6f
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/textcenter.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/textitalic.png b/examples/widgets/richtext/textedit/images/mac/textitalic.png
new file mode 100644
index 0000000000..0170ee26a6
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/textitalic.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/textjustify.png b/examples/widgets/richtext/textedit/images/mac/textjustify.png
new file mode 100644
index 0000000000..39cd6c1a9d
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/textjustify.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/textleft.png b/examples/widgets/richtext/textedit/images/mac/textleft.png
new file mode 100644
index 0000000000..83a66d5535
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/textleft.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/textright.png b/examples/widgets/richtext/textedit/images/mac/textright.png
new file mode 100644
index 0000000000..e7c04645cf
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/textright.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/textunder.png b/examples/widgets/richtext/textedit/images/mac/textunder.png
new file mode 100644
index 0000000000..968bac5e90
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/textunder.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/zoomin.png b/examples/widgets/richtext/textedit/images/mac/zoomin.png
new file mode 100644
index 0000000000..d46f5aff0d
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/zoomin.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/mac/zoomout.png b/examples/widgets/richtext/textedit/images/mac/zoomout.png
new file mode 100644
index 0000000000..46326566d1
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/zoomout.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/editcopy.png b/examples/widgets/richtext/textedit/images/win/editcopy.png
new file mode 100644
index 0000000000..1121b47d8b
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/editcopy.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/editcut.png b/examples/widgets/richtext/textedit/images/win/editcut.png
new file mode 100644
index 0000000000..38e55f7420
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/editcut.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/editpaste.png b/examples/widgets/richtext/textedit/images/win/editpaste.png
new file mode 100644
index 0000000000..ffab15aaf8
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/editpaste.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/editredo.png b/examples/widgets/richtext/textedit/images/win/editredo.png
new file mode 100644
index 0000000000..9d679fe6fc
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/editredo.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/editundo.png b/examples/widgets/richtext/textedit/images/win/editundo.png
new file mode 100644
index 0000000000..eee23d24a3
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/editundo.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/exportpdf.png b/examples/widgets/richtext/textedit/images/win/exportpdf.png
new file mode 100644
index 0000000000..eef5132928
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/exportpdf.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/filenew.png b/examples/widgets/richtext/textedit/images/win/filenew.png
new file mode 100644
index 0000000000..af5d122141
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/filenew.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/fileopen.png b/examples/widgets/richtext/textedit/images/win/fileopen.png
new file mode 100644
index 0000000000..fc6f17e977
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/fileopen.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/fileprint.png b/examples/widgets/richtext/textedit/images/win/fileprint.png
new file mode 100644
index 0000000000..ba7c02dc18
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/fileprint.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/filesave.png b/examples/widgets/richtext/textedit/images/win/filesave.png
new file mode 100644
index 0000000000..8feec99bee
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/filesave.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/textbold.png b/examples/widgets/richtext/textedit/images/win/textbold.png
new file mode 100644
index 0000000000..9cbc7138b9
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/textbold.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/textcenter.png b/examples/widgets/richtext/textedit/images/win/textcenter.png
new file mode 100644
index 0000000000..11efb4b852
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/textcenter.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/textitalic.png b/examples/widgets/richtext/textedit/images/win/textitalic.png
new file mode 100644
index 0000000000..b30ce14c14
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/textitalic.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/textjustify.png b/examples/widgets/richtext/textedit/images/win/textjustify.png
new file mode 100644
index 0000000000..9de0c88085
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/textjustify.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/textleft.png b/examples/widgets/richtext/textedit/images/win/textleft.png
new file mode 100644
index 0000000000..16f80bc325
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/textleft.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/textright.png b/examples/widgets/richtext/textedit/images/win/textright.png
new file mode 100644
index 0000000000..16872df62a
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/textright.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/textunder.png b/examples/widgets/richtext/textedit/images/win/textunder.png
new file mode 100644
index 0000000000..c72eff53fb
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/textunder.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/zoomin.png b/examples/widgets/richtext/textedit/images/win/zoomin.png
new file mode 100644
index 0000000000..2e586fc7bf
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/zoomin.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/zoomout.png b/examples/widgets/richtext/textedit/images/win/zoomout.png
new file mode 100644
index 0000000000..a736d39343
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/zoomout.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/main.cpp b/examples/widgets/richtext/textedit/main.cpp
new file mode 100644
index 0000000000..ae12cd9979
--- /dev/null
+++ b/examples/widgets/richtext/textedit/main.cpp
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "textedit.h"
+#include <QApplication>
+
+int main( int argc, char ** argv )
+{
+ Q_INIT_RESOURCE(textedit);
+
+ QApplication a( argc, argv );
+ TextEdit mw;
+ mw.resize( 700, 800 );
+ mw.show();
+ return a.exec();
+}
diff --git a/examples/widgets/richtext/textedit/textedit.cpp b/examples/widgets/richtext/textedit/textedit.cpp
new file mode 100644
index 0000000000..0be60230ca
--- /dev/null
+++ b/examples/widgets/richtext/textedit/textedit.cpp
@@ -0,0 +1,737 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "textedit.h"
+
+#include <QAction>
+#include <QApplication>
+#include <QClipboard>
+#include <QColorDialog>
+#include <QComboBox>
+#include <QFontComboBox>
+#include <QFile>
+#include <QFileDialog>
+#include <QFileInfo>
+#include <QFontDatabase>
+#include <QMenu>
+#include <QMenuBar>
+#include <QTextCodec>
+#include <QTextEdit>
+#include <QToolBar>
+#include <QTextCursor>
+#include <QTextDocumentWriter>
+#include <QTextList>
+#include <QtDebug>
+#include <QCloseEvent>
+#include <QMessageBox>
+#include <QMimeData>
+#ifndef QT_NO_PRINTER
+#include <QPrintDialog>
+#include <QPrinter>
+#include <QPrintPreviewDialog>
+#endif
+
+#ifdef Q_OS_MAC
+const QString rsrcPath = ":/images/mac";
+#else
+const QString rsrcPath = ":/images/win";
+#endif
+
+TextEdit::TextEdit(QWidget *parent)
+ : QMainWindow(parent)
+{
+ setToolButtonStyle(Qt::ToolButtonFollowStyle);
+ setupFileActions();
+ setupEditActions();
+ setupTextActions();
+
+ {
+ QMenu *helpMenu = new QMenu(tr("Help"), this);
+ menuBar()->addMenu(helpMenu);
+ helpMenu->addAction(tr("About"), this, SLOT(about()));
+ helpMenu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt()));
+ }
+
+ textEdit = new QTextEdit(this);
+ connect(textEdit, SIGNAL(currentCharFormatChanged(QTextCharFormat)),
+ this, SLOT(currentCharFormatChanged(QTextCharFormat)));
+ connect(textEdit, SIGNAL(cursorPositionChanged()),
+ this, SLOT(cursorPositionChanged()));
+
+ setCentralWidget(textEdit);
+ textEdit->setFocus();
+ setCurrentFileName(QString());
+
+ fontChanged(textEdit->font());
+ colorChanged(textEdit->textColor());
+ alignmentChanged(textEdit->alignment());
+
+ connect(textEdit->document(), SIGNAL(modificationChanged(bool)),
+ actionSave, SLOT(setEnabled(bool)));
+ connect(textEdit->document(), SIGNAL(modificationChanged(bool)),
+ this, SLOT(setWindowModified(bool)));
+ connect(textEdit->document(), SIGNAL(undoAvailable(bool)),
+ actionUndo, SLOT(setEnabled(bool)));
+ connect(textEdit->document(), SIGNAL(redoAvailable(bool)),
+ actionRedo, SLOT(setEnabled(bool)));
+
+ setWindowModified(textEdit->document()->isModified());
+ actionSave->setEnabled(textEdit->document()->isModified());
+ actionUndo->setEnabled(textEdit->document()->isUndoAvailable());
+ actionRedo->setEnabled(textEdit->document()->isRedoAvailable());
+
+ connect(actionUndo, SIGNAL(triggered()), textEdit, SLOT(undo()));
+ connect(actionRedo, SIGNAL(triggered()), textEdit, SLOT(redo()));
+
+ actionCut->setEnabled(false);
+ actionCopy->setEnabled(false);
+
+ connect(actionCut, SIGNAL(triggered()), textEdit, SLOT(cut()));
+ connect(actionCopy, SIGNAL(triggered()), textEdit, SLOT(copy()));
+ connect(actionPaste, SIGNAL(triggered()), textEdit, SLOT(paste()));
+
+ connect(textEdit, SIGNAL(copyAvailable(bool)), actionCut, SLOT(setEnabled(bool)));
+ connect(textEdit, SIGNAL(copyAvailable(bool)), actionCopy, SLOT(setEnabled(bool)));
+
+#ifndef QT_NO_CLIPBOARD
+ connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged()));
+#endif
+
+ QString initialFile = ":/example.html";
+ const QStringList args = QCoreApplication::arguments();
+ if (args.count() == 2)
+ initialFile = args.at(1);
+
+ if (!load(initialFile))
+ fileNew();
+}
+
+void TextEdit::closeEvent(QCloseEvent *e)
+{
+ if (maybeSave())
+ e->accept();
+ else
+ e->ignore();
+}
+
+void TextEdit::setupFileActions()
+{
+ QToolBar *tb = new QToolBar(this);
+ tb->setWindowTitle(tr("File Actions"));
+ addToolBar(tb);
+
+ QMenu *menu = new QMenu(tr("&File"), this);
+ menuBar()->addMenu(menu);
+
+ QAction *a;
+
+ QIcon newIcon = QIcon::fromTheme("document-new", QIcon(rsrcPath + "/filenew.png"));
+ a = new QAction( newIcon, tr("&New"), this);
+ a->setPriority(QAction::LowPriority);
+ a->setShortcut(QKeySequence::New);
+ connect(a, SIGNAL(triggered()), this, SLOT(fileNew()));
+ tb->addAction(a);
+ menu->addAction(a);
+
+ a = new QAction(QIcon::fromTheme("document-open", QIcon(rsrcPath + "/fileopen.png")),
+ tr("&Open..."), this);
+ a->setShortcut(QKeySequence::Open);
+ connect(a, SIGNAL(triggered()), this, SLOT(fileOpen()));
+ tb->addAction(a);
+ menu->addAction(a);
+
+ menu->addSeparator();
+
+ actionSave = a = new QAction(QIcon::fromTheme("document-save", QIcon(rsrcPath + "/filesave.png")),
+ tr("&Save"), this);
+ a->setShortcut(QKeySequence::Save);
+ connect(a, SIGNAL(triggered()), this, SLOT(fileSave()));
+ a->setEnabled(false);
+ tb->addAction(a);
+ menu->addAction(a);
+
+ a = new QAction(tr("Save &As..."), this);
+ a->setPriority(QAction::LowPriority);
+ connect(a, SIGNAL(triggered()), this, SLOT(fileSaveAs()));
+ menu->addAction(a);
+ menu->addSeparator();
+
+#ifndef QT_NO_PRINTER
+ a = new QAction(QIcon::fromTheme("document-print", QIcon(rsrcPath + "/fileprint.png")),
+ tr("&Print..."), this);
+ a->setPriority(QAction::LowPriority);
+ a->setShortcut(QKeySequence::Print);
+ connect(a, SIGNAL(triggered()), this, SLOT(filePrint()));
+ tb->addAction(a);
+ menu->addAction(a);
+
+ a = new QAction(QIcon::fromTheme("fileprint", QIcon(rsrcPath + "/fileprint.png")),
+ tr("Print Preview..."), this);
+ connect(a, SIGNAL(triggered()), this, SLOT(filePrintPreview()));
+ menu->addAction(a);
+
+ a = new QAction(QIcon::fromTheme("exportpdf", QIcon(rsrcPath + "/exportpdf.png")),
+ tr("&Export PDF..."), this);
+ a->setPriority(QAction::LowPriority);
+ a->setShortcut(Qt::CTRL + Qt::Key_D);
+ connect(a, SIGNAL(triggered()), this, SLOT(filePrintPdf()));
+ tb->addAction(a);
+ menu->addAction(a);
+
+ menu->addSeparator();
+#endif
+
+ a = new QAction(tr("&Quit"), this);
+ a->setShortcut(Qt::CTRL + Qt::Key_Q);
+ connect(a, SIGNAL(triggered()), this, SLOT(close()));
+ menu->addAction(a);
+}
+
+void TextEdit::setupEditActions()
+{
+ QToolBar *tb = new QToolBar(this);
+ tb->setWindowTitle(tr("Edit Actions"));
+ addToolBar(tb);
+ QMenu *menu = new QMenu(tr("&Edit"), this);
+ menuBar()->addMenu(menu);
+
+ QAction *a;
+ a = actionUndo = new QAction(QIcon::fromTheme("edit-undo", QIcon(rsrcPath + "/editundo.png")),
+ tr("&Undo"), this);
+ a->setShortcut(QKeySequence::Undo);
+ tb->addAction(a);
+ menu->addAction(a);
+ a = actionRedo = new QAction(QIcon::fromTheme("edit-redo", QIcon(rsrcPath + "/editredo.png")),
+ tr("&Redo"), this);
+ a->setPriority(QAction::LowPriority);
+ a->setShortcut(QKeySequence::Redo);
+ tb->addAction(a);
+ menu->addAction(a);
+ menu->addSeparator();
+ a = actionCut = new QAction(QIcon::fromTheme("edit-cut", QIcon(rsrcPath + "/editcut.png")),
+ tr("Cu&t"), this);
+ a->setPriority(QAction::LowPriority);
+ a->setShortcut(QKeySequence::Cut);
+ tb->addAction(a);
+ menu->addAction(a);
+ a = actionCopy = new QAction(QIcon::fromTheme("edit-copy", QIcon(rsrcPath + "/editcopy.png")),
+ tr("&Copy"), this);
+ a->setPriority(QAction::LowPriority);
+ a->setShortcut(QKeySequence::Copy);
+ tb->addAction(a);
+ menu->addAction(a);
+ a = actionPaste = new QAction(QIcon::fromTheme("edit-paste", QIcon(rsrcPath + "/editpaste.png")),
+ tr("&Paste"), this);
+ a->setPriority(QAction::LowPriority);
+ a->setShortcut(QKeySequence::Paste);
+ tb->addAction(a);
+ menu->addAction(a);
+#ifndef QT_NO_CLIPBOARD
+ if (const QMimeData *md = QApplication::clipboard()->mimeData())
+ actionPaste->setEnabled(md->hasText());
+#endif
+}
+
+void TextEdit::setupTextActions()
+{
+ QToolBar *tb = new QToolBar(this);
+ tb->setWindowTitle(tr("Format Actions"));
+ addToolBar(tb);
+
+ QMenu *menu = new QMenu(tr("F&ormat"), this);
+ menuBar()->addMenu(menu);
+
+ actionTextBold = new QAction(QIcon::fromTheme("format-text-bold", QIcon(rsrcPath + "/textbold.png")),
+ tr("&Bold"), this);
+ actionTextBold->setShortcut(Qt::CTRL + Qt::Key_B);
+ actionTextBold->setPriority(QAction::LowPriority);
+ QFont bold;
+ bold.setBold(true);
+ actionTextBold->setFont(bold);
+ connect(actionTextBold, SIGNAL(triggered()), this, SLOT(textBold()));
+ tb->addAction(actionTextBold);
+ menu->addAction(actionTextBold);
+ actionTextBold->setCheckable(true);
+
+ actionTextItalic = new QAction(QIcon::fromTheme("format-text-italic", QIcon(rsrcPath + "/textitalic.png")),
+ tr("&Italic"), this);
+ actionTextItalic->setPriority(QAction::LowPriority);
+ actionTextItalic->setShortcut(Qt::CTRL + Qt::Key_I);
+ QFont italic;
+ italic.setItalic(true);
+ actionTextItalic->setFont(italic);
+ connect(actionTextItalic, SIGNAL(triggered()), this, SLOT(textItalic()));
+ tb->addAction(actionTextItalic);
+ menu->addAction(actionTextItalic);
+ actionTextItalic->setCheckable(true);
+
+ actionTextUnderline = new QAction(QIcon::fromTheme("format-text-underline", QIcon(rsrcPath + "/textunder.png")),
+ tr("&Underline"), this);
+ actionTextUnderline->setShortcut(Qt::CTRL + Qt::Key_U);
+ actionTextUnderline->setPriority(QAction::LowPriority);
+ QFont underline;
+ underline.setUnderline(true);
+ actionTextUnderline->setFont(underline);
+ connect(actionTextUnderline, SIGNAL(triggered()), this, SLOT(textUnderline()));
+ tb->addAction(actionTextUnderline);
+ menu->addAction(actionTextUnderline);
+ actionTextUnderline->setCheckable(true);
+
+ menu->addSeparator();
+
+ QActionGroup *grp = new QActionGroup(this);
+ connect(grp, SIGNAL(triggered(QAction*)), this, SLOT(textAlign(QAction*)));
+
+ // Make sure the alignLeft is always left of the alignRight
+ if (QApplication::isLeftToRight()) {
+ actionAlignLeft = new QAction(QIcon::fromTheme("format-justify-left", QIcon(rsrcPath + "/textleft.png")),
+ tr("&Left"), grp);
+ actionAlignCenter = new QAction(QIcon::fromTheme("format-justify-center", QIcon(rsrcPath + "/textcenter.png")), tr("C&enter"), grp);
+ actionAlignRight = new QAction(QIcon::fromTheme("format-justify-right", QIcon(rsrcPath + "/textright.png")), tr("&Right"), grp);
+ } else {
+ actionAlignRight = new QAction(QIcon::fromTheme("format-justify-right", QIcon(rsrcPath + "/textright.png")), tr("&Right"), grp);
+ actionAlignCenter = new QAction(QIcon::fromTheme("format-justify-center", QIcon(rsrcPath + "/textcenter.png")), tr("C&enter"), grp);
+ actionAlignLeft = new QAction(QIcon::fromTheme("format-justify-left", QIcon(rsrcPath + "/textleft.png")), tr("&Left"), grp);
+ }
+ actionAlignJustify = new QAction(QIcon::fromTheme("format-justify-fill", QIcon(rsrcPath + "/textjustify.png")), tr("&Justify"), grp);
+
+ actionAlignLeft->setShortcut(Qt::CTRL + Qt::Key_L);
+ actionAlignLeft->setCheckable(true);
+ actionAlignLeft->setPriority(QAction::LowPriority);
+ actionAlignCenter->setShortcut(Qt::CTRL + Qt::Key_E);
+ actionAlignCenter->setCheckable(true);
+ actionAlignCenter->setPriority(QAction::LowPriority);
+ actionAlignRight->setShortcut(Qt::CTRL + Qt::Key_R);
+ actionAlignRight->setCheckable(true);
+ actionAlignRight->setPriority(QAction::LowPriority);
+ actionAlignJustify->setShortcut(Qt::CTRL + Qt::Key_J);
+ actionAlignJustify->setCheckable(true);
+ actionAlignJustify->setPriority(QAction::LowPriority);
+
+ tb->addActions(grp->actions());
+ menu->addActions(grp->actions());
+
+ menu->addSeparator();
+
+ QPixmap pix(16, 16);
+ pix.fill(Qt::black);
+ actionTextColor = new QAction(pix, tr("&Color..."), this);
+ connect(actionTextColor, SIGNAL(triggered()), this, SLOT(textColor()));
+ tb->addAction(actionTextColor);
+ menu->addAction(actionTextColor);
+
+
+ tb = new QToolBar(this);
+ tb->setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea);
+ tb->setWindowTitle(tr("Format Actions"));
+ addToolBarBreak(Qt::TopToolBarArea);
+ addToolBar(tb);
+
+ comboStyle = new QComboBox(tb);
+ tb->addWidget(comboStyle);
+ comboStyle->addItem("Standard");
+ comboStyle->addItem("Bullet List (Disc)");
+ comboStyle->addItem("Bullet List (Circle)");
+ comboStyle->addItem("Bullet List (Square)");
+ comboStyle->addItem("Ordered List (Decimal)");
+ comboStyle->addItem("Ordered List (Alpha lower)");
+ comboStyle->addItem("Ordered List (Alpha upper)");
+ comboStyle->addItem("Ordered List (Roman lower)");
+ comboStyle->addItem("Ordered List (Roman upper)");
+ connect(comboStyle, SIGNAL(activated(int)),
+ this, SLOT(textStyle(int)));
+
+ comboFont = new QFontComboBox(tb);
+ tb->addWidget(comboFont);
+ connect(comboFont, SIGNAL(activated(QString)),
+ this, SLOT(textFamily(QString)));
+
+ comboSize = new QComboBox(tb);
+ comboSize->setObjectName("comboSize");
+ tb->addWidget(comboSize);
+ comboSize->setEditable(true);
+
+ QFontDatabase db;
+ foreach(int size, db.standardSizes())
+ comboSize->addItem(QString::number(size));
+
+ connect(comboSize, SIGNAL(activated(QString)),
+ this, SLOT(textSize(QString)));
+ comboSize->setCurrentIndex(comboSize->findText(QString::number(QApplication::font()
+ .pointSize())));
+}
+
+bool TextEdit::load(const QString &f)
+{
+ if (!QFile::exists(f))
+ return false;
+ QFile file(f);
+ if (!file.open(QFile::ReadOnly))
+ return false;
+
+ QByteArray data = file.readAll();
+ QTextCodec *codec = Qt::codecForHtml(data);
+ QString str = codec->toUnicode(data);
+ if (Qt::mightBeRichText(str)) {
+ textEdit->setHtml(str);
+ } else {
+ str = QString::fromLocal8Bit(data);
+ textEdit->setPlainText(str);
+ }
+
+ setCurrentFileName(f);
+ return true;
+}
+
+bool TextEdit::maybeSave()
+{
+ if (!textEdit->document()->isModified())
+ return true;
+ if (fileName.startsWith(QLatin1String(":/")))
+ return true;
+ QMessageBox::StandardButton ret;
+ ret = QMessageBox::warning(this, tr("Application"),
+ tr("The document has been modified.\n"
+ "Do you want to save your changes?"),
+ QMessageBox::Save | QMessageBox::Discard
+ | QMessageBox::Cancel);
+ if (ret == QMessageBox::Save)
+ return fileSave();
+ else if (ret == QMessageBox::Cancel)
+ return false;
+ return true;
+}
+
+void TextEdit::setCurrentFileName(const QString &fileName)
+{
+ this->fileName = fileName;
+ textEdit->document()->setModified(false);
+
+ QString shownName;
+ if (fileName.isEmpty())
+ shownName = "untitled.txt";
+ else
+ shownName = QFileInfo(fileName).fileName();
+
+ setWindowTitle(tr("%1[*] - %2").arg(shownName).arg(tr("Rich Text")));
+ setWindowModified(false);
+}
+
+void TextEdit::fileNew()
+{
+ if (maybeSave()) {
+ textEdit->clear();
+ setCurrentFileName(QString());
+ }
+}
+
+void TextEdit::fileOpen()
+{
+ QString fn = QFileDialog::getOpenFileName(this, tr("Open File..."),
+ QString(), tr("HTML-Files (*.htm *.html);;All Files (*)"));
+ if (!fn.isEmpty())
+ load(fn);
+}
+
+bool TextEdit::fileSave()
+{
+ if (fileName.isEmpty())
+ return fileSaveAs();
+
+ QTextDocumentWriter writer(fileName);
+ bool success = writer.write(textEdit->document());
+ if (success)
+ textEdit->document()->setModified(false);
+ return success;
+}
+
+bool TextEdit::fileSaveAs()
+{
+ QString fn = QFileDialog::getSaveFileName(this, tr("Save as..."),
+ QString(), tr("ODF files (*.odt);;HTML-Files (*.htm *.html);;All Files (*)"));
+ if (fn.isEmpty())
+ return false;
+ if (! (fn.endsWith(".odt", Qt::CaseInsensitive) || fn.endsWith(".htm", Qt::CaseInsensitive) || fn.endsWith(".html", Qt::CaseInsensitive)) )
+ fn += ".odt"; // default
+ setCurrentFileName(fn);
+ return fileSave();
+}
+
+void TextEdit::filePrint()
+{
+#ifndef QT_NO_PRINTER
+ QPrinter printer(QPrinter::HighResolution);
+ QPrintDialog *dlg = new QPrintDialog(&printer, this);
+ if (textEdit->textCursor().hasSelection())
+ dlg->addEnabledOption(QAbstractPrintDialog::PrintSelection);
+ dlg->setWindowTitle(tr("Print Document"));
+ if (dlg->exec() == QDialog::Accepted) {
+ textEdit->print(&printer);
+ }
+ delete dlg;
+#endif
+}
+
+void TextEdit::filePrintPreview()
+{
+#ifndef QT_NO_PRINTER
+ QPrinter printer(QPrinter::HighResolution);
+ QPrintPreviewDialog preview(&printer, this);
+ connect(&preview, SIGNAL(paintRequested(QPrinter*)), SLOT(printPreview(QPrinter*)));
+ preview.exec();
+#endif
+}
+
+void TextEdit::printPreview(QPrinter *printer)
+{
+#ifdef QT_NO_PRINTER
+ Q_UNUSED(printer);
+#else
+ textEdit->print(printer);
+#endif
+}
+
+
+void TextEdit::filePrintPdf()
+{
+#ifndef QT_NO_PRINTER
+//! [0]
+ QString fileName = QFileDialog::getSaveFileName(this, "Export PDF",
+ QString(), "*.pdf");
+ if (!fileName.isEmpty()) {
+ if (QFileInfo(fileName).suffix().isEmpty())
+ fileName.append(".pdf");
+ QPrinter printer(QPrinter::HighResolution);
+ printer.setOutputFormat(QPrinter::PdfFormat);
+ printer.setOutputFileName(fileName);
+ textEdit->document()->print(&printer);
+ }
+//! [0]
+#endif
+}
+
+void TextEdit::textBold()
+{
+ QTextCharFormat fmt;
+ fmt.setFontWeight(actionTextBold->isChecked() ? QFont::Bold : QFont::Normal);
+ mergeFormatOnWordOrSelection(fmt);
+}
+
+void TextEdit::textUnderline()
+{
+ QTextCharFormat fmt;
+ fmt.setFontUnderline(actionTextUnderline->isChecked());
+ mergeFormatOnWordOrSelection(fmt);
+}
+
+void TextEdit::textItalic()
+{
+ QTextCharFormat fmt;
+ fmt.setFontItalic(actionTextItalic->isChecked());
+ mergeFormatOnWordOrSelection(fmt);
+}
+
+void TextEdit::textFamily(const QString &f)
+{
+ QTextCharFormat fmt;
+ fmt.setFontFamily(f);
+ mergeFormatOnWordOrSelection(fmt);
+}
+
+void TextEdit::textSize(const QString &p)
+{
+ qreal pointSize = p.toFloat();
+ if (p.toFloat() > 0) {
+ QTextCharFormat fmt;
+ fmt.setFontPointSize(pointSize);
+ mergeFormatOnWordOrSelection(fmt);
+ }
+}
+
+void TextEdit::textStyle(int styleIndex)
+{
+ QTextCursor cursor = textEdit->textCursor();
+
+ if (styleIndex != 0) {
+ QTextListFormat::Style style = QTextListFormat::ListDisc;
+
+ switch (styleIndex) {
+ default:
+ case 1:
+ style = QTextListFormat::ListDisc;
+ break;
+ case 2:
+ style = QTextListFormat::ListCircle;
+ break;
+ case 3:
+ style = QTextListFormat::ListSquare;
+ break;
+ case 4:
+ style = QTextListFormat::ListDecimal;
+ break;
+ case 5:
+ style = QTextListFormat::ListLowerAlpha;
+ break;
+ case 6:
+ style = QTextListFormat::ListUpperAlpha;
+ break;
+ case 7:
+ style = QTextListFormat::ListLowerRoman;
+ break;
+ case 8:
+ style = QTextListFormat::ListUpperRoman;
+ break;
+ }
+
+ cursor.beginEditBlock();
+
+ QTextBlockFormat blockFmt = cursor.blockFormat();
+
+ QTextListFormat listFmt;
+
+ if (cursor.currentList()) {
+ listFmt = cursor.currentList()->format();
+ } else {
+ listFmt.setIndent(blockFmt.indent() + 1);
+ blockFmt.setIndent(0);
+ cursor.setBlockFormat(blockFmt);
+ }
+
+ listFmt.setStyle(style);
+
+ cursor.createList(listFmt);
+
+ cursor.endEditBlock();
+ } else {
+ // ####
+ QTextBlockFormat bfmt;
+ bfmt.setObjectIndex(-1);
+ cursor.mergeBlockFormat(bfmt);
+ }
+}
+
+void TextEdit::textColor()
+{
+ QColor col = QColorDialog::getColor(textEdit->textColor(), this);
+ if (!col.isValid())
+ return;
+ QTextCharFormat fmt;
+ fmt.setForeground(col);
+ mergeFormatOnWordOrSelection(fmt);
+ colorChanged(col);
+}
+
+void TextEdit::textAlign(QAction *a)
+{
+ if (a == actionAlignLeft)
+ textEdit->setAlignment(Qt::AlignLeft | Qt::AlignAbsolute);
+ else if (a == actionAlignCenter)
+ textEdit->setAlignment(Qt::AlignHCenter);
+ else if (a == actionAlignRight)
+ textEdit->setAlignment(Qt::AlignRight | Qt::AlignAbsolute);
+ else if (a == actionAlignJustify)
+ textEdit->setAlignment(Qt::AlignJustify);
+}
+
+void TextEdit::currentCharFormatChanged(const QTextCharFormat &format)
+{
+ fontChanged(format.font());
+ colorChanged(format.foreground().color());
+}
+
+void TextEdit::cursorPositionChanged()
+{
+ alignmentChanged(textEdit->alignment());
+}
+
+void TextEdit::clipboardDataChanged()
+{
+#ifndef QT_NO_CLIPBOARD
+ if (const QMimeData *md = QApplication::clipboard()->mimeData())
+ actionPaste->setEnabled(md->hasText());
+#endif
+}
+
+void TextEdit::about()
+{
+ QMessageBox::about(this, tr("About"), tr("This example demonstrates Qt's "
+ "rich text editing facilities in action, providing an example "
+ "document for you to experiment with."));
+}
+
+void TextEdit::mergeFormatOnWordOrSelection(const QTextCharFormat &format)
+{
+ QTextCursor cursor = textEdit->textCursor();
+ if (!cursor.hasSelection())
+ cursor.select(QTextCursor::WordUnderCursor);
+ cursor.mergeCharFormat(format);
+ textEdit->mergeCurrentCharFormat(format);
+}
+
+void TextEdit::fontChanged(const QFont &f)
+{
+ comboFont->setCurrentIndex(comboFont->findText(QFontInfo(f).family()));
+ comboSize->setCurrentIndex(comboSize->findText(QString::number(f.pointSize())));
+ actionTextBold->setChecked(f.bold());
+ actionTextItalic->setChecked(f.italic());
+ actionTextUnderline->setChecked(f.underline());
+}
+
+void TextEdit::colorChanged(const QColor &c)
+{
+ QPixmap pix(16, 16);
+ pix.fill(c);
+ actionTextColor->setIcon(pix);
+}
+
+void TextEdit::alignmentChanged(Qt::Alignment a)
+{
+ if (a & Qt::AlignLeft) {
+ actionAlignLeft->setChecked(true);
+ } else if (a & Qt::AlignHCenter) {
+ actionAlignCenter->setChecked(true);
+ } else if (a & Qt::AlignRight) {
+ actionAlignRight->setChecked(true);
+ } else if (a & Qt::AlignJustify) {
+ actionAlignJustify->setChecked(true);
+ }
+}
+
diff --git a/examples/widgets/richtext/textedit/textedit.h b/examples/widgets/richtext/textedit/textedit.h
new file mode 100644
index 0000000000..e04fde4604
--- /dev/null
+++ b/examples/widgets/richtext/textedit/textedit.h
@@ -0,0 +1,130 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the demonstration applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TEXTEDIT_H
+#define TEXTEDIT_H
+
+#include <QMainWindow>
+#include <QMap>
+#include <QPointer>
+
+QT_FORWARD_DECLARE_CLASS(QAction)
+QT_FORWARD_DECLARE_CLASS(QComboBox)
+QT_FORWARD_DECLARE_CLASS(QFontComboBox)
+QT_FORWARD_DECLARE_CLASS(QTextEdit)
+QT_FORWARD_DECLARE_CLASS(QTextCharFormat)
+QT_FORWARD_DECLARE_CLASS(QMenu)
+QT_FORWARD_DECLARE_CLASS(QPrinter)
+
+class TextEdit : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ TextEdit(QWidget *parent = 0);
+
+protected:
+ virtual void closeEvent(QCloseEvent *e);
+
+private:
+ void setupFileActions();
+ void setupEditActions();
+ void setupTextActions();
+ bool load(const QString &f);
+ bool maybeSave();
+ void setCurrentFileName(const QString &fileName);
+
+private slots:
+ void fileNew();
+ void fileOpen();
+ bool fileSave();
+ bool fileSaveAs();
+ void filePrint();
+ void filePrintPreview();
+ void filePrintPdf();
+
+ void textBold();
+ void textUnderline();
+ void textItalic();
+ void textFamily(const QString &f);
+ void textSize(const QString &p);
+ void textStyle(int styleIndex);
+ void textColor();
+ void textAlign(QAction *a);
+
+ void currentCharFormatChanged(const QTextCharFormat &format);
+ void cursorPositionChanged();
+
+ void clipboardDataChanged();
+ void about();
+ void printPreview(QPrinter *);
+
+private:
+ void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
+ void fontChanged(const QFont &f);
+ void colorChanged(const QColor &c);
+ void alignmentChanged(Qt::Alignment a);
+
+ QAction *actionSave,
+ *actionTextBold,
+ *actionTextUnderline,
+ *actionTextItalic,
+ *actionTextColor,
+ *actionAlignLeft,
+ *actionAlignCenter,
+ *actionAlignRight,
+ *actionAlignJustify,
+ *actionUndo,
+ *actionRedo,
+ *actionCut,
+ *actionCopy,
+ *actionPaste;
+
+ QComboBox *comboStyle;
+ QFontComboBox *comboFont;
+ QComboBox *comboSize;
+
+ QToolBar *tb;
+ QString fileName;
+ QTextEdit *textEdit;
+};
+
+#endif
diff --git a/examples/widgets/richtext/textedit/textedit.pro b/examples/widgets/richtext/textedit/textedit.pro
new file mode 100644
index 0000000000..e172e79fe6
--- /dev/null
+++ b/examples/widgets/richtext/textedit/textedit.pro
@@ -0,0 +1,23 @@
+TEMPLATE = app
+TARGET = textedit
+
+CONFIG += qt warn_on
+
+HEADERS = textedit.h
+SOURCES = textedit.cpp \
+ main.cpp
+
+RESOURCES += textedit.qrc
+build_all:!build_pass {
+ CONFIG -= build_all
+ CONFIG += release
+}
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/richtext/textedit
+sources.files = $$SOURCES $$HEADERS $$RESOURCES *.pro *.html *.doc images
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/richtext/textedit
+INSTALLS += target sources
+
+QT += widgets
+!isEmpty(QT.printsupport.name): QT += printsupport
diff --git a/examples/widgets/richtext/textedit/textedit.qdoc b/examples/widgets/richtext/textedit/textedit.qdoc
new file mode 100644
index 0000000000..7a3aa76ab6
--- /dev/null
+++ b/examples/widgets/richtext/textedit/textedit.qdoc
@@ -0,0 +1,45 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:FDL$
+** GNU Free Documentation License
+** Alternatively, this file may be used under the terms of the GNU Free
+** Documentation License version 1.3 as published by the Free Software
+** Foundation and appearing in the file included in the packaging of
+** this file.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms
+** and conditions contained in a signed written agreement between you
+** and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*! \page textedit-example.html
+
+ \ingroup examples
+ \title Text Edit Example
+
+ This example displays a text editor with the user interface written
+ in pure C++.
+
+ A similar example which uses \link designer-manual.book Qt
+ Designer\endlink to produce the user interface is in the \link
+ designer-manual.book Qt Designer manual\endlink.
+
+
+ See \c{$QTDIR/examples/textedit} for the source code.
+
+*/
+
+
diff --git a/examples/widgets/richtext/textedit/textedit.qrc b/examples/widgets/richtext/textedit/textedit.qrc
new file mode 100644
index 0000000000..7d6efd7d67
--- /dev/null
+++ b/examples/widgets/richtext/textedit/textedit.qrc
@@ -0,0 +1,44 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource prefix="/">
+ <file>images/logo32.png</file>
+ <file>images/mac/editcopy.png</file>
+ <file>images/mac/editcut.png</file>
+ <file>images/mac/editpaste.png</file>
+ <file>images/mac/editredo.png</file>
+ <file>images/mac/editundo.png</file>
+ <file>images/mac/exportpdf.png</file>
+ <file>images/mac/filenew.png</file>
+ <file>images/mac/fileopen.png</file>
+ <file>images/mac/fileprint.png</file>
+ <file>images/mac/filesave.png</file>
+ <file>images/mac/textbold.png</file>
+ <file>images/mac/textcenter.png</file>
+ <file>images/mac/textitalic.png</file>
+ <file>images/mac/textjustify.png</file>
+ <file>images/mac/textleft.png</file>
+ <file>images/mac/textright.png</file>
+ <file>images/mac/textunder.png</file>
+ <file>images/mac/zoomin.png</file>
+ <file>images/mac/zoomout.png</file>
+ <file>images/win/editcopy.png</file>
+ <file>images/win/editcut.png</file>
+ <file>images/win/editpaste.png</file>
+ <file>images/win/editredo.png</file>
+ <file>images/win/editundo.png</file>
+ <file>images/win/exportpdf.png</file>
+ <file>images/win/filenew.png</file>
+ <file>images/win/fileopen.png</file>
+ <file>images/win/fileprint.png</file>
+ <file>images/win/filesave.png</file>
+ <file>images/win/textbold.png</file>
+ <file>images/win/textcenter.png</file>
+ <file>images/win/textitalic.png</file>
+ <file>images/win/textjustify.png</file>
+ <file>images/win/textleft.png</file>
+ <file>images/win/textright.png</file>
+ <file>images/win/textunder.png</file>
+ <file>images/win/zoomin.png</file>
+ <file>images/win/zoomout.png</file>
+ <file>example.html</file>
+</qresource>
+</RCC>