digiKam
perspectivewidget.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2005-01-18
7  * Description : a widget class to edit perspective.
8  *
9  * Copyright (C) 2005-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  * Copyright (C) 2006-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option)
16  * any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * ============================================================ */
24 
25 #ifndef DIGIKAM_EDITOR_PERSPECTIVE_WIDGET_H
26 #define DIGIKAM_EDITOR_PERSPECTIVE_WIDGET_H
27 
28 // Qt includes
29 
30 #include <QWidget>
31 #include <QResizeEvent>
32 #include <QMouseEvent>
33 #include <QPaintEvent>
34 #include <QPoint>
35 #include <QRect>
36 #include <QColor>
37 
38 // Local includes
39 
40 #include "dimg.h"
41 #include "perspectivematrix.h"
42 #include "imageiface.h"
43 
44 using namespace Digikam;
45 
47 {
48 
49 class PerspectiveWidget : public QWidget
50 {
51  Q_OBJECT
52 
53 public:
54 
55  PerspectiveWidget(int width, int height, QWidget* const parent = nullptr);
56  ~PerspectiveWidget() override;
57 
58  QRect getTargetSize() const;
59  QPoint getTopLeftCorner() const;
60  QPoint getTopRightCorner() const;
61  QPoint getBottomLeftCorner() const;
62  QPoint getBottomRightCorner() const;
63 
64  float getAngleTopLeft() const;
65  float getAngleTopRight() const;
66  float getAngleBottomLeft() const;
67  float getAngleBottomRight() const;
68 
69  ImageIface* imageIface() const;
70 
71  void setBackgroundColor(const QColor& bg);
72  void applyPerspectiveAdjustment();
73  void reset();
74 
75 public Q_SLOTS:
76 
77  void slotToggleAntiAliasing(bool a);
78  void slotToggleDrawWhileMoving(bool draw);
79  void slotToggleDrawGrid(bool grid);
80 
81  void slotChangeGuideColor(const QColor& color);
82  void slotChangeGuideSize(int size);
83  void slotInverseTransformationChanged(bool isEnabled);
84 
85 Q_SIGNALS:
86 
87  void signalPerspectiveChanged(const QRect& newSize, float topLeftAngle, float topRightAngle,
88  float bottomLeftAngle, float bottomRightAngle, bool valid);
89 
90 protected:
91 
92  void paintEvent(QPaintEvent*) override;
93  void resizeEvent(QResizeEvent*) override;
94  void mousePressEvent(QMouseEvent*) override;
95  void mouseReleaseEvent(QMouseEvent*) override;
96  void mouseMoveEvent(QMouseEvent*) override;
97 
98 private: // Widget methods.
99 
100  void updatePixmap();
101 
102  void transformAffine(DImg* const orgImage, DImg* const destImage,
103  const PerspectiveMatrix& matrix, const DColor& background);
104 
105  QPoint buildPerspective(const QPoint& orignTopLeft, const QPoint& orignBottomRight,
106  const QPoint& transTopLeft, const QPoint& transTopRight,
107  const QPoint& transBottomLeft, const QPoint& transBottomRight,
108  DImg* const orgImage=nullptr, DImg* const destImage=nullptr,
109  const DColor& background=DColor());
110 
111 private:
112 
113  class Private;
114  Private* const d;
115 };
116 
117 } // namespace DigikamEditorPerspectiveToolPlugin
118 
119 #endif // DIGIKAM_EDITOR_PERSPECTIVE_WIDGET_H
void signalPerspectiveChanged(const QRect &newSize, float topLeftAngle, float topRightAngle, float bottomLeftAngle, float bottomRightAngle, bool valid)
Definition: dcolor.h:43
Definition: dimg.h:62
Definition: imageiface.h:47
Definition: perspectivematrix.cpp:36
MetaEngineRotation matrix(MetaEngineRotation::TransformationAction action)
Definition: metaengine_rotation.cpp:81
Definition: datefolderview.cpp:43