GNU Octave  4.2.1
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.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2012-2017 Michael Goffioul.
4 Copyright (C) 2012-2016 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 #include "QTerminal.h"
25 
26 #if defined (Q_OS_WIN32)
27 # include "win32/QWinTerminalImpl.h"
28 #else
29 # include "unix/QUnixTerminalImpl.h"
30 #endif
31 
32 QTerminal *
34 {
35 #if defined (Q_OS_WIN32)
36  return new QWinTerminalImpl (xparent);
37 #else
38  return new QUnixTerminalImpl (xparent);
39 #endif
40 }
41 
44 {
45  static QList<QColor> colors;
46 
47  if (colors.isEmpty ())
48  {
49  colors << QColor(0,0,0)
50  << QColor(255,255,255)
51  << QColor(192,192,192)
52  << QColor(128,128,128);
53  }
54 
55  return colors;
56 }
57 
58 QStringList
60 {
61  static QStringList names;
62 
63  if (names.isEmpty ())
64  {
65  names << QObject::tr ("foreground")
66  << QObject::tr ("background")
67  << QObject::tr ("selection")
68  << QObject::tr ("cursor");
69  }
70 
71  return names;
72 }
73 
74 // slot for disabling the interrupt action when terminal loses focus
75 void
77  {
78  if (focus_out)
79  {
80  _interrupt_action->setShortcut (QKeySequence ());
81  _nop_action->setShortcut (QKeySequence ());
82  }
83  else
84  {
85  _interrupt_action->setShortcut (
86  QKeySequence (Qt::ControlModifier | Qt::Key_C));
87  _nop_action->setShortcut (
88  QKeySequence (Qt::ControlModifier | Qt::Key_D));
89  }
90  }
91 
92 // slot for the terminal's context menu
93 void
95  {
96  QClipboard * cb = QApplication::clipboard ();
97  QString selected_text = selectedText();
98  bool has_selected_text = ! selected_text.isEmpty ();
99 
100  _edit_action->setVisible (false);
101 
102  if (has_selected_text)
103  {
104  QRegExp file ("(?:[ \\t]+)(\\S+) at line (\\d+) column (?:\\d+)");
105 
106  int pos = file.indexIn (selected_text);
107 
108  if (pos > -1)
109  {
110  QString file_name = file.cap (1);
111  QString line = file.cap (2);
112 
113  _edit_action->setVisible (true);
114  _edit_action->setText (tr ("Edit %1 at line %2")
115  .arg (file_name).arg (line));
116 
117  QStringList data;
118  data << file_name << line;
119  _edit_action->setData (data);
120  }
121  }
122 
123  _paste_action->setEnabled (cb->text().length() > 0);
124  _copy_action->setEnabled (has_selected_text);
125 
126  _contextMenu->exec (mapToGlobal (at));
127  }
128 
129 // slot for edit files in error messages
130 void
132 {
133  QString file = _edit_action->data ().toStringList ().at (0);
134  int line = _edit_action->data ().toStringList ().at (1).toInt ();
135 
136  emit edit_mfile_request (file,line);
137 }
138 
139 void
140 QTerminal::notice_settings (const QSettings *settings)
141 {
142  // QSettings pointer is checked before emitting.
143 
144  // Set terminal font:
145  QFont term_font = QFont ();
146  term_font.setStyleHint (QFont::TypeWriter);
147  term_font.setFamily
148  (settings->value ("terminal/fontName", "Courier New").toString ());
149  term_font.setPointSize (settings->value ("terminal/fontSize", 10).toInt ());
150  setTerminalFont (term_font);
151 
152  QString cursorType
153  = settings->value ("terminal/cursorType", "ibeam").toString ();
154 
155  bool cursorBlinking
156  = settings->value ("terminal/cursorBlinking", true).toBool ();
157 
158  if (cursorType == "ibeam")
159  setCursorType (QTerminal::IBeamCursor, cursorBlinking);
160  else if (cursorType == "block")
161  setCursorType (QTerminal::BlockCursor, cursorBlinking);
162  else if (cursorType == "underline")
163  setCursorType (QTerminal::UnderlineCursor, cursorBlinking);
164 
165  bool cursorUseForegroundColor
166  = settings->value ("terminal/cursorUseForegroundColor", true).toBool ();
167 
168  QList<QColor> colors = default_colors ();
169 
171  (settings->value ("terminal/color_f",
172  QVariant (colors.at (0))).value<QColor> ());
173 
175  (settings->value ("terminal/color_b",
176  QVariant (colors.at (1))).value<QColor> ());
177 
179  (settings->value ("terminal/color_s",
180  QVariant (colors.at (2))).value<QColor> ());
181 
183  (cursorUseForegroundColor,
184  settings->value ("terminal/color_c",
185  QVariant (colors.at (3))).value<QColor> ());
186  setScrollBufferSize (settings->value ("terminal/history_buffer",1000).toInt () );
187 
188  // check whether Copy shortcut is Ctrl-C
189  QKeySequence sc;
190  sc = QKeySequence (settings->value ("shortcuts/main_edit:copy").toString ());
191 
192  // if sc is empty, shortcuts are not yet in the settings (take the default)
193  if (sc.isEmpty ()) // QKeySequence::Copy as second argument in
194  sc = QKeySequence::Copy; // settings->value () does not work!
195 
196  // dis- or enable extra interrupt action
197  bool extra_ir_action = (sc != QKeySequence (Qt::ControlModifier | Qt::Key_C));
198  _interrupt_action->setEnabled (extra_ir_action);
199  has_extra_interrupt (extra_ir_action);
200 
201  // check whether shortcut Ctrl-D is in use by the main-window
202  bool ctrld = settings->value ("shortcuts/main_ctrld",false).toBool ();
203  _nop_action->setEnabled (! ctrld);
204 }
void edit_mfile_request(const QString &, int)
void edit_file(void)
Definition: QTerminal.cc:131
For example cd octave end example noindent changes the current working directory to an error message is printed and the working directory is not changed sc
Definition: dirfns.cc:120
For example cd octave end example noindent changes the current working directory to file
Definition: dirfns.cc:120
virtual void setScrollBufferSize(int value=1000)=0
virtual void setForegroundColor(const QColor &color)=0
QAction * _interrupt_action
Definition: QTerminal.h:199
QAction * _nop_action
Definition: QTerminal.h:200
virtual void setSelectionColor(const QColor &color)=0
octave_value arg
Definition: pr-output.cc:3440
virtual void has_extra_interrupt(bool extra)=0
QMenu * _contextMenu
Definition: QTerminal.h:193
QAction * _edit_action
Definition: QTerminal.h:197
virtual QString selectedText()=0
void set_global_shortcuts(bool focus_out)
Definition: QTerminal.cc:76
QAction * _copy_action
Definition: QTerminal.h:194
QAction * _paste_action
Definition: QTerminal.h:195
virtual void setCursorColor(bool useForegroundColor, const QColor &color)=0
OCTAVE_EXPORT octave_value_list at
Definition: time.cc:115
void notice_settings(const QSettings *settings)
Definition: QTerminal.cc:140
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
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.cc:94