1 #pragma once 2 3 #ifndef IMAGEVIEWER_INCLUDE 4 #define IMAGEVIEWER_INCLUDE 5 6 #include "toonz/imagepainter.h" 7 #include "toonzqt/glwidget_for_highdpi.h" 8 9 #include <QTouchDevice> 10 11 //----------------------------------------------------------------------------- 12 13 // Forward declarations 14 class FlipBook; 15 class HistogramPopup; 16 class QOpenGLFramebufferObject; 17 class LutCalibrator; 18 class QTouchEvent; 19 class QGestureEvent; 20 //----------------------------------------------------------------------------- 21 22 //==================== 23 // ImageViewer 24 //-------------------- 25 26 class ImageViewer final : public GLWidgetForHighDpi { 27 Q_OBJECT 28 enum DragType { 29 eNone, 30 eDrawRect = 0x1, 31 eMoveRect = 0x2, 32 eMoveLeft = 0x4, 33 eMoveRight = 0x8, 34 eMoveUp = 0x10, 35 eMoveDown = 0x20 36 }; 37 int m_dragType; 38 FlipBook *m_flipbook; 39 TPoint m_pressedMousePos; 40 41 Qt::MouseButton m_mouseButton; 42 bool m_draggingZoomSelection; 43 44 bool m_rectRGBPick; 45 46 int m_FPS; 47 48 ImagePainter::VisualSettings m_visualSettings; 49 ImagePainter::CompareSettings m_compareSettings; 50 51 TImageP m_image; 52 TAffine m_viewAff; 53 QPoint m_pos; 54 bool m_isHistogramEnable; 55 HistogramPopup *m_histogramPopup; 56 bool m_firstImage; 57 58 bool m_isColorModel; 59 // when fx parameter is modified with showing the fx preview, 60 // a flipbook shows a red border line before the rendered result is shown. 61 bool m_isRemakingPreviewFx; 62 63 // used for color calibration with 3DLUT 64 QOpenGLFramebufferObject *m_fbo = NULL; 65 LutCalibrator *m_lutCalibrator = NULL; 66 67 bool m_touchActive = false; 68 bool m_gestureActive = false; 69 QTouchDevice::DeviceType m_touchDevice = QTouchDevice::TouchScreen; 70 bool m_zooming = false; 71 bool m_panning = false; 72 double m_scaleFactor; // used for zoom gesture 73 74 bool m_stylusUsed = false; 75 bool m_firstInitialized = true; 76 77 int getDragType(const TPoint &pos, const TRect &loadBox); 78 void updateLoadbox(const TPoint &curPos); 79 void updateCursor(const TPoint &curPos); 80 81 // for RGB color picker 82 void pickColor(QMouseEvent *event, bool putValueToStyleEditor = false); 83 void rectPickColor(bool putValueToStyleEditor = false); 84 void setPickedColorToStyleEditor(const TPixel32 &color); 85 // get the image (m_image or the snapshot) to be picked. 86 TImageP getPickedImage(QPointF mousePos); 87 88 public: 89 ImageViewer(QWidget *parent, FlipBook *flipbook, bool showHistogram); 90 ~ImageViewer(); 91 setIsColorModel(bool isColorModel)92 void setIsColorModel(bool isColorModel) { m_isColorModel = isColorModel; } isColorModel()93 bool isColorModel() { return m_isColorModel; } 94 95 void setVisual(const ImagePainter::VisualSettings &settings); 96 97 void setImage(TImageP image); getImage()98 TImageP getImage() { return m_image; } 99 getViewAff()100 TAffine getViewAff() { return m_viewAff; } 101 void setViewAff(TAffine viewAff); 102 103 TAffine getImgToWidgetAffine(const TRectD &imgBounds) const; 104 TAffine getImgToWidgetAffine() const; 105 106 /*! If histogram popup exist and is open set its title to "Histogram: level 107 name" 108 if level Name is not empty. */ 109 void setHistogramTitle(QString levelName); 110 void setHistogramEnable(bool enable); 111 /*! If histogram popup exist and is open, it is set to default and is hidden. 112 */ 113 void hideHistogram(); 114 void zoomQt(bool forward, bool reset); 115 void resetZoom(); 116 setIsRemakingPreviewFx(bool on)117 void setIsRemakingPreviewFx(bool on) { 118 m_isRemakingPreviewFx = on; 119 update(); 120 } isRemakingPreviewFx()121 bool isRemakingPreviewFx() { return m_isRemakingPreviewFx; } 122 123 void adaptView(const TRect &imgRect, const TRect &viewRect); 124 void adaptView(const QRect &viewerRect); 125 126 void doSwapBuffers(); 127 void changeSwapBehavior(bool enable); 128 129 protected: 130 void contextMenuEvent(QContextMenuEvent *event) override; 131 void initializeGL() override; 132 void resizeGL(int width, int height) override; 133 void paintGL() override; 134 135 void showEvent(QShowEvent *) override; 136 void hideEvent(QHideEvent *) override; 137 void mouseMoveEvent(QMouseEvent *event) override; 138 void mousePressEvent(QMouseEvent *event) override; 139 void mouseReleaseEvent(QMouseEvent *event) override; 140 void keyPressEvent(QKeyEvent *event) override; 141 void mouseDoubleClickEvent(QMouseEvent *event) override; 142 void wheelEvent(QWheelEvent *) override; 143 144 void panQt(const QPoint &delta); 145 void zoomQt(const QPoint ¢er, double factor); 146 147 void dragCompare(const QPoint &dp); 148 149 void tabletEvent(QTabletEvent *e) override; 150 void touchEvent(QTouchEvent *e, int type); 151 void gestureEvent(QGestureEvent *e); 152 bool event(QEvent *e) override; 153 154 public slots: 155 156 void updateImageViewer(); 157 void resetView(); 158 void fitView(); 159 void showHistogram(); 160 void swapCompared(); 161 void onContextAboutToBeDestroyed(); 162 void onPreferenceChanged(const QString &prefName); 163 164 private: 165 QPointF m_firstPanPoint; 166 }; 167 168 #endif // IMAGEVIEWER_INCLUDE 169