forked from magnocube/POV-Globe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pixeleditor.cpp
153 lines (115 loc) · 3.93 KB
/
pixeleditor.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include "pixeleditor.h"
#include "ui_pixeleditor.h"
PixelEditor::PixelEditor(QWidget *parent) :
QWidget(parent),
ui(new Ui::PixelEditor)
{
ui->setupUi(this);
ui->pixelGraphicsView->acceptDrops(); //------------------------------------------ try to remove when evrrything is done
setupLayout();
}
PixelEditor::~PixelEditor()
{
delete ui;
}
void PixelEditor::setCurrentSlide(Slide *s)
{
myCurrentSlide = s;
ui->pixelGraphicsView->setScene(myCurrentSlide->getScene());
repaint(); //needed for obvious reasons (forces to repaint the gui)
}
void PixelEditor::on_SafeButton_clicked()
{
// myCurrentSlide->getScene()->clearSelection(); // Selections would also render to the file
// myCurrentSlide->getScene()->setSceneRect(scene->itemsBoundingRect()); // Re-shrink the scene to it's bounding contents
// QImage image(myCurrentSlide->getScene()->sceneRect().size().toSize(), QImage::Format_ARGB32); // Create the image with the exact size of the shrunk scene
// image.fill(Qt::transparent);
// QPainter painter(&image);
// myCurrentSlide->getScene()->render(&painter);
// myCurrentSlide->setImage(image);
// QRectF myRect(10,10,30,30);
// myCurrentSlide->getScene()->addRect(myRect,QPen(),QBrush());
if(myCurrentSlide == nullptr){
return;
}
myCurrentSlide->safe();
}
void PixelEditor::on_zoomInButton_clicked()
{
ui->pixelGraphicsView->scale(1.3,1.3);
}
void PixelEditor::on_zoomOutButton_clicked()
{
ui->pixelGraphicsView->scale(0.7,0.7);
}
void PixelEditor::setupLayout()
{
int width = 40;
int height = 40;
QPixmap pixmapRect(":/icons/icons/rectangle.png");
QIcon rectIcon(pixmapRect);
ui->addRectangleButton->setIconSize(QSize(width,height));
ui->addRectangleButton->setIcon(rectIcon);
QPixmap pixmapEllipse(":/icons/icons/ellipse.png");
QIcon ellipseIcon(pixmapEllipse);
ui->addEllipseButton->setIconSize(QSize(width,height));
ui->addEllipseButton->setIcon(ellipseIcon);
QPixmap pixmapText(":/icons/icons/text.png");
QIcon textIcon(pixmapText);
ui->addTextButton->setIconSize(QSize(width,height));
ui->addTextButton->setIcon(textIcon);
QPixmap pixmapImage(":/icons/icons/image.png");
QIcon imageIcon(pixmapImage);
ui->addImageButton->setIconSize(QSize(width,height));
ui->addImageButton->setIcon(imageIcon);
}
void PixelEditor::on_addEllipseButton_clicked()
{
if(myCurrentSlide == nullptr){
return;
}
CustomEllipse *ellipse = new CustomEllipse();
myCurrentSlide->getScene()->addItem(ellipse);
connect(ellipse,SIGNAL(updateGraphics()),this,SLOT(updateGraphicsview()));
}
void PixelEditor::on_addRectangleButton_clicked()
{
if(myCurrentSlide == nullptr){
return;
}
CustomRect *rect = new CustomRect();
myCurrentSlide->getScene()->addItem(rect);
connect(rect,SIGNAL(updateGraphics()),this,SLOT(updateGraphicsview()));
}
void PixelEditor::on_addTextButton_clicked()
{
if(myCurrentSlide == nullptr){
return;
}
CustomText *text = new CustomText();
myCurrentSlide->getScene()->addItem(text);
connect(text,SIGNAL(updateGraphics()),this,SLOT(updateGraphicsview()));
}
void PixelEditor::on_addImageButton_clicked()
{
if(myCurrentSlide == nullptr){
return;
}
QImage myImage;
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Image"), "/C", tr("Image Files (*.png *.jpg *.bmp *.jpeg *.gif)"));
qDebug() << fileName;
if(fileName != ""){
myImage = QImage(fileName);
} else{
return;
}
CustomImage *image = new CustomImage();
image->setImage(myImage);
myCurrentSlide->getScene()->addItem(image);
connect(image,SIGNAL(updateGraphics()),this,SLOT(updateGraphicsview()));
}
void PixelEditor::updateGraphicsview()
{
ui->pixelGraphicsView->update();
}