1 /* ============================================================ 2 * 3 * This file is a part of digiKam project 4 * https://www.digikam.org 5 * 6 * Date : 2013-08-04 7 * Description : image editor canvas management class 8 * 9 * Copyright (C) 2013-2014 by Yiou Wang <geow812 at gmail dot com> 10 * Copyright (C) 2004-2005 by Renchi Raju <renchi dot raju at gmail dot com> 11 * Copyright (C) 2004-2021 by Gilles Caulier <caulier dot gilles at gmail dot com> 12 * 13 * This program is free software; you can redistribute it 14 * and/or modify it under the terms of the GNU General 15 * Public License as published by the Free Software Foundation; 16 * either version 2, or (at your option) 17 * any later version. 18 * 19 * This program is distributed in the hope that it will be useful, 20 * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 * GNU General Public License for more details. 23 * 24 * ============================================================ */ 25 26 #ifndef DIGIKAM_IMAGE_EDITOR_CANVAS_H 27 #define DIGIKAM_IMAGE_EDITOR_CANVAS_H 28 29 // Qt includes 30 31 #include <QRect> 32 #include <QWheelEvent> 33 #include <QMouseEvent> 34 #include <QKeyEvent> 35 36 // Local includes 37 38 #include "digikam_export.h" 39 #include "dimg.h" 40 #include "graphicsdimgview.h" 41 #include "editorcore.h" 42 43 class QWheelEvent; 44 class QKeyEvent; 45 46 namespace Digikam 47 { 48 49 class EditorCore; 50 class ExposureSettingsContainer; 51 class ICCSettingsContainer; 52 class IccTransform; 53 class IOFileSettings; 54 55 class DIGIKAM_EXPORT Canvas : public GraphicsDImgView 56 { 57 Q_OBJECT 58 59 public: 60 61 explicit Canvas(QWidget* const parent = nullptr); 62 ~Canvas() override; 63 64 void load(const QString& filename, IOFileSettings* const IOFileSettings); 65 void preload(const QString& filename); 66 67 void resetImage(); 68 void abortSaving(); 69 void setModified(); 70 void makeDefaultEditingCanvas(); 71 72 QString ensureHasCurrentUuid() const; 73 74 /** 75 * Return the core interface instance of editor. 76 */ 77 EditorCore* interface() const; 78 79 /** 80 * Return a copy of current image loaded in editor. 81 */ 82 DImg currentImage() const; 83 84 /** 85 * Return the type mime of current image loaded in editor. 86 */ 87 QString currentImageFileFormat() const; 88 89 /** 90 * Return the file path of current image loaded in editor. 91 */ 92 QString currentImageFilePath() const; 93 94 /** 95 * Return the width of current image loaded in editor. 96 */ 97 int imageWidth() const; 98 99 /** 100 * Return the height of current image loaded in editor. 101 */ 102 int imageHeight() const; 103 104 /** 105 * Return the rectangle information of current canvas selection. 106 */ 107 QRect getSelectedArea() const; 108 109 /** 110 * If current image file format is only available in read only, 111 * typically all RAW image file formats. 112 */ 113 bool isReadOnly() const; 114 115 /** 116 * Apply Color management settings (typically screen profile). 117 */ 118 void setICCSettings(const ICCSettingsContainer& cmSettings); 119 120 /** 121 * Apply Color Management transformation to image (typically working color space). 122 */ 123 void applyTransform(const IccTransform& transform); 124 125 /** 126 * Apply under.over exposure indicator settings. 127 */ 128 void setExposureSettings(ExposureSettingsContainer* const expoSettings); 129 130 /** 131 * Turn on/off Color Management Soft proofing mode. 132 */ 133 void setSoftProofingEnabled(bool enable); 134 135 /** 136 * Rotate image following Exif information. 137 */ 138 void setExifOrient(bool exifOrient); 139 140 /** 141 * Return true if image have been rotated following Exif information. 142 */ 143 bool exifRotated() const; 144 145 /** 146 * Change zoom level to fit current selection on canvas size. 147 */ 148 void fitToSelect(); 149 150 Q_SIGNALS: 151 152 void signalChanged(); 153 void signalSelected(bool); 154 void signalRightButtonClicked(); 155 void signalShowNextImage(); 156 void signalShowPrevImage(); 157 void signalPrepareToLoad(); 158 void signalLoadingStarted(const QString& filename); 159 void signalLoadingFinished(const QString& filename, bool success); 160 void signalLoadingProgress(const QString& filePath, float progress); 161 void signalSavingStarted(const QString& filename); 162 void signalSavingFinished(const QString& filename, bool success); 163 void signalSavingProgress(const QString& filePath, float progress); 164 void signalSelectionChanged(const QRect&); 165 void signalSelectionSetText(const QRect&); 166 void signalToggleOffFitToWindow(); 167 void signalUndoSteps(int); 168 void signalRedoSteps(int); 169 void signalZoomChanged(double); 170 void signalAddedDropedItems(QDropEvent*); 171 172 public Q_SLOTS: 173 174 /// image modifiers 175 void slotRotate90(); 176 void slotRotate180(); 177 void slotRotate270(); 178 void slotFlipHoriz(); 179 void slotFlipVert(); 180 void slotCrop(); 181 182 void slotRestore(); 183 void slotUndo(int steps = 1); 184 void slotRedo(int steps = 1); 185 186 void slotCopy(); 187 188 void slotSelectAll(); 189 void slotSelectNone(); 190 void slotSelected(); 191 void slotSelectionMoved(); 192 193 protected: 194 195 void keyPressEvent(QKeyEvent*) override; 196 void mousePressEvent(QMouseEvent*) override; 197 void addRubber(); 198 199 void dragMoveEvent(QDragMoveEvent*) override; 200 void dragEnterEvent(QDragEnterEvent*) override; 201 void dropEvent(QDropEvent*) override; 202 203 private: 204 205 QRect calcSelectedArea() const; 206 void reset(); 207 208 private Q_SLOTS: 209 210 void slotModified(); 211 void slotImageLoaded(const QString& filePath, bool success); 212 void slotImageSaved(const QString& filePath, bool success); 213 void slotAddItemStarted(const QPointF& pos); 214 void slotAddItemMoving(const QRectF& rect); 215 void slotAddItemFinished(const QRectF& rect); 216 void cancelAddItem(); 217 218 private: 219 220 class Private; 221 Private* const d; 222 }; 223 224 } // namespace Digikam 225 226 #endif // DIGIKAM_IMAGE_EDITOR_CANVAS_H 227