diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-04-07 22:14:23 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-04-14 08:24:04 +0200 |
commit | 0e69349f6f8e9445877ea5b2105973115ad79cf7 (patch) | |
tree | 90f7a68a57be20ac3fbf1ecd06c25808c4a999b2 /examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp | |
parent | 2df3d8ed415d01b169071e01b775d920292df555 (diff) |
Brush up the mandelbrot example
The example refines the image by running a number of passes
with increasing number of iterations, which is not really
visible to the user. Set an informational text string on
the generated image which provides this information
along with the elapsed time.
The idea is to do the same to the corresponding
Qt for Python example to have some sort of speed comparison
for number crunching.
Add a command line option for the number of passes.
Make the window a bit larger to accommodate the
information.
Change-Id: I2afc1009ab53b580123d82a6aa645d9ffaa63ea2
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Diffstat (limited to 'examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp')
-rw-r--r-- | examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp b/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp index b0c3733b22..bb1f83482b 100644 --- a/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp +++ b/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -73,6 +73,8 @@ MandelbrotWidget::MandelbrotWidget(QWidget *parent) : pixmapScale(DefaultScale), curScale(DefaultScale) { + help = tr("Use mouse wheel or the '+' and '-' keys to zoom. " + "Press and hold left mouse button to scroll."); connect(&thread, &RenderThread::renderedImage, this, &MandelbrotWidget::updatePixmap); @@ -80,8 +82,6 @@ MandelbrotWidget::MandelbrotWidget(QWidget *parent) : #if QT_CONFIG(cursor) setCursor(Qt::CrossCursor); #endif - resize(550, 400); - } //! [1] @@ -127,8 +127,9 @@ void MandelbrotWidget::paintEvent(QPaintEvent * /* event */) } //! [8] //! [9] - QString text = tr("Use mouse wheel or the '+' and '-' keys to zoom. " - "Press and hold left mouse button to scroll."); + QString text = help; + if (!info.isEmpty()) + text += ' ' + info; QFontMetrics metrics = painter.fontMetrics(); int textWidth = metrics.horizontalAdvance(text); @@ -169,6 +170,9 @@ void MandelbrotWidget::keyPressEvent(QKeyEvent *event) case Qt::Key_Up: scroll(0, +ScrollStep); break; + case Qt::Key_Q: + close(); + break; default: QWidget::keyPressEvent(event); } @@ -226,6 +230,8 @@ void MandelbrotWidget::updatePixmap(const QImage &image, double scaleFactor) if (!lastDragPos.isNull()) return; + info = image.text(RenderThread::infoKey()); + pixmap = QPixmap::fromImage(image); pixmapOffset = QPoint(); lastDragPos = QPoint(); |