QtBase: examples/widgets/richtext code style

Change-Id: Ie0c27464e0fdb8f26caf0d8f27043da4ec45f41f
Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
David Schulz 2012-11-23 13:36:40 +01:00 committed by The Qt Project
parent cf1e315e28
commit d5ec06be63
15 changed files with 90 additions and 87 deletions

View File

@ -38,7 +38,7 @@
**
****************************************************************************/
#include <QtWidgets>
#include <QApplication>
#include "mainwindow.h"

View File

@ -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]

View File

@ -70,4 +70,4 @@ private:
};
//! [0]
#endif
#endif // MAINWINDOW_H

View File

@ -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

View File

@ -38,7 +38,7 @@
**
****************************************************************************/
#include <QtWidgets>
#include <QApplication>
#include "mainwindow.h"

View File

@ -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]

View File

@ -73,4 +73,4 @@ private:
};
//! [0]
#endif
#endif // MAINWINDOW_H

View File

@ -38,8 +38,6 @@
**
****************************************************************************/
#include <QtWidgets>
#include "highlighter.h"
//! [0]

View File

@ -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

View File

@ -38,10 +38,10 @@
**
****************************************************************************/
#include <QApplication>
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);

View File

@ -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()

View File

@ -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

View File

@ -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();
}

View File

@ -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);
}
}

View File

@ -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