-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQPainterDebuggerMainWindow.cpp
67 lines (51 loc) · 1.53 KB
/
QPainterDebuggerMainWindow.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
#include "QPainterDebuggerMainWindow.h"
#include "ui_QPainterDebuggerMainWindow.h"
// Qt includes
#include <QtGui/QMessageBox>
#include <QtGui/QPainter>
// Local includess
#include "DSLHighlighter.h"
#include "Lexer.h"
#include "Parser.h"
#include "PainterContext.h"
QPainterDebuggerMainWindow::QPainterDebuggerMainWindow(QWidget *parent)
: QMainWindow(parent),ui(new Ui::QPainterDebuggerMainWindow)
{
ui->setupUi(this);
connectSlots();
m_highlighter = new DSLHighlighter(ui->textEditCode->document());
}
QPainterDebuggerMainWindow::~QPainterDebuggerMainWindow()
{
delete ui;
delete m_highlighter;
}
void QPainterDebuggerMainWindow::connectSlots()
{
connect(ui->actionAbout_Qt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
connect(ui->actionExit, SIGNAL(triggered()), qApp, SLOT(quit()));
connect(ui->buttonDebug, SIGNAL(clicked()), this, SLOT(buttonDebug_Clicked()));
}
void QPainterDebuggerMainWindow::buttonDebug_Clicked()
{
QImage resultImage(ui->labelGraphicPreview->width(),ui->labelGraphicPreview->height(), QImage::Format_ARGB32);
resultImage.fill(0);
QPainter painter(&resultImage);
QString readCode = ui->textEditCode->toPlainText();
PainterContext context;
context.setPainter(&painter);
Parser parser;
parser.setContext(&context);
ASTNode* rootNode = parser.parse(readCode);
if(parser.hasError())
{
QMessageBox::critical(this, "Parsing error", parser.errorMessage());
return;
}
if(rootNode)
{
rootNode->evaluate();
ui->labelGraphicPreview->setPixmap(QPixmap::fromImage(resultImage));
}
delete rootNode;
}