blob: 869c49fcef5154d15b01e264a3e61d46c7ac1268 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
//===========================================
// Lumina-DE source code
// Copyright (c) 2016, Ken Moore
// Available under the 3-clause BSD license
// See the LICENSE file for full details
//===========================================
// This is a simple widget for viewing a QImage and allowing the user to
// highlight/select portions of the image with possible actions on the selection
//===========================================
#ifndef _LUMINA_SCREENSHOT_IMAGE_EDITOR_H
#define _LUMINA_SCREENSHOT_IMAGE_EDITOR_H
#include <QImage>
#include <QWidget>
#include <QRect>
#include <QMouseEvent>
#include <QPaintEvent>
#include <QMenu>
class ImageEditor : public QWidget{
Q_OBJECT
public:
ImageEditor(QWidget*parent = 0);
~ImageEditor();
void LoadImage(QImage img);
void setDefaultSize(QSize sz);
bool hasSelection();
QImage image();
int getScalingValue();
private:
QImage fullIMG, scaledIMG; //Note: the aspect ratio between the two images must be preserved!!
QSize defaultSize; //for loading new images
QRect selRect; //selection rectangle (scaledIMG coordinates)
QPoint selPoint; //initial selection point (used during click/drags)
QMenu *contextMenu;
//simplification functions
qreal getScaleFactor(){
//return the scale factor between the full/scaled images
return ( ( (qreal) scaledIMG.height()) / ( (qreal) fullIMG.height()) );
}
void rescaleImage(qreal scfactor){
if(fullIMG.isNull()){ return; }
scaledIMG = fullIMG.scaled( fullIMG.width()*scfactor, fullIMG.height()*scfactor, Qt::KeepAspectRatio,Qt::SmoothTransformation);
selRect = QRect();
emit selectionChanged(false);
this->update(); //trigger a repaint event
}
private slots:
void showMenu();
public slots:
void setScaling(int perc); //10% <--> 200% range is valid
void scaleUp(int val = 10); //10% change by default
void scaleDown(int val = 10); //10% change by default
void cropImage();
void resizeImage();
protected:
void mousePressEvent(QMouseEvent *ev);
void mouseMoveEvent(QMouseEvent *ev);
void mouseReleaseEvent(QMouseEvent *);
void paintEvent(QPaintEvent*);
signals:
void selectionChanged(bool); //true if there is a selection
void scaleFactorChanged(int);
};
#endif
|