annotate gui-main.h @ 7:04867eba6428

function objects and signals/slots for errors and results
author John W. Eaton <jwe@octave.org>
date Thu, 23 May 2019 09:27:09 -0400
parents 54edd85237ab
children 7c4b04a6346d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
b97ffa8e4019 multiple inclusion guards in .h files
John W. Eaton <jwe@octave.org>
parents: 1
diff changeset
1 #if ! defined (calc_gui_main_h)
b97ffa8e4019 multiple inclusion guards in .h files
John W. Eaton <jwe@octave.org>
parents: 1
diff changeset
2 #define calc_gui_main_h 1
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4 #include <iostream>
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 #include <sstream>
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 #include <string>
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 #include <cstdlib>
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 #include <cstring>
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11 #include <QApplication>
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12 #include <QTextDocument>
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 #include <QTextEdit>
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14
4
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents: 2
diff changeset
15 #include "qt-interpreter.h"
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents: 2
diff changeset
16
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 namespace gui
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 class command_window : public QTextEdit
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20 {
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 Q_OBJECT
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23 public:
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 command_window (QWidget *p = nullptr);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 virtual ~command_window (void) = default;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 // Accept an input line, parse and possibly execute it.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30
5
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
31 void accept_line (const std::string& line);
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 // Redisplay current command line.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 void insert_at_end (const std::string& text);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36
1
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
37 void emit_error (const std::string& msg);
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
38
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 void emit_result (double value);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 signals:
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42
1
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
43 void input_char_available (int key);
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
44
7
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
45 void accept_line_signal (const QString& line);
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46
7
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
47 void redisplay_signal (void);
5
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
48
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 public slots:
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50
1
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
51 void handle_input_char (int key);
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
52
7
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
53 void handle_error (const QString& msg);
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
54
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 void handle_result (double value);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56
7
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
57 void redisplay (void);
04867eba6428 function objects and signals/slots for errors and results
John W. Eaton <jwe@octave.org>
parents: 5
diff changeset
58
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 protected:
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61 void keyPressEvent (QKeyEvent *event);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63 int do_arrow_key (int arrow_key);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 // Retrieve a command from the history list and insert it on the
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 // current command.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68 void history (bool up);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 void erase_line (void);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 void insert_at_cursor (const std::string& text);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74 void insert_line (const std::string& prompt, const std::string& line);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76 int set_mark (void);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78 void insert_result (double value);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80 void scroll_to_bottom (void);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82 // Child widgets:
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84 QTextDocument *m_buffer;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85
4
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents: 2
diff changeset
86 calc::qt_interpreter *m_interpreter;
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents: 2
diff changeset
87
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88 int beg_mark;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89 int prompt_mark;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90 };
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92 extern int main (int argc, char **argv);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95 #endif