summaryrefslogtreecommitdiffstats
path: root/examples/widgets/richtext
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/richtext')
-rw-r--r--examples/widgets/richtext/calendar/main.cpp2
-rw-r--r--examples/widgets/richtext/calendar/mainwindow.cpp7
-rw-r--r--examples/widgets/richtext/calendar/mainwindow.h2
-rw-r--r--examples/widgets/richtext/orderform/detailsdialog.h3
-rw-r--r--examples/widgets/richtext/orderform/main.cpp2
-rw-r--r--examples/widgets/richtext/orderform/mainwindow.cpp3
-rw-r--r--examples/widgets/richtext/orderform/mainwindow.h2
-rw-r--r--examples/widgets/richtext/syntaxhighlighter/highlighter.cpp2
-rw-r--r--examples/widgets/richtext/syntaxhighlighter/highlighter.h4
-rw-r--r--examples/widgets/richtext/syntaxhighlighter/main.cpp4
-rw-r--r--examples/widgets/richtext/syntaxhighlighter/mainwindow.cpp14
-rw-r--r--examples/widgets/richtext/syntaxhighlighter/mainwindow.h6
-rw-r--r--examples/widgets/richtext/textedit/main.cpp6
-rw-r--r--examples/widgets/richtext/textedit/textedit.cpp74
-rw-r--r--examples/widgets/richtext/textedit/textedit.h46
15 files changed, 90 insertions, 87 deletions
diff --git a/examples/widgets/richtext/calendar/main.cpp b/examples/widgets/richtext/calendar/main.cpp
index 4fbb6cb4fc..9d78002710 100644
--- a/examples/widgets/richtext/calendar/main.cpp
+++ b/examples/widgets/richtext/calendar/main.cpp
@@ -38,7 +38,7 @@
**
****************************************************************************/
-#include <QtWidgets>
+#include <QApplication>
#include "mainwindow.h"
diff --git a/examples/widgets/richtext/calendar/mainwindow.cpp b/examples/widgets/richtext/calendar/mainwindow.cpp
index 5a0a5cc1d2..3b9dfa83b0 100644
--- a/examples/widgets/richtext/calendar/mainwindow.cpp
+++ b/examples/widgets/richtext/calendar/mainwindow.cpp
@@ -38,10 +38,10 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "mainwindow.h"
+#include <QtWidgets>
+
//! [0]
MainWindow::MainWindow()
{
@@ -158,8 +158,7 @@ void MainWindow::insertCalendar()
QTextTableCell cell = table->cellAt(0, weekDay-1);
//! [11] //! [12]
QTextCursor cellCursor = cell.firstCursorPosition();
- cellCursor.insertText(QString("%1").arg(QDate::longDayName(weekDay)),
- boldFormat);
+ cellCursor.insertText(QString("%1").arg(QDate::longDayName(weekDay)), boldFormat);
}
//! [12]
diff --git a/examples/widgets/richtext/calendar/mainwindow.h b/examples/widgets/richtext/calendar/mainwindow.h
index 340d5b7107..0a53c9460c 100644
--- a/examples/widgets/richtext/calendar/mainwindow.h
+++ b/examples/widgets/richtext/calendar/mainwindow.h
@@ -70,4 +70,4 @@ private:
};
//! [0]
-#endif
+#endif // MAINWINDOW_H
diff --git a/examples/widgets/richtext/orderform/detailsdialog.h b/examples/widgets/richtext/orderform/detailsdialog.h
index ccef66785e..567e79d9ad 100644
--- a/examples/widgets/richtext/orderform/detailsdialog.h
+++ b/examples/widgets/richtext/orderform/detailsdialog.h
@@ -44,7 +44,6 @@
#include <QDialog>
#include <QList>
#include <QPair>
-#include <QString>
QT_BEGIN_NAMESPACE
class QCheckBox;
@@ -87,4 +86,4 @@ private:
};
//! [0]
-#endif
+#endif // DETAILSDIALOG_H
diff --git a/examples/widgets/richtext/orderform/main.cpp b/examples/widgets/richtext/orderform/main.cpp
index c97453b89a..911128336e 100644
--- a/examples/widgets/richtext/orderform/main.cpp
+++ b/examples/widgets/richtext/orderform/main.cpp
@@ -38,7 +38,7 @@
**
****************************************************************************/
-#include <QtWidgets>
+#include <QApplication>
#include "mainwindow.h"
diff --git a/examples/widgets/richtext/orderform/mainwindow.cpp b/examples/widgets/richtext/orderform/mainwindow.cpp
index 8cd16abb20..4334e8bb71 100644
--- a/examples/widgets/richtext/orderform/mainwindow.cpp
+++ b/examples/widgets/richtext/orderform/mainwindow.cpp
@@ -225,9 +225,10 @@ void MainWindow::openDialog()
{
DetailsDialog dialog(tr("Enter Customer Details"), this);
- if (dialog.exec() == QDialog::Accepted)
+ if (dialog.exec() == QDialog::Accepted) {
createLetter(dialog.senderName(), dialog.senderAddress(),
dialog.orderItems(), dialog.sendOffers());
+ }
}
//! [16]
diff --git a/examples/widgets/richtext/orderform/mainwindow.h b/examples/widgets/richtext/orderform/mainwindow.h
index bd93b90475..37bd5dc09b 100644
--- a/examples/widgets/richtext/orderform/mainwindow.h
+++ b/examples/widgets/richtext/orderform/mainwindow.h
@@ -73,4 +73,4 @@ private:
};
//! [0]
-#endif
+#endif // MAINWINDOW_H
diff --git a/examples/widgets/richtext/syntaxhighlighter/highlighter.cpp b/examples/widgets/richtext/syntaxhighlighter/highlighter.cpp
index d84589f938..5c660ddb6d 100644
--- a/examples/widgets/richtext/syntaxhighlighter/highlighter.cpp
+++ b/examples/widgets/richtext/syntaxhighlighter/highlighter.cpp
@@ -38,8 +38,6 @@
**
****************************************************************************/
-#include <QtWidgets>
-
#include "highlighter.h"
//! [0]
diff --git a/examples/widgets/richtext/syntaxhighlighter/highlighter.h b/examples/widgets/richtext/syntaxhighlighter/highlighter.h
index c7ff0b7367..32e91ffa4d 100644
--- a/examples/widgets/richtext/syntaxhighlighter/highlighter.h
+++ b/examples/widgets/richtext/syntaxhighlighter/highlighter.h
@@ -42,8 +42,6 @@
#define HIGHLIGHTER_H
#include <QSyntaxHighlighter>
-
-#include <QHash>
#include <QTextCharFormat>
QT_BEGIN_NAMESPACE
@@ -81,4 +79,4 @@ private:
};
//! [0]
-#endif
+#endif // HIGHLIGHTER_H
diff --git a/examples/widgets/richtext/syntaxhighlighter/main.cpp b/examples/widgets/richtext/syntaxhighlighter/main.cpp
index 61c54138b8..a1a8f4aedf 100644
--- a/examples/widgets/richtext/syntaxhighlighter/main.cpp
+++ b/examples/widgets/richtext/syntaxhighlighter/main.cpp
@@ -38,10 +38,10 @@
**
****************************************************************************/
-#include <QApplication>
-
#include "mainwindow.h"
+#include <QApplication>
+
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
diff --git a/examples/widgets/richtext/syntaxhighlighter/mainwindow.cpp b/examples/widgets/richtext/syntaxhighlighter/mainwindow.cpp
index e8e5015f7b..6c30121e43 100644
--- a/examples/widgets/richtext/syntaxhighlighter/mainwindow.cpp
+++ b/examples/widgets/richtext/syntaxhighlighter/mainwindow.cpp
@@ -74,8 +74,7 @@ void MainWindow::openFile(const QString &path)
QString fileName = path;
if (fileName.isNull())
- fileName = QFileDialog::getOpenFileName(this,
- tr("Open File"), "", "C++ Files (*.cpp *.h)");
+ fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "", "C++ Files (*.cpp *.h)");
if (!fileName.isEmpty()) {
QFile file(fileName);
@@ -108,14 +107,9 @@ 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);
+ 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()
diff --git a/examples/widgets/richtext/syntaxhighlighter/mainwindow.h b/examples/widgets/richtext/syntaxhighlighter/mainwindow.h
index c120b35be6..f50ef22faf 100644
--- a/examples/widgets/richtext/syntaxhighlighter/mainwindow.h
+++ b/examples/widgets/richtext/syntaxhighlighter/mainwindow.h
@@ -41,10 +41,10 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
-#include <QMainWindow>
-
#include "highlighter.h"
+#include <QMainWindow>
+
QT_BEGIN_NAMESPACE
class QTextEdit;
QT_END_NAMESPACE
@@ -72,4 +72,4 @@ private:
};
//! [0]
-#endif
+#endif // MAINWINDOW_H
diff --git a/examples/widgets/richtext/textedit/main.cpp b/examples/widgets/richtext/textedit/main.cpp
index 0fc0b575a8..8a9d6fbb58 100644
--- a/examples/widgets/richtext/textedit/main.cpp
+++ b/examples/widgets/richtext/textedit/main.cpp
@@ -42,13 +42,13 @@
#include "textedit.h"
#include <QApplication>
-int main( int argc, char ** argv )
+int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(textedit);
- QApplication a( argc, argv );
+ QApplication a(argc, argv);
TextEdit mw;
- mw.resize( 700, 800 );
+ 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
index 8f4c38c186..0bdc84a37c 100644
--- a/examples/widgets/richtext/textedit/textedit.cpp
+++ b/examples/widgets/richtext/textedit/textedit.cpp
@@ -39,8 +39,6 @@
**
****************************************************************************/
-#include "textedit.h"
-
#include <QAction>
#include <QApplication>
#include <QClipboard>
@@ -69,6 +67,8 @@
#include <QPrintPreviewDialog>
#endif
+#include "textedit.h"
+
#ifdef Q_OS_MAC
const QString rsrcPath = ":/images/mac";
#else
@@ -209,7 +209,7 @@ void TextEdit::setupFileActions()
menu->addAction(a);
a = new QAction(QIcon::fromTheme("exportpdf", QIcon(rsrcPath + "/exportpdf.png")),
- tr("&Export PDF..."), this);
+ tr("&Export PDF..."), this);
a->setPriority(QAction::LowPriority);
a->setShortcut(Qt::CTRL + Qt::Key_D);
connect(a, SIGNAL(triggered()), this, SLOT(filePrintPdf()));
@@ -291,7 +291,8 @@ void TextEdit::setupTextActions()
menu->addAction(actionTextBold);
actionTextBold->setCheckable(true);
- actionTextItalic = new QAction(QIcon::fromTheme("format-text-italic", QIcon(rsrcPath + "/textitalic.png")),
+ 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);
@@ -303,7 +304,8 @@ void TextEdit::setupTextActions()
menu->addAction(actionTextItalic);
actionTextItalic->setCheckable(true);
- actionTextUnderline = new QAction(QIcon::fromTheme("format-text-underline", QIcon(rsrcPath + "/textunder.png")),
+ 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);
@@ -322,16 +324,29 @@ void TextEdit::setupTextActions()
// 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")),
+ 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);
+ 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);
+ 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);
+ 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);
@@ -358,7 +373,6 @@ void TextEdit::setupTextActions()
tb->addAction(actionTextColor);
menu->addAction(actionTextColor);
-
tb = new QToolBar(this);
tb->setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea);
tb->setWindowTitle(tr("Format Actions"));
@@ -376,13 +390,11 @@ void TextEdit::setupTextActions()
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)));
+ 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)));
+ connect(comboFont, SIGNAL(activated(QString)), this, SLOT(textFamily(QString)));
comboSize = new QComboBox(tb);
comboSize->setObjectName("comboSize");
@@ -393,8 +405,7 @@ void TextEdit::setupTextActions()
foreach(int size, db.standardSizes())
comboSize->addItem(QString::number(size));
- connect(comboSize, SIGNAL(activated(QString)),
- this, SLOT(textSize(QString)));
+ connect(comboSize, SIGNAL(activated(QString)), this, SLOT(textSize(QString)));
comboSize->setCurrentIndex(comboSize->findText(QString::number(QApplication::font()
.pointSize())));
}
@@ -431,8 +442,7 @@ bool TextEdit::maybeSave()
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);
+ QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
if (ret == QMessageBox::Save)
return fileSave();
else if (ret == QMessageBox::Cancel)
@@ -485,12 +495,16 @@ bool TextEdit::fileSave()
bool TextEdit::fileSaveAs()
{
- QString fn = QFileDialog::getSaveFileName(this, tr("Save as..."),
- QString(), tr("ODF files (*.odt);;HTML-Files (*.htm *.html);;All Files (*)"));
+ 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)) )
+ if (!(fn.endsWith(".odt", Qt::CaseInsensitive)
+ || fn.endsWith(".htm", Qt::CaseInsensitive)
+ || fn.endsWith(".html", Qt::CaseInsensitive))) {
fn += ".odt"; // default
+ }
setCurrentFileName(fn);
return fileSave();
}
@@ -503,9 +517,8 @@ void TextEdit::filePrint()
if (textEdit->textCursor().hasSelection())
dlg->addEnabledOption(QAbstractPrintDialog::PrintSelection);
dlg->setWindowTitle(tr("Print Document"));
- if (dlg->exec() == QDialog::Accepted) {
+ if (dlg->exec() == QDialog::Accepted)
textEdit->print(&printer);
- }
delete dlg;
#endif
}
@@ -724,14 +737,13 @@ void TextEdit::colorChanged(const QColor &c)
void TextEdit::alignmentChanged(Qt::Alignment a)
{
- if (a & Qt::AlignLeft) {
+ if (a & Qt::AlignLeft)
actionAlignLeft->setChecked(true);
- } else if (a & Qt::AlignHCenter) {
+ else if (a & Qt::AlignHCenter)
actionAlignCenter->setChecked(true);
- } else if (a & Qt::AlignRight) {
+ else if (a & Qt::AlignRight)
actionAlignRight->setChecked(true);
- } else if (a & Qt::AlignJustify) {
+ else if (a & Qt::AlignJustify)
actionAlignJustify->setChecked(true);
- }
}
diff --git a/examples/widgets/richtext/textedit/textedit.h b/examples/widgets/richtext/textedit/textedit.h
index 2477953d11..87f59ddbf1 100644
--- a/examples/widgets/richtext/textedit/textedit.h
+++ b/examples/widgets/richtext/textedit/textedit.h
@@ -46,13 +46,15 @@
#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)
+QT_BEGIN_NAMESPACE
+class QAction;
+class QComboBox;
+class QFontComboBox;
+class QTextEdit;
+class QTextCharFormat;
+class QMenu;
+class QPrinter;
+QT_END_NAMESPACE
class TextEdit : public QMainWindow
{
@@ -103,20 +105,20 @@ private:
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;
+ QAction *actionSave;
+ QAction *actionTextBold;
+ QAction *actionTextUnderline;
+ QAction *actionTextItalic;
+ QAction *actionTextColor;
+ QAction *actionAlignLeft;
+ QAction *actionAlignCenter;
+ QAction *actionAlignRight;
+ QAction *actionAlignJustify;
+ QAction *actionUndo;
+ QAction *actionRedo;
+ QAction *actionCut;
+ QAction *actionCopy;
+ QAction *actionPaste;
QComboBox *comboStyle;
QFontComboBox *comboFont;
@@ -127,4 +129,4 @@ private:
QTextEdit *textEdit;
};
-#endif
+#endif // TEXTEDIT_H