QElectroTech 0.200.1-dev
Loading...
Searching...
No Matches
imagecropdialog.h
Go to the documentation of this file.
1/*
2 Copyright 2006-2026 The QElectroTech Team
3 This file is part of QElectroTech.
4
5 QElectroTech is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 2 of the License, or
8 (at your option) any later version.
9
10 QElectroTech is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17*/
18#ifndef IMAGE_CROP_DIALOG_H
19#define IMAGE_CROP_DIALOG_H
20
21#include <QDialog>
22#include <QImage>
23#include <QRect>
24#include <QWidget>
25
26class QMouseEvent;
27class QPaintEvent;
28class QPushButton;
29
42class CropAreaWidget : public QWidget
43{
44 Q_OBJECT
45
46 public:
52 explicit CropAreaWidget(const QImage &sourceImage, const QRect &initialCropRect = QRect(), QWidget *parent = nullptr);
53
57 QRect cropRect() const;
58
59 public slots:
64 void resetToFullImage();
65
66 signals:
68
69 protected:
70 void paintEvent(QPaintEvent *event) override;
71 void mousePressEvent(QMouseEvent *event) override;
72 void mouseMoveEvent(QMouseEvent *event) override;
73 void mouseReleaseEvent(QMouseEvent *event) override;
74
75 private:
77
78 DragMode handleAt(const QPoint &pos) const;
79 void applyDrag(const QPoint &pos);
80
81 QImage m_source;
82 qreal m_displayScale = 1.0;
83 QRect m_displayImageRect; // where the (possibly scaled) pixmap actually sits within this widget
84 QRect m_cropRect; // in display-space, relative to m_displayImageRect's own origin
85
89
90 static constexpr int HANDLE_SIZE = 8;
91 static constexpr int MIN_CROP_SIZE = 16;
92};
93
101class ImageCropDialog : public QDialog
102{
103 Q_OBJECT
104
105 public:
111 explicit ImageCropDialog(const QPixmap &pixmap, const QRect &existingCropRect = QRect(), QWidget *parent = nullptr);
112
115 QRect cropRect() const;
116
117 private:
119};
120
121#endif // IMAGE_CROP_DIALOG_H
The CropAreaWidget class Displays the image scaled to fit a reasonable dialog size,...
Definition imagecropdialog.h:43
qreal m_displayScale
Definition imagecropdialog.h:82
QImage m_source
Definition imagecropdialog.h:81
CropAreaWidget(const QImage &sourceImage, const QRect &initialCropRect=QRect(), QWidget *parent=nullptr)
CropAreaWidget::CropAreaWidget.
Definition imagecropdialog.cpp:42
void mouseMoveEvent(QMouseEvent *event) override
Definition imagecropdialog.cpp:188
DragMode m_dragMode
Definition imagecropdialog.h:86
static constexpr int HANDLE_SIZE
Definition imagecropdialog.h:90
void cropRectChanged()
QRect m_displayImageRect
Definition imagecropdialog.h:83
QRect cropRect() const
CropAreaWidget::cropRect.
Definition imagecropdialog.cpp:90
DragMode handleAt(const QPoint &pos) const
CropAreaWidget::handleAt.
Definition imagecropdialog.cpp:106
void resetToFullImage()
CropAreaWidget::resetToFullImage.
Definition imagecropdialog.cpp:78
void mousePressEvent(QMouseEvent *event) override
Definition imagecropdialog.cpp:179
void mouseReleaseEvent(QMouseEvent *event) override
Definition imagecropdialog.cpp:197
void applyDrag(const QPoint &pos)
CropAreaWidget::applyDrag Recomputes m_cropRect from m_dragStartRect plus however far pos has moved f...
Definition imagecropdialog.cpp:135
QRect m_cropRect
Definition imagecropdialog.h:84
void paintEvent(QPaintEvent *event) override
CropAreaWidget::paintEvent Draws the image, dims everything outside the crop rect (four strips around...
Definition imagecropdialog.cpp:211
DragMode
Definition imagecropdialog.h:76
@ ResizeSW
Definition imagecropdialog.h:76
@ ResizeNW
Definition imagecropdialog.h:76
@ ResizeN
Definition imagecropdialog.h:76
@ None
Definition imagecropdialog.h:76
@ Move
Definition imagecropdialog.h:76
@ ResizeW
Definition imagecropdialog.h:76
@ ResizeS
Definition imagecropdialog.h:76
@ ResizeNE
Definition imagecropdialog.h:76
@ ResizeE
Definition imagecropdialog.h:76
@ ResizeSE
Definition imagecropdialog.h:76
QPoint m_dragStartPos
Definition imagecropdialog.h:87
static constexpr int MIN_CROP_SIZE
Definition imagecropdialog.h:91
QRect m_dragStartRect
Definition imagecropdialog.h:88
CropAreaWidget * m_cropArea
Definition imagecropdialog.h:118
QRect cropRect() const
ImageCropDialog::cropRect.
Definition imagecropdialog.cpp:284
ImageCropDialog(const QPixmap &pixmap, const QRect &existingCropRect=QRect(), QWidget *parent=nullptr)
ImageCropDialog::ImageCropDialog.
Definition imagecropdialog.cpp:254