view libgui/src/variable-editor.h @ 28300:0c6dcf803529

Remove support for Qt4 in Octave 7. * configure.ac: Change QT_VERSIONS variable to just "5". * m4/acinclude.m4 (OCTAVE_CHECK_FUNC_QABSTRACTITEMMODEL_BEGINRESETMODEL, OCTAVE_CHECK_FUNC_QCOMBOBOX_SETCURRENTTEXT, OCTAVE_CHECK_FUNC_QHEADERVIEW_SETSECTIONRESIZEMODE, OCTAVE_CHECK_FUNC_QHEADERVIEW_SETSECTIONSCLICKABLE, OCTAVE_CHECK_FUNC_QHEADERVIEW_SETSECTIONSMOVABLE, OCTAVE_CHECK_FUNC_QINSTALLMESSAGEHANDLER, OCTAVE_CHECK_FUNC_QLINEEDIT_SETPLACEHOLDERTEXT, OCTAVE_CHECK_FUNC_QMOUSEEVENT_LOCALPOS, OCTAVE_CHECK_FUNC_QOBJECT_FINDCHILDREN_ACCEPTS_FINDCHILDOPTIONS, OCTAVE_CHECK_FUNC_QTABWIDGET_SETMOVABLE, OCTAVE_CHECK_FUNC_QWHEELEVENT_ANGLEDELTA, OCTAVE_CHECK_FUNC_QTMESSAGEHANDLER_ACCEPTS_QMESSAGELOGCONTEXT, OCTAVE_CHECK_MEMBER_QFONT_FORCE_INTEGER_METRICS, OCTAVE_CHECK_MEMBER_QFONT_MONOSPACE, OCTAVE_HAVE_QGUIAPPLICATION): Remove obsolete macros * m4/acinclude.m4 (HAVE_QT_SCINTILLA): Remove option '4' in case statement for Qt version. * m4/acinclude.m4 (OCTAVE_HAVE_QT): Remove test for Qt4 and AC_DEFINE for HAVE_QT. * m4/acinclude.m4 (OCTAVE_CHECK_QT_VERSION): Remove option '4' in case statement for $qt_version. Remove test for $qt_version = 4 calling pkg_config. Delete calls to macros that were removed. * Canvas.cc (select_object): Remove HAVE_QMOUSEEVENT_LOCALPOS conditionals. * QtHandlesUtils.cc (makeScrollEventStruct): Remove HAVE_QWHEELEVENT_ANGLEDELTA conditional. * Table.cc (updateEnable, updateRearrangeableColumns): Remove HAVE_QT4 conditional. * files-dock-widget.cc (files_dock_widget): Remove HAVE_QHEADERVIEW_SETSECTIONSCLICKABLE conditional. * find-files-dialog.cc (find_files_dialog): Remove HAVE_QHEADERVIEW_SETSECTIONSCLICKABLE conditional. * file-editor.cc (file_editor_tab_widget): Remove HAVE_QTABWIDGET_SETMOVABLE conditional. * find-dialog.cc (init_search_text): Remove HAVE_QCOMBOBOX_SETCURRENTTEXT conditional. * main-window.cc (display_community_news): Remove QOBJECT_FINDCHILDREN_ACCEPTS_FINDCHILDOPTIONS conditional. * octave-qobject.cc (message_handler): Remove QTMESSAGEHANDLER_ACCEPTS_QMESSAGELOGCONTEXT conditional. * octave-qobject.cc (base_qobject): Remove HAVE_QINSTALLMESSAGEHANDLER, HAVE_QT4 conditionals. * resource-manager.cc (get_default_font_family): Remove HAVE_QFONT_MONOSPACE conditional. * shortcut-manager.cc (enter_shortcut::keyPressEvent): Remove HAVE_QGUIAPPLICATION conditional. * shortcut-manager.cc (shortcut_manager::fill_treewidget): Remove HAVE_QHEADERVIEW_SETSECTIONRESIZEMODE conditional. * tab-bar.cc (move_tab_left, move_tab_right, switch_tab): Remove HAVE_QTABWIDGET_SETMOVABLE conditional. * variable-editor.cc (variable_dock_widget, change_floating, change_fullscreen): Remove HAVE_QGUIAPPLICATION conditional. * variable-editor.cc (variable_editor_view, setModel): Remove HAVE_QHEADERVIEW_SETSECTIONRESIZEMODE conditional. * variable-editor.cc (construct_tool_bar): Remove QOBJECT_FINDCHILDREN_ACCEPTS_FINDCHILDOPTIONS conditional. * variable-editor.h (class variable_dock_widget): Remove HAVE_QGUIAPPLICATION conditional. * workspace-view.cc (workspace_view): Remove HAVE_QHEADERVIEW_SETSECTIONSCLICKABLE conditionals.
author Rik <rik@octave.org>
date Sat, 16 May 2020 13:32:24 -0700
parents bd51beb6205e
children 37c5532e558c
line wrap: on
line source

