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.cc
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 #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  _interrupt_action->setShortcut (QKeySequence ());
80  else
81  _interrupt_action->setShortcut (
82  QKeySequence (Qt::ControlModifier + Qt::Key_C));
83  }
84 
85 void
86 QTerminal::notice_settings (const QSettings *settings)
87 {
88  // QSettings pointer is checked before emitting.
89 
90  // Set terminal font:
91  QFont term_font = QFont ();
92  term_font.setStyleHint (QFont::TypeWriter);
93  term_font.setFamily
94  (settings->value ("terminal/fontName", "Courier New").toString ());
95  term_font.setPointSize (settings->value ("terminal/fontSize", 10).toInt ());
96  setTerminalFont (term_font);
97 
98  QString cursorType
99  = settings->value ("terminal/cursorType", "ibeam").toString ();
100 
101  bool cursorBlinking
102  = settings->value ("terminal/cursorBlinking", true).toBool ();
103 
104  if (cursorType == "ibeam")
105  setCursorType (QTerminal::IBeamCursor, cursorBlinking);
106  else if (cursorType == "block")
107  setCursorType (QTerminal::BlockCursor, cursorBlinking);
108  else if (cursorType == "underline")
109  setCursorType (QTerminal::UnderlineCursor, cursorBlinking);
110 
111  bool cursorUseForegroundColor
112  = settings->value ("terminal/cursorUseForegroundColor", true).toBool ();
113 
114  QList<QColor> colors = default_colors ();
115 
117  (settings->value ("terminal/color_f",
118  QVariant (colors.at (0))).value<QColor> ());
119 
121  (settings->value ("terminal/color_b",
122  QVariant (colors.at (1))).value<QColor> ());
123 
125  (settings->value ("terminal/color_s",
126  QVariant (colors.at (2))).value<QColor> ());
127 
129  (cursorUseForegroundColor,
130  settings->value ("terminal/color_c",
131  QVariant (colors.at (3))).value<QColor> ());
132  setScrollBufferSize (settings->value ("terminal/history_buffer",1000).toInt () );
133 
134  // check whether Copy shoretcut is Ctrl-C
135  int set = settings->value ("shortcuts/set",0).toInt ();
136  QKeySequence copy;
137  QString key = QString ("shortcuts/main_edit:copy");
138  if (set)
139  key.append ("_1"); // if second set is active
140  copy = QKeySequence (settings->value (key).toString ()); // the copy shortcut
141 
142  // if copy is empty, shortcuts are not yet in the settings (take the default)
143  if (copy.isEmpty ()) // QKeySequence::Copy as second argument in
144  copy = QKeySequence::Copy; // settings->value () does not work!
145 
146  // dis- or enable extra interrupt action
147  QKeySequence ctrl;
148  ctrl = Qt::ControlModifier;
149 
150  bool extra_ir_action = (copy != QKeySequence (ctrl + Qt::Key_C));
151 
152  _interrupt_action->setEnabled (extra_ir_action);
153  has_extra_interrupt (extra_ir_action);
154 }
virtual void setScrollBufferSize(int value=1000)=0
virtual void setForegroundColor(const QColor &color)=0
static string_vector names(const map_type &lst)
Definition: help.cc:782
QAction * _interrupt_action
Definition: QTerminal.h:191
virtual void setSelectionColor(const QColor &color)=0
virtual void has_extra_interrupt(bool extra)=0
void set_global_shortcuts(bool focus_out)
Definition: QTerminal.cc:76
virtual void setCursorColor(bool useForegroundColor, const QColor &color)=0
void notice_settings(const QSettings *settings)
Definition: QTerminal.cc:86
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