1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date        : 2004-08-20
7  * Description : a widget to display an image with guides
8  *
9  * Copyright (C) 2004-2021 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option)
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #ifndef DIGIKAM_IMAGE_GUIDE_WIDGET_H
25 #define DIGIKAM_IMAGE_GUIDE_WIDGET_H
26 
27 // Qt includes
28 
29 #include <QWidget>
30 #include <QColor>
31 #include <QPixmap>
32 #include <QResizeEvent>
33 #include <QMouseEvent>
34 #include <QPaintEvent>
35 #include <QPoint>
36 #include <QEvent>
37 #include <QTimerEvent>
38 
39 // Local includes
40 
41 #include "imageiface.h"
42 #include "dcolor.h"
43 #include "digikam_export.h"
44 
45 namespace Digikam
46 {
47 
48 class DColor;
49 
50 class DIGIKAM_EXPORT ImageGuideWidget : public QWidget
51 {
52     Q_OBJECT
53 
54 public:
55 
56     enum GuideToolMode
57     {
58         HVGuideMode = 0,
59         PickColorMode
60     };
61 
62     enum ColorPointSrc
63     {
64         OriginalImage = 0,
65         PreviewImage,
66         TargetPreviewImage
67     };
68 
69 public:
70 
71     explicit ImageGuideWidget(QWidget* const parent = nullptr,
72                               bool spotVisible = true,
73                               int guideMode = PickColorMode,
74                               const QColor& guideColor = Qt::red,
75                               int guideSize = 1,
76                               bool blink = false,
77                               ImageIface::PreviewType type= ImageIface::FullImage);
78     ~ImageGuideWidget() override;
79 
80     ImageIface* imageIface()                   const;
81     QImage      getMask()                      const;
82     QPoint      getSpotPosition()              const;
83     DColor      getSpotColor(int getColorFrom) const;
84     int         previewMode()                  const;
85 
86     void   setSpotVisible(bool spotVisible, bool blink = false);
87     void setSpotVisibleNoUpdate(bool spotVisible);
88     void   resetSpotPosition();
89     void   updatePreview();
90     void   setPoints(const QPolygon& p, bool drawLine = false);
91     void   resetPoints();
92 
93     void   setPaintColor(const QColor& color);
94     void   setEraseMode(bool erase);
95     void   setMaskEnabled(bool enabled);
96     void   setMaskPenSize(int size);
97     void   setMaskCursor();
98 
99     void   setBackgroundColor(const QColor&);
100     void   ICCSettingsChanged();
101     void   exposureSettingsChanged();
102 
103 public Q_SLOTS:
104 
105     void slotChangeGuideColor(const QColor& color);
106     void slotChangeGuideSize(int size);
107     void slotPreviewModeChanged(int mode);
108 
109 Q_SIGNALS:
110 
111     void spotPositionChangedFromOriginal(const Digikam::DColor& color, const QPoint& position);
112     void spotPositionChangedFromTarget(const Digikam::DColor& color, const QPoint& position);
113     void signalResized();
114 
115 protected:
116 
117     void   paintEvent(QPaintEvent*)         override;
118     void   resizeEvent(QResizeEvent*)       override;
119     void   timerEvent(QTimerEvent*)         override;
120     void   mousePressEvent(QMouseEvent*)    override;
121     void   mouseReleaseEvent(QMouseEvent*)  override;
122     void   mouseMoveEvent(QMouseEvent*)     override;
123     void   enterEvent(QEvent*)              override;
124     void   leaveEvent(QEvent*)              override;
125     void   updatePixmap();
126     void   drawLineTo(const QPoint& endPoint);
127     void   drawLineTo(int width, bool erase, const QColor& color, const QPoint& start, const QPoint& end);
128     QPoint translatePointPosition(const QPoint& point) const;
129     void   drawText(QPainter* const p, const QPoint& corner, const QString& text);
130     void   updateMaskCursor();
131     void   setSpotPosition(const QPoint& point);
132     void   updateSpotPosition(int x, int y);
133     QPoint translateItemPosition(const QPoint& point, bool src) const;
134 
135 private:
136 
137     class Private;
138     Private* const d;
139 };
140 
141 } // namespace Digikam
142 
143 #endif // DIGIKAM_IMAGE_GUIDE_WIDGET_H
144