-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_window.cpp
70 lines (49 loc) · 2.07 KB
/
main_window.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
// File: main_window.cpp
// Author: Samuel McFalls
#include "main_window.hpp"
#include <QWidget>
#include <QLayout>
#include <QDebug>
#include <fstream>
#include "qt_interpreter.hpp"
MainWindow::MainWindow(QWidget * parent) : QWidget(parent) {
MessageWidget * message = new MessageWidget(this);
CanvasWidget * canvas = new CanvasWidget(this);
REPLWidget * repl = new REPLWidget(this);
QVBoxLayout * layout = new QVBoxLayout(this);
layout->addWidget(message);
layout->addWidget(canvas);
layout->addWidget(repl);
this->setLayout(layout);
QtInterpreter * interp = new QtInterpreter(this);
QObject::connect(repl, SIGNAL(lineEntered(QString)), interp, SLOT(parseAndEvaluate(QString)));
QObject::connect(interp, SIGNAL(info(QString)), message, SLOT(info(QString)));
QObject::connect(interp, SIGNAL(error(QString)), message, SLOT(error(QString)));
QObject::connect(interp, SIGNAL(drawGraphic(QGraphicsItem *)), canvas, SLOT(addGraphic(QGraphicsItem *)));
}
MainWindow::MainWindow(std::string filename, QWidget * parent) : QWidget(parent) {
MessageWidget * message = new MessageWidget(this);
CanvasWidget * canvas = new CanvasWidget(this);
REPLWidget * repl = new REPLWidget(this);
QVBoxLayout * layout = new QVBoxLayout(this);
layout->addWidget(message);
layout->addWidget(canvas);
layout->addWidget(repl);
this->setLayout(layout);
QtInterpreter * interp = new QtInterpreter(this);
QObject::connect(repl, SIGNAL(lineEntered(QString)), interp, SLOT(parseAndEvaluate(QString)));
QObject::connect(interp, SIGNAL(info(QString)), message, SLOT(info(QString)));
QObject::connect(interp, SIGNAL(error(QString)), message, SLOT(error(QString)));
QObject::connect(interp, SIGNAL(drawGraphic(QGraphicsItem *)), canvas, SLOT(addGraphic(QGraphicsItem *)));
std::ifstream ifs(filename);
if (!ifs.good()) {
qDebug() << "File " << QString::fromStdString(filename) <<
"does not exist or could not be opened for reading. Ignoring...";
}
else {
std::stringstream buffer;
buffer << ifs.rdbuf();
QString program = QString::fromStdString(buffer.str());
repl->lineEntered(program);
}
}