Skip to content

Commit accc827

Browse files
committed
Implemented framework for GUI
1 parent 4c45bf7 commit accc827

File tree

8 files changed

+224
-2
lines changed

8 files changed

+224
-2
lines changed

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ set(tui_src
4040
# EDIT
4141
# add source for any GUI modules here
4242
set(gui_src
43-
)
43+
notebook_app.hpp notebook_app.cpp
44+
input_widget.hpp input_widget.cpp
45+
output_widget.hpp output_widget.cpp
46+
)
4447

4548
# EDIT
4649
# add source for any GUI tests here

input_widget.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include "input_widget.hpp"
2+
3+
#include <QWidget>
4+
#include <QDebug>
5+
#include <QLineEdit>
6+
7+
// public:
8+
InputWidget::InputWidget(QWidget * parent): QPlainTextEdit(parent){
9+
10+
//inputExp = new QLineEdit();
11+
//inputExp = new QLineEdit();
12+
//inputExp->setParent(parent);
13+
//QObject::connect();
14+
15+
// Evaluate
16+
}
17+
/*
18+
QString InputWidget::getUserText(){
19+
return inputExp;
20+
}
21+
22+
Expression InputWidget::getEvalResult(){
23+
return result;
24+
}
25+
26+
//private slots:
27+
void InputWidget::textChanged(std::string s){
28+
qDebug() << s;
29+
inputExp = s;
30+
}
31+
*/
32+
void InputWidget::keyPressEvent(QKeyEvent * event){
33+
// Stub
34+
}
35+
36+

input_widget.hpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#ifndef INPUT_WIDGET_H
2+
#define INPUT_WIDGET_H
3+
4+
#include <QPlainTextEdit>
5+
#include <QLineEdit>
6+
#include <QWidget>
7+
#include <QDebug>
8+
#include <QKeyEvent>
9+
10+
#include <QString>
11+
#include <string>
12+
13+
class InputWidget: public QPlainTextEdit
14+
{
15+
Q_OBJECT // Necessary macro in class definition
16+
17+
public:
18+
InputWidget(QWidget * parent = nullptr);
19+
20+
//std::string getUserText();
21+
//QString getUserText();
22+
//Expression getEvalResult();
23+
24+
//public slots:
25+
26+
private slots:
27+
//void textChanged(QString text);
28+
29+
signals:
30+
// When the shift+enter keys are pushed, the text is put into the stream
31+
void textChanged(QString text);
32+
33+
private:
34+
//QLineEdit * value;
35+
//std::string inputExp;
36+
QString inputExp;
37+
//QLineEdit * inputExp;
38+
void keyPressEvent(QKeyEvent *event);
39+
//signals: // Neither public nor private
40+
//Expression * result; // Send result to OutputWidget
41+
};
42+
#endif // INPUT_WIDGET_H

notebook.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#include <QApplication>
22
#include <QWidget>
33

4+
#include "notebook_app.hpp"
5+
46
int main(int argc, char *argv[])
57
{
68
QApplication app(argc, argv);
79

8-
QWidget widget;
10+
NotebookApp widget;
911

1012
widget.show();
1113

notebook_app.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "notebook_app.hpp"
2+
3+
//#include <InputWidget>
4+
//#include <OutputWidget>
5+
6+
//#include <QLayout>
7+
//#include <QDebug>
8+
9+
NotebookApp::NotebookApp(QWidget * parent): QWidget(parent){
10+
11+
input = new InputWidget();
12+
input->setParent(parent);
13+
14+
output = new OutputWidget();
15+
output->setParent(parent);
16+
17+
QObject::connect(input, SIGNAL(textChanged(QString)),
18+
output, SLOT(showResult(QString)));
19+
20+
auto layout = new QGridLayout();
21+
22+
// layout->addWidget(widget, row, column)
23+
layout->addWidget(input, 0, 0);
24+
layout->addWidget(output, 1, 0);
25+
26+
setLayout(layout);
27+
}

notebook_app.hpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef NOTEBOOK_APP_H
2+
#define NOTEBOOK_APP_H
3+
4+
#include <QWidget>
5+
#include <QLayout>
6+
#include <QDebug>
7+
8+
#include"input_widget.hpp"
9+
#include"output_widget.hpp"
10+
11+
class NotebookApp: public QWidget // Extends QObject base class
12+
{
13+
Q_OBJECT // Necessary macro first line of class definition
14+
15+
public:
16+
NotebookApp(QWidget * parent = nullptr);
17+
18+
//public slots:
19+
20+
private slots:
21+
// Keypress in the input widget has occurred
22+
//void plotScriptUpdated(std::string input);
23+
24+
private:
25+
InputWidget * input;
26+
OutputWidget * output;
27+
28+
//signals: // Neither public nor private
29+
30+
};
31+
#endif // NOTEBOOK_APP_H

output_widget.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "output_widget.hpp"
2+
3+
//#include <QGraphicsView>
4+
//#include <QGraphicsScene>
5+
//#include <QLineEdit>
6+
//#include <QDebug>
7+
#include <QWidget>
8+
#include <QDebug>
9+
#include <QLayout>
10+
11+
12+
// public:
13+
OutputWidget::OutputWidget(QWidget * parent){
14+
15+
image = new QGraphicsView;
16+
//QObject::connect();
17+
18+
19+
display = new QGraphicsScene;
20+
//QObject::connect();
21+
22+
// Display
23+
auto layout = new QGridLayout();
24+
// layout->addWidget(widget, row, column)
25+
layout->addWidget(image, 0, 0);
26+
27+
setLayout(layout);
28+
}
29+
30+
//public slots:
31+
void OutputWidget::showResult(QString res){
32+
//qDebug() << "Hello World!";
33+
qDebug() << res;
34+
result = res;
35+
36+
}
37+
/*
38+
void OutputWidget::resultEvaluated(Expression res){
39+
qDebug() << s;
40+
inputExp = s;
41+
qDebug() << "Hello World!";
42+
}
43+
*/
44+

output_widget.hpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#ifndef OUTPUT_WIDGET_H
2+
#define OUTPUT_WIDGET_H
3+
4+
#include <QWidget>
5+
#include <QGraphicsView>
6+
#include <QGraphicsScene>
7+
#include <QGraphicsLayout>
8+
#include <QLayout>
9+
#include <QBoxLayout>
10+
11+
//class GraphicsView;
12+
//class GraphicsScene;
13+
14+
class OutputWidget: public QWidget // Extends QWidget base class
15+
{
16+
Q_OBJECT // Necessary macro in class definition
17+
18+
public:
19+
OutputWidget(QWidget * parent = nullptr);
20+
21+
public slots:
22+
//void resultEvaluated(Expression res); // Catch the result of evaluating input
23+
void showResult(QString res);
24+
25+
//private slots:
26+
27+
private:
28+
QGraphicsView * image;
29+
QGraphicsScene * display;
30+
31+
QString result;
32+
//std::string result;
33+
34+
//signals: // Neither public nor private
35+
36+
};
37+
#endif // OUTPUT_WIDGET_H

0 commit comments

Comments
 (0)