From 0e69349f6f8e9445877ea5b2105973115ad79cf7 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 7 Apr 2021 22:14:23 +0200 Subject: 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 --- examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp') 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(); -- cgit v1.2.3