1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| #include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::onInit()
{
desktopEnv = QApplication::desktop();
screensCount = desktopEnv->screenCount();
QStringList screenNumbers;
for (int i=0; i<screensCount; i++)
{
//Pour chaque écran, on créée une ligne dans laquelle apparait le numéro et la résolution.
QString number;
QRect screenGeometry = desktopEnv->screenGeometry(i);
int width = screenGeometry.width();
int height = screenGeometry.height();
number.sprintf("%d : %dx%d", i+1, width, height);
screenNumbers.append(number);
}
ui->comboBox_numScreen->addItems(screenNumbers);
}
void MainWindow::on_pushButton_browse_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this, "Ouvrir une image", NULL, "Fichiers Images (*.png *.jpg *.bmp)");
if (fileName != "") ui->lineEdit_pathToImage->setText(fileName);
}
void MainWindow::on_pushButton_display_clicked()
{
displayedPicture.hide();
//Etape N°1 : on regarde quel numéro écran l'utilisateur a choisi
//Etape N°2 : on charge le fichier image que l'utilisateur a choisi
//Etape N°3 : affichage en pleiné écran
//Etape 1
int selectedScreen = ui->comboBox_numScreen->currentIndex();
if ((selectedScreen >= screensCount) || (selectedScreen < 0))
{
QMessageBox::warning(this, "Echec", "Numéro d'écran selectionné incorrect");
return;
}
//Etape 2
QString fileName;
fileName = ui->lineEdit_pathToImage->text();
QPixmap Pixmap(fileName);
bool failed = Pixmap.isNull();
if (failed == true)
{
QMessageBox::warning(this, "Echec", "Problème lors de la lecture de l'image demandée");
return;
}
//else : on continue
//Etape 3
QRect selectedScreenGeometry = desktopEnv->screenGeometry(selectedScreen);
displayedPicture.setGeometry(selectedScreenGeometry);
displayedPicture.setPixmap(Pixmap);
displayedPicture.showFullScreen();
}
void MainWindow::closeEvent(QCloseEvent *event)
{
displayedPicture.hide();
QMainWindow::closeEvent(event);
} |
Partager