-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_view.h
46 lines (37 loc) · 1.07 KB
/
image_view.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// QML QImage display
// Author: Max Schwarz <[email protected]>
#ifndef IMAGE_VIEW_H
#define IMAGE_VIEW_H
#include <QQuickPaintedItem>
#include <QImage>
class ImageView : public QQuickPaintedItem
{
Q_OBJECT
Q_PROPERTY(QImage image READ image WRITE setImage NOTIFY imageChanged)
Q_PROPERTY(float aspectRatio READ aspectRatio NOTIFY imageChanged)
Q_PROPERTY(QImage nullImage CONSTANT READ nullImage)
Q_PROPERTY(QRectF imageRect READ imageRect NOTIFY imageRectChanged)
public:
explicit ImageView(QQuickItem* parent = 0);
virtual ~ImageView();
void paint(QPainter* painter) override;
QImage image() const
{ return m_image; }
inline QImage nullImage() const
{ return QImage(); }
float aspectRatio() const;
QRectF imageRect() const
{ return m_imageRect; }
public Q_SLOTS:
void setImage(const QImage& image);
Q_SIGNALS:
void imageChanged();
void imageRectChanged();
protected:
void geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) override;
void recalculateImageRect(const QSizeF& outerSize);
private:
QImage m_image;
QRectF m_imageRect;
};
#endif