digiKam
dpreviewimage.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 : 2009-12-13
7  * Description : a widget to preview image effect.
8  *
9  * Copyright (C) 2009-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  * Copyright (C) 2008 by Kare Sars <kare dot sars at iki dot fi>
11  * Copyright (C) 2012 by Benjamin Girault <benjamin dot girault at gmail dot com>
12  *
13  * This program is free software; you can redistribute it
14  * and/or modify it under the terms of the GNU General
15  * Public License as published by the Free Software Foundation;
16  * either version 2, or (at your option)
17  * any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * ============================================================ */
25 
26 #ifndef DIGIKAM_DPREVIEW_IMAGE_H
27 #define DIGIKAM_DPREVIEW_IMAGE_H
28 
29 // Qt includes
30 
31 #include <QGraphicsView>
32 #include <QGraphicsPixmapItem>
33 #include <QString>
34 #include <QColor>
35 
36 // Local includes
37 
38 #include "digikam_export.h"
39 
40 class QResizeEvent;
41 class QWheelEvent;
42 class QMouseEvent;
43 class QEvent;
44 
45 namespace Digikam
46 {
47 
48 class DIGIKAM_EXPORT DSelectionItem : public QGraphicsItem
49 {
50 public:
51 
52  typedef enum
53  {
55  Top,
63  Move
64  } Intersects;
65 
66 public:
67 
68  explicit DSelectionItem(const QRectF& rect);
69  ~DSelectionItem() override;
70 
71 public:
72 
73  void setMaxRight(qreal maxRight);
74  void setMaxBottom(qreal maxBottom);
75 
76  Intersects intersects(QPointF& point);
77 
78  void saveZoom(qreal zoom);
79 
80  void setRect(const QRectF& rect);
81  QRectF rect() const;
82  QPointF fixTranslation(QPointF dp) const;
83 
84 public:
85 
86  // Graphics Item methods
87  QRectF boundingRect() const override;
88  void paint(QPainter* painter,
89  const QStyleOptionGraphicsItem* option,
90  QWidget* widget) override;
91 
92 private:
93 
94  void updateAnchors();
95 
96 private:
97 
98  class Private;
99  Private* const d;
100 };
101 
102 // -----------------------------------------------------------------------------------------
103 
104 class DIGIKAM_EXPORT DPreviewImage : public QGraphicsView
105 {
106  Q_OBJECT
107 
108 public:
109 
110  explicit DPreviewImage(QWidget* const parent);
111  ~DPreviewImage() override;
112 
113 public:
114 
115  bool load(const QUrl& file) const;
116  bool setImage(const QImage& img) const;
117  void enableSelectionArea(bool b);
118 
124  void setSelectionArea(const QRectF& rectangle);
125  QRectF getSelectionArea() const;
126 
127 public Q_SLOTS:
128 
129  void slotZoomIn();
130  void slotZoomOut();
131 // void slotZoomSel(); // TODO: add a button for that purpose
132  void slotZoom2Fit();
133 
136  void slotSetTLX(float ratio);
137  void slotSetTLY(float ratio);
138  void slotSetBRX(float ratio);
139  void slotSetBRY(float ratio);
141 
150  void slotSetSelection(float tl_x, float tl_y, float br_x, float br_y);
151  void slotClearActiveSelection();
152 
161  void slotSetHighlightArea(float tl_x, float tl_y, float br_x, float br_y);
162 
169  void slotSetHighlightShown(int percentage, const QColor& highLightColor = Qt::white);
170 
174  void slotClearHighlight();
175 
176 protected:
177 
178  void wheelEvent(QWheelEvent*) override;
179  void mousePressEvent(QMouseEvent*) override;
180  void mouseReleaseEvent(QMouseEvent*) override;
181  void mouseMoveEvent(QMouseEvent*) override;
182  void leaveEvent(QEvent*) override;
183  bool eventFilter(QObject*, QEvent*) override;
184  void resizeEvent(QResizeEvent*) override;
185 
186 #if (QT_VERSION > QT_VERSION_CHECK(5, 99, 0))
187  void enterEvent(QEnterEvent*) override;
188 #else
189  void enterEvent(QEvent*) override;
190 #endif
191 
192  void updateSelVisibility();
193  void updateHighlight();
194 
195 private:
196 
197  class Private;
198  Private* const d;
199 };
200 
201 } // namespace Digikam
202 
203 #endif // DIGIKAM_DPREVIEW_IMAGE_H
Definition: dpreviewimage.h:105
Definition: dpreviewimage.h:49
@ Top
Definition: dpreviewimage.h:55
@ None
Definition: dpreviewimage.h:54
@ TopLeft
Definition: dpreviewimage.h:62
@ TopRight
Definition: dpreviewimage.h:56
@ BottomRight
Definition: dpreviewimage.h:58
@ BottomLeft
Definition: dpreviewimage.h:60
@ Right
Definition: dpreviewimage.h:57
@ Bottom
Definition: dpreviewimage.h:59
@ Left
Definition: dpreviewimage.h:61
Definition: datefolderview.cpp:43