OpenAlbum 1.0.b

/home/manuel/PFC/open-album/OpenAlbum-Unix/fondodialog.cpp

00001 #include <QtGui>
00002 #include <QFont>
00003 #include <iostream>
00004 #include "fondodialog.h"
00005 #include "ui_fondodialog.h"
00006 #include "error.h"
00007 #include "dialogtexturas.h"
00008 #include "controladorresolucion.h"
00009 
00010 
00011 FondoDialog::FondoDialog(QWidget *parent, QString plantilla, bool pagina, controladorResolucion *controlador_, QDir directoriodetrabajo) :
00012     QDialog(parent),
00013     ui(new Ui::FondoDialog)
00014 {
00015     ui->setupUi(this);
00016     color=false;
00017     this->textura=false;
00018     this->controlador=controlador_;
00019     this->setDimensiones();
00020     this->directorioPpal=directoriodetrabajo;
00021     this->ui->radioButtonColor->setStyle(new QWindowsStyle);
00022     this->ui->radioButtonImagen->setStyle(new QWindowsStyle);
00023     this->ui->radioButtonTextura->setStyle(new QWindowsStyle);
00024     this->tareaCompleta=false;
00025     QImage *img=new QImage();
00026     int size=plantilla.remove(".xml").size();
00027     img->load(plantilla.insert(size,"_fondo.png"));
00028     QGraphicsScene *scena=new QGraphicsScene();
00029     ui->plantillaPreview->setStyle(new QWindowsStyle);
00030     ui->plantillaPreview->setScene(scena);
00031     QPixmap image=QPixmap::fromImage(*img);
00032     ui->plantillaPreview->scene()->addPixmap(image.scaled((127*this->controlador->getWfondodialog())/391, (104*this->controlador->getHfondodialog())/297, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
00033     if(pagina){
00034         this->ui->labelTexto->setText(tr("Seleccione a continuación un color sólido, una imagen o una textura como fondo para las dos páginas que está tratando en este momento. El fondo será el mismo para ambas páginas."));
00035         this->setWindowTitle(tr("Establecer fondo de las páginas"));
00036     }else{
00037         this->ui->labelTexto->setText(tr("Seleccione a continuación un color sólido, una imagen o una textura como fondo para la portada del álbum. El fondo será el mismo para la portada y la contraportada."));
00038     }
00039     this->ui->groupBox->setStyle(new QWindowsStyle());
00040     delete img;
00041 
00042  QIcon *iconoVentana=new QIcon(directoriodetrabajo.absolutePath() + "/data/iconlargue.png");
00043     this->setWindowIcon(*iconoVentana);
00044     delete iconoVentana;
00045 }
00046 
00047 bool FondoDialog::ColordeFondo(){
00048     return color;
00049 }
00050 
00051 FondoDialog::~FondoDialog()
00052 {
00053     for(int i=0; i < ui->plantillaPreview->items().size(); i++){
00054         delete ui->plantillaPreview->items().at(i);
00055     }
00056     delete ui->plantillaPreview->scene();
00057     delete ui->plantillaPreview;
00058     delete ui;
00059 
00060 }
00061 
00062 void FondoDialog::setDimensiones(){
00063     this->setFixedSize(this->controlador->getWfondodialog(), this->controlador->getHfondodialog());
00064     int W=this->controlador->getWfondodialog();
00065     int H=this->controlador->getHfondodialog();
00066     int x,y;
00067     x=this->ui->groupBox->x();
00068     y=this->ui->groupBox->y();
00069     this->ui->groupBox->setGeometry((x*W)/371, (y*H)/297, (351*W)/371, (231*H)/297);
00070     x=this->ui->labelTexto->x();
00071     y=this->ui->labelTexto->y();
00072     this->ui->labelTexto->setGeometry((x*W)/371, (y*H)/297, (321*W)/371, (91*H)/297);
00073     x=this->ui->plantillaPreview->x();
00074     y=this->ui->plantillaPreview->y();
00075     this->ui->plantillaPreview->setGeometry((x*W)/371, (y*H)/297, (127*W)/371, (104*H)/297);
00076     x=this->ui->pushButtonCancelar->x();
00077     y=this->ui->pushButtonCancelar->y();
00078     this->ui->pushButtonCancelar->setGeometry((x*W)/371, (y*H)/297, (93*W)/371, (27*H)/297);
00079     x=this->ui->pushButtonSiguiente->x();
00080     y=this->ui->pushButtonSiguiente->y();
00081     this->ui->pushButtonSiguiente->setGeometry((x*W)/371, (y*H)/297, (93*W)/371, (27*H)/297);
00082     x=this->ui->radioButtonColor->x();
00083     y=this->ui->radioButtonColor->y();
00084     this->ui->radioButtonColor->setGeometry((x*W)/371, (y*H)/297, (141*W)/371, (22*H)/297);
00085     x=this->ui->radioButtonImagen->x();
00086     y=this->ui->radioButtonImagen->y();
00087     this->ui->radioButtonImagen->setGeometry((x*W)/371, (y*H)/297, (141*W)/371, (22*H)/297);
00088     x=this->ui->radioButtonTextura->x();
00089     y=this->ui->radioButtonTextura->y();
00090     this->ui->radioButtonTextura->setGeometry((x*W)/371, (y*H)/297, (141*W)/371, (22*H)/297);
00091        
00092 }
00093 
00094 QColor FondoDialog::ColorFondo(){
00095     return colorelegido;
00096 }
00097 
00098 QString FondoDialog::ImagenFondo(){
00099     return imagenelegida;
00100 }
00101 void FondoDialog::ActivarBotonSiguiente(){
00102     if(ui->radioButtonColor->isChecked() || ui->radioButtonImagen->isChecked() || ui->radioButtonTextura->isChecked())
00103         ui->pushButtonSiguiente->setEnabled(true);
00104     else
00105         ui->pushButtonSiguiente->setEnabled(false);
00106 }
00107 
00108 void FondoDialog::setMiniaturasTexturas(std::vector<QGraphicsView*> min){
00109     this->miniaturasTexturas=min;
00110 }
00111 
00112 bool FondoDialog::getTareaCompleta(){
00113     return this->tareaCompleta;
00114 }
00115 bool FondoDialog::TexturadeFondo(){
00116     return this->textura;
00117 }
00118 
00119 void FondoDialog::ElegirTipoFondo(){
00120     if(ui->radioButtonColor->isChecked()){
00121         this->accept();
00122         QColorDialog *SeleccionColor;
00123         try{
00124         SeleccionColor= new QColorDialog();
00125         }catch(std::exception& e){
00126                 Error *err=new Error(2, e.what(), this);
00127                 err->LanzarDialogo();
00128                 delete err;
00129                 exit(1);
00130         }
00131         SeleccionColor->exec();
00132         colorelegido= SeleccionColor->selectedColor();
00133         if(SeleccionColor->result()==1){
00134         
00135         this->tareaCompleta=true;
00136         }
00137         color=true;
00138         delete SeleccionColor;
00139 
00140     }else{
00141         if(ui->radioButtonImagen->isChecked()){
00142             this->accept();
00143             QString path = QDir::homePath();
00144             imagenelegida=QFileDialog::getOpenFileName(this, tr("Abrir Imagen"), path, tr("Todas las imágenes (*.png *.bmp *.jpg *.jpeg *.jpe *.tiff *.tif);; Imágenes: JPEG (*.jpg *.jpeg *.jpe);; Imágenes: BMP (*.bmp);; Imágenes: PNG (*.png);; Imágenes: TIFF (*.tiff *.tif)"));
00145             
00146         }else{
00147             if(ui->radioButtonTextura->isChecked()){
00148                 this->accept();
00149                 
00150                 dialogTexturas *texturas=new dialogTexturas(this, this->controlador, this->directorioPpal);
00151                 this->textura=true;
00152                 texturas->setMiniaturasTextura(this->miniaturasTexturas);
00153                 texturas->seleccionarPrimerItem();
00154                 texturas->exec();
00155                 if(texturas->getTareaCompletada()){
00156                     imagenelegida=texturas->getTexturaElegida();
00157                 }
00158                 delete texturas;
00159                 
00160             }
00161         }
00162 
00163 
00164     }
00165     if(!imagenelegida.isNull()){
00166         this->tareaCompleta=true;
00167     }
00168     
00169     
00170 
00171 }
 Todo Clases Archivos Funciones Variables