Used QGesture for this as per the gesture example. Moved the help and info text to separate lines. Enabled word wrap to prevent text going off screen. As a drive-by, the code to center the window at a size that's a fraction of the screen is replaced with a simple sizeHint() override. The user should have control over placement, particularly now that it should be placed manually onto a touchscreen if the user has one. Done-with: Shawn Rutledge Fixes: QTBUG-96702 Change-Id: I8dba8b09bed474f585341e9a7a8c71fb60293eee Reviewed-by: Rami Potinkara <rami.potinkara@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> (cherry picked from commit fc5482cac6e69364c9d09fb8d994065e2a5fb542) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
60 lines
1.4 KiB
C++
60 lines
1.4 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 <QGestureEvent>
|
|
#include <QPixmap>
|
|
#include <QWidget>
|
|
#include "renderthread.h"
|
|
|
|
|
|
//! [0]
|
|
class MandelbrotWidget : public QWidget
|
|
{
|
|
Q_OBJECT
|
|
|
|
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 slots:
|
|
void updatePixmap(const QImage &image, double scaleFactor);
|
|
void zoom(double zoomFactor);
|
|
|
|
private:
|
|
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
|