GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Canvas.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2011-2023 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_Canvas_h)
27 #define octave_Canvas_h 1
28 
29 #include <QObject>
30 #include <QPoint>
31 
32 #include "event-manager.h"
33 #include "graphics.h"
34 
35 #include "Figure.h"
36 
37 class QKeyEvent;
38 class QMouseEvent;
39 class QWheelEvent;
40 class QWidget;
41 
42 class octave_value_list;
43 
45 
46 class base_qobject;
47 class interpreter;
48 
49 class Canvas : public QObject
50 {
51  Q_OBJECT
52 
53 public:
54  enum EventMask
55  {
56  KeyPress = 0x01,
57  KeyRelease = 0x02
58  };
59 
60 public:
61  virtual ~Canvas (void) = default;
62 
63  void redraw (bool sync = false);
64  void blockRedraw (bool block = true);
65 
66  void print (const QString& file_cmd, const QString& term)
67  {
68  do_print (file_cmd, term, m_handle);
69  }
70 
71  void addEventMask (int m) { m_eventMask |= m; }
72  void clearEventMask (int m) { m_eventMask &= (~m); }
73  void setEventMask (int m) { m_eventMask = m; }
74 
75  void setCursor (MouseMode mode, std::string fallback,
76  QImage cdata, Matrix hotspot);
77 
78  virtual QWidget * qWidget (void) = 0;
79 
80  static Canvas *
81  create (octave::base_qobject& oct_qobj, octave::interpreter& interp,
82  const graphics_handle& handle, QWidget *parent,
83  const std::string& name);
84 
85  virtual uint8NDArray getPixels (void) { return do_getPixels (m_handle); };
86 
87 signals:
88 
91 
92  void gh_callback_event (const graphics_handle& h, const std::string& name);
93 
94  void gh_callback_event (const graphics_handle& h, const std::string& name,
95  const octave_value& data);
96 
97  void gh_set_event (const graphics_handle& h, const std::string& name,
98  const octave_value& value);
99 
100  void gh_set_event (const graphics_handle& h, const std::string& name,
101  const octave_value& value, bool notify_toolkit);
102 
103  void gh_set_event (const graphics_handle& h, const std::string& name,
104  const octave_value& value, bool notify_toolkit,
105  bool redraw_figure);
106 protected:
107  virtual void draw (const graphics_handle& handle) = 0;
108  virtual void drawZoomBox (const QPoint& p1, const QPoint& p2) = 0;
109  virtual void resize (int x, int y, int width, int height) = 0;
110  virtual graphics_object selectFromAxes (const graphics_object& ax,
111  const QPoint& pt) = 0;
112  virtual uint8NDArray do_getPixels (const graphics_handle& handle) = 0;
113  virtual void do_print (const QString& file_cmd, const QString& term,
114  const graphics_handle& handle) = 0;
115 
116 protected:
117  Canvas (octave::base_qobject& oct_qobj, octave::interpreter& interp,
118  const graphics_handle& handle)
119  : m_octave_qobj (oct_qobj),
120  m_interpreter (interp),
121  m_handle (handle),
122  m_redrawBlocked (false),
124  m_clickMode (false),
125  m_eventMask (0),
126  m_rectMode (false)
127  { }
128 
129  void canvasToggleAxes (const graphics_handle& handle);
130  void canvasToggleGrid (const graphics_handle& handle);
131  void canvasAutoAxes (const graphics_handle& handle);
132  void canvasPaintEvent (void);
133  void canvasMouseDoubleClickEvent (QMouseEvent *event);
134  void canvasMouseMoveEvent (QMouseEvent *event);
135  void canvasMousePressEvent (QMouseEvent *event);
136  void canvasMouseReleaseEvent (QMouseEvent *event);
137  void canvasWheelEvent (QWheelEvent *event);
138  bool canvasKeyPressEvent (QKeyEvent *event);
139  bool canvasKeyReleaseEvent (QKeyEvent *event);
140 
141  void updateCurrentPoint (const graphics_object& fig,
142  const graphics_object& obj, QMouseEvent *event);
143  void updateCurrentPoint (const graphics_object& fig,
144  const graphics_object& obj);
145 
146  void select_object (graphics_object obj, QMouseEvent *event,
147  graphics_object& currentObj, graphics_object& axesObj,
148  bool axes_only = false,
149  std::vector<std::string> omit = std::vector<std::string> ());
150 
151 protected:
152  octave::base_qobject& m_octave_qobj;
153  octave::interpreter& m_interpreter;
154 
155 private:
156 
157  QCursor make_cursor (const QString& name, int hot_x = -1, int hot_y = -1);
158 
162  bool m_clickMode; // True: ZoomIn, False: ZoomOut
168 };
169 
171 
172 #endif
OCTAVE_END_NAMESPACE(octave)
MouseMode
Definition: Figure.h:46
@ NoMode
Definition: Figure.h:47
Definition: Canvas.h:50
void addEventMask(int m)
Definition: Canvas.h:71
void print(const QString &file_cmd, const QString &term)
Definition: Canvas.h:66
QPoint m_mouseAnchor
Definition: Canvas.h:163
void select_object(graphics_object obj, QMouseEvent *event, graphics_object &currentObj, graphics_object &axesObj, bool axes_only=false, std::vector< std::string > omit=std::vector< std::string >())
Definition: Canvas.cc:339
static Canvas * create(octave::base_qobject &oct_qobj, octave::interpreter &interp, const graphics_handle &handle, QWidget *parent, const std::string &name)
Definition: Canvas.cc:1088
QCursor make_cursor(const QString &name, int hot_x=-1, int hot_y=-1)
Definition: Canvas.cc:77
Canvas(octave::base_qobject &oct_qobj, octave::interpreter &interp, const graphics_handle &handle)
Definition: Canvas.h:117
virtual uint8NDArray do_getPixels(const graphics_handle &handle)=0
void gh_set_event(const graphics_handle &h, const std::string &name, const octave_value &value, bool notify_toolkit)
void gh_set_event(const graphics_handle &h, const std::string &name, const octave_value &value, bool notify_toolkit, bool redraw_figure)
bool m_redrawBlocked
Definition: Canvas.h:160
virtual ~Canvas(void)=default
bool m_rectMode
Definition: Canvas.h:167
int m_eventMask
Definition: Canvas.h:166
void canvasToggleGrid(const graphics_handle &handle)
void setEventMask(int m)
Definition: Canvas.h:73
void canvasAutoAxes(const graphics_handle &handle)
octave::base_qobject & m_octave_qobj
Definition: Canvas.h:152
void canvasMouseReleaseEvent(QMouseEvent *event)
Definition: Canvas.cc:787
void clearEventMask(int m)
Definition: Canvas.h:72
octave::interpreter & m_interpreter
Definition: Canvas.h:153
virtual uint8NDArray getPixels(void)
Definition: Canvas.h:85
void interpreter_event(const octave::meth_callback &meth)
graphics_handle m_handle
Definition: Canvas.h:159
void canvasPaintEvent(void)
Definition: Canvas.cc:275
void canvasMouseDoubleClickEvent(QMouseEvent *event)
Definition: Canvas.cc:541
bool canvasKeyReleaseEvent(QKeyEvent *event)
Definition: Canvas.cc:1064
virtual void draw(const graphics_handle &handle)=0
virtual void resize(int x, int y, int width, int height)=0
virtual void do_print(const QString &file_cmd, const QString &term, const graphics_handle &handle)=0
bool m_clickMode
Definition: Canvas.h:162
void redraw(bool sync=false)
Definition: Canvas.cc:57
void blockRedraw(bool block=true)
Definition: Canvas.cc:71
void gh_callback_event(const graphics_handle &h, const std::string &name, const octave_value &data)
void interpreter_event(const octave::fcn_callback &fcn)
virtual void drawZoomBox(const QPoint &p1, const QPoint &p2)=0
void canvasWheelEvent(QWheelEvent *event)
Definition: Canvas.cc:897
QPoint m_mouseCurrent
Definition: Canvas.h:164
void setCursor(MouseMode mode, std::string fallback, QImage cdata, Matrix hotspot)
Definition: Canvas.cc:87
EventMask
Definition: Canvas.h:55
@ KeyRelease
Definition: Canvas.h:57
@ KeyPress
Definition: Canvas.h:56
graphics_handle m_mouseAxes
Definition: Canvas.h:165
void canvasToggleAxes(const graphics_handle &handle)
void gh_set_event(const graphics_handle &h, const std::string &name, const octave_value &value)
MouseMode m_mouseMode
Definition: Canvas.h:161
void gh_callback_event(const graphics_handle &h, const std::string &name)
virtual graphics_object selectFromAxes(const graphics_object &ax, const QPoint &pt)=0
void updateCurrentPoint(const graphics_object &fig, const graphics_object &obj, QMouseEvent *event)
Definition: Canvas.cc:180
virtual QWidget * qWidget(void)=0
void canvasMousePressEvent(QMouseEvent *event)
Definition: Canvas.cc:574
void canvasMouseMoveEvent(QMouseEvent *event)
Definition: Canvas.cc:439
bool canvasKeyPressEvent(QKeyEvent *event)
Definition: Canvas.cc:1033
Definition: dMatrix.h:42
Base class for Octave interfaces that use Qt.
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
std::function< void(void)> fcn_callback
Definition: event-manager.h:43
std::function< void(interpreter &)> meth_callback
Definition: event-manager.h:48
F77_RET_T const F77_DBLE * x
T octave_idx_type m
Definition: mx-inlines.cc:773