1 #include "customizesplashdialog.h"
2 #include "ui_customizesplashdialog.h"
3 #include "flashfirmwaredialog.h"
6 #include "splashlibrary.h"
7 #include "firmwareinterface.h"
17 loadProfileButton
= 0;
18 saveToFileName
= new QString("");
19 source
= new Source(UNDEFINED
);
20 format
= new LCDFormat(LCDTARANIS
);
23 void Side::markSourceButton()
25 loadFwButton
->setChecked(*source
== FW
? true : false );
26 loadPictButton
->setChecked(*source
== PICT
? true : false );
27 loadProfileButton
->setChecked(*source
== PROFILE
? true : false );
30 void Side::copyImage( Side side
)
32 if ((*source
!=UNDEFINED
) && (*side
.source
!=UNDEFINED
))
33 imageLabel
->setPixmap(*side
.imageLabel
->pixmap());
36 bool Side::displayImage( QString fileName
, Source pictSource
)
40 if (fileName
.isEmpty())
43 // Determine which picture format to use
44 if (pictSource
== FW
){
45 FirmwareInterface
firmware(fileName
);
46 if (!firmware
.hasSplash())
49 image
= firmware
.getSplash();
50 *format
= (firmware
.getSplashWidth()==WIDTH_TARANIS
? LCDTARANIS
: LCD9X
);
54 if (pictSource
== PICT
)
55 *format
= image
.width()>WIDTH_9X
? LCDTARANIS
: LCD9X
;
56 else if (pictSource
== PROFILE
)
57 *format
= (g
.profile
[g
.id()].fwType().contains("taranis")) ? LCDTARANIS
: LCD9X
;
63 if (*format
==LCDTARANIS
) {
64 imageLabel
->setPixmap( makePixMap( image
, "taranis" ));
65 imageLabel
->setFixedSize(WIDTH_TARANIS
*2, HEIGHT_TARANIS
*2);
68 imageLabel
->setPixmap( makePixMap( image
, "9x" ));
69 imageLabel
->setFixedSize(WIDTH_9X
*2, HEIGHT_9X
*2);
74 fileNameEdit
->setText(QObject::tr("FW: %1").arg(fileName
));
75 *saveToFileName
= fileName
;
79 fileNameEdit
->setText(QObject::tr("Pict: %1").arg(fileName
));
80 *saveToFileName
= fileName
;
84 fileNameEdit
->setText(QObject::tr("Profile image"));
85 *saveToFileName
= fileName
;
91 saveButton
->setEnabled(true);
92 libraryButton
->setEnabled(true);
93 invertButton
->setEnabled(true);
97 bool Side::refreshImage()
99 return displayImage( *saveToFileName
, *source
);
102 bool Side::saveImage()
106 FirmwareInterface
firmware(*saveToFileName
);
107 if (!firmware
.hasSplash()) {
110 QImage image
= imageLabel
->pixmap()->toImage().scaled(firmware
.getSplashWidth(), firmware
.getSplashHeight());
111 if (firmware
.setSplash(image
) && (firmware
.save(*saveToFileName
) > 0)) {
112 g
.flashDir( QFileInfo(*saveToFileName
).dir().absolutePath() );
118 else if (*source
== PICT
) {
119 QImage image
= imageLabel
->pixmap()->toImage().scaled(imageLabel
->width()/2, imageLabel
->height()/2).convertToFormat(QImage::Format_Indexed8
);
120 if (image
.save(*saveToFileName
)) {
121 g
.imagesDir( QFileInfo(*saveToFileName
).dir().absolutePath() );
127 else if (*source
== PROFILE
) {
128 QImage image
= imageLabel
->pixmap()->toImage().scaled(imageLabel
->width()/2, imageLabel
->height()/2).convertToFormat(QImage::Format_Indexed8
);
129 if (!image
.save(*saveToFileName
)) {
136 //*** customizeSplashDialog Class ***
138 customizeSplashDialog::customizeSplashDialog(QWidget
*parent
) :
140 ui(new Ui::customizeSplashDialog
)
143 setWindowIcon(CompanionIcon("paintbrush.png"));
144 ui
->leftLibraryButton
->setIcon(CompanionIcon("library.png"));
145 ui
->rightLibraryButton
->setIcon(CompanionIcon("library.png"));
147 left
.imageLabel
= ui
->leftImageLabel
;
148 right
.imageLabel
= ui
->rightImageLabel
;
149 left
.fileNameEdit
= ui
->leftFileNameEdit
;
150 right
.fileNameEdit
= ui
->rightFileNameEdit
;
151 left
.saveButton
= ui
->leftSaveButton
;
152 right
.saveButton
= ui
->rightSaveButton
;
153 left
.libraryButton
= ui
->leftLibraryButton
;
154 right
.libraryButton
= ui
->rightLibraryButton
;
155 left
.invertButton
= ui
->leftInvertButton
;
156 right
.invertButton
= ui
->rightInvertButton
;
158 left
.loadFwButton
= ui
->leftLoadFwButton
;
159 right
.loadFwButton
= ui
->rightLoadFwButton
;
160 left
.loadPictButton
= ui
->leftLoadPictButton
;
161 right
.loadPictButton
= ui
->rightLoadPictButton
;
162 left
.loadProfileButton
= ui
->leftLoadProfileButton
;
163 right
.loadProfileButton
= ui
->rightLoadProfileButton
;
166 left
.markSourceButton();
171 customizeSplashDialog::~customizeSplashDialog()
176 void customizeSplashDialog::on_copyRightToLeftButton_clicked() {
177 left
.copyImage(right
);
179 void customizeSplashDialog::on_copyLeftToRightButton_clicked() {
180 right
.copyImage(left
);
184 void customizeSplashDialog::on_leftLoadFwButton_clicked() {loadFirmware(left
);}
185 void customizeSplashDialog::on_rightLoadFwButton_clicked() {loadFirmware(right
);}
186 void customizeSplashDialog::loadFirmware(Side side
)
188 QString fileName
= QFileDialog::getOpenFileName(this, tr("Open Firmware File"), g
.flashDir(), FLASH_FILES_FILTER
);
189 if (!fileName
.isEmpty()) {
190 if (!side
.displayImage( fileName
, FW
))
191 QMessageBox::critical(this, tr("Error"), tr("Can not load embedded image from firmware file %1.").arg(fileName
));
193 g
.flashDir( QFileInfo(fileName
).dir().absolutePath() );
195 side
.markSourceButton();
198 void customizeSplashDialog::on_leftLoadPictButton_clicked() {loadPicture(left
);}
199 void customizeSplashDialog::on_rightLoadPictButton_clicked() {loadPicture(right
);}
200 void customizeSplashDialog::loadPicture(Side side
)
202 QString supportedImageFormats
;
203 for (int formatIndex
= 0; formatIndex
< QImageReader::supportedImageFormats().count(); formatIndex
++) {
204 supportedImageFormats
+= QLatin1String(" *.") + QImageReader::supportedImageFormats()[formatIndex
];
206 QString fileName
= QFileDialog::getOpenFileName(this,
207 tr("Open Image to load"), g
.imagesDir(), tr("Images (%1)").arg(supportedImageFormats
));
209 if (!fileName
.isEmpty()) {
210 if (!side
.displayImage( fileName
, PICT
))
211 QMessageBox::critical(this, tr("Error"), tr("Cannot load the image file %1.").arg(fileName
));
213 g
.imagesDir( QFileInfo(fileName
).dir().absolutePath() );
215 side
.markSourceButton();
218 void customizeSplashDialog::on_leftLoadProfileButton_clicked() {loadProfile(left
);}
219 void customizeSplashDialog::on_rightLoadProfileButton_clicked() {loadProfile(right
);}
220 void customizeSplashDialog::loadProfile(Side side
)
222 QString fileName
=g
.profile
[g
.id()].splashFile();
224 if (!fileName
.isEmpty()) {
225 if (!side
.displayImage( fileName
, PROFILE
))
226 QMessageBox::critical(this, tr("Error"), tr("Cannot load profile image %1.").arg(fileName
));
228 side
.markSourceButton();
231 void customizeSplashDialog::on_leftLibraryButton_clicked(){libraryButton_clicked(left
);}
232 void customizeSplashDialog::on_rightLibraryButton_clicked(){libraryButton_clicked(right
);}
233 void customizeSplashDialog::libraryButton_clicked( Side side
)
236 splashLibrary
*ld
= new splashLibrary(this,&fileName
);
238 if (!fileName
.isEmpty()) {
239 if (!side
.displayImage( fileName
, UNDEFINED
))
240 QMessageBox::critical(this, tr("Error"), tr("Cannot load the library image %1.").arg(fileName
));
244 void customizeSplashDialog::on_leftSaveButton_clicked(){saveButton_clicked(left
);}
245 void customizeSplashDialog::on_rightSaveButton_clicked(){saveButton_clicked(right
);}
246 void customizeSplashDialog::saveButton_clicked( Side side
)
248 if (side
.saveImage()){
249 QMessageBox::information(this, tr("File Saved"), tr("The image was saved to the file %1").arg(*side
.saveToFileName
));
250 if ( !side
.refreshImage()){
251 QMessageBox::critical(this, tr("Image Refresh Error"), tr("Failed to refresh image from file %1").arg(*side
.saveToFileName
));
255 QMessageBox::critical(this, tr("File Save Error"), tr("Failed to write image to %1").arg(*side
.saveToFileName
));
258 void customizeSplashDialog::on_leftInvertButton_clicked(){invertButton_clicked(left
);}
259 void customizeSplashDialog::on_rightInvertButton_clicked(){invertButton_clicked(right
);}
260 void customizeSplashDialog::invertButton_clicked(Side side
)
262 QImage image
= side
.imageLabel
->pixmap()->toImage();
263 image
.invertPixels();
264 side
.imageLabel
->setPixmap(QPixmap::fromImage(image
));