pineapple-pictures/app/graphicsview.h

67 lines
2.0 KiB
C
Raw Normal View History

2019-09-28 01:18:08 +08:00
#ifndef GRAPHICSVIEW_H
#define GRAPHICSVIEW_H
#include <QGraphicsView>
#include <QUrl>
2019-09-28 01:18:08 +08:00
2019-09-29 15:52:35 +08:00
class GraphicsScene;
2019-09-28 01:18:08 +08:00
class GraphicsView : public QGraphicsView
{
2019-10-03 17:57:14 +08:00
Q_OBJECT
2019-09-28 01:18:08 +08:00
public:
GraphicsView(QWidget *parent = nullptr);
void showFileFromUrl(const QUrl &url, bool requestGallery = false);
2019-09-29 15:52:35 +08:00
void showImage(const QPixmap &pixmap);
void showImage(const QImage &image);
2019-09-29 15:52:35 +08:00
void showText(const QString &text);
2019-09-29 23:53:29 +08:00
void showSvg(const QString &filepath);
2019-09-30 13:11:43 +08:00
void showGif(const QString &filepath);
2019-09-29 15:52:35 +08:00
GraphicsScene * scene() const;
void setScene(GraphicsScene *scene);
2019-10-02 16:04:50 +08:00
qreal scaleFactor() const;
void resetTransform();
void zoomView(qreal scaleFactor);
void resetScale();
void rotateView(qreal rotateAngel);
void fitInView(const QRectF &rect, Qt::AspectRatioMode aspectRadioMode = Qt::IgnoreAspectRatio);
2020-07-27 20:47:54 +08:00
void checkAndDoFitInView(bool markItOnAnyway = true);
2019-10-02 14:31:24 +08:00
2019-10-03 17:57:14 +08:00
signals:
void navigatorViewRequired(bool required, qreal angle);
2019-10-04 09:54:13 +08:00
void viewportRectChanged();
void requestGallery(const QString &filePath);
2019-10-03 17:57:14 +08:00
2019-09-30 23:02:44 +08:00
public slots:
void toggleCheckerboard();
2019-09-28 01:18:08 +08:00
private:
void mousePressEvent(QMouseEvent * event) override;
void mouseMoveEvent(QMouseEvent * event) override;
void mouseReleaseEvent(QMouseEvent * event) override;
void wheelEvent(QWheelEvent *event) override;
2019-09-29 21:22:20 +08:00
void resizeEvent(QResizeEvent *event) override;
2019-09-29 15:52:35 +08:00
void dragEnterEvent(QDragEnterEvent *event) override;
void dragMoveEvent(QDragMoveEvent *event) override;
void dropEvent(QDropEvent *event) override;
2019-09-29 21:22:20 +08:00
bool isThingSmallerThanWindowWith(const QTransform &transform) const;
bool shouldIgnoreMousePressMoveEvent(const QMouseEvent *event) const;
2019-09-30 23:02:44 +08:00
void setCheckerboardEnabled(bool enabled);
void applyTransformationModeByScaleFactor();
2019-09-29 21:22:20 +08:00
2019-11-02 13:32:13 +08:00
void resetWithScaleAndRotate(qreal scaleFactor, qreal rotateAngle);
2019-10-02 16:04:50 +08:00
2019-09-29 21:22:20 +08:00
bool m_enableFitInView = false;
2019-09-30 23:02:44 +08:00
bool m_checkerboardEnabled = false;
2019-10-02 16:04:50 +08:00
qreal m_rotateAngle = 0;
2019-09-28 01:18:08 +08:00
};
#endif // GRAPHICSVIEW_H