File indexing completed on 2025-01-19 03:59:13

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2008-08-20
0007  * Description : editor tool template class.
0008  *
0009  * SPDX-FileCopyrightText: 2008-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #ifndef DIGIKAM_IMAGE_EDITOR_TOOL_H
0016 #define DIGIKAM_IMAGE_EDITOR_TOOL_H
0017 
0018 // Qt includes
0019 
0020 #include <QObject>
0021 #include <QString>
0022 #include <QPixmap>
0023 #include <QPoint>
0024 
0025 // Local includes
0026 
0027 #include "digikam_export.h"
0028 #include "dcolor.h"
0029 #include "previewtoolbar.h"
0030 #include "filteraction.h"
0031 #include "dplugineditor.h"
0032 
0033 namespace Digikam
0034 {
0035 
0036 class DImgThreadedFilter;
0037 class DImgThreadedAnalyser;
0038 class EditorToolSettings;
0039 
0040 class DIGIKAM_EXPORT EditorTool : public QObject
0041 {
0042     Q_OBJECT
0043 
0044 public:
0045 
0046     explicit EditorTool(QObject* const parent);
0047     ~EditorTool()                               override;
0048 
0049     void setPlugin(DPlugin* const plugin);
0050     DPlugin* plugin()                     const;
0051 
0052     /**
0053      * Called by editor tool interface to initialized tool when all is ready, through slotInit().
0054      */
0055     void init();
0056 
0057     /**
0058      * Set this option to on if you want to call slotPreview() in slotInit() at tool startup.
0059      */
0060     void setInitPreview(bool b);
0061 
0062     QString                toolHelp()     const;
0063     QString                toolName()     const;
0064     int                    toolVersion()  const;
0065     QIcon                  toolIcon()     const;
0066     QWidget*               toolView()     const;
0067     EditorToolSettings*    toolSettings() const;
0068     FilterAction::Category toolCategory() const;
0069 
0070     virtual void setBackgroundColor(const QColor& bg);
0071     virtual void ICCSettingsChanged();
0072     virtual void exposureSettingsChanged();
0073 
0074 public Q_SLOTS:
0075 
0076     void slotUpdateSpotInfo(const Digikam::DColor& col, const QPoint& point);
0077     void slotPreviewModeChanged();
0078 
0079     virtual void slotCloseTool();
0080     virtual void slotApplyTool();
0081 
0082 Q_SIGNALS:
0083 
0084     void okClicked();
0085     void cancelClicked();
0086 
0087 protected:
0088 
0089     void setToolInfoMessage(const QString& txt);
0090     void setToolHelp(const QString& anchor);
0091     void setToolName(const QString& name);
0092     void setToolVersion(const int version);
0093     void setToolIcon(const QIcon& icon);
0094     void setPreviewModeMask(int mask);
0095     void setToolCategory(const FilterAction::Category category);
0096 
0097     virtual void setToolView(QWidget* const view);
0098     virtual void setToolSettings(EditorToolSettings* const settings);
0099     virtual void setBusy(bool);
0100     virtual void readSettings();
0101     virtual void writeSettings();
0102     virtual void finalRendering()     {};
0103 
0104 protected Q_SLOTS:
0105 
0106     void slotTimer();
0107 
0108     virtual void slotOk();
0109     virtual void slotCancel();
0110     virtual void slotInit();
0111     virtual void slotResetSettings();
0112     virtual void slotLoadSettings()   {};
0113     virtual void slotSaveAsSettings() {};
0114     virtual void slotPreview()        {};
0115     virtual void slotChannelChanged() {};
0116     virtual void slotScaleChanged()   {};
0117 
0118 private:
0119 
0120     class Private;
0121     Private* const d;
0122 };
0123 
0124 // -----------------------------------------------------------------
0125 
0126 class DIGIKAM_EXPORT EditorToolThreaded : public EditorTool
0127 {
0128     Q_OBJECT
0129 
0130 public:
0131 
0132     enum RenderingMode
0133     {
0134         NoneRendering = 0,
0135         PreviewRendering,
0136         FinalRendering
0137     };
0138 
0139 public:
0140 
0141     explicit EditorToolThreaded(QObject* const parent);
0142     ~EditorToolThreaded()                                     override;
0143 
0144     /**
0145      * Set the small text to show in editor status progress bar during
0146      * tool computation. If it's not set, tool name is used instead.
0147      */
0148     void setProgressMessage(const QString& mess);
0149 
0150     /**
0151      * return the current tool rendering mode.
0152      */
0153     RenderingMode renderingMode()                       const;
0154 
0155 public Q_SLOTS:
0156 
0157     virtual void slotAbort();
0158 
0159 protected:
0160 
0161     /**
0162      * Manage filter instance plugged in tool interface
0163      */
0164     DImgThreadedFilter* filter()                        const;
0165     void setFilter(DImgThreadedFilter* const filter);
0166 
0167     /**
0168      * Manage analyser instance plugged in tool interface
0169      */
0170     DImgThreadedAnalyser* analyser()                    const;
0171     void setAnalyser(DImgThreadedAnalyser* const analyser);
0172 
0173     /**
0174      * If true, delete filter instance when preview or final rendering is processed.
0175      * If false, filter instance will be managed outside for ex. with ContentAwareResizing tool.
0176      */
0177     void deleteFilterInstance(bool b = true);
0178 
0179     virtual void preparePreview()    {};
0180     virtual void prepareFinal()      {};
0181     virtual void setPreviewImage()   {};
0182     virtual void setFinalImage()     {};
0183     virtual void renderingFinished() {};
0184     virtual void analyserCompleted() {};
0185 
0186 protected Q_SLOTS:
0187 
0188     /**
0189      * Manage start and end events from filter
0190      */
0191     void slotFilterStarted();
0192     void slotFilterFinished(bool success);
0193 
0194     /**
0195      * Manage start and end events from analyser
0196      */
0197     void slotAnalyserStarted();
0198     void slotAnalyserFinished(bool success);
0199 
0200     /**
0201      * Dispatch progress event from filter and analyser
0202      */
0203     void slotProgress(int progress);
0204 
0205     void slotInit()                                           override;
0206     void slotOk()                                             override;
0207     void slotCancel()                                         override;
0208     void slotPreview()                                        override;
0209 
0210 private Q_SLOTS:
0211 
0212     void slotResized();
0213 
0214 private:
0215 
0216     class Private;
0217     Private* const d;
0218 };
0219 
0220 } // namespace Digikam
0221 
0222 #endif // DIGIKAM_IMAGE_EDITOR_TOOL_H