1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2013-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 (octave_octave_qscintilla_h)
27 #define octave_octave_qscintilla_h 1
28 
29 #include <QContextMenuEvent>
30 #include <QKeyEvent>
31 #include <QLabel>
32 #include <QMenu>
33 #include <Qsci/qsciscintilla.h>
34 #include <QTemporaryFile>
35 
36 #include "gui-settings.h"
37 #include "qt-interpreter-events.h"
38 
39 namespace octave
40 {
41   class base_qobject;
42 
43   class octave_qscintilla : public QsciScintilla
44   {
45     Q_OBJECT
46 
47   public:
48 
49     octave_qscintilla (QWidget *p, base_qobject& oct_qobj);
50 
51     ~octave_qscintilla (void) = default;
52 
53     enum
54     {
55       ST_NONE = 0,
56       ST_LINE_COMMENT,
57       ST_BLOCK_COMMENT
58     };
59 
60     virtual void contextMenuEvent (QContextMenuEvent *e);
61 
62     void context_help_doc (bool);
63     void context_edit (void);
64     void context_run (void);
65     void get_global_textcursor_pos (QPoint *global_pos, QPoint *local_pos);
66     bool get_actual_word (void);
67     void clear_selection_markers (void);
68     void get_current_position (int *pos, int *line, int *col);
69     QStringList comment_string (bool comment = true);
70     int get_style (int pos = -1);
71     int is_style_comment (int pos = -1);
72     void smart_indent (bool do_smart_indent, int do_auto_close,
73                        int line, int ind_char_width);
74 
75     void smart_indent_line_or_selected_text (int lineFrom, int lineTo);
76 
77     void set_word_selection (const QString& word = QString ());
78 
79     void show_selection_markers (int l1, int c1, int l2, int c2);
80 
81     void set_selection_marker_color (const QColor& c);
82 
83   signals:
84 
85     void execute_command_in_terminal_signal (const QString&);
86     void create_context_menu_signal (QMenu*);
87     void context_menu_edit_signal (const QString&);
88     void qsci_has_focus_signal (bool);
89     void status_update (bool, bool);
90     void show_doc_signal (const QString&);
91     void context_menu_break_condition_signal (int);
92     void context_menu_break_once (int);
93     void ctx_menu_run_finished_signal (bool, int, QTemporaryFile*,
94                                        QTemporaryFile*, bool, bool);
95     void focus_console_after_command_signal (void);
96 
97     void interpreter_event (const fcn_callback& fcn);
98     void interpreter_event (const meth_callback& meth);
99 
100   private slots:
101 
102     void ctx_menu_run_finished (bool, int, QTemporaryFile*, QTemporaryFile*,
103                                 bool, bool);
104 
105     void contextmenu_help (bool);
106     void contextmenu_doc (bool);
107     void contextmenu_help_doc (bool);
108     void contextmenu_edit (bool);
109     void contextmenu_run (bool);
110     void contextmenu_run_temp_error (void);
111 
112     void contextmenu_break_condition (bool);
113     void contextmenu_break_once (const QPoint&);
114 
115     void text_changed (void);
116     void cursor_position_changed (int, int);
117 
118   protected:
119 
120     void focusInEvent (QFocusEvent *focusEvent);
121 
122     void show_replace_action_tooltip (void);
123 
124     void keyPressEvent (QKeyEvent *e);
125 
126     void dragEnterEvent (QDragEnterEvent *e);
127 
128   private:
129 
130     void auto_close (int auto_endif, int l,
131                      const QString& line, QString& first_word);
132 
133     base_qobject& m_octave_qobj;
134 
135     QString m_word_at_cursor;
136 
137     QString m_selection;
138     QString m_selection_replacement;
139     int m_selection_line;
140     int m_selection_col;
141     int m_indicator_id;
142   };
143 }
144 
145 #endif
146