forked from magnocube/POV-Globe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slide.cpp
103 lines (72 loc) · 2.46 KB
/
slide.cpp
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "slide.h"
Slide::Slide(QWidget *parent, QGraphicsScene *myS, const QString oName, int width, int height) : QPushButton(parent)
{
myObjectName = oName;
setObjectName(oName);
resolutionX = width;
resolutionY = height;
myScene = myS;
minimumSlideSizeWidth = 120;
minimumSlideSizeHeight = 60;
this->setMinimumHeight(minimumSlideSizeHeight);
this->setMinimumWidth(minimumSlideSizeWidth);
safe();
}
QString Slide::getObjetName()
{
return objectName();
}
QImage Slide::getImage()
{
return myImage;
}
QGraphicsScene *Slide::getScene()
{
return myScene;
}
void Slide::setScene(QGraphicsScene* i)
{
myScene = i;
safe();
}
void Slide::setImage(QImage i)
{
myImage = i;
myScaledImageForDisplaying = myImage.scaled(minimumSlideSizeWidth, minimumSlideSizeHeight, Qt::IgnoreAspectRatio);
safe();
}
void Slide::safe()
{
//myScene->clearSelection(); // Selections would also render to the file
myScene->setSceneRect(myScene->itemsBoundingRect()); // Re-shrink the scene to it's bounding contents
QImage image(myScene->sceneRect().size().toSize(), QImage::Format_ARGB32); // Create the image with the exact size of the shrunk scene
image.fill(Qt::transparent);
QPainter painter(&image);
myScene->render(&painter);
myImage = image.scaled(resolutionX, resolutionY, Qt::IgnoreAspectRatio);;
myScaledImageForDisplaying = myImage.scaled(minimumSlideSizeWidth, minimumSlideSizeHeight, Qt::IgnoreAspectRatio);
emit onClick(objectName()); // make sure the image is selected and updated on all other places
repaint(); //so it updates instantly in the slides
}
QString Slide::safeToDisk(QString path)
{
QImage imageToSafe = myImage;
//do edits on 'imageToSafe'
if(path == ""){ //if no path is given, get a path!.
QFileDialog dialof(this);
path = dialof.getSaveFileName(this,tr("select output folder"),QDir::currentPath(),tr("bmp"));
path.append(".bmp");
}
qDebug() << path;
qDebug() << QString(imageToSafe.save(path,"jpg")); //quallity 25. size of 3.1kb
return("C:/Users/stefa/desktop");
}
void Slide::paintEvent(QPaintEvent *event) //maybe for displaying an image in sted of a pixmap
{
QPainter painter(this);
painter.drawImage(QPoint(0,0),myScaledImageForDisplaying);
}
void Slide::mousePressEvent(QMouseEvent *e)
{
emit onClick(objectName());
}