mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-06 09:15:23 +08:00
6.5.3 clean
This commit is contained in:
@ -2,15 +2,14 @@
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include "mandelbrotwidget.h"
|
||||
#include "renderthread.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
#include <QScreen>
|
||||
|
||||
#include <QCommandLineParser>
|
||||
#include <QCommandLineOption>
|
||||
#include <QDebug>
|
||||
#include <QRect>
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
//! [0]
|
||||
int main(int argc, char *argv[])
|
||||
@ -18,10 +17,10 @@ int main(int argc, char *argv[])
|
||||
QApplication app(argc, argv);
|
||||
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription("Qt Mandelbrot Example");
|
||||
parser.setApplicationDescription(u"Qt Mandelbrot Example"_s);
|
||||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
QCommandLineOption passesOption("passes", "Number of passes (1-8)", "passes");
|
||||
QCommandLineOption passesOption(u"passes"_s, u"Number of passes (1-8)"_s, u"passes"_s);
|
||||
parser.addOption(passesOption);
|
||||
parser.process(app);
|
||||
|
||||
|
@ -4,19 +4,20 @@
|
||||
#include "mandelbrotwidget.h"
|
||||
|
||||
#include <QGesture>
|
||||
#include <QGestureEvent>
|
||||
#include <QKeyEvent>
|
||||
#include <QPainter>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
//! [0]
|
||||
const double DefaultCenterX = -0.637011;
|
||||
const double DefaultCenterY = -0.0395159;
|
||||
const double DefaultScale = 0.00403897;
|
||||
constexpr double DefaultCenterX = -0.637011;
|
||||
constexpr double DefaultCenterY = -0.0395159;
|
||||
constexpr double DefaultScale = 0.00403897;
|
||||
|
||||
const double ZoomInFactor = 0.8;
|
||||
const double ZoomOutFactor = 1 / ZoomInFactor;
|
||||
const int ScrollStep = 20;
|
||||
constexpr double ZoomInFactor = 0.8;
|
||||
constexpr double ZoomOutFactor = 1 / ZoomInFactor;
|
||||
constexpr int ScrollStep = 20;
|
||||
//! [0]
|
||||
|
||||
//! [1]
|
||||
@ -46,7 +47,8 @@ void MandelbrotWidget::paintEvent(QPaintEvent * /* event */)
|
||||
|
||||
if (pixmap.isNull()) {
|
||||
painter.setPen(Qt::white);
|
||||
painter.drawText(rect(), Qt::AlignCenter|Qt::TextWordWrap, tr("Rendering initial image, please wait..."));
|
||||
painter.drawText(rect(), Qt::AlignCenter|Qt::TextWordWrap,
|
||||
tr("Rendering initial image, please wait..."));
|
||||
//! [2] //! [3]
|
||||
return;
|
||||
//! [3] //! [4]
|
||||
@ -60,47 +62,47 @@ void MandelbrotWidget::paintEvent(QPaintEvent * /* event */)
|
||||
//! [6] //! [7]
|
||||
} else {
|
||||
//! [7] //! [8]
|
||||
auto previewPixmap = qFuzzyCompare(pixmap.devicePixelRatio(), qreal(1))
|
||||
const auto previewPixmap = qFuzzyCompare(pixmap.devicePixelRatio(), qreal(1))
|
||||
? pixmap
|
||||
: pixmap.scaled(pixmap.deviceIndependentSize().toSize(), Qt::KeepAspectRatio,
|
||||
Qt::SmoothTransformation);
|
||||
double scaleFactor = pixmapScale / curScale;
|
||||
int newWidth = int(previewPixmap.width() * scaleFactor);
|
||||
int newHeight = int(previewPixmap.height() * scaleFactor);
|
||||
int newX = pixmapOffset.x() + (previewPixmap.width() - newWidth) / 2;
|
||||
int newY = pixmapOffset.y() + (previewPixmap.height() - newHeight) / 2;
|
||||
const double scaleFactor = pixmapScale / curScale;
|
||||
const int newWidth = int(previewPixmap.width() * scaleFactor);
|
||||
const int newHeight = int(previewPixmap.height() * scaleFactor);
|
||||
const int newX = pixmapOffset.x() + (previewPixmap.width() - newWidth) / 2;
|
||||
const int newY = pixmapOffset.y() + (previewPixmap.height() - newHeight) / 2;
|
||||
|
||||
painter.save();
|
||||
painter.translate(newX, newY);
|
||||
painter.scale(scaleFactor, scaleFactor);
|
||||
|
||||
QRectF exposed = painter.transform().inverted().mapRect(rect()).adjusted(-1, -1, 1, 1);
|
||||
const QRectF exposed = painter.transform().inverted().mapRect(rect())
|
||||
.adjusted(-1, -1, 1, 1);
|
||||
painter.drawPixmap(exposed, previewPixmap, exposed);
|
||||
painter.restore();
|
||||
}
|
||||
//! [8] //! [9]
|
||||
|
||||
QFontMetrics metrics = painter.fontMetrics();
|
||||
const QFontMetrics metrics = painter.fontMetrics();
|
||||
if (!info.isEmpty()){
|
||||
int infoWidth = metrics.horizontalAdvance(info);
|
||||
int infoHeight = metrics.height();
|
||||
const int infoWidth = metrics.horizontalAdvance(info);
|
||||
const int infoHeight = (infoWidth/width() + 1) * (metrics.height() + 5);
|
||||
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.setBrush(QColor(0, 0, 0, 127));
|
||||
infoHeight = (infoWidth/width()+1) * (infoHeight + 5);
|
||||
painter.drawRect((width() - infoWidth) / 2 - 5, 0, infoWidth + 10, infoHeight);
|
||||
|
||||
painter.setPen(Qt::white);
|
||||
painter.drawText(rect(), Qt::AlignHCenter|Qt::AlignTop|Qt::TextWordWrap, info);
|
||||
}
|
||||
|
||||
int helpWidth = metrics.horizontalAdvance(help);
|
||||
int helpHeight = metrics.height();
|
||||
const int helpWidth = metrics.horizontalAdvance(help);
|
||||
const int helpHeight = (helpWidth/width() + 1) * (metrics.height() + 5);
|
||||
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.setBrush(QColor(0, 0, 0, 127));
|
||||
helpHeight = (helpWidth/width()+1) * (helpHeight + 5);
|
||||
painter.drawRect((width() - helpWidth) / 2 - 5, height()-helpHeight, helpWidth + 10, helpHeight);
|
||||
painter.drawRect((width() - helpWidth) / 2 - 5, height()-helpHeight, helpWidth + 10,
|
||||
helpHeight);
|
||||
|
||||
painter.setPen(Qt::white);
|
||||
painter.drawText(rect(), Qt::AlignHCenter|Qt::AlignBottom|Qt::TextWordWrap, help);
|
||||
@ -184,8 +186,8 @@ void MandelbrotWidget::mouseReleaseEvent(QMouseEvent *event)
|
||||
lastDragPos = QPoint();
|
||||
|
||||
const auto pixmapSize = pixmap.deviceIndependentSize().toSize();
|
||||
int deltaX = (width() - pixmapSize.width()) / 2 - pixmapOffset.x();
|
||||
int deltaY = (height() - pixmapSize.height()) / 2 - pixmapOffset.y();
|
||||
const int deltaX = (width() - pixmapSize.width()) / 2 - pixmapOffset.x();
|
||||
const int deltaY = (height() - pixmapSize.height()) / 2 - pixmapOffset.y();
|
||||
scroll(deltaX, deltaY);
|
||||
}
|
||||
}
|
||||
|
@ -4,11 +4,14 @@
|
||||
#ifndef MANDELBROTWIDGET_H
|
||||
#define MANDELBROTWIDGET_H
|
||||
|
||||
#include <QGestureEvent>
|
||||
#include <QPixmap>
|
||||
#include <QWidget>
|
||||
#include "renderthread.h"
|
||||
|
||||
#include <QPixmap>
|
||||
#include <QWidget>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QGestureEvent;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
//! [0]
|
||||
class MandelbrotWidget : public QWidget
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include "renderthread.h"
|
||||
|
||||
#include <QImage>
|
||||
|
||||
#include <QElapsedTimer>
|
||||
#include <QTextStream>
|
||||
|
||||
@ -70,16 +69,16 @@ void RenderThread::run()
|
||||
//! [3]
|
||||
|
||||
//! [4]
|
||||
int halfWidth = resultSize.width() / 2;
|
||||
const int halfWidth = resultSize.width() / 2;
|
||||
//! [4] //! [5]
|
||||
int halfHeight = resultSize.height() / 2;
|
||||
const int halfHeight = resultSize.height() / 2;
|
||||
QImage image(resultSize, QImage::Format_RGB32);
|
||||
image.setDevicePixelRatio(devicePixelRatio);
|
||||
|
||||
int pass = 0;
|
||||
while (pass < numPasses) {
|
||||
const int MaxIterations = (1 << (2 * pass + 6)) + 32;
|
||||
const int Limit = 4;
|
||||
constexpr int Limit = 4;
|
||||
bool allBlack = true;
|
||||
|
||||
timer.restart();
|
||||
|
Reference in New Issue
Block a user