File indexing completed on 2025-01-19 03:51:14
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2005-01-18 0007 * Description : a widget class to edit perspective. 0008 * 0009 * SPDX-FileCopyrightText: 2005-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * SPDX-FileCopyrightText: 2006-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #ifndef DIGIKAM_EDITOR_PERSPECTIVE_WIDGET_H 0017 #define DIGIKAM_EDITOR_PERSPECTIVE_WIDGET_H 0018 0019 // Qt includes 0020 0021 #include <QWidget> 0022 #include <QResizeEvent> 0023 #include <QMouseEvent> 0024 #include <QPaintEvent> 0025 #include <QPoint> 0026 #include <QRect> 0027 #include <QColor> 0028 0029 // Local includes 0030 0031 #include "dimg.h" 0032 #include "perspectivematrix.h" 0033 #include "imageiface.h" 0034 0035 using namespace Digikam; 0036 0037 namespace DigikamEditorPerspectiveToolPlugin 0038 { 0039 0040 class PerspectiveWidget : public QWidget 0041 { 0042 Q_OBJECT 0043 0044 public: 0045 0046 PerspectiveWidget(int width, int height, QWidget* const parent = nullptr); 0047 ~PerspectiveWidget() override; 0048 0049 QRect getTargetSize() const; 0050 QPoint getTopLeftCorner() const; 0051 QPoint getTopRightCorner() const; 0052 QPoint getBottomLeftCorner() const; 0053 QPoint getBottomRightCorner() const; 0054 0055 float getAngleTopLeft() const; 0056 float getAngleTopRight() const; 0057 float getAngleBottomLeft() const; 0058 float getAngleBottomRight() const; 0059 0060 ImageIface* imageIface() const; 0061 0062 void setBackgroundColor(const QColor& bg); 0063 void applyPerspectiveAdjustment(); 0064 void reset(); 0065 0066 public Q_SLOTS: 0067 0068 void slotToggleAntiAliasing(bool a); 0069 void slotToggleDrawWhileMoving(bool draw); 0070 void slotToggleDrawGrid(bool grid); 0071 0072 void slotChangeGuideColor(const QColor& color); 0073 void slotChangeGuideSize(int size); 0074 void slotInverseTransformationChanged(bool isEnabled); 0075 0076 Q_SIGNALS: 0077 0078 void signalPerspectiveChanged(const QRect& newSize, float topLeftAngle, float topRightAngle, 0079 float bottomLeftAngle, float bottomRightAngle, bool valid); 0080 0081 protected: 0082 0083 void paintEvent(QPaintEvent*) override; 0084 void resizeEvent(QResizeEvent*) override; 0085 void mousePressEvent(QMouseEvent*) override; 0086 void mouseReleaseEvent(QMouseEvent*) override; 0087 void mouseMoveEvent(QMouseEvent*) override; 0088 0089 private: // Widget methods. 0090 0091 void updatePixmap(); 0092 0093 void transformAffine(DImg* const orgImage, DImg* const destImage, 0094 const PerspectiveMatrix& matrix, const DColor& background); 0095 0096 QPoint buildPerspective(const QPoint& orignTopLeft, const QPoint& orignBottomRight, 0097 const QPoint& transTopLeft, const QPoint& transTopRight, 0098 const QPoint& transBottomLeft, const QPoint& transBottomRight, 0099 DImg* const orgImage=nullptr, DImg* const destImage=nullptr, 0100 const DColor& background=DColor()); 0101 0102 private: 0103 0104 class Private; 0105 Private* const d; 0106 }; 0107 0108 } // namespace DigikamEditorPerspectiveToolPlugin 0109 0110 #endif // DIGIKAM_EDITOR_PERSPECTIVE_WIDGET_H