GNU Octave  3.8.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-2013 Michael Goffioul.
4 Copyright (C) 2012-2013 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 
37 class QTerminal : public QWidget
38 {
39  Q_OBJECT
40 
41 public:
42 
43  static QTerminal *create (QWidget *xparent = 0);
44 
45  static QList<QColor> default_colors (void);
46 
47  static QStringList color_names (void);
48 
49  virtual ~QTerminal (void) { }
50 
51  virtual void setTerminalFont (const QFont& font) = 0;
52 
53  virtual void setSize (int h, int v) = 0;
54 
55  virtual void sendText (const QString& text) = 0;
56 
57  virtual QString selectedText () = 0;
58 
60  {
64  };
65 
66  virtual void setCursorType (CursorType type, bool blinking)
67  {
68  // Provide empty default impl in order to avoid conflicts with the
69  // win impl.
70 
71  Q_UNUSED (type);
72  Q_UNUSED (blinking);
73  }
74 
75  virtual void setBackgroundColor (const QColor& color) = 0;
76 
77  virtual void setForegroundColor (const QColor& color) = 0;
78 
79  virtual void setSelectionColor (const QColor& color) = 0;
80 
81  virtual void setCursorColor (bool useForegroundColor,
82  const QColor& color) = 0;
83 
84 signals:
85 
86  void report_status_message (const QString&);
87 
88  void interrupt_signal (void);
89 
90 public slots:
91 
92  virtual void copyClipboard (void) = 0;
93 
94  virtual void pasteClipboard (void) = 0;
95 
96  virtual void handleCustomContextMenuRequested (const QPoint& at)
97  {
98  QClipboard * cb = QApplication::clipboard ();
99 
100  _paste_action->setEnabled (cb->text().length() > 0);
101  _copy_action->setEnabled (selectedText().length() > 0);
102 
103  _contextMenu->move (mapToGlobal (at));
104  _contextMenu->show ();
105  }
106 
107  void notice_settings (const QSettings *settings);
108 
109  void terminal_interrupt (void) { emit interrupt_signal (); }
110 
111 protected:
112 
113  QTerminal (QWidget *xparent = 0) : QWidget (xparent)
114  {
115  setContextMenuPolicy (Qt::CustomContextMenu);
116 
117  _contextMenu = new QMenu (this);
118 
119  _copy_action = _contextMenu->addAction (
120  QIcon (":/actions/icons/editcopy.png"),
121  tr ("Copy"), this, SLOT (copyClipboard ()));
122 
123  _paste_action = _contextMenu->addAction (
124  QIcon (":/actions/icons/editpaste.png"),
125  tr ("Paste"), this, SLOT (pasteClipboard ()));
126 
127  _contextMenu->addSeparator ();
128 
129  _contextMenu->addAction (tr ("Clear All"), parent (),
130  SLOT (handle_clear_command_window_request ()));
131 
132  connect (this, SIGNAL (customContextMenuRequested (QPoint)),
133  this, SLOT (handleCustomContextMenuRequested (QPoint)));
134 
135  connect (this, SIGNAL (report_status_message (const QString&)),
136  xparent, SLOT (report_status_message (const QString&)));
137 
138  connect (xparent, SIGNAL (settings_changed (const QSettings *)),
139  this, SLOT (notice_settings (const QSettings *)));
140 
141  connect (xparent, SIGNAL (copyClipboard_signal ()),
142  this, SLOT (copyClipboard ()));
143 
144  connect (xparent, SIGNAL (pasteClipboard_signal ()),
145  this, SLOT (pasteClipboard ()));
146  }
147 
148 private:
149 
150  QMenu *_contextMenu;
151  QAction * _copy_action;
152  QAction * _paste_action;
153 };
154 
155 #endif // QTERMINAL_H