Repository navigation
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
69 lines (50 loc) · 1.48 KB
/
Copy pathmainwindow.cpp
File metadata and controls
69 lines (50 loc) · 1.48 KB
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
setCentralWidget(ui->scrollArea);
//https://doc.qt.io/archives/qt-4.8/qstyle.html
ui->actionOpen->setIcon(QApplication::style()->standardIcon(QStyle::SP_DialogOpenButton));
ui->actionZoom_In->setIcon(QApplication::style()->standardIcon(QStyle::SP_ArrowUp));
ui->actionZoom_Out->setIcon(QApplication::style()->standardIcon(QStyle::SP_ArrowDown));
m_lblImage = new QLabel(this);
ui->scrollArea->setWidget(m_lblImage);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionOpen_triggered()
{
m_path = QFileDialog::getOpenFileName(this,"Open",QString(),"All Files(*.*);;JPG (*.jpg);;PNG (*.png)");
if(m_path.isEmpty()) return;
if(!m_img.load(m_path))
{
QMessageBox::critical(this,"Error","Could not load the image!");
return;
}
m_lblImage->setPixmap(m_img);
}
void MainWindow::on_actionZoom_In_triggered()
{
int w = m_lblImage->width();
int h = m_lblImage->height();
w += 10;
h += 10;
m_lblImage->resize(w,h);
m_lblImage->setPixmap(m_img.scaled(w,h));
}
void MainWindow::on_actionZoom_Out_triggered()
{
int w = m_lblImage->width();
int h = m_lblImage->height();
w -= 10;
h -= 10;
if(w < 10) w = 10;
if(h < 10) h = 10;
m_lblImage->resize(w,h);
m_lblImage->setPixmap(m_img.scaled(w,h));
}