source: s10k/Vago/bgImageWizard/bgimagepage2.cpp@ 1092

Last change on this file since 1092 was 1058, checked in by s10k, 8 years ago

Vago 1.2

File size: 4.1 KB
Line 
1#include "bgimagepage2.h"
2#include "ui_bgimagepage2.h"
3
4BGImagePage2::BGImagePage2(Logger *myLogger, QWidget *parent) :
5 QWizardPage(parent),
6 ui(new Ui::BGImagePage2)
7{
8 ui->setupUi(this);
9 this->myLogger = myLogger;
10
11 this->setTitle("Image to use as background");
12 this->setSubTitle("Add here the image that you want to convert. Image width and height must be greater than or equal 256 pixels. Example of valid image resolutions: 640x480, 1024x768.");
13
14 //Register fields
15 registerField("leImageFullPath", ui->leImageFullPath);
16 registerField("lbImageType", ui->lbImageType, "text");
17}
18
19void BGImagePage2::initializePage()
20{
21 // To the first time the page is displayed and when the wizard is restarted
22 if(ui->leImageFullPath->text().isEmpty()){
23 // enable / hide image fields until we have an image
24 ui->gbImageInformation->setEnabled(false);
25 ui->lbImagePreview->hide();
26 ui->lbImageName->hide();
27 ui->lbImageWidth->hide();
28 ui->lbImageHeight->hide();
29 ui->lbImageSize->hide();
30 ui->lbDateCreated->hide();
31 ui->lbDateModified->hide();
32 ui->lbImageType->hide();
33 }
34}
35
36bool BGImagePage2::validatePage(){
37 QString leImageFullPath=ui->leImageFullPath->text().trimmed();
38
39 if(!validateField(leImageFullPath)){
40 return false;
41 }
42
43 return true;
44}
45
46bool BGImagePage2::validateField(QString &field){
47 if(field.isEmpty()){
48 Util::showErrorPopUp("You need to choose an image.");
49 return false;
50 }
51
52 return true;
53}
54
55BGImagePage2::~BGImagePage2()
56{
57 delete ui;
58}
59
60void BGImagePage2::on_pbBrowse_clicked()
61{
62 QString selectedImage = QFileDialog::getOpenFileName(this,"Choose the image file...","./" , "Image (*.JPG *.JPEG *.PNG)");
63
64 if(!selectedImage.isEmpty()){
65
66 QImage myImage;
67 if(!myImage.load(selectedImage)){
68 UtilVago::showAndLogErrorPopUp(this->myLogger,"Couldn't load image '" + Util::cutNameWithoutBackSlash(selectedImage) + "'. Is the image corrupt?");
69 return;
70 }
71
72 if(myImage.width() < 256 || myImage.height() < 256){
73 UtilVago::showAndLogErrorPopUp(this->myLogger,"Image '" + Util::cutNameWithoutBackSlash(selectedImage) +
74 "' does not have a width and height >= 256.");
75 return;
76 }
77
78 ui->leImageFullPath->setText(selectedImage);
79 ui->leImageFullPath->setToolTip(selectedImage);
80 setImage(selectedImage, myImage);
81 }
82}
83
84void BGImagePage2::setImage(const QString &imagePath, const QImage &image){
85
86 QFileInfo myImageFileInfo(imagePath);
87
88 ui->gbImageInformation->setEnabled(true);
89 ui->lbImagePreview->show();
90 ui->lbImageName->show();
91 ui->lbImageWidth->show();
92 ui->lbImageHeight->show();
93 ui->lbImageSize->show();
94 ui->lbDateCreated->show();
95 ui->lbDateModified->show();
96 ui->lbImageType->show();
97
98 QPixmap previewImage(imagePath);
99 ui->lbImagePreview->setPixmap( previewImage );
100 ui->lbImagePreview->setMask(previewImage.mask());
101
102 // Thanks bukkfa!
103 // http://stackoverflow.com/questions/5653114/display-image-in-qt-to-fit-label-size
104 ui->lbImagePreview->setScaledContents( true );
105 ui->lbImagePreview->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored );
106
107 // Update image information
108 QString imageName = myImageFileInfo.baseName().replace("." + myImageFileInfo.suffix(), "");
109
110 ui->lbImageName->setToolTip(imageName);
111
112 if(imageName.length() > 30){
113 imageName = imageName.mid(0,27) + "...";
114 }
115
116 ui->lbImageName->setText(imageName);
117 ui->lbImageWidth->setText(QString::number(image.width()));
118 ui->lbImageHeight->setText(QString::number(image.height()));
119 ui->lbImageType->setText(myImageFileInfo.suffix());
120 ui->lbImageSize->setText(QString::number(myImageFileInfo.size()/1024.0));
121 ui->lbDateCreated->setText(myImageFileInfo.created().toString());
122 ui->lbDateModified->setText(myImageFileInfo.lastModified().toString());
123
124 ui->lbImagePreview->show();
125}
Note: See TracBrowser for help on using the repository browser.