#ifndef __HGIMGVIEW_H__ #define __HGIMGVIEW_H__ #include "base/HGDef.h" #include "base/HGBaseErr.h" #include "base/HGImage.h" #include class HGImgView : public QWidget { Q_OBJECT public: HGImgView(QWidget* parent = nullptr); virtual ~HGImgView(); HGResult setScrollSize(int size); HGResult setMinScrollSliderSize(int size); HGResult setHScrollLeftImage(const QImage *normalImage, const QImage *hotImage, const QImage *pushImage); HGResult setHScrollRightImage(const QImage *normalImage, const QImage *hotImage, const QImage *pushImage); HGResult setVScrollTopImage(const QImage *normalImage, const QImage *hotImage, const QImage *pushImage); HGResult setVScrollBottomImage(const QImage *normalImage, const QImage *hotImage, const QImage *pushImage); HGResult setHScrollImage(const QImage *image, const HGRect *stretch); HGResult setHScrollSliderImage(const QImage *normalImage, const HGRect *normalStretch, const QImage *hotImage, const HGRect *hotStretch, const QImage *pushImage, const HGRect *pushStretch); HGResult setVScrollImage(const QImage *image, const HGRect *stretch); HGResult setVScrollSliderImage(const QImage *normalImage, const HGRect *normalStretch, const QImage *hotImage, const HGRect *hotStretch, const QImage *pushImage, const HGRect *pushStretch); HGResult setNullScrollImage(const QImage *image); HGResult enableScroll(bool enable); HGResult addImage(HGImage image); HGResult clearImage(); HGResult getImage(HGImage *image); HGResult rotateLeft(); HGResult rotateRight(); HGResult rotate180(); HGResult zoomIn(const HGPoint *pCenter); HGResult zoomOut(const HGPoint *pCenter); HGResult realSize(); HGResult fitWndSize(); HGResult fitWndWidth(); HGResult showColorInfo(bool show); signals: void escape(); void doubleClicked(); void mousePos(int x, int y); void scaleChanged(double scale); void drop(const QObject *source, const QStringList &fileNames); private: enum MouseStatus { MouseStatus_Null = 0, MouseStatus_HScroll, MouseStatus_HScrollSlider, MouseStatus_HScrollLeft, MouseStatus_HScrollRight, MouseStatus_VScroll, MouseStatus_VScrollSlider, MouseStatus_VScrollTop, MouseStatus_VScrollBottom, MouseStatus_NullScroll }; protected: virtual void mousePressEvent(QMouseEvent *e); virtual void mouseMoveEvent(QMouseEvent* e); virtual void mouseReleaseEvent(QMouseEvent *e); virtual void enterEvent(QEvent *e); virtual void leaveEvent(QEvent *e); virtual void paintEvent(QPaintEvent* e); virtual void wheelEvent(QWheelEvent* e); virtual void resizeEvent(QResizeEvent* e); virtual void keyPressEvent(QKeyEvent *e); virtual void dragEnterEvent(QDragEnterEvent *e); virtual void dragMoveEvent(QDragMoveEvent *e); virtual void dragLeaveEvent(QDragLeaveEvent *e); virtual void dropEvent(QDropEvent *e); virtual void mouseDoubleClickEvent(QMouseEvent* e); private: static void GetMinShowImageRect(const HGRect *pWnd, int nImgWidth, int nImgHeight, bool &bShowImage, HGRectF &rcShowImage); static void ResizeShowImageRect(bool &bShowImage, HGRectF &rcShowImage, float fNewWidth, float fNewHeight, const HGPoint *pCenter); static void recalcShowRect(int wndWidth, int wndHeight, int scrollSize, bool hScroll, bool vScroll, bool showImage, HGRectF &imageRect); static void DrawImage(QPainter &painter, const QRect &destRect, const QImage *image, const QRect &stretchRect); void DrawScroll(QPainter &painter); void reset(); void updateMoveStatusAndCursor(); MouseStatus getMouseStatus(const QPoint &pt); QRect getHScrollLeftPos(); QRect getHScrollRightPos(); QRect getHScrollPos(); QRect getHScrollSliderPos(); QRect getVScrollTopPos(); QRect getVScrollBottomPos(); QRect getVScrollPos(); QRect getVScrollSliderPos(); QRect getNullScrollPos(); void Show(); private: int m_scrollSize; int m_minScrollSliderSize; QImage *m_hScrollLeftImage[3]; QImage *m_hScrollRightImage[3]; QImage *m_vScrollTopImage[3]; QImage *m_vScrollBottomImage[3]; QImage *m_hScrollImage; QRect m_hScrollImageStretch; QImage *m_hScrollSliderImage[3]; QRect m_hScrollSliderImageStretch[3]; QImage *m_vScrollImage; QRect m_vScrollImageStretch; QImage *m_vScrollSliderImage[3]; QRect m_vScrollSliderImageStretch[3]; QImage *m_nullScrollImage; bool m_enableScroll; bool m_mouseOn; bool m_hScroll; bool m_vScroll; HGImage m_image; bool m_showImage; HGRectF m_showRect; MouseStatus m_mouseMoveStatus; MouseStatus m_mousePressStatus; int m_mousePressBeginX; int m_mousePressBeginY; bool m_showColorInfo; int m_operate; int m_beginX; int m_beginY; bool m_draging; }; #endif /* __HGIMGVIEW_HPP__ */