annotate gui-main.h @ 5:54edd85237ab

use signal to send input to qt interpreter object
author John W. Eaton <jwe@octave.org>
date Wed, 22 May 2019 18:07:37 -0400
parents 0e154787183d
children 04867eba6428
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 redisplay (void);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 void insert_at_end (const std::string& text);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38
1
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
39 void emit_error (const std::string& msg);
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
40
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 void emit_result (double value);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 signals:
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44
1
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
45 void input_char_available (int key);
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
46
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 void result_available (double value);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48
5
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
49 void accept_line_signal (const QString& line);
54edd85237ab use signal to send input to qt interpreter object
John W. Eaton <jwe@octave.org>
parents: 4
diff changeset
50
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 public slots:
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52
1
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
53 void handle_input_char (int key);
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
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
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 protected:
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 void keyPressEvent (QKeyEvent *event);
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 int do_arrow_key (int arrow_key);
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 // Retrieve a command from the history list and insert it on the
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 // current command.
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 void history (bool up);
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 erase_line (void);
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 insert_at_cursor (const std::string& text);
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_line (const std::string& prompt, const std::string& line);
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 int set_mark (void);
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 void insert_result (double value);
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 scroll_to_bottom (void);
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 // Child widgets:
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 QTextDocument *m_buffer;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83
4
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents: 2
diff changeset
84 calc::qt_interpreter *m_interpreter;
0e154787183d new interpreter and qt_interpreter objects
John W. Eaton <jwe@octave.org>
parents: 2
diff changeset
85
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86 int beg_mark;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87 int prompt_mark;
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88 };
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90 extern int main (int argc, char **argv);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91
1
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
92 extern void emit_error (const std::string& msg);
08df60a01bc1 debug flag, handle input with signal
John W. Eaton <jwe@octave.org>
parents: 0
diff changeset
93
0
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94 extern void emit_result (double value);
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95 }
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96
dff751fb985c initial revision
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97 #endif