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

Last change on this file since 1142 was 1093, checked in by s10k, 7 years ago

Vago 1.4

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