qt5base-lts/examples/corelib/threads/mandelbrot/mandelbrotwidget.h
Rym Bouabid 2a2275756b Revamp Mandelbrot example: Declare slots as methods instead
Declare zoom as a method because it's never used as a slot.

Declare updatePixmap as a method because it's used as a slot
as pointer-to-member-function, so it doesn't need help from moc.

Q_OBJECT is not needed anymore as the MandelbrotWidget class
doesn't contain signals ans slots anymore. It's replaced by
Q_DECLARE_TR_FUNCTIONS because we are using tr() function.

Fixes: QTBUG-108861
Pick-to: 6.6 6.5 6.6.0
Change-Id: I9a1d66711cdc9f0ca5a1bc6645f7e0ed3395645c
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-09-13 20:45:17 +02:00

62 lines
1.5 KiB
C++

// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef MANDELBROTWIDGET_H
#define MANDELBROTWIDGET_H
#include "renderthread.h"
#include <QCoreApplication>
#include <QPixmap>
#include <QWidget>
QT_BEGIN_NAMESPACE
class QGestureEvent;
QT_END_NAMESPACE
//! [0]
class MandelbrotWidget : public QWidget
{
Q_DECLARE_TR_FUNCTIONS(MandelbrotWidget)
public:
MandelbrotWidget(QWidget *parent = nullptr);
protected:
QSize sizeHint() const override { return {1024, 768}; };
void paintEvent(QPaintEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
#if QT_CONFIG(wheelevent)
void wheelEvent(QWheelEvent *event) override;
#endif
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
#ifndef QT_NO_GESTURES
bool event(QEvent *event) override;
#endif
private:
void updatePixmap(const QImage &image, double scaleFactor);
void zoom(double zoomFactor);
void scroll(int deltaX, int deltaY);
#ifndef QT_NO_GESTURES
bool gestureEvent(QGestureEvent *event);
#endif
RenderThread thread;
QPixmap pixmap;
QPoint pixmapOffset;
QPoint lastDragPos;
QString help;
QString info;
double centerX;
double centerY;
double pixmapScale;
double curScale;
};
//! [0]
#endif // MANDELBROTWIDGET_H