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
|
#include "mainwindow.hpp"
#include <qaction.h>
#include <qapplication.h>
#include <qlabel.h>
#include <qnamespace.h>
#include <QFileDialog>
#include <QMessageBox>
MainWindow::MainWindow(Renderer r)
: m_drawer(500, 500),
runstatus("Not running", this),
m_render(this, m_drawer, r, &runstatus)
{
setCentralWidget(&m_drawer);
auto saveAct = new QAction(tr("&Save as"), this);
saveAct->setStatusTip(tr("Save the rendered image"));
connect(saveAct, &QAction::triggered, this, &MainWindow::saveimage);
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(saveAct);
helpMenu = menuBar()->addMenu(tr("&Help"));
helpMenu->addAction(tr("About Qt"), qApp, &QApplication::aboutQt);
statusBar()->addWidget(&runstatus);
}
void MainWindow::saveimage() {
QGuiApplication::setOverrideCursor(Qt::WaitCursor);
QString fileName = QFileDialog::getSaveFileName(this,
tr("Save image"), "", tr("PNG image (*.png);;All Files (*)"));
if (fileName.isEmpty()) {
return;
}
if (!m_drawer.m_img.save(fileName)) {
QMessageBox::information(this, tr("Unable to save file"), "");
}
}
|