diff options
Diffstat (limited to 'examples/widgets/painting/shared')
-rw-r--r-- | examples/widgets/painting/shared/arthurstyle.cpp | 10 | ||||
-rw-r--r-- | examples/widgets/painting/shared/arthurwidgets.cpp | 46 | ||||
-rw-r--r-- | examples/widgets/painting/shared/hoverpoints.cpp | 6 |
3 files changed, 34 insertions, 28 deletions
diff --git a/examples/widgets/painting/shared/arthurstyle.cpp b/examples/widgets/painting/shared/arthurstyle.cpp index f4fc76bda6..3fc461bbd2 100644 --- a/examples/widgets/painting/shared/arthurstyle.cpp +++ b/examples/widgets/painting/shared/arthurstyle.cpp @@ -61,10 +61,10 @@ QPixmap cached(const QString &img) { - if (QPixmap *p = QPixmapCache::find(img)) - return *p; - QPixmap pm; + if (QPixmapCache::find(img, &pm)) + return pm; + pm = QPixmap::fromImage(QImage(img), Qt::OrderedDither | Qt::OrderedAlphaDither); if (pm.isNull()) return QPixmap(); @@ -443,9 +443,9 @@ void ArthurStyle::polish(QWidget *widget) if (widget->layout() && qobject_cast<QGroupBox *>(widget)) { if (widget->findChildren<QGroupBox *>().size() == 0) { widget->layout()->setSpacing(0); - widget->layout()->setMargin(12); + widget->layout()->setContentsMargins(12, 12, 12, 12); } else { - widget->layout()->setMargin(13); + widget->layout()->setContentsMargins(13, 13, 13, 13); } } diff --git a/examples/widgets/painting/shared/arthurwidgets.cpp b/examples/widgets/painting/shared/arthurwidgets.cpp index 442fb69ac1..bdac5de13c 100644 --- a/examples/widgets/painting/shared/arthurwidgets.cpp +++ b/examples/widgets/painting/shared/arthurwidgets.cpp @@ -330,32 +330,40 @@ void ArthurFrame::showSource() QString contents; if (m_sourceFileName.isEmpty()) { - contents = QString("No source for widget: '%1'").arg(objectName()); + contents = tr("No source for widget: '%1'").arg(objectName()); } else { QFile f(m_sourceFileName); if (!f.open(QFile::ReadOnly)) - contents = QString("Could not open file: '%1'").arg(m_sourceFileName); + contents = tr("Could not open file: '%1'").arg(m_sourceFileName); else contents = f.readAll(); } - contents.replace('&', "&"); - contents.replace('<', "<"); - contents.replace('>', ">"); - - QStringList keywords; - keywords << "for " << "if " << "switch " << " int " << "#include " << "const" - << "void " << "uint " << "case " << "double " << "#define " << "static" - << "new" << "this"; - - foreach (QString keyword, keywords) + contents.replace(QLatin1Char('&'), QStringLiteral("&")); + contents.replace(QLatin1Char('<'), QStringLiteral("<")); + contents.replace(QLatin1Char('>'), QStringLiteral(">")); + + static const QString keywords[] = { + QStringLiteral("for "), QStringLiteral("if "), + QStringLiteral("switch "), QStringLiteral(" int "), + QStringLiteral("#include "), QStringLiteral("const"), + QStringLiteral("void "), QStringLiteral("uint "), + QStringLiteral("case "), QStringLiteral("double "), + QStringLiteral("#define "), QStringLiteral("static"), + QStringLiteral("new"), QStringLiteral("this") + }; + + for (const QString &keyword : keywords) contents.replace(keyword, QLatin1String("<font color=olive>") + keyword + QLatin1String("</font>")); - contents.replace("(int ", "(<font color=olive><b>int </b></font>"); + contents.replace(QStringLiteral("(int "), QStringLiteral("(<font color=olive><b>int </b></font>")); - QStringList ppKeywords; - ppKeywords << "#ifdef" << "#ifndef" << "#if" << "#endif" << "#else"; + static const QString ppKeywords[] = { + QStringLiteral("#ifdef"), QStringLiteral("#ifndef"), + QStringLiteral("#if"), QStringLiteral("#endif"), + QStringLiteral("#else") + }; - foreach (QString keyword, ppKeywords) + for (const QString &keyword : ppKeywords) contents.replace(keyword, QLatin1String("<font color=navy>") + keyword + QLatin1String("</font>")); contents.replace(QRegularExpression("(\\d\\d?)"), QLatin1String("<font color=navy>\\1</font>")); @@ -366,12 +374,10 @@ void ArthurFrame::showSource() QRegularExpression stringLiteralRe("(\".+?\")"); contents.replace(stringLiteralRe, QLatin1String("<font color=green>\\1</font>")); - QString html = contents; - html.prepend("<html><pre>"); - html.append("</pre></html>"); + const QString html = QStringLiteral("<html><pre>") + contents + QStringLiteral("</pre></html>"); QTextBrowser *sourceViewer = new QTextBrowser(0); - sourceViewer->setWindowTitle("Source: " + m_sourceFileName.mid(5)); + sourceViewer->setWindowTitle(tr("Source: %1").arg(m_sourceFileName.midRef(5))); sourceViewer->setParent(this, Qt::Dialog); sourceViewer->setAttribute(Qt::WA_DeleteOnClose); sourceViewer->setLineWrapMode(QTextEdit::NoWrap); diff --git a/examples/widgets/painting/shared/hoverpoints.cpp b/examples/widgets/painting/shared/hoverpoints.cpp index 7cd8cc0b29..74c78088ad 100644 --- a/examples/widgets/painting/shared/hoverpoints.cpp +++ b/examples/widgets/painting/shared/hoverpoints.cpp @@ -73,8 +73,8 @@ HoverPoints::HoverPoints(QWidget *widget, PointShape shape) m_editable = true; m_enabled = true; - connect(this, SIGNAL(pointsChanged(QPolygonF)), - m_widget, SLOT(update())); + connect(this, &HoverPoints::pointsChanged, + m_widget, QOverload<>::of(&QWidget::update)); } @@ -174,7 +174,7 @@ bool HoverPoints::eventFilter(QObject *object, QEvent *event) const QTouchEvent *const touchEvent = static_cast<const QTouchEvent*>(event); const QList<QTouchEvent::TouchPoint> points = touchEvent->touchPoints(); const qreal pointSize = qMax(m_pointSize.width(), m_pointSize.height()); - foreach (const QTouchEvent::TouchPoint &touchPoint, points) { + for (const QTouchEvent::TouchPoint &touchPoint : points) { const int id = touchPoint.id(); switch (touchPoint.state()) { case Qt::TouchPointPressed: |