GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
terminal-dock-widget.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2011-2023 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include <QScreen>
31 
32 // This header is only needed for the new terminal widget.
33 #if defined (HAVE_QSCINTILLA)
34 # include "command-widget.h"
35 #endif
36 
37 // This header is only needed for the old terminal widget.
38 #include "QTerminal.h"
39 
40 #include "gui-preferences-cs.h"
41 #include "gui-preferences-global.h"
42 
43 #include "octave-qobject.h"
44 #include "terminal-dock-widget.h"
45 
47 
49  base_qobject& oct_qobj)
50 : octave_dock_widget ("TerminalDockWidget", p, oct_qobj),
51  m_experimental_terminal_widget (oct_qobj.experimental_terminal_widget ())
52 {
53  // FIXME: we could do this in a better way, but improving it doesn't
54  // matter much if we will eventually be removing the old terminal.
55  if (m_experimental_terminal_widget)
56  {
57 #if defined (HAVE_QSCINTILLA)
58  command_widget *widget = new command_widget (oct_qobj, this);
59  console *con = widget->get_console ();
60 
63 
66 
69 
72 
75 
76  m_terminal = widget;
77 #endif
78  }
79  else
80  {
81  QTerminal *widget = QTerminal::create (oct_qobj, this);
82 
85 
86  // Connect the visibility signal to the terminal for
87  // dis-/enabling timers.
88  connect (this, &terminal_dock_widget::visibilityChanged,
90 
91  m_terminal = widget;
92  }
93 
94  m_terminal->setObjectName ("OctaveTerminal");
95  m_terminal->setFocusPolicy (Qt::StrongFocus);
96 
97  set_title (tr ("Command Window"));
98 
99  setWidget (m_terminal);
100  setFocusProxy (m_terminal);
101 
102  // Chose a reasonable size at startup in order to avoid truncated
103  // startup messages
104  resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
106 
107  QFont font = QFont ();
108  font.setStyleHint (QFont::TypeWriter);
109  QString default_font = settings->value (global_mono_font).toString ();
110  font.setFamily
111  (settings->value (cs_font.key, default_font).toString ());
112  font.setPointSize
113  (settings->value (cs_font_size).toInt ());
114 
115  QFontMetrics metrics(font);
116 
117  int win_x = metrics.maxWidth()*80;
118  int win_y = metrics.height()*25;
119 
120  int max_x = QGuiApplication::primaryScreen ()->availableGeometry ().width ();
121  int max_y = QGuiApplication::primaryScreen ()->availableGeometry ().height ();
122 
123  if (win_x > max_x)
124  win_x = max_x;
125  if (win_y > max_y)
126  win_y = max_y;
127 
128  setGeometry (0, 0, win_x, win_y);
129 
130  if (! p)
131  make_window ();
132 }
133 
135 {
136  QWidget *w = widget ();
137  return w->hasFocus ();
138 }
139 
141 {
143  ? nullptr : dynamic_cast<QTerminal *> (m_terminal));
144 }
145 
146 #if defined (HAVE_QSCINTILLA)
148 {
150  ? dynamic_cast<command_widget *> (m_terminal) : nullptr);
151 }
152 #endif
153 
155 {
156  emit settings_changed (settings);
157 }
158 
160 {
162  {
163 #if defined (HAVE_QSCINTILLA)
165  if (cmd)
166  cmd->init_command_prompt ();
167 #endif
168  }
169 }
170 
OCTAVE_END_NAMESPACE(octave)
virtual void handle_visibility_changed(bool)
Definition: QTerminal.h:145
void notice_settings(const gui_settings *settings)
Definition: QTerminal.cc:202
static QTerminal * create(octave::base_qobject &oct_qobj, QWidget *xparent)
Definition: QTerminal.cc:52
Base class for Octave interfaces that use Qt.
console * get_console()
void init_command_prompt()
void insert_interpreter_output(const QString &msg)
void notice_settings(const gui_settings *settings)
void update_prompt(const QString &prompt)
void execute_command(const QString &command)
void new_command_line(const QString &command=QString())
gui_settings * get_settings(void) const
void notice_settings(const gui_settings *settings)
command_widget * get_command_widget(void)
void new_command_line_signal(const QString &=QString())
QTerminal * get_qterminal(void)
void interpreter_output_signal(const QString &)
void update_prompt_signal(const QString &)
void settings_changed(const gui_settings *settings)
void execute_command_signal(const QString &)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
const gui_pref cs_font_size("terminal/fontSize", QVariant(10))
const gui_pref cs_font("terminal/fontName", QVariant())
const gui_pref global_mono_font("monospace_font", global_font_family)
std::complex< double > w(std::complex< double > z, double relerr=0)
const QString key