GNU Octave  4.4.1
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) 2013-2018 John W. Eaton
4 Copyright (C) 2011-2018 Jacob Dawid
5 
6 This file is part of Octave.
7 
8 Octave is free software: you can redistribute it and/or modify it
9 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 Octave is distributed in the hope that it will be useful, but
14 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 Octave; see the file COPYING. If not, see
20 <https://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if defined (HAVE_CONFIG_H)
25 # include "config.h"
26 #endif
27 
28 #include <QDesktopWidget>
29 
30 #include "quit.h"
31 #include "signal-wrappers.h"
32 
33 #include "sighandlers.h"
34 
35 #include "terminal-dock-widget.h"
36 #include "resource-manager.h"
37 
38 namespace octave
39 {
41  : octave_dock_widget (p), m_terminal (QTerminal::create (p))
42  {
43  m_terminal->setObjectName ("OctaveTerminal");
44  m_terminal->setFocusPolicy (Qt::StrongFocus);
45 
46  setObjectName ("TerminalDockWidget");
47  setWindowIcon (QIcon (":/actions/icons/logo.png"));
48  set_title (tr ("Command Window"));
49 
50  setWidget (m_terminal);
51  setFocusProxy (m_terminal);
52 
53  connect (m_terminal, SIGNAL (interrupt_signal (void)),
54  this, SLOT (terminal_interrupt (void)));
55 
56  // Connect the visibility signal to the terminal for dis-/enabling timers
57  connect (this, SIGNAL (visibilityChanged (bool)),
58  m_terminal, SLOT (handle_visibility_changed (bool)));
59 
60  // Chose a reasonable size at startup in order to avoid truncated
61  // startup messages
62  QSettings *settings = resource_manager::get_settings ();
63 
64  QFont font = QFont ();
65  font.setStyleHint (QFont::TypeWriter);
66  font.setFamily
67  (settings->value ("terminal/fontName", "Courier New").toString ());
68  font.setPointSize (settings->value ("terminal/fontSize", 10).toInt ());
69 
70  QFontMetrics metrics(font);
71 
72  int win_x = metrics.maxWidth()*80;
73  int win_y = metrics.height()*25;
74 
75  int max_x = QApplication::desktop ()->screenGeometry (this).width ();
76  int max_y = QApplication::desktop ()->screenGeometry (this).height ();
77 
78  if (win_x > max_x)
79  win_x = max_x;
80  if (win_y > max_y)
81  win_y = max_y;
82 
83  setGeometry (0, 0, win_x, win_y);
84  }
85 
87  {
88  delete m_terminal;
89  }
90 
92  {
93  QWidget *w = widget ();
94 
95  return w->hasFocus ();
96  }
97 
99  {
101 
102  QWidget *w = widget ();
103 
104  w->setFocus ();
105  w->activateWindow ();
106  w->raise ();
107  }
108 
110  {
111  // FIXME: Protect with mutex?
112 
115 
116  // Send SIGINT to all other processes in our process group.
117  // This is needed to interrupt calls to system (), for example.
118 
119  int sigint;
120  octave_get_sig_number ("SIGINT", &sigint);
121 
122  octave_kill_wrapper (0, sigint);
123  }
124 }
volatile sig_atomic_t octave_signal_caught
Definition: cquit.c:49
int octave_kill_wrapper(pid_t pid, int signum)
virtual void handle_visibility_changed(bool visible)
Slot to steer changing visibility from outside.
std::complex< double > w(std::complex< double > z, double relerr=0)
sig_atomic_t octave_interrupt_state
Definition: cquit.c:32
void set_title(const QString &)
terminal_dock_widget(QWidget *parent=nullptr)
p
Definition: lu.cc:138
static QSettings * get_settings(void)
bool octave_get_sig_number(const char *signame, int *signum)