Mercurial > jwe > qt-gui-with-push-parser
annotate command-window.h @ 11:b652a5528fb1
handle EOF on input; more misc refactoring
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 23 May 2019 13:42:57 -0400 |
parents | 822a2fe5bb51 |
children | 2ddf3fe6fa33 |
rev | line source |
---|---|
9
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1 #if ! defined (calc_command_window_h) |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
2 #define calc_command_window_h 1 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
3 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
4 #include <string> |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
5 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
6 #include <QTextDocument> |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
7 #include <QTextEdit> |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
8 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
9 #include "qt-interpreter.h" |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
10 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
11 namespace calc |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
12 { |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
13 class command_window : public QTextEdit |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
14 { |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
15 Q_OBJECT |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
16 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
17 public: |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
18 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
19 static command_window *the_command_window; |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
20 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
21 command_window (QWidget *p = nullptr); |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
22 |
11
b652a5528fb1
handle EOF on input; more misc refactoring
John W. Eaton <jwe@octave.org>
parents:
9
diff
changeset
|
23 ~command_window (void); |
9
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
24 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 // Accept an input line, parse and possibly execute it. |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
27 void accept_line (const std::string& line); |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 |
11
b652a5528fb1
handle EOF on input; more misc refactoring
John W. Eaton <jwe@octave.org>
parents:
9
diff
changeset
|
29 // Handle EOF on input. |
b652a5528fb1
handle EOF on input; more misc refactoring
John W. Eaton <jwe@octave.org>
parents:
9
diff
changeset
|
30 |
b652a5528fb1
handle EOF on input; more misc refactoring
John W. Eaton <jwe@octave.org>
parents:
9
diff
changeset
|
31 void eof (void); |
b652a5528fb1
handle EOF on input; more misc refactoring
John W. Eaton <jwe@octave.org>
parents:
9
diff
changeset
|
32 |
9
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
33 // Redisplay current command line. |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
34 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
35 void insert_at_end (const std::string& text); |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
36 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 void emit_error (const std::string& msg); |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
38 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
39 void emit_result (double value); |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
40 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
41 signals: |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
42 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
43 void input_char_available (int key); |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
44 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
45 void accept_line_signal (const QString& line); |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
46 |
11
b652a5528fb1
handle EOF on input; more misc refactoring
John W. Eaton <jwe@octave.org>
parents:
9
diff
changeset
|
47 void eof_signal (void); |
b652a5528fb1
handle EOF on input; more misc refactoring
John W. Eaton <jwe@octave.org>
parents:
9
diff
changeset
|
48 |
9
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
49 void redisplay_signal (void); |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
50 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
51 public slots: |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
52 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
53 void handle_input_char (int key); |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
54 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
55 void handle_error (const QString& msg); |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
56 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
57 void handle_result (double value); |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
58 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
59 void redisplay (void); |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
60 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
61 protected: |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
62 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
63 void keyPressEvent (QKeyEvent *event); |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
64 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
65 int do_arrow_key (int arrow_key); |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
66 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
67 // Retrieve a command from the history list and insert it on the |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
68 // current command. |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
69 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
70 void history (bool up); |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
71 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
72 void erase_line (void); |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
73 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
74 void insert_at_cursor (const std::string& text); |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
75 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
76 void insert_line (const std::string& prompt, const std::string& line); |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
77 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
78 int set_mark (void); |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
79 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
80 void insert_result (double value); |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
81 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
82 void scroll_to_bottom (void); |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
83 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
84 // Child widgets: |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
85 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
86 QTextDocument *m_buffer; |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
87 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
88 calc::qt_interpreter *m_interpreter; |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
89 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
90 int beg_mark; |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
91 int prompt_mark; |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
92 }; |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
93 } |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
94 |
822a2fe5bb51
move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
95 #endif |