DtkWidget
DTK Widget module
载入中...
搜索中...
未找到
dimageviewer.h
浏览该文件的文档.
1// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#ifndef DIMAGEVIEWER_H
6#define DIMAGEVIEWER_H
7
8#include <dtkwidget_global.h>
9#include <DGraphicsView>
10#include <DObject>
11
12DWIDGET_BEGIN_NAMESPACE
13
15class LIBDTKWIDGETSHARED_EXPORT DImageViewer : public DGraphicsView, public DCORE_NAMESPACE::DObject
16{
17 Q_OBJECT
18
19 Q_PROPERTY(QImage image READ image WRITE setImage NOTIFY imageChanged)
20 Q_PROPERTY(QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged)
21 Q_PROPERTY(qreal scaleFactor READ scaleFactor WRITE setScaleFactor NOTIFY scaleFactorChanged)
22 Q_PROPERTY(int rotateAngle READ rotateAngle NOTIFY rotateAngleChanged)
23
24public:
25 explicit DImageViewer(QWidget *parent = nullptr);
26 explicit DImageViewer(const QImage &image, QWidget *parent = nullptr);
27 explicit DImageViewer(const QString &fileName, QWidget *parent = nullptr);
28 ~DImageViewer() Q_DECL_OVERRIDE;
29
30 QImage image() const;
31 void setImage(const QImage &image);
32 QString fileName() const;
33 void setFileName(const QString &fileName);
34
35 qreal scaleFactor() const;
36 void setScaleFactor(qreal factor);
37 void scaleImage(qreal factor);
38
39 void autoFitImage();
40 void fitToWidget();
41 void fitNormalSize();
42 void rotateClockwise();
43 void rotateCounterclockwise();
44 int rotateAngle() const;
45 void resetRotateAngle();
46 void clear();
47
48 void centerOn(qreal x, qreal y);
49 QRect visibleImageRect() const;
50
51 Q_SLOT void scaleAtPoint(QPoint pos, qreal factor);
52
53 void beginCropImage();
54 void endCropImage();
55 void resetCropImage();
56 void setCropAspectRatio(qreal w, qreal h);
57 QRect cropImageRect() const;
58
59Q_SIGNALS:
60 void imageChanged(const QImage &image);
61 void fileNameChanged(const QString &fileName);
62 void scaleFactorChanged(qreal scaleFactor);
63 void rotateAngleChanged(int angle);
67 void cropImageChanged(const QRect &rect);
68
69protected:
70 void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
71 void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE;
72 bool event(QEvent *event) Q_DECL_OVERRIDE;
73
74private:
75 Q_DISABLE_COPY(DImageViewer)
76 D_DECLARE_PRIVATE(DImageViewer)
77
78 D_PRIVATE_SLOT(void _q_pinchAnimeFinished())
79};
80
81DWIDGET_END_NAMESPACE
82
83#endif // DIMAGEVIEWER_H
DImageViewer 提供基础的图片浏览功能。
Definition dimageviewer.h:16
void cropImageChanged(const QRect &rect)
图片裁剪矩形变更信号,图片裁剪完成后触发
void imageChanged(const QImage &image)
图片变更信号,展示图片实例变更后触发
void transformChanged()
坐标变换信号,当图片通过界面交互或属性变更导致图片显示坐标、大小等变更时触发
void rotateAngleChanged(int angle)
当展示图片旋转时触发,旋转角度为90°的倍数,范围在 -360° ~ 360°
void requestPreviousImage()
请求切换上一张图片,触摸屏滑动切换时触发
void requestNextImage()
请求切换下一张图片,触摸屏滑动切换时触发
void scaleFactorChanged(qreal scaleFactor)
图片缩放比例系数变更信号,通过界面交互或 setScaleFactor 设置缩放比例系数后触发
void fileNameChanged(const QString &fileName)
图片文件路径变更信号,通过 setFileName 设置文件路径后触发