annotate command-window.h @ 9:822a2fe5bb51

move command window to separate file and other refactoring
author John W. Eaton <jwe@octave.org>
date Thu, 23 May 2019 12:36:26 -0400
parents
children b652a5528fb1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
822a2fe5bb51 move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23 virtual ~command_window (void) = default;
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
822a2fe5bb51 move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 // Redisplay current command line.
822a2fe5bb51 move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30
822a2fe5bb51 move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 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
32
822a2fe5bb51 move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 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
34
822a2fe5bb51 move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 void emit_result (double value);
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 signals:
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 input_char_available (int key);
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 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
42
822a2fe5bb51 move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 void redisplay_signal (void);
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 public slots:
822a2fe5bb51 move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46
822a2fe5bb51 move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 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
48
822a2fe5bb51 move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 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
50
822a2fe5bb51 move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 void handle_result (double value);
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 redisplay (void);
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 protected:
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 keyPressEvent (QKeyEvent *event);
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 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
60
822a2fe5bb51 move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61 // 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
62 // current command.
822a2fe5bb51 move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63
822a2fe5bb51 move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 void history (bool up);
822a2fe5bb51 move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65
822a2fe5bb51 move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 void erase_line (void);
822a2fe5bb51 move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67
822a2fe5bb51 move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68 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
69
822a2fe5bb51 move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 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
71
822a2fe5bb51 move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 int set_mark (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_result (double value);
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 scroll_to_bottom (void);
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 // Child widgets:
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 QTextDocument *m_buffer;
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 calc::qt_interpreter *m_interpreter;
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 int beg_mark;
822a2fe5bb51 move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85 int prompt_mark;
822a2fe5bb51 move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86 };
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 extern void readline_init (void);
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 extern void readline_fini (void);
822a2fe5bb51 move command window to separate file and other refactoring
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91 }
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 #endif