File indexing completed on 2025-01-05 03:59:44
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2004-08-20 0007 * Description : a widget to display an image with guides 0008 * 0009 * SPDX-FileCopyrightText: 2004-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_GUIDE_WIDGET_H 0016 #define DIGIKAM_IMAGE_GUIDE_WIDGET_H 0017 0018 // Qt includes 0019 0020 #include <QWidget> 0021 #include <QColor> 0022 #include <QPixmap> 0023 #include <QResizeEvent> 0024 #include <QMouseEvent> 0025 #include <QPaintEvent> 0026 #include <QPoint> 0027 #include <QEvent> 0028 #include <QTimerEvent> 0029 0030 // Local includes 0031 0032 #include "imageiface.h" 0033 #include "dcolor.h" 0034 #include "digikam_export.h" 0035 0036 namespace Digikam 0037 { 0038 0039 class DColor; 0040 0041 class DIGIKAM_EXPORT ImageGuideWidget : public QWidget 0042 { 0043 Q_OBJECT 0044 0045 public: 0046 0047 enum GuideToolMode 0048 { 0049 HVGuideMode = 0, 0050 PickColorMode 0051 }; 0052 0053 enum ColorPointSrc 0054 { 0055 OriginalImage = 0, 0056 PreviewImage, 0057 TargetPreviewImage 0058 }; 0059 0060 public: 0061 0062 explicit ImageGuideWidget(QWidget* const parent = nullptr, 0063 bool spotVisible = true, 0064 int guideMode = PickColorMode, 0065 const QColor& guideColor = Qt::red, 0066 int guideSize = 1, 0067 bool blink = false, 0068 ImageIface::PreviewType type= ImageIface::FullImage); 0069 ~ImageGuideWidget() override; 0070 0071 ImageIface* imageIface() const; 0072 QImage getMask() const; 0073 QPoint getSpotPosition() const; 0074 DColor getSpotColor(int getColorFrom) const; 0075 int previewMode() const; 0076 0077 void setSpotVisible(bool spotVisible, bool blink = false); 0078 void setSpotVisibleNoUpdate(bool spotVisible); 0079 void resetSpotPosition(); 0080 void updatePreview(); 0081 void setPoints(const QPolygon& p, bool drawLine = false); 0082 void resetPoints(); 0083 0084 void setPaintColor(const QColor& color); 0085 void setEraseMode(bool erase); 0086 void setMaskEnabled(bool enabled); 0087 void setMaskPenSize(int size); 0088 void setMaskCursor(); 0089 0090 void setBackgroundColor(const QColor&); 0091 void ICCSettingsChanged(); 0092 void exposureSettingsChanged(); 0093 0094 public Q_SLOTS: 0095 0096 void slotChangeGuideColor(const QColor& color); 0097 void slotChangeGuideSize(int size); 0098 void slotPreviewModeChanged(int mode); 0099 0100 Q_SIGNALS: 0101 0102 void spotPositionChangedFromOriginal(const Digikam::DColor& color, const QPoint& position); 0103 void spotPositionChangedFromTarget(const Digikam::DColor& color, const QPoint& position); 0104 void signalResized(); 0105 0106 protected: 0107 0108 void paintEvent(QPaintEvent*) override; 0109 void resizeEvent(QResizeEvent*) override; 0110 void timerEvent(QTimerEvent*) override; 0111 void mousePressEvent(QMouseEvent*) override; 0112 void mouseReleaseEvent(QMouseEvent*) override; 0113 void mouseMoveEvent(QMouseEvent*) override; 0114 0115 #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) 0116 0117 void enterEvent(QEnterEvent*) override; 0118 0119 #else 0120 0121 void enterEvent(QEvent*) override; 0122 0123 #endif 0124 0125 void leaveEvent(QEvent*) override; 0126 void updatePixmap(); 0127 void drawLineTo(const QPoint& endPoint); 0128 void drawLineTo(int width, bool erase, const QColor& color, const QPoint& start, const QPoint& end); 0129 QPoint translatePointPosition(const QPoint& point) const; 0130 void drawText(QPainter* const p, const QPoint& corner, const QString& text); 0131 void updateMaskCursor(); 0132 void setSpotPosition(const QPoint& point); 0133 void updateSpotPosition(int x, int y); 0134 QPoint translateItemPosition(const QPoint& point, bool src) const; 0135 0136 private: 0137 0138 class Private; 0139 Private* const d; 0140 }; 0141 0142 } // namespace Digikam 0143 0144 #endif // DIGIKAM_IMAGE_GUIDE_WIDGET_H