File indexing completed on 2025-01-05 03:59:43

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2013-08-04
0007  * Description : image editor canvas management class
0008  *
0009  * SPDX-FileCopyrightText: 2013-2014 by Yiou Wang <geow812 at gmail dot com>
0010  * SPDX-FileCopyrightText: 2004-2005 by Renchi Raju <renchi dot raju at gmail dot com>
0011  * SPDX-FileCopyrightText: 2004-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0012  *
0013  * SPDX-License-Identifier: GPL-2.0-or-later
0014  *
0015  * ============================================================ */
0016 
0017 #ifndef DIGIKAM_IMAGE_EDITOR_CANVAS_H
0018 #define DIGIKAM_IMAGE_EDITOR_CANVAS_H
0019 
0020 // Qt includes
0021 
0022 #include <QRect>
0023 #include <QWheelEvent>
0024 #include <QMouseEvent>
0025 #include <QKeyEvent>
0026 
0027 // Local includes
0028 
0029 #include "digikam_export.h"
0030 #include "dimg.h"
0031 #include "graphicsdimgview.h"
0032 #include "editorcore.h"
0033 
0034 
0035 namespace Digikam
0036 {
0037 
0038 class EditorCore;
0039 class ExposureSettingsContainer;
0040 class ICCSettingsContainer;
0041 class IccTransform;
0042 class IOFileSettings;
0043 
0044 class DIGIKAM_EXPORT Canvas : public GraphicsDImgView
0045 {
0046     Q_OBJECT
0047 
0048 public:
0049 
0050     explicit Canvas(QWidget* const parent = nullptr);
0051     ~Canvas() override;
0052 
0053     void load(const QString& filename, IOFileSettings* const IOFileSettings);
0054     void preload(const QString& filename);
0055 
0056     void resetImage();
0057     void abortSaving();
0058     void setModified();
0059     void makeDefaultEditingCanvas();
0060 
0061     QString     ensureHasCurrentUuid()   const;
0062 
0063     /**
0064      * Return the core interface instance of editor.
0065      */
0066     EditorCore* interface()              const;
0067 
0068     /**
0069      * Return a copy of current image loaded in editor.
0070      */
0071     DImg        currentImage()           const;
0072 
0073     /**
0074      * Return the type mime of current image loaded in editor.
0075      */
0076     QString     currentImageFileFormat() const;
0077 
0078     /**
0079      * Return the file path of current image loaded in editor.
0080      */
0081     QString     currentImageFilePath()   const;
0082 
0083     /**
0084      * Return the width of current image loaded in editor.
0085      */
0086     int         imageWidth()             const;
0087 
0088     /**
0089      * Return the height of current image loaded in editor.
0090      */
0091     int         imageHeight()            const;
0092 
0093     /**
0094      * Return the rectangle information of current canvas selection.
0095      */
0096     QRect       getSelectedArea()        const;
0097 
0098     /**
0099      * If current image file format is only available in read only,
0100      * typically all RAW image file formats.
0101      */
0102     bool        isReadOnly()             const;
0103 
0104     /**
0105      * Apply Color management settings (typically screen profile).
0106      */
0107     void setICCSettings(const ICCSettingsContainer& cmSettings);
0108 
0109     /**
0110      * Apply Color Management transformation to image (typically working color space).
0111      */
0112     void applyTransform(const IccTransform& transform);
0113 
0114     /**
0115      * Apply under.over exposure indicator settings.
0116      */
0117     void setExposureSettings(ExposureSettingsContainer* const expoSettings);
0118 
0119     /**
0120      * Turn on/off Color Management Soft proofing mode.
0121      */
0122     void setSoftProofingEnabled(bool enable);
0123 
0124     /**
0125      * Rotate image following Exif information.
0126      */
0127     void setExifOrient(bool exifOrient);
0128 
0129     /**
0130      * Return true if image have been rotated following Exif information.
0131      */
0132     bool exifRotated() const;
0133 
0134     /**
0135      * Change zoom level to fit current selection on canvas size.
0136      */
0137     void fitToSelect();
0138 
0139 Q_SIGNALS:
0140 
0141     void signalChanged();
0142     void signalSelected(bool);
0143     void signalRightButtonClicked();
0144     void signalShowNextImage();
0145     void signalShowPrevImage();
0146     void signalPrepareToLoad();
0147     void signalLoadingStarted(const QString& filename);
0148     void signalLoadingFinished(const QString& filename, bool success);
0149     void signalLoadingProgress(const QString& filePath, float progress);
0150     void signalSavingStarted(const QString& filename);
0151     void signalSavingFinished(const QString& filename, bool success);
0152     void signalSavingProgress(const QString& filePath, float progress);
0153     void signalSelectionChanged(const QRect&);
0154     void signalSelectionSetText(const QRect&);
0155     void signalToggleOffFitToWindow();
0156     void signalUndoSteps(int);
0157     void signalRedoSteps(int);
0158     void signalZoomChanged(double);
0159     void signalAddedDropedItems(QDropEvent*);
0160 
0161 public Q_SLOTS:
0162 
0163     /// image modifiers
0164     void slotRotate90();
0165     void slotRotate180();
0166     void slotRotate270();
0167     void slotFlipHoriz();
0168     void slotFlipVert();
0169     void slotCrop();
0170 
0171     void slotRestore();
0172     void slotUndo(int steps = 1);
0173     void slotRedo(int steps = 1);
0174 
0175     void slotCopy();
0176 
0177     void slotSelectAll();
0178     void slotSelectNone();
0179     void slotSelected();
0180     void slotSelectionMoved();
0181 
0182 protected:
0183 
0184     void keyPressEvent(QKeyEvent*) override;
0185     void mousePressEvent(QMouseEvent*) override;
0186     void addRubber();
0187 
0188     void dragMoveEvent(QDragMoveEvent*) override;
0189     void dragEnterEvent(QDragEnterEvent*) override;
0190     void dropEvent(QDropEvent*) override;
0191 
0192 private:
0193 
0194     QRect calcSelectedArea() const;
0195     void  reset();
0196 
0197 private Q_SLOTS:
0198 
0199     void slotModified();
0200     void slotImageLoaded(const QString& filePath, bool success);
0201     void slotImageSaved(const QString& filePath, bool success);
0202     void slotAddItemStarted(const QPointF& pos);
0203     void slotAddItemMoving(const QRectF& rect);
0204     void slotAddItemFinished(const QRectF& rect);
0205     void cancelAddItem();
0206 
0207 private:
0208 
0209     class Private;
0210     Private* const d;
0211 };
0212 
0213 } // namespace Digikam
0214 
0215 #endif // DIGIKAM_IMAGE_EDITOR_CANVAS_H