1 /******************************************************************************* 2 ** 3 ** Photivo 4 ** 5 ** Copyright (C) 2009-2011 Michael Munzert <mail@mm-log.com> 6 ** Copyright (C) 2011 Bernd Schoeler <brjohn@brother-john.net> 7 ** Copyright (C) 2013 Alexander Tzyganenko <tz@fast-report.com> 8 ** 9 ** This file is part of Photivo. 10 ** 11 ** Photivo is free software: you can redistribute it and/or modify 12 ** it under the terms of the GNU General Public License version 3 13 ** as published by the Free Software Foundation. 14 ** 15 ** Photivo is distributed in the hope that it will be useful, 16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 ** GNU General Public License for more details. 19 ** 20 ** You should have received a copy of the GNU General Public License 21 ** along with Photivo. If not, see <http://www.gnu.org/licenses/>. 22 ** 23 *******************************************************************************/ 24 /*! 25 \class ptViewWindow 26 27 \brief Displays the preview image and manages all interactions that happen directly 28 on the image itself, e.g. zoom, crop, spot repair. 29 30 Usage notes: 31 32 The global instances of ptMainWindow and ptTheme must be created BEFORE 33 creating the global ptViewWindow instance. 34 35 Consider ptViewWindow to be a singleton. DO NOT create additional instances. 36 37 Current horizontal scale factor: this->transform().m11(); 38 Current vertical scale factor: this->transform().m22(); 39 Because we do not change aspect ratio both factors are always the same. 40 Use FZoomFactor whenever possible and m11() otherwise. 41 **/ 42 43 #ifndef PTVIEWWINDOW_H 44 #define PTVIEWWINDOW_H 45 46 //============================================================================== 47 48 #include <functional> 49 50 #include <QLine> 51 #include <QMenu> 52 #include <QGraphicsView> 53 54 #include "ptMainWindow.h" 55 #include "ptReportOverlay.h" 56 #include "ptLineInteraction.h" 57 #include "ptSimpleRectInteraction.h" 58 #include "ptRichRectInteraction.h" 59 #include "ptGridInteraction.h" 60 #include "filters/imagespot/ptSpotInteraction.h" 61 #include "filters/imagespot/ptRepairInteraction.h" 62 63 //============================================================================== 64 65 // forward for faster compilation 66 class ptImage; 67 68 //============================================================================== 69 70 enum ptInteraction { 71 iaNone = 0, 72 iaCrop = 1, 73 iaSelectRect = 2, // simple rectangle selection: e.g. for spot WB 74 iaDrawLine = 3, // draw a single straight line: e.g. for rotate angle 75 iaSpotRepair = 4, 76 iaSpotTuning = 5 77 }; 78 79 enum ptPixelReading { 80 prNone = 0, 81 prLinear = 1, 82 prPreview = 2 83 }; 84 85 //============================================================================== 86 87 class ptViewWindow : public QGraphicsView { 88 Q_OBJECT 89 90 public: 91 ptViewWindow(QWidget* Parent, ptMainWindow* mainWin); 92 ~ptViewWindow(); 93 interaction()94 inline ptInteraction interaction() const { return FInteraction; } zoomPercent()95 inline int zoomPercent() { return qRound(FZoomFactor * 100); } zoomFactor()96 inline float zoomFactor() const { return FZoomFactor; } 97 98 // Save (and later restore) current zoom settings. Takes care of 99 // everything incl. ptSettings. RestoreZoom() also updates the 100 // viewport accordingly. 101 void SaveZoom(); 102 void RestoreZoom(); 103 104 // Show status overlay in the top left viewport corner. 105 // For mode use ptStatus_ constants. 106 void ShowStatus(short mode); 107 void ShowStatus(const QString text); // shown for 1.5sec 108 109 // Start, stop, control interactions 110 // - StartSimpleRect: Pass the function that is called after the 111 // selection finishes. 112 void StartLine(); 113 void StartSimpleRect(void (*CB_SimpleRect)(const ptStatus, QRect)); 114 void StartCrop(); 115 void StartLocalAdjust(std::function<void()> ACleanupFunc); 116 crop()117 ptRichRectInteraction *crop() const { return FCrop; } spotTuning()118 ptSpotInteraction *spotTuning() const { return FSpotTuning; } spotRepair()119 ptRepairInteraction *spotRepair() const { return FSpotRepair; } 120 121 void setGrid(const short enabled, const uint linesX, const uint linesY); 122 void UpdateImage(const ptImage* relatedImage); 123 void ZoomTo(float factor); // 1.0 means 100% 124 int ZoomToFit(const short withMsg = 1); // fit complete image into viewport 125 void ZoomStep(int direction); 126 isPixelReading()127 ptPixelReading isPixelReading() const { return FPixelReading; } SetPixelReader(void (* PixelReader)(const QPointF Point,const ptPixelReading PixelReading))128 void SetPixelReader(void (*PixelReader)(const QPointF Point, const ptPixelReading PixelReading)) 129 { FPixelReader = PixelReader; } 130 131 //------------------------------------------------------------------------------ 132 133 protected: 134 void contextMenuEvent(QContextMenuEvent* event); 135 void dragEnterEvent(QDragEnterEvent* event); 136 void dropEvent(QDropEvent* event); 137 void keyPressEvent(QKeyEvent* event); 138 void keyReleaseEvent(QKeyEvent* event); 139 void paintEvent(QPaintEvent* event); 140 void resizeEvent(QResizeEvent* event); 141 void mouseDoubleClickEvent(QMouseEvent* event); 142 void mousePressEvent(QMouseEvent* event); 143 void mouseReleaseEvent(QMouseEvent* event); 144 void mouseMoveEvent(QMouseEvent* event); 145 void wheelEvent(QWheelEvent* event); 146 void leaveEvent(QEvent*); 147 148 //------------------------------------------------------------------------------ 149 150 private: 151 // Determine how/if visible image area can be moved with the mouse. 152 // Default is dragging the image, alternatively Ctrl+Drag depending on current interaction 153 bool isImgDragging(); 154 155 const float MinZoom; 156 const float MaxZoom; 157 QList<float> ZoomFactors; // steps for wheel zoom 158 159 short FCtrlIsPressed; 160 bool FInteractionHasMousePress; 161 ptAbstractInteraction *FCurrentInteraction; // for easy basic access to current interaction 162 ptLineInteraction *FDrawLine; 163 ptSpotInteraction *FSpotTuning; 164 ptSimpleRectInteraction *FSelectRect; 165 ptRichRectInteraction *FCrop; 166 ptGridInteraction *FGrid; 167 ptRepairInteraction *FSpotRepair; 168 ptInteraction FInteraction; 169 bool FLeftMousePressed; 170 void (*FCB_SimpleRect)(const ptStatus, QRect); 171 std::function<void()> FSpotTuningCleanupFunc; 172 short FZoomIsSaved; 173 float FZoomFactor; 174 float FZoomFactorSav; 175 short FZoomModeSav; 176 ptPixelReading FPixelReading; 177 QTimer *FPReadTimer; 178 179 QGraphicsPixmapItem *F8bitImageItem; 180 QLine *FDragDelta; 181 QGraphicsScene *FImageScene; 182 ptReportOverlay *FStatusOverlay; 183 ptReportOverlay *FZoomSizeOverlay; 184 185 // context menu stuff 186 void ConstructContextMenu(); 187 QAction *ac_Copy; 188 QAction *ac_Paste; 189 QAction *ac_Reset; 190 QAction *ac_UserReset; 191 QAction *ac_ZoomFit; 192 QAction *ac_Zoom100; 193 QAction *ac_ZoomIn; 194 QAction *ac_ZoomOut; 195 QAction *ac_Mode_RGB; 196 QAction *ac_Mode_Structure; 197 QAction *ac_Mode_L; 198 QAction *ac_Mode_A; 199 QAction *ac_Mode_B; 200 QAction *ac_Mode_Gradient; 201 QAction *ac_PRead_None; 202 QAction *ac_PRead_Linear; 203 QAction *ac_PRead_Preview; 204 QAction *ac_Clip_Indicate; 205 QAction *ac_Clip_Over; 206 QAction *ac_Clip_Under; 207 QAction *ac_Clip_R; 208 QAction *ac_Clip_G; 209 QAction *ac_Clip_B; 210 QAction *ac_SensorClip; 211 QAction *ac_SensorClipSep; 212 QAction *ac_ShowTools; 213 QAction *ac_ShowZoomBar; 214 QAction *ac_OpenFileMgr; 215 QAction* ac_OpenBatch; 216 QAction *ac_Fullscreen; 217 QActionGroup *ac_ModeGroup; 218 QActionGroup *ac_PReadGroup; 219 220 ptMainWindow *FMainWindow; 221 222 void (*FPixelReader)(const QPointF Point, const ptPixelReading PixelReading); 223 224 //------------------------------------------------------------------------------ 225 226 private slots: 227 void finishInteraction(ptStatus ExitStatus); 228 229 // context menu stuff 230 void Menu_Clip_Indicate(); 231 void Menu_Clip_Over(); 232 void Menu_Clip_Under(); 233 void Menu_Clip_R(); 234 void Menu_Clip_G(); 235 void Menu_Clip_B(); 236 void Menu_SensorClip(); 237 void Menu_ShowZoomBar(); 238 void Menu_ShowTools(); 239 void Menu_Fullscreen(); 240 void Menu_ZoomIn(); 241 void Menu_ZoomFit(); 242 void Menu_Zoom100(); 243 void Menu_ZoomOut(); 244 void Menu_Mode(); 245 void Menu_OpenFileMgr(); 246 void Menu_OpenBatch(); 247 void Menu_PixelReading(); 248 void Menu_Copy(); 249 void Menu_Paste(); 250 void Menu_Reset(); 251 void Menu_UserReset(); 252 253 //------------------------------------------------------------------------------ 254 255 signals: 256 void keyChanged(QKeyEvent* event); 257 void mouseChanged(QMouseEvent* event); 258 void openFileMgr(); 259 void openBatch(); 260 261 262 }; 263 #endif // PTVIEWWINDOW_H 264