![]() |
OpenAlbum 1.0.b
|
00001 #include "dialogcreacionpaginas.h" 00002 #include "ui_dialogcreacionpaginas.h" 00003 #include <QDir> 00004 #include "parser.h" 00005 #include "fondodialog.h" 00006 #include "ui_fondodialog.h" 00007 #include "dialogtextopagina.h" 00008 #include <stdlib.h> 00009 #include <time.h> 00010 #include <error.h> 00011 00012 DialogCreacionPaginas::DialogCreacionPaginas(QWidget *parent, controladorResolucion *controlador_, QDir directoriodetrabajo) : 00013 QDialog(parent), 00014 ui(new Ui::DialogCreacionPaginas) 00015 { 00016 ui->setupUi(this); 00017 this->controlador=controlador_; 00018 this->setDimensiones(); 00019 this->directorioPpal=directoriodetrabajo; 00020 this->ui->radioAutoAle->setStyle(new QWindowsStyle); 00021 this->ui->radioAutoFija->setStyle(new QWindowsStyle); 00022 this->ui->radioPersonalizada->setStyle(new QWindowsStyle); 00023 this->ui->groupBox->setStyle(new QWindowsStyle); 00024 this->ui->groupBoxAleatorio->setStyle(new QWindowsStyle); 00025 this->ui->groupBoxFija->setStyle(new QWindowsStyle); 00026 this->ui->SelectorPlantilla->setStyle(new QWindowsStyle); 00027 this->ui->VisualizarPlantilla->setStyle(new QWindowsStyle); 00028 fija=false; 00029 00030 aleatoria=false; 00031 personalizada=false; 00032 color=false; 00033 escritooNo1=false; 00034 this->textoEstablecido=false; 00035 this->subTareaCompleta=false; 00036 escritooNo2=false; 00037 escritooNo3=false; 00038 escritooNo4=false; 00039 coloreadooNo1=false; 00040 coloreadooNo2=false; 00041 coloreadooNo3=false; 00042 coloreadooNo4=false; 00043 this->numTextos=0; 00044 this->ColorElegido=new QColor(); 00045 this->FondoElegido=new QString(); 00046 00047 QGraphicsScene *scene; 00048 try{ 00049 00050 scene= new QGraphicsScene(); 00051 }catch(std::exception& e){ 00052 Error *err=new Error(2, e.what(), this); 00053 err->LanzarDialogo(); 00054 delete err; 00055 exit(1); 00056 } 00057 ui->VisualizarPlantilla->setScene(scene); 00058 QImage *img=new QImage(); 00059 img->load(this->directorioPpal.absolutePath() +"/data/paginaDisabled.png"); 00060 QPixmap image=QPixmap::fromImage(*img); 00061 ui->VisualizarPlantilla->scene()->addPixmap(image.scaled((136*this->controlador->getWcreacionpaginas())/478, (101*this->controlador->getHcreacionpaginas())/476, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); 00062 ui->VisualizarPlantilla->hide(); 00063 ui->SelectorPlantilla->hide(); 00064 ui->pushCancelar->move(ui->pushCancelar->x(), ui->pushCancelar->y()-120); 00065 ui->pushFondo->move(ui->pushFondo->x(), ui->pushFondo->y()-120); 00066 ui->pushIntroTexto->move(ui->pushIntroTexto->x(), ui->pushIntroTexto->y()-120); 00067 ui->pushSiguiente->move(ui->pushSiguiente->x(), ui->pushSiguiente->y()-120); 00068 this->setFixedHeight(this->controlador->getHcreacionpaginas()-121); 00069 this->ui->groupBoxFija->setFixedHeight(this->ui->groupBoxFija->height()-120); 00070 delete img; 00071 QIcon *iconoVentana=new QIcon(directoriodetrabajo.absolutePath() + "/data/iconlargue.png"); 00072 this->setWindowIcon(*iconoVentana); 00073 delete iconoVentana; 00074 } 00075 00076 DialogCreacionPaginas::~DialogCreacionPaginas() 00077 { 00078 for(int i=0; i < ui->VisualizarPlantilla->items().size(); i++){ 00079 delete ui->VisualizarPlantilla->items().at(i); 00080 } 00081 delete ui->VisualizarPlantilla->scene(); 00082 delete ui->VisualizarPlantilla; 00083 delete ui; 00084 delete this->ColorElegido; 00085 delete this->FondoElegido; 00086 00087 } 00088 00089 00090 void DialogCreacionPaginas::setDimensiones(){ 00091 this->setFixedSize(this->controlador->getWcreacionpaginas(), this->controlador->getHcreacionpaginas()); 00092 int W=this->controlador->getWcreacionpaginas(); 00093 int H=this->controlador->getHcreacionpaginas(); 00094 int x,y; 00095 x=this->ui->SelectorPlantilla->x(); 00096 y=this->ui->SelectorPlantilla->y(); 00097 this->ui->SelectorPlantilla->setGeometry((x*W)/478, (y*H)/466, (261*W)/478, (101*H)/466); 00098 x=this->ui->VisualizarPlantilla->x(); 00099 y=this->ui->VisualizarPlantilla->y(); 00100 this->ui->VisualizarPlantilla->setGeometry((x*W)/478, (y*H)/466, (136*W)/478, (101*H)/466); 00101 x=this->ui->groupBox->x(); 00102 y=this->ui->groupBox->y(); 00103 this->ui->groupBox->setGeometry((x*W)/478, (y*H)/466, (451*W)/478, (91*H)/466); 00104 x=this->ui->groupBoxAleatorio->x(); 00105 y=this->ui->groupBoxAleatorio->y(); 00106 this->ui->groupBoxAleatorio->setGeometry((x*W)/478, (y*H)/466, (451*W)/478, (101*H)/466); 00107 x=this->ui->groupBoxFija->x(); 00108 y=this->ui->groupBoxFija->y(); 00109 this->ui->groupBoxFija->setGeometry((x*W)/478, (y*H)/466, (451*W)/478, (201*H)/466); 00110 x=this->ui->label->x(); 00111 y=this->ui->label->y(); 00112 this->ui->label->setGeometry((x*W)/478, (y*H)/466, (421*W)/478, (51*H)/466); 00113 x=this->ui->labelAleatorio->x(); 00114 y=this->ui->labelAleatorio->y(); 00115 this->ui->labelAleatorio->setGeometry((x*W)/478, (y*H)/466, (421*W)/478, (51*H)/466); 00116 x=this->ui->labelFija->x(); 00117 y=this->ui->labelFija->y(); 00118 this->ui->labelFija->setGeometry((x*W)/478, (y*H)/466, (421*W)/478, (51*H)/466); 00119 x=this->ui->pushCancelar->x(); 00120 y=this->ui->pushCancelar->y(); 00121 this->ui->pushCancelar->setGeometry((x*W)/478, (y*H)/466, (98*W)/478, (27*H)/466); 00122 x=this->ui->pushFondo->x(); 00123 y=this->ui->pushFondo->y(); 00124 this->ui->pushFondo->setGeometry((x*W)/478, (y*H)/466, (98*W)/478, (27*H)/466); 00125 x=this->ui->pushIntroTexto->x(); 00126 y=this->ui->pushIntroTexto->y(); 00127 this->ui->pushIntroTexto->setGeometry((x*W)/478, (y*H)/466, (98*W)/478, (27*H)/466); 00128 x=this->ui->pushSiguiente->x(); 00129 y=this->ui->pushSiguiente->y(); 00130 this->ui->pushSiguiente->setGeometry((x*W)/478, (y*H)/466, (98*W)/478, (27*H)/466); 00131 x=this->ui->radioAutoAle->x(); 00132 y=this->ui->radioAutoAle->y(); 00133 this->ui->radioAutoAle->setGeometry((x*W)/478, (y*H)/466, (441*W)/478, (22*H)/466); 00134 x=this->ui->radioAutoFija->x(); 00135 y=this->ui->radioAutoFija->y(); 00136 this->ui->radioAutoFija->setGeometry((x*W)/478, (y*H)/466, (441*W)/478, (22*H)/466); 00137 x=this->ui->radioPersonalizada->x(); 00138 y=this->ui->radioPersonalizada->y(); 00139 this->ui->radioPersonalizada->setGeometry((x*W)/478, (y*H)/466, (441*W)/478, (22*H)/466); 00140 00141 00142 } 00143 00144 void DialogCreacionPaginas::InicializarTexto1(bool cc1, bool nn1, bool ss1, QString tt1, QFont ff1){ 00145 00146 c1=cc1; 00147 n1=nn1; 00148 s1=ss1; 00149 t1=tt1; 00150 fuente1=ff1; 00151 } 00152 00153 void DialogCreacionPaginas::InicializarTexto2(bool cc2, bool nn2, bool ss2, QString tt2, QFont ff2){ 00154 00155 c2=cc2; 00156 n2=nn2; 00157 s2=ss2; 00158 t2=tt2; 00159 fuente2=ff2; 00160 } 00161 00162 void DialogCreacionPaginas::InicializarTexto3(bool cc3, bool nn3, bool ss3, QString tt3, QFont ff3){ 00163 00164 c3=cc3; 00165 n3=nn3; 00166 s3=ss3; 00167 t3=tt3; 00168 fuente3=ff3; 00169 } 00170 00171 void DialogCreacionPaginas::InicializarTexto4 (bool cc4, bool nn4, bool ss4, QString tt4, QFont ff4){ 00172 00173 c4=cc4; 00174 n4=nn4; 00175 s4=ss4; 00176 t4=tt4; 00177 fuente4=ff4; 00178 } 00179 00180 void DialogCreacionPaginas::PushTexto(){ 00181 DialogTextoPagina *formTexto; 00182 try{ 00183 formTexto= new DialogTextoPagina(0, GetNumTextos(), NombrePlantillaFija(), this->controlador, this->directorioPpal); 00184 }catch(std::exception& e){ 00185 Error *err=new Error(2, e.what(), this); 00186 err->LanzarDialogo(); 00187 delete err; 00188 exit(1); 00189 } 00190 00191 formTexto->exec(); 00192 if(formTexto->formularioAceptado()){ 00193 00194 if(GetNumTextos()>0){ 00195 InicializarTexto1(formTexto->cur1, formTexto->neg1, formTexto->sub1, formTexto->text1, formTexto->f1); 00196 escritooNo1=true; 00197 if(formTexto->coloreado1){ 00198 coloreadooNo1=true; 00199 clr1=formTexto->colortexto1; 00200 } 00201 } 00202 00203 if(GetNumTextos()>1){ 00204 InicializarTexto2(formTexto->cur2, formTexto->neg2, formTexto->sub2, formTexto->text2, formTexto->f2); 00205 escritooNo2=true; 00206 if(formTexto->coloreado2){ 00207 coloreadooNo2=true; 00208 clr2=formTexto->colortexto2; 00209 } 00210 } 00211 00212 if(GetNumTextos()>2){ 00213 InicializarTexto3(formTexto->cur3, formTexto->neg3, formTexto->sub3, formTexto->text3, formTexto->f3); 00214 escritooNo3=true; 00215 if(formTexto->coloreado3){ 00216 coloreadooNo3=true; 00217 clr3=formTexto->colortexto3; 00218 } 00219 } 00220 00221 if(GetNumTextos()>3){ 00222 InicializarTexto4(formTexto->cur4, formTexto->neg4, formTexto->sub4, formTexto->text4, formTexto->f4); 00223 escritooNo4=true; 00224 if(formTexto->coloreado4){ 00225 coloreadooNo4=true; 00226 clr4=formTexto->colortexto4; 00227 } 00228 } 00229 00230 00231 00232 00233 if(GetNumTextos()==1){ 00234 00235 if(!this->t1.isNull()){ 00236 this->textoEstablecido=true; 00237 00238 }else{ 00239 this->textoEstablecido=false; 00240 } 00241 } 00242 if(GetNumTextos()==2){ 00243 00244 if(!this->t1.isNull() && !this->t2.isNull()){ 00245 this->textoEstablecido=true; 00246 00247 }else{ 00248 this->textoEstablecido=false; 00249 } 00250 } 00251 if(GetNumTextos()==3){ 00252 00253 if(!this->t1.isNull() && !this->t2.isNull() && !this->t3.isNull()){ 00254 this->textoEstablecido=true; 00255 00256 }else{ 00257 this->textoEstablecido=false; 00258 } 00259 } 00260 if(GetNumTextos()==4){ 00261 00262 if(!this->t1.isNull() && !this->t2.isNull() && !this->t3.isNull() && !this->t4.isNull()){ 00263 this->textoEstablecido=true; 00264 00265 }else{ 00266 this->textoEstablecido=false; 00267 } 00268 } 00269 if(this->textoEstablecido && this->subTareaCompleta){ 00270 ui->pushSiguiente->setEnabled(true); 00271 ui->SelectorPlantilla->setDisabled(true); 00272 } 00273 00274 } 00275 delete formTexto; 00276 00277 } 00278 00279 void DialogCreacionPaginas::DesactivarSeleccionPlantilla(){ 00280 if(this->height()==this->controlador->getHcreacionpaginas()){ 00281 ui->VisualizarPlantilla->hide(); 00282 ui->SelectorPlantilla->hide(); 00283 ui->pushCancelar->move(ui->pushCancelar->x(), ui->pushCancelar->y()-120); 00284 ui->pushFondo->move(ui->pushFondo->x(), ui->pushFondo->y()-120); 00285 ui->pushIntroTexto->move(ui->pushIntroTexto->x(), ui->pushIntroTexto->y()-120); 00286 ui->pushSiguiente->move(ui->pushSiguiente->x(), ui->pushSiguiente->y()-120); 00287 this->setFixedHeight(this->controlador->getHcreacionpaginas()-121); 00288 this->ui->groupBoxFija->setFixedHeight(this->ui->groupBoxFija->height()-120); 00289 } 00290 00291 QGraphicsScene *scene; 00292 try{ 00293 00294 scene= new QGraphicsScene(); 00295 }catch(std::exception& e){ 00296 Error *err=new Error(2, e.what(), this); 00297 err->LanzarDialogo(); 00298 delete err; 00299 exit(1); 00300 } 00301 ui->VisualizarPlantilla->setScene(scene); 00302 QImage *img=new QImage(); 00303 img->load(this->directorioPpal.absolutePath() +"/data/paginaDisabled.png"); 00304 QPixmap image=QPixmap::fromImage(*img); 00305 ui->VisualizarPlantilla->scene()->addPixmap(image.scaled((129*this->controlador->getWcreacionpaginas())/478, (95*this->controlador->getHcreacionpaginas())/476, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); 00306 00307 ui->pushSiguiente->setEnabled(true); 00308 ui->SelectorPlantilla->setDisabled(true); 00309 ui->VisualizarPlantilla->setDisabled(true); 00310 ui->pushFondo->setDisabled(true); 00311 ui->pushIntroTexto->setDisabled(true); 00312 if(ui->radioPersonalizada->isDown()){ 00313 this->ui->label->setEnabled(true); 00314 }else{ 00315 this->ui->label->setDisabled(true); 00316 } 00317 if(ui->radioAutoAle->isDown()){ 00318 this->ui->labelAleatorio->setEnabled(true); 00319 }else{ 00320 this->ui->labelAleatorio->setDisabled(true); 00321 } 00322 00323 this->ui->labelFija->setDisabled(true); 00324 00325 delete img; 00326 } 00327 00328 00329 00330 00331 00332 00333 00334 bool DialogCreacionPaginas::ColorFondo(){ 00335 00336 return color; 00337 00338 } 00339 00340 QColor DialogCreacionPaginas::GetColorFondo(){ 00341 00342 return *ColorElegido; 00343 } 00344 00345 QString DialogCreacionPaginas::GetImagenFondo(){ 00346 00347 return *FondoElegido; 00348 } 00349 00350 void DialogCreacionPaginas::setMiniaturasTexturas(std::vector<QGraphicsView*> min){ 00351 this->miniaturasTextura=min; 00352 } 00353 00354 void DialogCreacionPaginas::EstablecerFondo(QWidget *parent){ 00355 00356 FondoDialog *dialog; 00357 if(parent==0){ 00358 parent=this; 00359 } 00360 try{ 00361 dialog=new FondoDialog(parent, this->NombrePlantillaFija(), true, this->controlador, this->directorioPpal); 00362 }catch(std::exception& e){ 00363 Error *err=new Error(2, e.what(), this); 00364 err->LanzarDialogo(); 00365 delete err; 00366 exit(1); 00367 } 00368 dialog->setMiniaturasTexturas(this->miniaturasTextura); 00369 00370 dialog->exec(); 00371 00372 this->color=false; 00373 if(dialog->ColordeFondo()){ 00374 try{ 00375 *ColorElegido= dialog->ColorFondo(); 00376 }catch(std::exception& e){ 00377 Error *err=new Error(2, e.what(), this); 00378 err->LanzarDialogo(); 00379 delete err; 00380 exit(1); 00381 } 00382 00383 color=true; 00384 if(dialog->getTareaCompleta()){ 00385 this->subTareaCompleta=true; 00386 } 00387 }else{ 00388 try{ 00389 *FondoElegido= dialog->ImagenFondo(); 00390 }catch(std::exception& e){ 00391 Error *err=new Error(2, e.what(), this); 00392 err->LanzarDialogo(); 00393 delete err; 00394 exit(1); 00395 } 00396 if(!FondoElegido->isNull()){ 00397 this->subTareaCompleta=true; 00398 } 00399 } 00400 if(this->GetNumTextos()==0 && this->subTareaCompleta){ 00401 ui->pushSiguiente->setEnabled(true); 00402 }else{ 00403 if(this->textoEstablecido && this->subTareaCompleta){ 00404 ui->pushSiguiente->setEnabled(true); 00405 } 00406 } 00407 delete dialog; 00408 00409 00410 } 00411 00412 QString DialogCreacionPaginas::NombrePlantillaFija(){ 00413 00414 return nombreplantillafija; 00415 } 00416 00417 00418 int DialogCreacionPaginas::GetNumTextos(){ 00419 return numTextos; 00420 00421 } 00422 00423 void DialogCreacionPaginas::ActivarVisualizacionPlantilla(){ 00424 if(this->height()!=this->controlador->getHcreacionpaginas()){ 00425 ui->VisualizarPlantilla->show(); 00426 ui->SelectorPlantilla->show(); 00427 ui->pushCancelar->move(ui->pushCancelar->x(), ui->pushCancelar->y()+120); 00428 ui->pushFondo->move(ui->pushFondo->x(), ui->pushFondo->y()+120); 00429 ui->pushIntroTexto->move(ui->pushIntroTexto->x(), ui->pushIntroTexto->y()+120); 00430 ui->pushSiguiente->move(ui->pushSiguiente->x(), ui->pushSiguiente->y()+120); 00431 this->setFixedHeight(this->controlador->getHcreacionpaginas()); 00432 this->ui->groupBoxFija->setFixedHeight(this->ui->groupBoxFija->height()+120); 00433 } 00434 00435 QGraphicsScene *scene; 00436 try{ 00437 00438 scene= new QGraphicsScene(); 00439 }catch(std::exception& e){ 00440 Error *err=new Error(2, e.what(), this); 00441 err->LanzarDialogo(); 00442 delete err; 00443 exit(1); 00444 } 00445 ui->VisualizarPlantilla->setScene(scene); 00446 this->ui->pushSiguiente->setDisabled(true); 00447 for (int i = ui->SelectorPlantilla->topLevelItemCount() - 1; i >= 0; i--){ 00448 00449 if((ui->SelectorPlantilla->topLevelItem(i))->isSelected()){ 00450 ui->pushFondo->setEnabled(true); 00451 00452 00453 00454 QString filename=this->directorioPpal.absolutePath() + "/templates/pages/" + (ui->SelectorPlantilla->topLevelItem(i))->text(0) + ".xml"; 00455 nombreplantillafija=filename; 00456 Parser parser(filename.toStdString(), this); 00457 ticpp::Element* element = parser.root(); 00458 std::string filenameprev = parser.get_attribute("preview", element); 00459 int texto; 00460 parser.get_attribute("texto", element, &texto); 00461 if(texto!=0){ 00462 ui->pushIntroTexto->setEnabled(true); 00463 numTextos=texto; 00464 00465 00466 }else{ 00467 ui->pushIntroTexto->setDisabled(true); 00468 numTextos=0; 00469 } 00470 00471 if(this->GetNumTextos()==0 && this->subTareaCompleta){ 00472 ui->pushSiguiente->setEnabled(true); 00473 }else{ 00474 if(this->textoEstablecido && this->subTareaCompleta){ 00475 ui->pushSiguiente->setEnabled(true); 00476 } 00477 } 00478 00479 QString *aux; 00480 QImage *img; 00481 try{ 00482 img= new QImage(); 00483 aux=new QString(filenameprev.c_str()); 00484 }catch(std::exception& e){ 00485 Error *err=new Error(2, e.what(), this); 00486 err->LanzarDialogo(); 00487 delete err; 00488 exit(1); 00489 } 00490 00491 QString filenameprev2=this->directorioPpal.absolutePath() + "/templates/pages/"; 00492 try{ 00493 img->load(filenameprev2 + *aux); 00494 }catch(std::exception& e){ 00495 Error *err=new Error(4, e.what(), this); 00496 err->LanzarDialogo(); 00497 delete err; 00498 exit(1); 00499 } 00500 QPixmap image=QPixmap::fromImage(*img); 00501 ui->VisualizarPlantilla->scene()->addPixmap(image.scaled((136*this->controlador->getWcreacionpaginas())/478, (101*this->controlador->getHcreacionpaginas())/476, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); 00502 00503 } 00504 00505 } 00506 00507 00508 00509 00510 00511 } 00512 00513 bool DialogCreacionPaginas::PaginasFijas(){ 00514 return fija; 00515 } 00516 00517 bool DialogCreacionPaginas::PaginasAleatorias(){ 00518 return aleatoria; 00519 } 00520 00521 void DialogCreacionPaginas::EstablecerTipoPagina(){ 00522 if(ui->radioPersonalizada->isChecked()) 00523 personalizada=true; 00524 else{ 00525 if(ui->radioAutoAle->isChecked()) 00526 aleatoria=true; 00527 else{ 00528 if(ui->radioAutoFija->isChecked()) 00529 fija=true; 00530 00531 } 00532 } 00533 close(); 00534 this->finished(1); 00535 this->setResult(1); 00536 00537 } 00538 00539 bool DialogCreacionPaginas::PaginasPersonalizadas(){ 00540 return personalizada; 00541 } 00542 00543 00544 void DialogCreacionPaginas::ActivarSeleccionPlantilla(){ 00545 00546 QDir *dir; 00547 QStringList *por; 00548 try{ 00549 00550 QString path=this->directorioPpal.absolutePath() + "/templates/pages"; 00551 dir=new QDir(path); 00552 por=new QStringList("*.xml"); 00553 }catch(std::exception& e){ 00554 Error *err=new Error(2, e.what(), this); 00555 err->LanzarDialogo(); 00556 delete err; 00557 exit(1); 00558 } 00559 ui->SelectorPlantilla->setEnabled(true); 00560 ui->VisualizarPlantilla->setEnabled(true); 00561 ui->SelectorPlantilla->clear(); 00562 ui->pushSiguiente->setDisabled(true); 00563 00564 QStringList fileNames = dir->entryList(*por); 00565 for (int i = 0; i < fileNames.count(); i++) { 00566 QFileInfo fi(fileNames.at(i).toLocal8Bit()); 00567 QTreeWidgetItem *item = new QTreeWidgetItem(ui->SelectorPlantilla); 00568 QString recorte=fi.fileName(); 00569 item->setText(0, recorte.remove(".xml")); 00570 QString aux=this->directorioPpal.absolutePath() + "/templates/pages/" + fi.fileName(); 00571 Parser par(aux.toStdString(), this); 00572 ticpp::Element* elementAux=par.root(); 00573 std::string resultado=par.get_attribute("editable", elementAux); 00574 if(resultado=="todo"){ 00575 item->setText(1, tr("Si")); 00576 }else{ 00577 if(resultado=="solotexto"){ 00578 item->setText(1, tr("Solo texto")); 00579 }else{ 00580 item->setText(1, tr("No")); 00581 } 00582 } 00583 00584 } 00585 ui->SelectorPlantilla->topLevelItem(0)->setSelected(true); 00586 00587 00588 this->ui->label->setDisabled(true); 00589 00590 this->ui->labelAleatorio->setDisabled(true); 00591 00592 this->ui->labelFija->setEnabled(true); 00593 } 00594