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 brush for use with tool to replace part of the image using another
0008  *
0009  * SPDX-FileCopyrightText: 2017 by Shaza Ismail Kaoud <shaza dot ismail dot k at gmail dot com>
0010  * SPDX-FileCopyrightText: 2019 by Ahmed Fathi <ahmed dot fathi dot abdelmageed at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #ifndef DIGIKAM_HEALING_CLONE_TOOL_WIDGET_H
0017 #define DIGIKAM_HEALING_CLONE_TOOL_WIDGET_H
0018 
0019 // Local includes
0020 
0021 #include "previewtoolbar.h"
0022 #include "imageregionwidget.h"
0023 #include "imageregionitem.h"
0024 
0025 using namespace Digikam;
0026 
0027 namespace DigikamEditorHealingCloneToolPlugin
0028 {
0029 
0030 class HealingCloneToolWidget : public ImageRegionWidget
0031 {
0032     Q_OBJECT
0033 
0034 public:
0035 
0036     enum HealingCloneState
0037     {
0038         SELECT_SOURCE,
0039         PAINT,
0040         LASSO_DRAW_BOUNDARY,
0041         LASSO_CLONE,
0042         MOVE_IMAGE,
0043         DO_NOTHING
0044     };
0045     Q_ENUM(HealingCloneState)
0046 
0047 public:
0048 
0049     /**
0050      * Standard constructor
0051      */
0052     explicit HealingCloneToolWidget(QWidget* const parent = nullptr);
0053     ~HealingCloneToolWidget()                                                       override;
0054 
0055     void setBrushValue(int value);
0056     void setIsLassoPointsVectorEmpty(bool);
0057     void setCloneVectorChanged(bool);
0058     void setDrawCursorPosition(const QPointF& topLeftPos);
0059     void setSourceCursorPosition(const QPointF& topLeftPos);
0060 
0061     void changeCursorShape(const QColor& color);
0062 
0063     bool checkPointOutsideScene(const QPoint& point)                          const;
0064     void updateSourceCursor(const QPointF& pos = QPoint(),
0065                             int diamter = 10);
0066 
0067     QPoint mapToImageCoordinates(const QPoint& point)                         const;
0068     QPoint mapFromImageCoordinates(const QPoint& point)                       const;
0069 
0070 public Q_SLOTS:
0071 
0072     /**
0073      * @brief slotSrcSet toggles the fixing of the brush source center
0074      */
0075     void slotSetSourcePoint();
0076     void slotMoveImage();
0077     void slotLassoSelect();
0078 
0079 Q_SIGNALS:
0080 
0081     /**
0082      * @brief signalClone emitted when the src is set and the user initiated a brush click
0083      * and keeps emitting with motion
0084      */
0085     void signalClone(const QPoint& currentSrc, const QPoint& currentDst);
0086     void signalLasso(const QPoint& dst);
0087     void signalResetLassoPoint();
0088     void signalContinuePolygon();
0089     void signalIncreaseBrushRadius();
0090     void signalDecreaseBrushRadius();
0091     void signalPushToUndoStack();
0092     void signalUndoClone();
0093     void signalRedoClone();
0094 
0095 private Q_SLOTS:
0096 
0097     void slotImageRegionChanged();
0098 
0099 protected:
0100 
0101     void mouseReleaseEvent(QMouseEvent*)                                            override;
0102     void mousePressEvent(QMouseEvent*)                                              override;
0103     void mouseMoveEvent(QMouseEvent*)                                               override;
0104     void mouseDoubleClickEvent(QMouseEvent*)                                        override;
0105     void keyPressEvent(QKeyEvent*)                                                  override;
0106     void keyReleaseEvent(QKeyEvent*)                                                override;
0107     void focusOutEvent(QFocusEvent*)                                                override;
0108     void focusInEvent(QFocusEvent*)                                                 override;
0109     bool event(QEvent*)                                                             override;
0110 
0111     void undoSlotSetSourcePoint();
0112     void activateState(HealingCloneState state);
0113 
0114 private:
0115 
0116     // Disable
0117     HealingCloneToolWidget(const HealingCloneToolWidget&)            = delete;
0118     HealingCloneToolWidget& operator=(const HealingCloneToolWidget&) = delete;
0119 
0120 private:
0121 
0122     class Private;
0123     Private* const d;
0124 };
0125 
0126 } // namespace DigikamEditorHealingCloneToolPlugin
0127 
0128 #endif // DIGIKAM_HEALING_CLONE_TOOL_WIDGET_H