-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
99 lines (88 loc) · 3.44 KB
/
mainwindow.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
/***************************************************************************
* HyperArt Copyright (C) 2005-2023 by Ajit Datar ([email protected]) *
* *
* Hyperbolic geometry drawing algorithms developed by *
* and credited to Dr. Douglas Dunham ([email protected]) *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* Please see LICENSE file for more details. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include <QtWidgets>
#include "datareader.h"
#include <QFileDialog>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
view = new PoincareView(this);
centralWidget()->layout()->addWidget(view);
}
MainWindow::~MainWindow()
{
delete diagram;
delete view;
delete ui;
}
void MainWindow::on_action_file_open_triggered()
{
auto filePath = QFileDialog::getOpenFileName(
this,
tr("Open a HyperArt Design"),
"../../../../../hyperart_qtwidgets/designs/",
tr("HyperArt Designs (*.had)")
);
qDebug() << "File: " << filePath;
if (!filePath.isEmpty())
openFile(filePath);
}
void MainWindow::on_action_file_save_as_triggered()
{
qDebug() << "File > Save as...";
auto filePath = QFileDialog::getSaveFileName(
this,
tr("Save this design as a PNG or JPEG image"),
"",
tr("Images (*.png *.jpg *.jpeg)")
);
if (!filePath.isEmpty())
view->saveAs(filePath);
}
bool MainWindow::openFile(const QString &filePath)
{
const bool succeeded = loadFile(filePath);
if (succeeded) {
statusBar()->showMessage(tr("File loaded"), 2000);
QFileInfo fileinfo(filePath);
this->setWindowTitle(fileinfo.baseName());
}
else
statusBar()->showMessage(tr("Didn't load a design"), 2000);
return succeeded;
}
bool MainWindow::loadFile(const QString &fileName)
{
diagram = DataReader::createDiagram(fileName);
bool succeeded = false;
if(diagram != nullptr) {
succeeded = true;
view->documentChanged(diagram);
}
return succeeded;
}