////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2013-2020 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 (octave_variable_editor_h)
#define octave_variable_editor_h 1

#include <QHeaderView>
#include <QStackedWidget>
#include <QTableView>

#include "dw-main-window.h"
#include "gui-settings.h"
#include "octave-dock-widget.h"
#include "tab-bar.h"

class octave_value;

class QModelIndex;
class QTextEdit;
class QToolBar;

namespace octave
{
  class base_qobject;

  class variable_editor_model;
  class variable_editor_view;

  // The individual variable subwindow class

  class variable_dock_widget : public label_dock_widget
  {
    Q_OBJECT

  public:

    variable_dock_widget (QWidget *p, base_qobject& oct_qobj);

  signals:

    void variable_focused_signal (const QString& name);

  protected:

    virtual void closeEvent (QCloseEvent *e);

    void resizeEvent (QResizeEvent *event);

  public slots:

    void handle_focus_change (QWidget *old, QWidget *now);

  private slots:

    void change_floating (bool);

    void change_existence (bool);

    void toplevel_change (bool);

    void change_fullscreen (void);

  protected:

    QFrame *m_frame;

    QAction *m_fullscreen_action;

    bool m_full_screen;

    bool m_prev_floating;

    QRect m_prev_geom;

// See Octave bug #53807 and https://bugreports.qt.io/browse/QTBUG-44813
#define QTBUG_44813_FIX_VERSION 0x999999
  signals:

    void queue_unfloat_float (void);

    void queue_float (void);

  protected slots:

    void unfloat_float (void);

    void refloat (void);

#if (QT_VERSION >= 0x050302) && (QT_VERSION <= QTBUG_44813_FIX_VERSION)
  protected:

    bool event (QEvent *event);

  private:

    bool m_waiting_for_mouse_move;

    bool m_waiting_for_mouse_button_release;
#endif
  };

  class variable_editor_stack : public QStackedWidget
  {
    Q_OBJECT

  public:

    variable_editor_stack (QWidget *p, base_qobject& oct_qobj);

    variable_editor_view *edit_view (void) {return m_edit_view;};

    QTextEdit *disp_view (void) {return m_disp_view;};

  signals:

    void command_signal (const QString& cmd);

    void edit_variable_signal (const QString& name, const octave_value& val);

  public slots:

    void set_editable (bool editable);

    void levelUp (void);

    void save (void);

  private:

    QTextEdit *make_disp_view (QWidget *parent);

    base_qobject& m_octave_qobj;

    variable_editor_view *m_edit_view;

    QTextEdit *m_disp_view;
  };


  class variable_editor_view : public QTableView
  {
    Q_OBJECT

  public:

    variable_editor_view (QWidget *p, base_qobject& oct_qobj);

    void setModel (QAbstractItemModel *model);

  signals:

    void command_signal (const QString& cmd);

    void add_edit_actions_signal (QMenu *menu, const QString& qualifier_string);

  public slots:

    void createVariable (void);

    void transposeContent (void);

    QList<int> range_selected (void);

    void delete_selected (void);

    void clearContent (void);

    void cutClipboard (void);

    void copyClipboard (void);

