annotate libgui/src/terminal-dock-widget.cc @ 27281:0915fec3d3a9

prevent gui from catching focus when its desktop workspace becomes active * file-editor.cc (focus): renamed into activate and make use of octave_dock_widget::activate; (set_focus): use qt setFocus instead of own old octave_dock_widget::focus; (request_new_file, request_close_file, active_tab_changed, handle_visibility, request_open_file): call new method activate instead of old focus; * file-editor.h: removed method focus and added new method activate * main-window.cc (focus_command_window): activate instead of focus; (editor_tabs_changed, construct_documentation_menu): use activate slot instead of focus; * octave-dock-widget.cc (make_window, make_widget, set_focus_predecessor): use qt setFocus instead of removed focus method; (activate): implementation of renamed method; (handle_visibility): moved implementation from header to here * octave-dock-widget.h: renamed focus into activate, moved implementation from here to cc-file, use setFocus in handle_visibility, moved implementation for handle_visibility from here to cc-file * terminal-dock-widget.cc (focus): removed virtual implementation * terminal-dock-widget.h: removed focus method
author Torsten Lilge <ttl-octave@mailbox.org>
date Mon, 22 Jul 2019 22:20:56 +0200
parents 00f796120a6d
children da1f59fe04b3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15204
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
1 /*
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
2
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 26008
diff changeset
3 Copyright (C) 2013-2019 John W. Eaton
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 26008
diff changeset
4 Copyright (C) 2011-2019 Jacob Dawid
15204
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
5
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
6 This file is part of Octave.
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
7
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24011
diff changeset
8 Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
9 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24011
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
11 (at your option) any later version.
15204
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
12
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
14 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
16 GNU General Public License for more details.
15204
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
17
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
18 You should have received a copy of the GNU General Public License
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
19 along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24011
diff changeset
20 <https://www.gnu.org/licenses/>.
15204
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
21
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
22 */
14692
d6d250812c01 Made the terminal window dockable, too. Now the whole interface is fully dockable.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
23
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
24 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21203
diff changeset
25 # include "config.h"
15286
ae9079bbc627 Add '#include <config.h>' to C++ files in libgui/src
Rik <rik@octave.org>
parents: 15204
diff changeset
26 #endif
ae9079bbc627 Add '#include <config.h>' to C++ files in libgui/src
Rik <rik@octave.org>
parents: 15204
diff changeset
27
24791
9421e891294e fix truncated startup message in terminal widget on windows (bug #53189)
Torsten <mttl@mailbox.org>
parents: 24768
diff changeset
28 #include <QDesktopWidget>
9421e891294e fix truncated startup message in terminal widget on windows (bug #53189)
Torsten <mttl@mailbox.org>
parents: 24768
diff changeset
29
25277
692fbde19871 restore ability to interrupt subprocesses on Unixy systems (bug #53635)
John W. Eaton <jwe@octave.org>
parents: 25275
diff changeset
30 #include "quit.h"
692fbde19871 restore ability to interrupt subprocesses on Unixy systems (bug #53635)
John W. Eaton <jwe@octave.org>
parents: 25275
diff changeset
31 #include "signal-wrappers.h"
692fbde19871 restore ability to interrupt subprocesses on Unixy systems (bug #53635)
John W. Eaton <jwe@octave.org>
parents: 25275
diff changeset
32
692fbde19871 restore ability to interrupt subprocesses on Unixy systems (bug #53635)
John W. Eaton <jwe@octave.org>
parents: 25275
diff changeset
33 #include "sighandlers.h"
692fbde19871 restore ability to interrupt subprocesses on Unixy systems (bug #53635)
John W. Eaton <jwe@octave.org>
parents: 25275
diff changeset
34
16460
4d4e7c6f839d use consistent names for dock-widget files
John W. Eaton <jwe@octave.org>
parents: 16455
diff changeset
35 #include "terminal-dock-widget.h"
24791
9421e891294e fix truncated startup message in terminal widget on windows (bug #53189)
Torsten <mttl@mailbox.org>
parents: 24768
diff changeset
36 #include "resource-manager.h"
26008
38a881b8fbec do not use courier new as default font (bug #54086)
Torsten <mttl@mailbox.org>
parents: 25508
diff changeset
37 #include "gui-preferences.h"
14692
d6d250812c01 Made the terminal window dockable, too. Now the whole interface is fully dockable.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
38
24733
e15d53d2de1e move more GUI classse inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
39 namespace octave
14692
d6d250812c01 Made the terminal window dockable, too. Now the whole interface is fully dockable.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
40 {
24733
e15d53d2de1e move more GUI classse inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
41 terminal_dock_widget::terminal_dock_widget (QWidget *p)
25355
5bb07f6e3707 fix uninitialized settings of octave dock widgets at startup (bug #53835)
Torsten <mttl@mailbox.org>
parents: 25354
diff changeset
42 : octave_dock_widget ("TerminalDockWidget", p),
5bb07f6e3707 fix uninitialized settings of octave dock widgets at startup (bug #53835)
Torsten <mttl@mailbox.org>
parents: 25354
diff changeset
43 m_terminal (QTerminal::create (p))
24733
e15d53d2de1e move more GUI classse inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
44 {
24768
11cc3973381b use "m_" prefix for member variable in terminal dock widget class
John W. Eaton <jwe@octave.org>
parents: 24733
diff changeset
45 m_terminal->setObjectName ("OctaveTerminal");
11cc3973381b use "m_" prefix for member variable in terminal dock widget class
John W. Eaton <jwe@octave.org>
parents: 24733
diff changeset
46 m_terminal->setFocusPolicy (Qt::StrongFocus);
17920
5c3f22dd0bbb raise SIGINT in octave_interpreter instead of in QTerminal
John W. Eaton <jwe@octave.org>
parents: 17790
diff changeset
47
24733
e15d53d2de1e move more GUI classse inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
48 setWindowIcon (QIcon (":/actions/icons/logo.png"));
25508
3edae6ba1fcd use a custom title bar widget for the main dock widgets
Torsten <mttl@mailbox.org>
parents: 25355
diff changeset
49 set_title (tr ("Command Window"));
24733
e15d53d2de1e move more GUI classse inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
50
24768
11cc3973381b use "m_" prefix for member variable in terminal dock widget class
John W. Eaton <jwe@octave.org>
parents: 24733
diff changeset
51 setWidget (m_terminal);
11cc3973381b use "m_" prefix for member variable in terminal dock widget class
John W. Eaton <jwe@octave.org>
parents: 24733
diff changeset
52 setFocusProxy (m_terminal);
23808
2b1b2a795ba6 update clickable urls in terminal also when visible terminal has no focus
Torsten <mttl@mailbox.org>
parents: 23220
diff changeset
53
24768
11cc3973381b use "m_" prefix for member variable in terminal dock widget class
John W. Eaton <jwe@octave.org>
parents: 24733
diff changeset
54 connect (m_terminal, SIGNAL (interrupt_signal (void)),
24733
e15d53d2de1e move more GUI classse inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
55 this, SLOT (terminal_interrupt (void)));
16446
4b3a4bf8569b improve encapsulation of command window object
John W. Eaton <jwe@octave.org>
parents: 16057
diff changeset
56
24733
e15d53d2de1e move more GUI classse inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
57 // Connect the visibility signal to the terminal for dis-/enabling timers
e15d53d2de1e move more GUI classse inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
58 connect (this, SIGNAL (visibilityChanged (bool)),
24768
11cc3973381b use "m_" prefix for member variable in terminal dock widget class
John W. Eaton <jwe@octave.org>
parents: 24733
diff changeset
59 m_terminal, SLOT (handle_visibility_changed (bool)));
24791
9421e891294e fix truncated startup message in terminal widget on windows (bug #53189)
Torsten <mttl@mailbox.org>
parents: 24768
diff changeset
60
9421e891294e fix truncated startup message in terminal widget on windows (bug #53189)
Torsten <mttl@mailbox.org>
parents: 24768
diff changeset
61 // Chose a reasonable size at startup in order to avoid truncated
9421e891294e fix truncated startup message in terminal widget on windows (bug #53189)
Torsten <mttl@mailbox.org>
parents: 24768
diff changeset
62 // startup messages
9421e891294e fix truncated startup message in terminal widget on windows (bug #53189)
Torsten <mttl@mailbox.org>
parents: 24768
diff changeset
63 QSettings *settings = resource_manager::get_settings ();
9421e891294e fix truncated startup message in terminal widget on windows (bug #53189)
Torsten <mttl@mailbox.org>
parents: 24768
diff changeset
64
9421e891294e fix truncated startup message in terminal widget on windows (bug #53189)
Torsten <mttl@mailbox.org>
parents: 24768
diff changeset
65 QFont font = QFont ();
9421e891294e fix truncated startup message in terminal widget on windows (bug #53189)
Torsten <mttl@mailbox.org>
parents: 24768
diff changeset
66 font.setStyleHint (QFont::TypeWriter);
26008
38a881b8fbec do not use courier new as default font (bug #54086)
Torsten <mttl@mailbox.org>
parents: 25508
diff changeset
67 QString default_font = settings->value (global_mono_font.key, global_mono_font.def).toString ();
24791
9421e891294e fix truncated startup message in terminal widget on windows (bug #53189)
Torsten <mttl@mailbox.org>
parents: 24768
diff changeset
68 font.setFamily
26008
38a881b8fbec do not use courier new as default font (bug #54086)
Torsten <mttl@mailbox.org>
parents: 25508
diff changeset
69 (settings->value (cs_font.key, default_font).toString ());
24791
9421e891294e fix truncated startup message in terminal widget on windows (bug #53189)
Torsten <mttl@mailbox.org>
parents: 24768
diff changeset
70 font.setPointSize (settings->value ("terminal/fontSize", 10).toInt ());
9421e891294e fix truncated startup message in terminal widget on windows (bug #53189)
Torsten <mttl@mailbox.org>
parents: 24768
diff changeset
71
9421e891294e fix truncated startup message in terminal widget on windows (bug #53189)
Torsten <mttl@mailbox.org>
parents: 24768
diff changeset
72 QFontMetrics metrics(font);
9421e891294e fix truncated startup message in terminal widget on windows (bug #53189)
Torsten <mttl@mailbox.org>
parents: 24768
diff changeset
73
9421e891294e fix truncated startup message in terminal widget on windows (bug #53189)
Torsten <mttl@mailbox.org>
parents: 24768
diff changeset
74 int win_x = metrics.maxWidth()*80;
9421e891294e fix truncated startup message in terminal widget on windows (bug #53189)
Torsten <mttl@mailbox.org>
parents: 24768
diff changeset
75 int win_y = metrics.height()*25;
9421e891294e fix truncated startup message in terminal widget on windows (bug #53189)
Torsten <mttl@mailbox.org>
parents: 24768
diff changeset
76
9421e891294e fix truncated startup message in terminal widget on windows (bug #53189)
Torsten <mttl@mailbox.org>
parents: 24768
diff changeset
77 int max_x = QApplication::desktop ()->screenGeometry (this).width ();
9421e891294e fix truncated startup message in terminal widget on windows (bug #53189)
Torsten <mttl@mailbox.org>
parents: 24768
diff changeset
78 int max_y = QApplication::desktop ()->screenGeometry (this).height ();
9421e891294e fix truncated startup message in terminal widget on windows (bug #53189)
Torsten <mttl@mailbox.org>
parents: 24768
diff changeset
79
9421e891294e fix truncated startup message in terminal widget on windows (bug #53189)
Torsten <mttl@mailbox.org>
parents: 24768
diff changeset
80 if (win_x > max_x)
9421e891294e fix truncated startup message in terminal widget on windows (bug #53189)
Torsten <mttl@mailbox.org>
parents: 24768
diff changeset
81 win_x = max_x;
9421e891294e fix truncated startup message in terminal widget on windows (bug #53189)
Torsten <mttl@mailbox.org>
parents: 24768
diff changeset
82 if (win_y > max_y)
9421e891294e fix truncated startup message in terminal widget on windows (bug #53189)
Torsten <mttl@mailbox.org>
parents: 24768
diff changeset
83 win_y = max_y;
9421e891294e fix truncated startup message in terminal widget on windows (bug #53189)
Torsten <mttl@mailbox.org>
parents: 24768
diff changeset
84
9421e891294e fix truncated startup message in terminal widget on windows (bug #53189)
Torsten <mttl@mailbox.org>
parents: 24768
diff changeset
85 setGeometry (0, 0, win_x, win_y);
24733
e15d53d2de1e move more GUI classse inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
86 }
24011
9107bae20480 style fixes for some GUI source files
John W. Eaton <jwe@octave.org>
parents: 23808
diff changeset
87
24733
e15d53d2de1e move more GUI classse inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
88 terminal_dock_widget::~terminal_dock_widget (void)
e15d53d2de1e move more GUI classse inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
89 {
24768
11cc3973381b use "m_" prefix for member variable in terminal dock widget class
John W. Eaton <jwe@octave.org>
parents: 24733
diff changeset
90 delete m_terminal;
24733
e15d53d2de1e move more GUI classse inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
91 }
16576
2754c5fd6ae0 keep focus in the command window after dbstop, dbstep, etc.
John W. Eaton <jwe@octave.org>
parents: 16570
diff changeset
92
24733
e15d53d2de1e move more GUI classse inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
93 bool terminal_dock_widget::has_focus (void) const
e15d53d2de1e move more GUI classse inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
94 {
e15d53d2de1e move more GUI classse inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
95 QWidget *w = widget ();
16576
2754c5fd6ae0 keep focus in the command window after dbstop, dbstep, etc.
John W. Eaton <jwe@octave.org>
parents: 16570
diff changeset
96
24733
e15d53d2de1e move more GUI classse inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
97 return w->hasFocus ();
e15d53d2de1e move more GUI classse inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
98 }
16461
094bd3627ead move common functionality to octave_dock_widget base class
John W. Eaton <jwe@octave.org>
parents: 16460
diff changeset
99
24733
e15d53d2de1e move more GUI classse inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
100 void terminal_dock_widget::terminal_interrupt (void)
e15d53d2de1e move more GUI classse inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
101 {
25275
4adeabc1bbfe improve Ctrl-C interrupt handling in the GUI (bug #53635)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
102 // FIXME: Protect with mutex?
4adeabc1bbfe improve Ctrl-C interrupt handling in the GUI (bug #53635)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
103
4adeabc1bbfe improve Ctrl-C interrupt handling in the GUI (bug #53635)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
104 octave_signal_caught = 1;
4adeabc1bbfe improve Ctrl-C interrupt handling in the GUI (bug #53635)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
105 octave_interrupt_state++;
25277
692fbde19871 restore ability to interrupt subprocesses on Unixy systems (bug #53635)
John W. Eaton <jwe@octave.org>
parents: 25275
diff changeset
106
692fbde19871 restore ability to interrupt subprocesses on Unixy systems (bug #53635)
John W. Eaton <jwe@octave.org>
parents: 25275
diff changeset
107 // Send SIGINT to all other processes in our process group.
692fbde19871 restore ability to interrupt subprocesses on Unixy systems (bug #53635)
John W. Eaton <jwe@octave.org>
parents: 25275
diff changeset
108 // This is needed to interrupt calls to system (), for example.
692fbde19871 restore ability to interrupt subprocesses on Unixy systems (bug #53635)
John W. Eaton <jwe@octave.org>
parents: 25275
diff changeset
109
692fbde19871 restore ability to interrupt subprocesses on Unixy systems (bug #53635)
John W. Eaton <jwe@octave.org>
parents: 25275
diff changeset
110 int sigint;
692fbde19871 restore ability to interrupt subprocesses on Unixy systems (bug #53635)
John W. Eaton <jwe@octave.org>
parents: 25275
diff changeset
111 octave_get_sig_number ("SIGINT", &sigint);
692fbde19871 restore ability to interrupt subprocesses on Unixy systems (bug #53635)
John W. Eaton <jwe@octave.org>
parents: 25275
diff changeset
112
692fbde19871 restore ability to interrupt subprocesses on Unixy systems (bug #53635)
John W. Eaton <jwe@octave.org>
parents: 25275
diff changeset
113 octave_kill_wrapper (0, sigint);
24733
e15d53d2de1e move more GUI classse inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
114 }
16461
094bd3627ead move common functionality to octave_dock_widget base class
John W. Eaton <jwe@octave.org>
parents: 16460
diff changeset
115 }