Repository navigation
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
83 lines (68 loc) · 2.5 KB
/
Copy pathmainwindow.cpp
File metadata and controls
83 lines (68 loc) · 2.5 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "calculatorPage/vectorpage.h"
#include "calculatorPage/matrixpage.h"
#include "history/calculationhistory.h"
#include "history/historywriter.h"
#include "history/historywindow.h"
#include <QtGui/qevent.h>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setWindowTitle("MatCalc");
this->ui->stackedWidget->addWidget(vecPage = (new VectorPage(ui->page_vector))->fillIndexPage(ui->bar_vector));
this->ui->stackedWidget->addWidget(matPage = (new MatrixPage(ui->page_matrix))->fillIndexPage(ui->bar_matrix));
this->ui->stackedWidget->setCurrentIndex(2);
for (QLayout* layout : ui->mainFrame->findChildren<QLayout*>()) {
QMargins m = layout->contentsMargins();
bool isDefault =
m.left() == 12 &&
m.top() == 12 &&
m.right() == 12 &&
m.bottom() == 12;
if (isDefault) layout->setContentsMargins(0, 0, 0, 0);
}
instance = this;
historyWindow = std::make_unique<HistoryWindow>();
calculator = std::make_unique<EvaluationPage>();
const bool historyLoaded = History::loadHistory();
historyWindow->refreshHistory();
if (!historyLoaded) History::promptFileAccess();
connect(ui->historyButton, &QPushButton::clicked, this, &MainWindow::openHistory);
connect(ui->calculator, &QPushButton::clicked, calculator.get(), &EvaluationPage::show);
}
void MainWindow::setPage(AbstractPage *page){
instance->ui->stackedWidget->setCurrentWidget(page);
}
void MainWindow::openHistory(){
historyWindow->show();
}
AbstractPage *MainWindow::setPage(History::Page page){
switch(page){
case History::Page::VECTOR:
instance->ui->stackedWidget->setCurrentWidget(instance->vecPage);
break;
case History::Page::MATRIX:
instance->ui->stackedWidget->setCurrentWidget(instance->matPage);
case History::Page::CALCULATOR:
break;
}
return static_cast<AbstractPage *>(instance->ui->stackedWidget->currentWidget());
}
void MainWindow::setMessage(QString message){
instance->ui->statusbar->showMessage(message, 3000);
}
void MainWindow::closeEvent(QCloseEvent *event) {
QCoreApplication::quit();
HistoryWindow::instance->close();
EvaluationPage::instance->close();
event->accept();
}
MainWindow *MainWindow::getInstance(){return instance;}
MainWindow::~MainWindow()
{
delete ui;
}
MainWindow *MainWindow::instance = nullptr;