    void pasteClipboard (void);

    void handle_horizontal_scroll_action (int action);

    void handle_vertical_scroll_action (int action);

    void createContextMenu (const QPoint& pt);

    void createColumnMenu (const QPoint& pt);

    void createRowMenu (const QPoint& pt);

    // Convert selection to an Octave expression.
    QString selected_to_octave (void);

    void selected_command_requested (const QString& cmd);

  private:

    void add_edit_actions (QMenu *menu, const QString& qualifier_string);

    base_qobject& m_octave_qobj;

    variable_editor_model *m_var_model;
  };

  // Gadgets to keep track of and restore what variable window was in focus
  // just prior to selecting something on the menu bar.

  class HoverToolButton : public QToolButton
  {
    Q_OBJECT

  public:

    HoverToolButton (QWidget *parent = nullptr);

  signals:

    void hovered_signal (void);

    void popup_shown_signal (void);

  protected:

    bool eventFilter (QObject *obj, QEvent *ev);
  };

  class ReturnFocusToolButton : public HoverToolButton
  {
    Q_OBJECT

  public:

    ReturnFocusToolButton (QWidget *parent = nullptr);

  signals:

    void about_to_activate (void);

  protected:

    bool eventFilter (QObject *obj, QEvent *ev);
  };

  class ReturnFocusMenu : public QMenu
  {
    Q_OBJECT

  public:

    ReturnFocusMenu (QWidget *parent = nullptr);

  signals:

    void about_to_activate (void);

  protected:

    bool eventFilter (QObject *obj, QEvent *ev);
  };

  // The variable editor class

  class variable_editor : public octave_dock_widget
  {
    Q_OBJECT

  public:

    variable_editor (QWidget *parent, base_qobject& oct_qobj);

    ~variable_editor (void) = default;

    // No copying!

    variable_editor (const variable_editor&) = delete;

    variable_editor& operator = (const variable_editor&) = delete;

    void refresh (void);

    void tab_to_front (void);

  signals:

    void updated (void);

    void finished (void);

    void command_signal (const QString& cmd);

    void refresh_signal (void);

    void clear_content_signal (void);

    void copy_clipboard_signal (void);

    void paste_clipboard_signal (void);

    void level_up_signal (void);

    void save_signal (void);

    void delete_selected_signal (void);

    void selected_command_signal (const QString& cmd);

  public slots:

    void callUpdate (const QModelIndex&, const QModelIndex&);

    void notice_settings (const gui_settings *);

    void edit_variable (const QString& name, const octave_value& val);

    void variable_destroyed (QObject *obj);

    void variable_focused (const QString& name);

    void record_hovered_focus_variable (void);

    void restore_hovered_focus_variable (void);

  protected slots:

    void closeEvent (QCloseEvent *);

    void save (void);

    void cutClipboard (void);

    void copyClipboard (void);

    void pasteClipboard (void);

    void levelUp (void);

    // Send command to Octave interpreter.
    // %1 in CMD is replaced with the value of selected_to_octave.
    void relay_selected_command (const QString& cmd);

  protected:

    void focusInEvent (QFocusEvent *ev);

  private:

    QAction * add_action (QMenu *menu, const QIcon& icon, const QString& text,
                          const char *member);

    dw_main_window *m_main;

    QToolBar *m_tool_bar;

    int m_default_width;

    int m_default_height;

    int m_add_font_height;

    bool m_use_terminal_font;

    bool m_alternate_rows;

    QString m_stylesheet;

    QFont m_font;

    // If use_terminal_font is true then this will be different since
    // "font" will contain the terminal font.
    QFont m_sel_font;

    QList<QColor> m_table_colors;

    void update_colors (void);

    QAction *add_tool_bar_button (const QIcon &icon, const QString &text,
                                  const QObject *receiver, const char *member);

    void construct_tool_bar (void);

    QString m_current_focus_vname;

    QString m_hovered_focus_vname;

    QWidget *m_focus_widget;

    variable_dock_widget *m_focus_widget_vdw;
  };
}

#endif