GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
QTerminal.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2012-2015 Michael Goffioul.
4 Copyright (C) 2012-2015 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 <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #ifndef QTERMINAL_H
25 #define QTERMINAL_H
26 
27 #include <QSettings>
28 #include <QKeySequence>
29 #include <QWidget>
30 #include <QStringList>
31 #include <QColor>
32 #include <QList>
33 #include <QMenu>
34 #include <QClipboard>
35 #include <QApplication>
36 #include <QAction>
37 
38 #include "resource-manager.h"
39 
40 class QTerminal : public QWidget
41 {
42  Q_OBJECT
43 
44 public:
45 
46  static QTerminal *create (QWidget *xparent = 0);
47 
48  static QList<QColor> default_colors (void);
49 
50  static QStringList color_names (void);
51 
52  virtual ~QTerminal (void) { }
53 
54  virtual void setTerminalFont (const QFont& font) = 0;
55 
56  virtual void setSize (int h, int v) = 0;
57 
58  virtual void sendText (const QString& text) = 0;
59 
60  virtual QString selectedText () = 0;
61 
62  virtual void has_extra_interrupt (bool extra) = 0;
63 
65  {
69  };
70 
71  virtual void setCursorType (CursorType type, bool blinking)
72  {
73  // Provide empty default impl in order to avoid conflicts with the
74  // win impl.
75 
76  Q_UNUSED (type);
77  Q_UNUSED (blinking);
78  }
79 
80  virtual void setBackgroundColor (const QColor& color) = 0;
81 
82  virtual void setForegroundColor (const QColor& color) = 0;
83 
84  virtual void setSelectionColor (const QColor& color) = 0;
85 
86  virtual void setCursorColor (bool useForegroundColor,
87  const QColor& color) = 0;
88 
89  virtual void setScrollBufferSize(int value=1000) = 0;
90 
91 signals:
92 
93  void report_status_message (const QString&);
94 
95  void interrupt_signal (void);
96 
97 public slots:
98 
99  virtual void copyClipboard (void) = 0;
100 
101  virtual void pasteClipboard (void) = 0;
102 
103  virtual void selectAll (void) = 0;
104 
105  virtual void handleCustomContextMenuRequested (const QPoint& at)
106  {
107  QClipboard * cb = QApplication::clipboard ();
108 
109  _paste_action->setEnabled (cb->text().length() > 0);
110  _copy_action->setEnabled (selectedText().length() > 0);
111 
112  _contextMenu->move (mapToGlobal (at));
113  _contextMenu->show ();
114  }
115 
116  void notice_settings (const QSettings *settings);
117 
118  virtual void init_terminal_size (void) { }
119 
120  void terminal_interrupt (void) { emit interrupt_signal (); }
121 
122  void set_global_shortcuts (bool focus_out);
123 
124 protected:
125 
126  QTerminal (QWidget *xparent = 0) : QWidget (xparent)
127  {
128  // context menu
129  setContextMenuPolicy (Qt::CustomContextMenu);
130 
131  _contextMenu = new QMenu (this);
132 
133  _copy_action = _contextMenu->addAction (
134  resource_manager::icon ("edit-copy"),
135  tr ("Copy"), this, SLOT (copyClipboard ()));
136 
137  _paste_action = _contextMenu->addAction (
138  resource_manager::icon ("edit-paste"),
139  tr ("Paste"), this, SLOT (pasteClipboard ()));
140 
141  _contextMenu->addSeparator ();
142 
143  _selectall_action = _contextMenu->addAction (
144  tr ("Select All"), this, SLOT (selectAll ()));
145 
146 
147  _contextMenu->addSeparator ();
148 
149  _contextMenu->addAction (tr ("Clear Window"), parent (),
150  SLOT (handle_clear_command_window_request ()));
151 
152  connect (this, SIGNAL (customContextMenuRequested (QPoint)),
153  this, SLOT (handleCustomContextMenuRequested (QPoint)));
154 
155  connect (this, SIGNAL (report_status_message (const QString&)),
156  xparent, SLOT (report_status_message (const QString&)));
157 
158  connect (xparent, SIGNAL (settings_changed (const QSettings *)),
159  this, SLOT (notice_settings (const QSettings *)));
160 
161  connect (xparent, SIGNAL (init_terminal_size_signal ()),
162  this, SLOT (init_terminal_size ()));
163 
164  connect (xparent, SIGNAL (copyClipboard_signal ()),
165  this, SLOT (copyClipboard ()));
166 
167  connect (xparent, SIGNAL (pasteClipboard_signal ()),
168  this, SLOT (pasteClipboard ()));
169 
170  connect (xparent, SIGNAL (selectAll_signal ()),
171  this, SLOT (selectAll ()));
172 
173  // extra interrupt action
174  _interrupt_action = new QAction (this);
175  addAction (_interrupt_action);
176 
177  _interrupt_action->setShortcut (
178  QKeySequence (Qt::ControlModifier + Qt::Key_C));
179 
180  connect (_interrupt_action, SIGNAL (triggered ()),
181  this, SLOT (terminal_interrupt ()));
182  }
183 
184 private:
185 
186  QMenu *_contextMenu;
187  QAction * _copy_action;
188  QAction * _paste_action;
189  QAction * _selectall_action;
190 
192 };
193 
194 #endif // QTERMINAL_H
virtual void sendText(const QString &text)=0
virtual void setScrollBufferSize(int value=1000)=0
virtual void init_terminal_size(void)
Definition: QTerminal.h:118
void interrupt_signal(void)
QAction * _selectall_action
Definition: QTerminal.h:189
virtual void setForegroundColor(const QColor &color)=0
void terminal_interrupt(void)
Definition: QTerminal.h:120
virtual void pasteClipboard(void)=0
QAction * _interrupt_action
Definition: QTerminal.h:191
virtual void setSelectionColor(const QColor &color)=0
virtual void selectAll(void)=0
virtual void has_extra_interrupt(bool extra)=0
virtual void copyClipboard(void)=0
QMenu * _contextMenu
Definition: QTerminal.h:186
virtual QString selectedText()=0
void report_status_message(const QString &)
void set_global_shortcuts(bool focus_out)
Definition: QTerminal.cc:76
virtual ~QTerminal(void)
Definition: QTerminal.h:52
QAction * _copy_action
Definition: QTerminal.h:187
virtual void setSize(int h, int v)=0
QAction * _paste_action
Definition: QTerminal.h:188
virtual void setCursorColor(bool useForegroundColor, const QColor &color)=0
void notice_settings(const QSettings *settings)
Definition: QTerminal.cc:86
QTerminal(QWidget *xparent=0)
Definition: QTerminal.h:126
static QTerminal * create(QWidget *xparent=0)
Definition: QTerminal.cc:33
static QStringList color_names(void)
Definition: QTerminal.cc:59
virtual void setTerminalFont(const QFont &font)=0
static QList< QColor > default_colors(void)
Definition: QTerminal.cc:43
static QIcon icon(const QString &icon_name, bool fallback=true)
virtual void setBackgroundColor(const QColor &color)=0
virtual void setCursorType(CursorType type, bool blinking)
Definition: QTerminal.h:71
virtual void handleCustomContextMenuRequested(const QPoint &at)
Definition: QTerminal.h:105