-
Notifications
You must be signed in to change notification settings - Fork 1
/
viewimage.cpp
108 lines (86 loc) · 2.37 KB
/
viewimage.cpp
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "viewimage.h"
#include "ui_viewimage.h"
#include <QFile>
#include <QPrinter>
viewImage::viewImage(QWidget *parent) :
QDialog(parent),
ui(new Ui::viewImage)
{
ui->setupUi(this);
// Set window maximimze during launch
// this->setWindowState(Qt::WindowMaximized);
// Set the window as a popup
// this->setWindowFlags(Qt::Popup);
this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
QPixmap printico(iconPrint);
QIcon printIcon(printico);
ui->pushButton_print->setIcon(printIcon);
ui->pushButton_print->setIconSize(QSize(60, 60));
QPixmap backico(iconBack);
QIcon backIcon(backico);
ui->pushButton_back->setIcon(backIcon);
ui->pushButton_back->setIconSize(QSize(60, 60));
}
viewImage::~viewImage()
{
delete ui;
}
void viewImage::setImage(int img)
{
currentNum = img + 1;
// Get pixmap
QPixmap pixmap = this->getPixMap(QString::number(img + 1));
QGraphicsScene *scene = new QGraphicsScene(this);
scene->addPixmap(pixmap);
ui->graphicsView->setScene(scene);
}
void viewImage::showEvent(QShowEvent *)
{
ui->graphicsView->fitInView(ui->graphicsView->sceneRect(), Qt::KeepAspectRatio);
}
void viewImage::on_pushButton_back_clicked()
{
this->close();
}
void viewImage::on_pushButton_print_clicked()
{
QPrinter printer(QPrinter::HighResolution);
printer.setPaperSize(QSize(102, 152), QPrinter::Millimeter);
// Get pixmap
QPixmap pixmap = this->getPixMap(QString::number(this->currentNum));
// If Landscape
if (pixmap.width() > pixmap.height())
{
qDebug("Landscape!");
printer.setOrientation(QPrinter::Landscape);
pixmap = pixmap.scaled(QSize(3591, 2409), Qt::KeepAspectRatio); //4R 4" × 6" or 102 × 152 mm
}else
{
//Portrait
qDebug("Portrait!");
pixmap = pixmap.scaled(QSize(2409, 3591), Qt::KeepAspectRatio); //4R 4" × 6" or 102 × 152 mm
}
// Draw image to painter
QPainter painter;
painter.begin(&printer);
painter.drawPixmap(0, 0, pixmap);
painter.end();
this->close();
}
QPixmap viewImage::getPixMap(QString index)
{
QString filename = (this->cacheFolder);
filename.append(index);
QFile file(filename + this->imageExtension);
file.open(QFile::ReadOnly);
QPixmap pixmap;
if (!pixmap.load(filename))
{
// What if image deleted? We will get them again here
// show error image error.jpg
pixmap.load(this->imageError);
qDebug("No image to view!");
}
file.close();
return pixmap;
}