Mercurial > octave
view libgui/src/terminal-dock-widget.cc @ 31808:90621682cc03
maint: Remove unnecessary indent after OCTAVE_BEGIN_NAMESPACE in libgui/
* BaseControl.cc, BaseControl.h, ButtonControl.cc, ButtonControl.h,
ButtonGroup.cc, ButtonGroup.h, Canvas.cc, Canvas.h, CheckBoxControl.cc,
CheckBoxControl.h, Container.cc, Container.h, ContextMenu.cc, ContextMenu.h,
EditControl.cc, EditControl.h, Figure.cc, Figure.h, GLCanvas.cc, GLCanvas.h,
ListBoxControl.cc, ListBoxControl.h, Menu.cc, Menu.h, Object.cc, Object.h,
Panel.cc, Panel.h, PopupMenuControl.cc, PopupMenuControl.h,
PushButtonControl.cc, PushButtonControl.h, PushTool.cc, PushTool.h,
RadioButtonControl.cc, RadioButtonControl.h, SliderControl.cc, SliderControl.h,
Table.cc, Table.h, TextControl.cc, TextControl.h, ToggleButtonControl.cc,
ToggleButtonControl.h, ToggleTool.cc, ToggleTool.h, ToolBar.cc, ToolBar.h,
ToolBarButton.cc, ToolBarButton.h, qt-graphics-toolkit.cc,
qt-graphics-toolkit.h, command-widget.cc, command-widget.h, community-news.cc,
community-news.h, dialog.cc, dialog.h, documentation-bookmarks.cc,
documentation-bookmarks.h, documentation-dock-widget.cc,
documentation-dock-widget.h, documentation.cc, documentation.h,
dw-main-window.cc, dw-main-window.h, external-editor-interface.cc,
external-editor-interface.h, files-dock-widget.cc, files-dock-widget.h,
find-files-dialog.cc, find-files-dialog.h, graphics-init.cc, graphics-init.h,
gui-settings.cc, gui-settings.h, history-dock-widget.cc, history-dock-widget.h,
interpreter-qobject.cc, file-editor-interface.h, file-editor-tab.cc,
file-editor-tab.h, file-editor.cc, file-editor.h, find-dialog.cc,
find-dialog.h, octave-qscintilla.cc, main-window.cc, main-window.h,
news-reader.cc, news-reader.h, octave-dock-widget.cc, octave-dock-widget.h,
octave-qobject.cc, qt-application.cc, qt-application.h,
qt-interpreter-events.cc, qt-interpreter-events.h, release-notes.cc,
release-notes.h, set-path-dialog.cc, set-path-dialog.h, settings-dialog.cc,
settings-dialog.h, terminal-dock-widget.cc, terminal-dock-widget.h,
variable-editor.cc, variable-editor.h, welcome-wizard.cc, welcome-wizard.h,
workspace-model.cc, workspace-model.h, workspace-view.cc, workspace-view.h:
maint: Remove unnecessary indent after OCTAVE_BEGIN_NAMESPACE in libgui/
author | Rik <rik@octave.org> |
---|---|
date | Thu, 02 Feb 2023 12:25:51 -0800 |
parents | 21f9b34eb893 |
children | 49d21a7b25a8 |
line wrap: on
line source
//////////////////////////////////////////////////////////////////////// // // Copyright (C) 2011-2023 The Octave Project Developers // // See the file COPYRIGHT.md in the top-level directory of this // distribution or <https://octave.org/copyright/>. // // This file is part of Octave. // // Octave is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Octave is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Octave; see the file COPYING. If not, see // <https://www.gnu.org/licenses/>. // //////////////////////////////////////////////////////////////////////// #if defined (HAVE_CONFIG_H) # include "config.h" #endif #include <QGuiApplication> #include <QScreen> // This header is only needed for the new terminal widget. #if defined (HAVE_QSCINTILLA) # include "command-widget.h" #endif // This header is only needed for the old terminal widget. #include "QTerminal.h" #include "gui-preferences-cs.h" #include "gui-preferences-global.h" #include "gui-preferences-sc.h" #include "gui-settings.h" #include "terminal-dock-widget.h" OCTAVE_BEGIN_NAMESPACE(octave) terminal_dock_widget::terminal_dock_widget (QWidget *p, bool experimental_terminal_widget) : octave_dock_widget ("TerminalDockWidget", p), m_experimental_terminal_widget (experimental_terminal_widget) { init_control_d_shortcut_behavior (); // FIXME: we could do this in a better way, but improving it doesn't // matter much if we will eventually be removing the old terminal. if (m_experimental_terminal_widget) { #if defined (HAVE_QSCINTILLA) command_widget *widget = new command_widget (this); console *con = widget->get_console (); connect (this, &terminal_dock_widget::settings_changed, widget, &command_widget::notice_settings); connect (this, &terminal_dock_widget::update_prompt_signal, widget, &command_widget::update_prompt); connect (this, &terminal_dock_widget::interpreter_output_signal, widget, &command_widget::insert_interpreter_output); connect (this, &terminal_dock_widget::execute_command_signal, con, &console::execute_command); connect (this, &terminal_dock_widget::new_command_line_signal, con, &console::new_command_line); m_terminal = widget; #endif } else { QTerminal *widget = QTerminal::create (this); connect (this, &terminal_dock_widget::settings_changed, widget, &QTerminal::notice_settings); // Connect the visibility signal to the terminal for // dis-/enabling timers. connect (this, &terminal_dock_widget::visibilityChanged, widget, &QTerminal::handle_visibility_changed); connect (widget, QOverload<const fcn_callback&>::of (&QTerminal::interpreter_event), this, QOverload<const fcn_callback&>::of (&terminal_dock_widget::interpreter_event)); connect (widget, QOverload<const meth_callback&>::of (&QTerminal::interpreter_event), this, QOverload<const meth_callback&>::of (&terminal_dock_widget::interpreter_event)); m_terminal = widget; } m_terminal->setObjectName ("OctaveTerminal"); m_terminal->setFocusPolicy (Qt::StrongFocus); set_title (tr ("Command Window")); setWidget (m_terminal); setFocusProxy (m_terminal); // Chose a reasonable size at startup in order to avoid truncated // startup messages gui_settings settings; QFont font = QFont (); font.setStyleHint (QFont::TypeWriter); QString default_font = settings.string_value (global_mono_font); font.setFamily (settings.value (cs_font.settings_key (), default_font).toString ()); font.setPointSize (settings.int_value (cs_font_size)); QFontMetrics metrics(font); int win_x = metrics.maxWidth()*80; int win_y = metrics.height()*25; int max_x = QGuiApplication::primaryScreen ()->availableGeometry ().width (); int max_y = QGuiApplication::primaryScreen ()->availableGeometry ().height (); if (win_x > max_x) win_x = max_x; if (win_y > max_y) win_y = max_y; setGeometry (0, 0, win_x, win_y); if (! p) make_window (); } bool terminal_dock_widget::has_focus () const { QWidget *w = widget (); return w->hasFocus (); } QTerminal * terminal_dock_widget::get_qterminal () { return (m_experimental_terminal_widget ? nullptr : dynamic_cast<QTerminal *> (m_terminal)); } #if defined (HAVE_QSCINTILLA) command_widget * terminal_dock_widget::get_command_widget () { return (m_experimental_terminal_widget ? dynamic_cast<command_widget *> (m_terminal) : nullptr); } #endif void terminal_dock_widget::notice_settings () { emit settings_changed (); } void terminal_dock_widget::init_command_prompt () { if (m_experimental_terminal_widget) { #if defined (HAVE_QSCINTILLA) command_widget *cmd = get_command_widget (); if (cmd) cmd->init_command_prompt (); #endif } } void terminal_dock_widget::init_control_d_shortcut_behavior () { gui_settings settings; // Reset use of Ctrl-D. Do this before the call to beginGroup // because sc_main_ctrld.key already begins with the sc_group // prefix. settings.setValue (sc_main_ctrld.settings_key (), false); settings.beginGroup (sc_group); const QStringList shortcut_settings_keys = settings.allKeys (); settings.endGroup (); for (const auto& settings_key : shortcut_settings_keys) { // Check whether Ctrl+D is used from main window, i.e. is a // global shortcut. QString section = get_shortcut_section (settings_key); if (section.startsWith ("main_")) { sc_pref scpref = all_shortcut_preferences::value (settings_key); QKeySequence actual = QKeySequence (settings.sc_value (scpref)); if (actual == QKeySequence (Qt::ControlModifier+Qt::Key_D)) { settings.setValue (sc_main_ctrld.settings_key (), true); break; } } } } OCTAVE_END_NAMESPACE(octave)