60 lines
1.6 KiB
C++
60 lines
1.6 KiB
C++
#ifndef QIMAGEWIDGET_H
|
|
#define QIMAGEWIDGET_H
|
|
#pragma once
|
|
#include <QWidget>
|
|
#include <QtGui>
|
|
#include <QImage>
|
|
#include <QPainter>
|
|
#include <QRectF>
|
|
#include <QMouseEvent>
|
|
#include <QPointF>
|
|
#include <QDragEnterEvent>
|
|
#include <QGraphicsSceneWheelEvent>
|
|
#include <QGraphicsItem>
|
|
#include <QObject>
|
|
#pragma execution_character_set("utf-8")
|
|
enum Enum_ZoomState {
|
|
NO_STATE,
|
|
RESET,
|
|
ZOOM_IN,
|
|
ZOOM_OUT
|
|
};
|
|
|
|
|
|
class QImageWidget :public QObject,
|
|
public QGraphicsItem
|
|
|
|
{
|
|
Q_OBJECT
|
|
Q_INTERFACES(QGraphicsItem)
|
|
//Warning: Class Node implements the interface QGraphicsItem but does not list it in Q_INTERFACES.
|
|
//qobject_cast to QGraphicsItem will not work!
|
|
public:
|
|
QImageWidget(QImage* pixmap);
|
|
QRectF boundingRect() const;
|
|
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);
|
|
void wheelEvent(QGraphicsSceneWheelEvent* event);
|
|
void ResetItemPos();
|
|
void mousePressEvent(QGraphicsSceneMouseEvent* event);
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
|
|
qreal getScaleValue() const;
|
|
void setQGraphicsViewWH(int nwidth, int nheight);
|
|
void GetImagepix(QPointF pos);
|
|
private:
|
|
int m_max_zoomState = 5;//最大放大倍数
|
|
qreal m_scaleValue;
|
|
qreal m_scaleDafault;
|
|
QImage m_pix;
|
|
int m_zoomState;
|
|
bool m_isMove;
|
|
QPointF m_startPos;
|
|
double m_zoom = 0.1;//缩放比例
|
|
|
|
signals:
|
|
void SetImagepix(QString msg);
|
|
|
|
};
|
|
|
|
#endif // QIMAGEWIDGET_H
|