1 /*
2 
3 Copyright (C) 2012-2019 Michael Goffioul.
4 Copyright (C) 2012-2019 Jacob Dawid.
5 
6 This file is part of QTerminal.
7 
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program.  If not,
20 see <https://www.gnu.org/licenses/>.
21 
22 */
23 
24 #ifndef QTERMINAL_H
25 #define QTERMINAL_H
26 
27 #include <QColor>
28 #include <QList>
29 #include <QPoint>
30 #include <QString>
31 #include <QWidget>
32 
33 // For now, we need to use the following #include and using statement
34 // for the signal/slot macros.  Could maybe change later when using
35 // Qt5-style signal/slot connections.
36 #include "gui-settings.h"
37 using octave::gui_settings;
38 
39 namespace octave
40 {
41   class base_qobject;
42 }
43 
44 class QMenu;
45 class QAction;
46 
47 class QTerminal : public QWidget
48 {
49   Q_OBJECT
50 
51 public:
52 
53   static QTerminal *
54   create (octave::base_qobject& oct_qobj, QWidget *xparent = nullptr);
55 
56   virtual ~QTerminal (void) = default;
57 
58   virtual void setTerminalFont (const QFont& font) = 0;
59 
60   virtual void setSize (int h, int v) = 0;
61 
62   virtual void sendText (const QString& text) = 0;
63 
64   virtual QString selectedText () = 0;
65 
66   virtual void has_extra_interrupt (bool extra) = 0;
67 
get_hotspot_actions(const QPoint &)68   virtual QList<QAction*> get_hotspot_actions (const QPoint&)
69   { return QList<QAction*> (); }
70 
71   enum CursorType
72   {
73     IBeamCursor,
74     BlockCursor,
75     UnderlineCursor
76   };
77 
setCursorType(CursorType type,bool blinking)78   virtual void setCursorType (CursorType type, bool blinking)
79   {
80     // Provide empty default impl in order to avoid conflicts with the
81     // win impl.
82 
83     Q_UNUSED (type);
84     Q_UNUSED (blinking);
85   }
86 
87   virtual void setBackgroundColor (const QColor& color) = 0;
88 
89   virtual void setForegroundColor (const QColor& color) = 0;
90 
91   virtual void setSelectionColor (const QColor& color) = 0;
92 
93   virtual void setCursorColor (bool useForegroundColor,
94                                const QColor& color) = 0;
95 
96   virtual void setScrollBufferSize(int value=1000) = 0;
97 
98 signals:
99 
100   void report_status_message (const QString&);
101 
102   void interrupt_signal (void);
103 
104   void edit_mfile_request (const QString&, int);
105 
106   void show_doc_signal (const QString&);
107 
108   void execute_command_in_terminal_signal (const QString&);
109 
110 public slots:
111 
112   virtual void copyClipboard (void) = 0;
113 
114   virtual void pasteClipboard (void) = 0;
115 
116   virtual void selectAll (void) = 0;
117 
118   virtual void handleCustomContextMenuRequested (const QPoint& at);
119 
120   void notice_settings (const gui_settings *settings);
121 
init_terminal_size(void)122   virtual void init_terminal_size (void) { }
123 
terminal_interrupt(void)124   void terminal_interrupt (void) { emit interrupt_signal (); }
125 
126   void set_global_shortcuts (bool focus_out);
127 
128   void run_selection (void);
129 
130   void edit_file (void);
131 
132   void edit_selected (void);
133 
134   void help_on_expression (void);
135 
136   void doc_on_expression (void);
137 
handle_visibility_changed(bool)138   virtual void handle_visibility_changed (bool) { };
139 
140 protected:
141 
QWidget(xparent)142   QTerminal (QWidget *xparent = nullptr) : QWidget (xparent) { }
143 
144   void construct (octave::base_qobject& oct_qobj, QWidget *xparent);
145 
146 private:
147 
148   QMenu *_contextMenu;
149   QAction * _copy_action;
150   QAction * _paste_action;
151   QAction * _selectall_action;
152   QAction * _edit_action;
153   QAction * _run_selection_action;
154   QAction * m_edit_selected_action;
155   QAction * m_help_selected_action;
156   QAction * m_doc_selected_action;
157 
158   QAction *_interrupt_action;
159   QAction *_nop_action;
160 };
161 
162 #endif // QTERMINAL_H
163