forked from herrgahr/qling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodewidget.cpp
97 lines (79 loc) · 3.32 KB
/
codewidget.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
/* Copyright (C) 2011 - 2012 Thomas Gahr <[email protected]>
This file is part of qling, a Qt Interface to cling, the llvm-based
C++ interpreter.
cling: http://root.cern.ch/drupal/content/cling
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 2 of the License, or the version 3 of the License.
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; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "codewidget.h"
#include "codeinput.h"
#include <QTextBrowser>
#include <QVBoxLayout>
#include <QScrollBar>
#include <QCheckBox>
#include <QTextEdit>
#include "qling/qling.h"
#include "qling/tests.h"
CodeWidget::CodeWidget(Qling* qling)
:QWidget()
,m_qling(qling)
{
setContentsMargins(0, 0, 0, 0);
QVBoxLayout* layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
m_codeOutput = new QTextEdit;
m_codeOutput->setFont(QFont("Monospace"));
m_codeOutput->setReadOnly(true);
layout->addWidget(m_codeOutput);
QHBoxLayout* hl = new QHBoxLayout;
QCheckBox* enableMultiLine = new QCheckBox("multi-line");
hl->addWidget(enableMultiLine);
m_codeInput = new CodeInput;
hl->addWidget(m_codeInput);
connect(enableMultiLine, SIGNAL(toggled(bool)),
m_codeInput, SLOT(enableMultiLineMode(bool)));
connect(enableMultiLine, SIGNAL(released()),
m_codeInput, SLOT(setFocus()));
layout->addLayout(hl);
m_codeInput->setFocus();
connect(m_codeInput, SIGNAL(entered(QString)), this, SLOT(processCode(QString)));
connect(qling, SIGNAL(aboutToMoc()), m_codeInput, SLOT(disallowInput()));
connect(qling, SIGNAL(doneMocing()), m_codeInput, SLOT(allowInput()));
}
void CodeWidget::processCode(const QString& str)
{
// static int lastIndent = 0;
QTextCursor cursor = m_codeOutput->textCursor();
//user might've selected some text so clear selection
cursor.clearSelection();
if(!cursor.atEnd())
cursor.movePosition(QTextCursor::End);
//submit code
//int indent = m_metaProcessor->process(str.toStdString().c_str());
m_inputStartPosition = m_codeOutput->textCursor().position();
cursor.insertText(str + QString("\n"));
/*int indent = */m_qling->processUserInput(str);
// QTextCharFormat format=cursor.charFormat();
// QString indentString;
// if(indent > 0){
// //use yellow background to mark code that is part of incomplete input
// format.setBackground(Qt::yellow);
// for(int i=0;i<qMin(lastIndent,indent);++i)
// indentString+=QString(" ");
// }else if(lastIndent>0)
// format.setBackground(palette().base());
// lastIndent=indent;
// cursor.insertText(indentString+str+QString("\n"),format);
m_codeOutput->verticalScrollBar()->setValue(m_codeOutput->verticalScrollBar()->maximum());
}