File indexing completed on 2025-01-05 03:51:41

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2017-06-15
0007  * Description : a tool to replace part of the image using another
0008  *
0009  * SPDX-FileCopyrightText: 2004-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2017      by Shaza Ismail Kaoud <shaza dot ismail dot k at gmail dot com>
0011  * SPDX-FileCopyrightText: 2019      by Ahmed Fathi <ahmed dot fathi dot abdelmageed at gmail dot com>
0012  *
0013  * SPDX-License-Identifier: GPL-2.0-or-later
0014  *
0015  * ============================================================ */
0016 
0017 #ifndef DIGIKAM_EDITOR_HEALING_CLONE_TOOL_H
0018 #define DIGIKAM_EDITOR_HEALING_CLONE_TOOL_H
0019 
0020 // C++ includes
0021 
0022 #include <vector>
0023 
0024 // Local includes
0025 
0026 #include "editortool.h"
0027 #include "dimg.h"
0028 
0029 using namespace Digikam;
0030 
0031 namespace DigikamEditorHealingCloneToolPlugin
0032 {
0033 
0034 class HealingCloneTool : public EditorTool
0035 {
0036     Q_OBJECT
0037 
0038 public:
0039 
0040     /**
0041      * Constructor.
0042      *
0043      * @param parent the parent for qt parent child mechanism
0044      */
0045     explicit HealingCloneTool(QObject* const parent);
0046 
0047     /**
0048      * Destructor.
0049      */
0050     ~HealingCloneTool()      override;
0051 
0052 private Q_SLOTS:
0053 
0054     void slotResetSettings() override;
0055     void slotResized();
0056 
0057 public Q_SLOTS:
0058 
0059     /**
0060      * @brief slotReplace called from the brush widget to start clone/heal
0061      * @param srcPoint the center point of brush source
0062      * @param dstPoint the center point of brush destination
0063      */
0064     void slotReplace(const QPoint& srcPoint, const QPoint& dstPoint);
0065     void slotRadiusChanged(int r);
0066 
0067     void slotLasso(const QPoint& dst);
0068     void slotResetLassoPoints();
0069     void slotContinuePolygon();
0070     void slotIncreaseBrushRadius();
0071     void slotDecreaseBrushRadius();
0072     void slotPushToUndoStack();
0073     void slotUndoClone();
0074     void slotRedoClone();
0075 
0076 private:
0077 
0078     void readSettings()      override;
0079     void writeSettings()     override;
0080     void finalRendering()    override;
0081 
0082     /**
0083      * @brief clone the method responsible for the clone/heal of preview image
0084      * @param img the preview image is passed to this method by reference
0085      * @param srcPoint center of brush source
0086      * @param dstPoint center of brush destination
0087      * @param radius the radius of cloning brush
0088      */
0089     void clone(DImg* const img, const QPoint& srcPoint, const QPoint& dstPoint);
0090     std::vector<QPoint> interpolate(const QPoint& start,const QPoint& end);
0091 
0092     void updateLasso(const std::vector<QPoint>& points);
0093     void initializeLassoFlags();
0094     void removeLassoPixels();
0095     void redrawLassoPixels();
0096 
0097     void refreshImage();
0098 
0099 private:
0100 
0101     class Private;
0102     Private* const d;
0103 };
0104 
0105 } // namespace DigikamEditorHealingCloneToolPlugin
0106 
0107 #endif // DIGIKAM_EDITOR_HEALING_CLONE_TOOL_H