GNU Octave  6.2.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-2021 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 <QDesktopWidget>
31 
32 #include "gui-preferences-cs.h"
33 #include "gui-preferences-global.h"
34 #include "octave-qobject.h"
35 #include "terminal-dock-widget.h"
36 
37 #include "quit.h"
38 #include "signal-wrappers.h"
39 
40 #include "sighandlers.h"
41 
42 namespace octave
43 {
45  base_qobject& oct_qobj)
46  : octave_dock_widget ("TerminalDockWidget", p, oct_qobj),
47  m_terminal (QTerminal::create (oct_qobj, p))
48  {
49  m_terminal->setObjectName ("OctaveTerminal");
50  m_terminal->setFocusPolicy (Qt::StrongFocus);
51 
52  setWindowIcon (QIcon (":/actions/icons/logo.png"));
53  set_title (tr ("Command Window"));
54 
55  setWidget (m_terminal);
56  setFocusProxy (m_terminal);
57 
58  connect (m_terminal, SIGNAL (interrupt_signal (void)),
59  this, SLOT (terminal_interrupt (void)));
60 
61  // Connect the visibility signal to the terminal for dis-/enabling timers
62  connect (this, SIGNAL (visibilityChanged (bool)),
63  m_terminal, SLOT (handle_visibility_changed (bool)));
64 
65  // Chose a reasonable size at startup in order to avoid truncated
66  // startup messages
69 
70  QFont font = QFont ();
71  font.setStyleHint (QFont::TypeWriter);
72  QString default_font = settings->value (global_mono_font).toString ();
73  font.setFamily
74  (settings->value (cs_font.key, default_font).toString ());
75  font.setPointSize
76  (settings->value (cs_font_size).toInt ());
77 
78  QFontMetrics metrics(font);
79 
80  int win_x = metrics.maxWidth()*80;
81  int win_y = metrics.height()*25;
82 
83  int max_x = QApplication::desktop ()->screenGeometry (this).width ();
84  int max_y = QApplication::desktop ()->screenGeometry (this).height ();
85 
86  if (win_x > max_x)
87  win_x = max_x;
88  if (win_y > max_y)
89  win_y = max_y;
90 
91  setGeometry (0, 0, win_x, win_y);
92  }
93 
95  {
96  delete m_terminal;
97  }
98 
100  {
101  QWidget *w = widget ();
102 
103  return w->hasFocus ();
104  }
105 
107  {
108  // FIXME: Protect with mutex?
109 
112 
113  // Send SIGINT to all other processes in our process group.
114  // This is needed to interrupt calls to system (), for example.
115 
116  int sigint;
117  octave_get_sig_number ("SIGINT", &sigint);
118 
119  octave_kill_wrapper (0, sigint);
120  }
121 }
Base class for Octave interfaces that use Qt.
resource_manager & get_resource_manager(void)
void set_title(const QString &)
virtual void handle_visibility_changed(bool visible)
Slot to steer changing visibility from outside.
gui_settings * get_settings(void) const
terminal_dock_widget(QWidget *parent, base_qobject &oct_qobj)
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)
volatile sig_atomic_t octave_signal_caught
Definition: quit.cc:47
sig_atomic_t octave_interrupt_state
Definition: quit.cc:38
bool octave_get_sig_number(const char *signame, int *signum)
int octave_kill_wrapper(pid_t pid, int signum)
const QString key