diff options
Diffstat (limited to 'examples/widgets/richtext')
-rw-r--r-- | examples/widgets/richtext/calendar/mainwindow.cpp | 10 | ||||
-rw-r--r-- | examples/widgets/richtext/orderform/mainwindow.cpp | 6 | ||||
-rw-r--r-- | examples/widgets/richtext/syntaxhighlighter/highlighter.cpp | 39 | ||||
-rw-r--r-- | examples/widgets/richtext/syntaxhighlighter/mainwindow.cpp | 13 | ||||
-rw-r--r-- | examples/widgets/richtext/textedit/images/mac/exportpdf.png | bin | 1215 -> 12637 bytes | |||
-rw-r--r-- | examples/widgets/richtext/textedit/images/mac/filesave.png | bin | 1206 -> 2699 bytes | |||
-rw-r--r-- | examples/widgets/richtext/textedit/images/win/exportpdf.png | bin | 1059 -> 1215 bytes | |||
-rw-r--r-- | examples/widgets/richtext/textedit/textedit.cpp | 6 |
8 files changed, 40 insertions, 34 deletions
diff --git a/examples/widgets/richtext/calendar/mainwindow.cpp b/examples/widgets/richtext/calendar/mainwindow.cpp index 38dc0e2849..3ddb1cf7ad 100644 --- a/examples/widgets/richtext/calendar/mainwindow.cpp +++ b/examples/widgets/richtext/calendar/mainwindow.cpp @@ -86,10 +86,12 @@ MainWindow::MainWindow() //! [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))); + connect(monthCombo, QOverload<int>::of(&QComboBox::activated), + this, &MainWindow::setMonth); + connect(yearEdit, &QDateTimeEdit::dateChanged, + this, &MainWindow::setYear); + connect(fontSizeSpinBox, QOverload<int>::of(&QSpinBox::valueChanged), + this, &MainWindow::setFontSize); //! [3] fontSizeSpinBox->setValue(10); diff --git a/examples/widgets/richtext/orderform/mainwindow.cpp b/examples/widgets/richtext/orderform/mainwindow.cpp index b207ee4dbc..0b6a2cac6c 100644 --- a/examples/widgets/richtext/orderform/mainwindow.cpp +++ b/examples/widgets/richtext/orderform/mainwindow.cpp @@ -66,7 +66,7 @@ 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 = fileMenu->addAction(tr("&Print..."), this, &MainWindow::printFile); printAction->setShortcuts(QKeySequence::Print); printAction->setEnabled(false); QAction *quitAction = fileMenu->addAction(tr("E&xit")); @@ -126,8 +126,8 @@ void MainWindow::createLetter(const QString &name, const QString &address, cursor.setPosition(topFrame->lastPosition()); cursor.insertText(name, textFormat); - QString line; - foreach (line, address.split("\n")) { + const QStringList lines = address.split('\n'); + for (const QString &line : lines) { cursor.insertBlock(); cursor.insertText(line); } diff --git a/examples/widgets/richtext/syntaxhighlighter/highlighter.cpp b/examples/widgets/richtext/syntaxhighlighter/highlighter.cpp index 6c420c328a..0c10eed6cf 100644 --- a/examples/widgets/richtext/syntaxhighlighter/highlighter.cpp +++ b/examples/widgets/richtext/syntaxhighlighter/highlighter.cpp @@ -58,18 +58,19 @@ Highlighter::Highlighter(QTextDocument *parent) 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" << "\\bbool\\b"; - foreach (const QString &pattern, keywordPatterns) { + const QString keywordPatterns[] = { + QStringLiteral("\\bchar\\b"), QStringLiteral("\\bclass\\b"), QStringLiteral("\\bconst\\b"), + QStringLiteral("\\bdouble\\b"), QStringLiteral("\\benum\\b"), QStringLiteral("\\bexplicit\\b"), + QStringLiteral("\\bfriend\\b"), QStringLiteral("\\binline\\b"), QStringLiteral("\\bint\\b"), + QStringLiteral("\\blong\\b"), QStringLiteral("\\bnamespace\\b"), QStringLiteral("\\boperator\\b"), + QStringLiteral("\\bprivate\\b"), QStringLiteral("\\bprotected\\b"), QStringLiteral("\\bpublic\\b"), + QStringLiteral("\\bshort\\b"), QStringLiteral("\\bsignals\\b"), QStringLiteral("\\bsigned\\b"), + QStringLiteral("\\bslots\\b"), QStringLiteral("\\bstatic\\b"), QStringLiteral("\\bstruct\\b"), + QStringLiteral("\\btemplate\\b"), QStringLiteral("\\btypedef\\b"), QStringLiteral("\\btypename\\b"), + QStringLiteral("\\bunion\\b"), QStringLiteral("\\bunsigned\\b"), QStringLiteral("\\bvirtual\\b"), + QStringLiteral("\\bvoid\\b"), QStringLiteral("\\bvolatile\\b"), QStringLiteral("\\bbool\\b") + }; + for (const QString &pattern : keywordPatterns) { rule.pattern = QRegularExpression(pattern); rule.format = keywordFormat; highlightingRules.append(rule); @@ -80,14 +81,14 @@ Highlighter::Highlighter(QTextDocument *parent) //! [2] classFormat.setFontWeight(QFont::Bold); classFormat.setForeground(Qt::darkMagenta); - rule.pattern = QRegularExpression("\\bQ[A-Za-z]+\\b"); + rule.pattern = QRegularExpression(QStringLiteral("\\bQ[A-Za-z]+\\b")); rule.format = classFormat; highlightingRules.append(rule); //! [2] //! [3] singleLineCommentFormat.setForeground(Qt::red); - rule.pattern = QRegularExpression("//[^\n]*"); + rule.pattern = QRegularExpression(QStringLiteral("//[^\n]*")); rule.format = singleLineCommentFormat; highlightingRules.append(rule); @@ -96,7 +97,7 @@ Highlighter::Highlighter(QTextDocument *parent) //! [4] quotationFormat.setForeground(Qt::darkGreen); - rule.pattern = QRegularExpression("\".*\""); + rule.pattern = QRegularExpression(QStringLiteral("\".*\"")); rule.format = quotationFormat; highlightingRules.append(rule); //! [4] @@ -104,21 +105,21 @@ Highlighter::Highlighter(QTextDocument *parent) //! [5] functionFormat.setFontItalic(true); functionFormat.setForeground(Qt::blue); - rule.pattern = QRegularExpression("\\b[A-Za-z0-9_]+(?=\\()"); + rule.pattern = QRegularExpression(QStringLiteral("\\b[A-Za-z0-9_]+(?=\\()")); rule.format = functionFormat; highlightingRules.append(rule); //! [5] //! [6] - commentStartExpression = QRegularExpression("/\\*"); - commentEndExpression = QRegularExpression("\\*/"); + commentStartExpression = QRegularExpression(QStringLiteral("/\\*")); + commentEndExpression = QRegularExpression(QStringLiteral("\\*/")); } //! [6] //! [7] void Highlighter::highlightBlock(const QString &text) { - foreach (const HighlightingRule &rule, highlightingRules) { + for (const HighlightingRule &rule : qAsConst(highlightingRules)) { QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch(text); while (matchIterator.hasNext()) { QRegularExpressionMatch match = matchIterator.next(); diff --git a/examples/widgets/richtext/syntaxhighlighter/mainwindow.cpp b/examples/widgets/richtext/syntaxhighlighter/mainwindow.cpp index dd58f1f45b..2dba0ba73e 100644 --- a/examples/widgets/richtext/syntaxhighlighter/mainwindow.cpp +++ b/examples/widgets/richtext/syntaxhighlighter/mainwindow.cpp @@ -117,9 +117,12 @@ 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, + &MainWindow::newFile, QKeySequence::New); + fileMenu->addAction(tr("&Open..."), + this, [this](){ openFile(); }, QKeySequence::Open); + fileMenu->addAction(tr("E&xit"), qApp, + &QApplication::quit, QKeySequence::Quit); } void MainWindow::setupHelpMenu() @@ -127,6 +130,6 @@ 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())); + helpMenu->addAction(tr("&About"), this, &MainWindow::about); + helpMenu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt); } diff --git a/examples/widgets/richtext/textedit/images/mac/exportpdf.png b/examples/widgets/richtext/textedit/images/mac/exportpdf.png Binary files differindex ebb44e6b88..9e199407af 100644 --- a/examples/widgets/richtext/textedit/images/mac/exportpdf.png +++ b/examples/widgets/richtext/textedit/images/mac/exportpdf.png diff --git a/examples/widgets/richtext/textedit/images/mac/filesave.png b/examples/widgets/richtext/textedit/images/mac/filesave.png Binary files differindex b41ecf5319..e65a29d5f1 100644 --- a/examples/widgets/richtext/textedit/images/mac/filesave.png +++ b/examples/widgets/richtext/textedit/images/mac/filesave.png diff --git a/examples/widgets/richtext/textedit/images/win/exportpdf.png b/examples/widgets/richtext/textedit/images/win/exportpdf.png Binary files differindex eef5132928..ebb44e6b88 100644 --- a/examples/widgets/richtext/textedit/images/win/exportpdf.png +++ b/examples/widgets/richtext/textedit/images/win/exportpdf.png diff --git a/examples/widgets/richtext/textedit/textedit.cpp b/examples/widgets/richtext/textedit/textedit.cpp index 0d51ce61ad..3ad9f48b67 100644 --- a/examples/widgets/richtext/textedit/textedit.cpp +++ b/examples/widgets/richtext/textedit/textedit.cpp @@ -369,7 +369,7 @@ void TextEdit::setupTextActions() comboFont = new QFontComboBox(tb); tb->addWidget(comboFont); - connect(comboFont, QOverload<const QString &>::of(&QComboBox::activated), this, &TextEdit::textFamily); + connect(comboFont, &QComboBox::textActivated, this, &TextEdit::textFamily); comboSize = new QComboBox(tb); comboSize->setObjectName("comboSize"); @@ -377,11 +377,11 @@ void TextEdit::setupTextActions() comboSize->setEditable(true); const QList<int> standardSizes = QFontDatabase::standardSizes(); - foreach (int size, standardSizes) + for (int size : standardSizes) comboSize->addItem(QString::number(size)); comboSize->setCurrentIndex(standardSizes.indexOf(QApplication::font().pointSize())); - connect(comboSize, QOverload<const QString &>::of(&QComboBox::activated), this, &TextEdit::textSize); + connect(comboSize, &QComboBox::textActivated, this, &TextEdit::textSize); } bool TextEdit::load(const QString &f) |