Page principale de Bitmap To Header File
Autres fichiers source de Bitmap To Header File
#include "MainWindow.h"
#include "ui_MainWindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
setWindowTitle(this->windowTitle() + appVersion);
setWindowIcon(QIcon(":/logo.png"));
setAcceptDrops(true);
QString home = QStandardPaths::locate(QStandardPaths::HomeLocation,
QStandardPaths::displayName(QStandardPaths::DocumentsLocation),
QStandardPaths::LocateDirectory);
dir = "";
file = "";
ui->dstPath->setText(home);
ui->imageSrc->setText("Image source<br>Faire glisser une image ou cliquer sur "Ouvrir"");
ui->imageDst->setText("Image convertie en 16 bits");
ui->btConvertir->setEnabled(false);
}
void MainWindow::on_actionOuvrir_triggered() {
QString fileName = QFileDialog::getOpenFileName(this, "Ouvrir une image",ui->dstPath->text(),"Images (*.png *.bmp *.gif *.jpg)");
openFile(fileName);
}
bool MainWindow::openFile(QString fileName) {
if(QFile::exists(fileName)) {
file = fileName.section("/",-1,-1);
dir = fileName.section("/",0,-2);
pixmapSource = QPixmap(fileName);
if(!(pixmapSource.isNull())) {
ui->imageSrc->setPixmap(pixmapSource.scaled(ui->imageSrc->width(),ui->imageSrc->height(),Qt::KeepAspectRatio));
ui->imageDst->setPixmap(QPixmap());
ui->btConvertir->setEnabled(true);
return true;
}
else {
QMessageBox::critical(this,"Erreur", "Ce fichier ne sempble pas être une image.");
file = "";
dir = "";
return false;
}
}
return false;
}
void MainWindow::dragEnterEvent(QDragEnterEvent *event) {
const QMimeData* mimeData = event->mimeData();
if (mimeData->hasUrls()) event->acceptProposedAction();
}
void MainWindow::dropEvent(QDropEvent *event) {
const QMimeData* mimeData = event->mimeData();
// check for our needed mime type, here a file or a list of files
if (mimeData->hasUrls())
{
QStringList pathList;
QList<QUrl> urlList = mimeData->urls();
// extract the local paths of the files
for (int i = 0; i < urlList.size() && i < 2; i++)
{
pathList.append(urlList.at(i).toLocalFile());
}
// call a function to open the files
openFile(pathList[0]);
}
}
void MainWindow::on_actionQuitter_triggered() {
close();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_btConvertir_clicked()
{
statusBar()->showMessage(START_CONVERSION);
setCursor(Qt::WaitCursor);
QImage monImage = pixmapSource.toImage();
monImage16 = monImage.convertToFormat(QImage::Format_RGB16);
ui->imageDst->setPixmap(QPixmap::fromImage(monImage16).scaled(ui->imageDst->width(),ui->imageDst->height(),Qt::KeepAspectRatio));
QString strDstFile = ui->dstPath->text() + "/" + file.section(".",0,-2) + "16bits.BMP";
if(monImage16.saveToBmp16bits(strDstFile)) {
QImage16::saveToHeaderFile(strDstFile, ui->dstPath->text() + "/" + file.section(".",0,-2) + ".h");
statusBar()->showMessage(CONVERSION_DONE);
}
else statusBar()->showMessage(ERREUR_CONVERSION);
setCursor(Qt::ArrowCursor);
}
void MainWindow::on_btParcourir_clicked()
{
QString dir = QFileDialog::getExistingDirectory(this, "Sélectionner le dossier de destination",
ui->dstPath->text(),
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);
if(QFile::exists(dir)) ui->dstPath->setText(dir);
}
void MainWindow::resizeEvent(QResizeEvent* event)
{
QMainWindow::resizeEvent(event);
if((dir!="") && (file!="")) {
if(QFile::exists(dir + "/" + file)) {
QPixmap monImage(dir + "/" + file);
ui->imageSrc->setPixmap(monImage.scaled(ui->imageSrc->width(),ui->imageSrc->height(),Qt::KeepAspectRatio));
}
if(!(monImage16.isnull()))
ui->imageDst->setPixmap(QPixmap::fromImage(monImage16).scaled(ui->imageDst->width(),ui->imageDst->height(),Qt::KeepAspectRatio));
}
}
void MainWindow::on_actionA_propos_triggered() {
QMessageBox *m = new QMessageBox(this);
m->setTextFormat(Qt::RichText);
m->setText("<h1>" + windowTitle() + "</h1>" + STR_INFO_LOGICIEL);
m->setWindowTitle(windowTitle());
m->setIconPixmap(QPixmap(":/logo.png").scaled(100,100));
m->setWindowIcon(QIcon(":/logo.png"));
m->show();
}
void MainWindow::on_btOpenDestFolder_clicked()
{
QString path = QDir::toNativeSeparators(ui->dstPath->text());
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
}