ultimo comit con mas efectos, conecciones y desconecciones...
[photoboothMX.git] / mainwindow.cpp
bloba2318620cc10b2b545d764bf8731797341ca91d8
1 #include "mainwindow.h"
2 #include "ui_mainwindow.h"
3 #include <opencv/cv.h>
4 #include <opencv/highgui.h>
5 #include <QMessageBox>
6 #include <QImage>
7 #include <QDebug>
8 #include "camara.h"
9 #include <QTimer>
10 #include <QList>
11 #include <QLabel>
12 #include "milabel.h"
13 #include <QPrinter>
14 #include <QPainter>
15 #include <QSpacerItem>
17 // importante ui->label->setPixmap(QPixmap::fromImage(qimg));
18 using namespace cv;
20 MainWindow::MainWindow(QWidget *parent) :
21 QMainWindow(parent),
22 ui(new Ui::MainWindow)
24 //constructor
25 ui->setupUi(this);
27 ui->buttonBox->hide();
29 timeer = new QTimer;
30 timi = new QTimer;
32 //parametros fijos
33 fotonum = 1; //este sive como indice para saber en que label se musetra la foto..
34 foto=0;
35 //setWindowState(Qt::WindowFullScreen);
36 //ui->butonFullscreen->hide();
38 ui->buttonBox->button(QDialogButtonBox::Cancel)->setText("Cancelar");
39 ui->buttonBox->button(QDialogButtonBox::Ok)->setText("Listo!!");
41 foto1 = new MiLabel();
42 foto2 = new MiLabel();
43 foto3 = new MiLabel();
44 foto4 = new MiLabel();
46 //foto1->setPixmap(QPixmap(":imas/admira"));
47 foto1->setidd(-1);
48 foto2->setidd(-2);
49 foto3->setidd(-3);
50 foto4->setidd(-4);
52 foto1->setParent(ui->filmstrip);
53 foto2->setParent(ui->filmstrip);
54 foto3->setParent(ui->filmstrip);
55 foto4->setParent(ui->filmstrip);
57 foto1->setGeometry(15,14,160,120);
58 foto2->setGeometry(15,159,160,120);
59 foto3->setGeometry(15,303,160,120);
60 foto4->setGeometry(15,447,160,120);
62 //agregar fondos
63 for(int i=0;i<=10;i++)
65 misfondos.append(new MiLabel(ui->scrollAreaFondos));
66 QString pixm;
67 pixm = ":fondos/fondo" + QString::number(i);
68 misfondos.last()->setPixmap(pixm);
69 misfondos.last()->setGeometry(5,(0 + i*120),160,120);
70 misfondos.last()->conmarco(true);
71 misfondos.last()->setidd(i);
72 connect(misfondos.last(),SIGNAL(seleccionado(int)),this,SLOT(seSelecciono(int)));
75 //agrega el objeto camaru de tipo camara
76 camaru = new camara;
78 //acomoda los widgets en principal
79 ui->verticalLayout_2->addWidget(ui->countdown);
80 ui->verticalLayout_2->addWidget(camaru);
81 ui->spacerCagalas->invalidate();
82 ui->verticalLayout_2->addStretch();
83 ui->verticalLayout_2->addWidget(ui->buttonBox);
84 ui->verticalLayout_2->addWidget(ui->botonfoto);
86 camaru->setpix(QPixmap(":imas/admira")); //esto es temporal solo para que muestre alguna imagen en cuanto habra el programa
87 camaru->adjustSize();
89 //conecciones debe haber un if y hacer todo esto si abrio bien la camara
90 connect(timeer, SIGNAL(timeout()), camaru, SLOT(newQframe()));
91 timeer->start(60);
93 connect(timi, SIGNAL(timeout()),this, SLOT(aumentaEnSegundo()));
94 connect(this,SIGNAL(yaaa()),this,SLOT(tomafotoReal()));
96 connect(foto1, SIGNAL(seleccionado(int)), this, SLOT(seSelecciono(int)));
97 connect(foto2, SIGNAL(seleccionado(int)), this, SLOT(seSelecciono(int)));
98 connect(foto3, SIGNAL(seleccionado(int)), this, SLOT(seSelecciono(int)));
99 connect(foto4, SIGNAL(seleccionado(int)), this, SLOT(seSelecciono(int)));
102 MainWindow::~MainWindow()
104 delete ui;
107 void MainWindow::on_botonfoto_clicked() //el boton que toma la foto
109 if (camaru->geterror() == 2)
111 ui->buttonBox->hide();
112 camaru->opencam();
115 ui->countdown->setStyleSheet("color: rgb(0, 0, 0);"
116 "border: 2px solid rgb(255, 255, 255);"
117 "border-radius: 18px;"
118 "padding: 15px;"
119 "background: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0.113122 rgba(132, 1, 158, 255), stop:1 rgba(187, 24, 187, 128));"
120 "min-width: 80px;"
121 "color: rgb(255, 255, 255);"
122 "font: 75 65pt Bitstream Charter;"
125 seg=4; // setea seg a 6 para comenzar cuenta regresiva
126 timi->start(1000); // comienza cuenta regresiva
127 ui->countdown->setText("!!Listos!!");
128 ui->countdown->show();
130 ui->filmstrip->blockSignals(true);
131 ui->filmstrip->setDisabled(true);
132 ui->printbut->blockSignals(true);
133 ui->printbut->setDisabled(true);
134 ui->buttonBox->hide();
135 ui->herramientas->blockSignals(true);
136 ui->herramientas->setDisabled(true);
137 ui->botonfoto->blockSignals(true);
138 ui->botonfoto->setDisabled(true);
142 void MainWindow::on_printbut_clicked() //el boton que debe abrir un widget donde muestre la vista previa de las fotos yyy un boton para imprimirles o descartar.
145 foto1->conmarco(false); foto2->conmarco(false); foto3->conmarco(false); foto4->conmarco(false);
147 QPrinter* mipdf=new QPrinter();
148 mipdf->setOutputFormat(QPrinter::PdfFormat);
149 mipdf->setOutputFileName("/tmp/impresion.pdf");
150 QPainter painter;
152 //mipdf->setResolution(QPrinter::HighResolution);
153 mipdf->setPageSize(QPrinter::Custom);
154 mipdf->setFullPage(false);
155 mipdf->setPageMargins(3,3,3,4,QPrinter::Millimeter);
156 mipdf->setPaperSize(QSize(55,158),QPrinter::Millimeter);
158 qDebug() << "page rect " << mipdf->pageRect();
159 qDebug() << "paper rect " << mipdf->paperRect();
161 if (! painter.begin(mipdf))
163 qWarning("failed to open file, is it writable?");
164 painter.end();
165 }else
167 painter.setWindow(0,0,210,600);
168 ui->filmstrip->render(&painter);
172 void MainWindow::on_butonFullscreen_clicked()
174 setWindowState(Qt::WindowFullScreen);
175 ui->butonFullscreen->hide();
178 void MainWindow::aumentaEnSegundo()
180 seg--;
181 ui->countdown->setText(QString::number(seg));
182 qDebug() << seg;
183 if (seg<=0)
184 emit yaaa();
187 void MainWindow::tomafotoReal()
190 ui->countdown->setText("");
191 ui->countdown->setStyleSheet("background: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0.195455 rgba(1, 173, 239, 0), stop:1 rgba(45, 49, 146, 0));"
192 "color: rgb(255, 255, 255);"
193 "font: 75 65pt Bitstream Charter;");
194 timi->stop();
196 ui->filmstrip->blockSignals(false);
197 ui->filmstrip->setEnabled(true);
198 ui->printbut->blockSignals(false);
199 ui->printbut->setEnabled(true);
200 ui->buttonBox->hide();
201 ui->herramientas->blockSignals(false);
202 ui->herramientas->setEnabled(true);
203 ui->botonfoto->blockSignals(false);
204 ui->botonfoto->setEnabled(true);
206 foto++;
207 switch(fotonum)
209 case 1: {foto1->setPixmap(camaru->getpix()); camaru->guardImagen("foto" + QString::number(foto) + ".jpg");} break;
210 case 2: {foto2->setPixmap(camaru->getpix()); camaru->guardImagen("foto" + QString::number(foto) + ".jpg");} break;
211 case 3: {foto3->setPixmap(camaru->getpix()); camaru->guardImagen("foto" + QString::number(foto) + ".jpg");} break;
212 case 4: {foto4->setPixmap(camaru->getpix()); camaru->guardImagen("foto" + QString::number(foto) + ".jpg");} break;
213 default:
215 QMessageBox pregunta;
216 pregunta.setText(tr("Ya no quieres las fotos?"));
217 pregunta.setInformativeText(tr("te pasaste de fotos, quieres sobre escribir las actuales?"));
218 pregunta.setStandardButtons(QMessageBox::No | QMessageBox::Yes);
219 pregunta.setDefaultButton(QMessageBox::No);
220 pregunta.button(QMessageBox::Yes)->setText("Si");
221 pregunta.setStyleSheet("color: rgb(255, 255, 0);"
222 "background-image: url(:/imas/fondo3);"
223 "background-position: padding;"
224 "background-origin: content;"
225 "font: 75 15pt Bitstream Charter;");
226 pregunta.setParent(this);
227 int ret = pregunta.exec();
228 switch (ret){
229 case QMessageBox::Yes : fotonum=0; break;
230 default: break;
232 } break;
234 fotonum++;
236 this->seleccion(fotonum);
240 void MainWindow::seSelecciono(const int &id)
243 switch (id)
245 case -1 : {camaru->setpix(foto1->getpix()); fotonum=1;} break;
246 case -2 : {camaru->setpix(foto2->getpix()); fotonum=2;} break;
247 case -3 : {camaru->setpix(foto3->getpix()); fotonum=3;} break;
248 case -4 : {camaru->setpix(foto4->getpix()); fotonum=4;} break;
249 default: {fondoid=id; camaru->setFondidd(fondoid); }
252 if (id<0)
254 this->seleccion(fotonum);
255 camaru->relacam();
256 ui->buttonBox->show();
263 void MainWindow::on_buttonBox_accepted()
265 ui->buttonBox->hide();
266 fotonum++;
267 camaru->opencam();
268 this->seleccion(fotonum);
272 void MainWindow::on_buttonBox_rejected()
274 ui->buttonBox->hide();
275 //fotonum++;
276 camaru->opencam();
277 this->seleccion(fotonum);
281 void MainWindow::seleccion(const int &caso)
283 switch (caso)
285 case 1 :
286 { foto1->setGeometry(15-10,14,160+15,120+15);
287 foto2->setGeometry(15,159,160,120);
288 foto3->setGeometry(15,303,160,120);
289 foto4->setGeometry(15,447,160,120);
290 foto1->conmarco(true); foto2->conmarco(false); foto3->conmarco(false); foto4->conmarco(false);
291 } break;
292 case 2 : { foto1->setGeometry(15,14,160,120);
293 foto2->setGeometry(15-10,159,160+15,120+15);
294 foto3->setGeometry(15,303,160,120);
295 foto4->setGeometry(15,447,160,120);
296 foto1->conmarco(false); foto2->conmarco(true); foto3->conmarco(false); foto4->conmarco(false);
297 } break;
298 case 3 : { foto1->setGeometry(15,14,160,120);
299 foto2->setGeometry(15,159,160,120);
300 foto3->setGeometry(15-10,303,160+15,120+15);
301 foto4->setGeometry(15,447,160,120);
302 foto1->conmarco(false); foto2->conmarco(false); foto3->conmarco(true); foto4->conmarco(false);
303 } break;
304 case 4 : { foto1->setGeometry(15,14,160,120);
305 foto2->setGeometry(15,159,160,120);
306 foto3->setGeometry(15,303,160,120);
307 foto4->setGeometry(15-10,447,160+15,120+15);
308 foto1->conmarco(false); foto2->conmarco(false); foto3->conmarco(false); foto4->conmarco(true);
309 } break;
315 //efectos
317 void MainWindow::on_blanegro_clicked(bool checked)
319 if (checked==true)
321 //desconeccines
322 disconnect(timeer, SIGNAL(timeout()), camaru, SLOT(newQframe()));
323 disconnect(timeer, SIGNAL(timeout()), camaru, SLOT(newQINframe()));
324 disconnect(timeer, SIGNAL(timeout()), camaru, SLOT(newQEXTframe()));
326 //coneccion
327 connect(timeer, SIGNAL(timeout()), camaru, SLOT(newQBWframe()));
332 void MainWindow::on_normal_clicked(bool checked)
334 if (checked==true)
336 //desconecciones
337 disconnect(timeer, SIGNAL(timeout()), camaru, SLOT(newQBWframe()));
338 disconnect(timeer, SIGNAL(timeout()), camaru, SLOT(newQINframe()));
339 disconnect(timeer, SIGNAL(timeout()), camaru, SLOT(newQEXTframe()));
341 //coneccion
342 connect(timeer, SIGNAL(timeout()), camaru, SLOT(newQframe()));
347 void MainWindow::on_Invertido_clicked(bool checked)
349 if (checked==true)
351 //desconecciones
352 disconnect(timeer, SIGNAL(timeout()), camaru, SLOT(newQBWframe()));
353 disconnect(timeer, SIGNAL(timeout()), camaru, SLOT(newQframe()));
354 disconnect(timeer, SIGNAL(timeout()), camaru, SLOT(newQEXTframe()));
356 //coneccion
357 connect(timeer, SIGNAL(timeout()), camaru, SLOT(newQINframe()));
361 void MainWindow::on_extrafond_clicked(bool checked)
363 if (checked==true)
365 //desconecciones
366 disconnect(timeer, SIGNAL(timeout()), camaru, SLOT(newQBWframe()));
367 disconnect(timeer, SIGNAL(timeout()), camaru, SLOT(newQframe()));
368 disconnect(timeer, SIGNAL(timeout()), camaru, SLOT(newQEXTframe()));
370 //coneccion
371 connect(timeer, SIGNAL(timeout()), camaru, SLOT(newQEXTframe()));
375 void MainWindow::on_experimento1_clicked(bool checked)
377 if (checked==true)
379 //desconecciones
380 disconnect(timeer, SIGNAL(timeout()), camaru, SLOT(newQBWframe()));
381 disconnect(timeer, SIGNAL(timeout()), camaru, SLOT(newQframe()));
382 disconnect(timeer, SIGNAL(timeout()), camaru, SLOT(newQEXTframe()));
383 disconnect(timeer, SIGNAL(timeout()), camaru, SLOT(newQEXTframe()));
385 //coneccion
386 connect(timeer, SIGNAL(timeout()), camaru, SLOT(newQEP1frame()));