GNU Octave  6.2.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-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_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 
44 namespace octave
45 {
46  class base_qobject;
47  class interpreter;
48 }
49 
50 namespace QtHandles
51 {
52 
53  class Canvas : public QObject
54  {
55  Q_OBJECT
56 
57  public:
58  enum EventMask
59  {
60  KeyPress = 0x01,
61  KeyRelease = 0x02
62  };
63 
64  public:
65  virtual ~Canvas (void) = default;
66 
67  void redraw (bool sync = false);
68  void blockRedraw (bool block = true);
69 
70  void print (const QString& file_cmd, const QString& term)
71  {
72  do_print (file_cmd, term, m_handle);
73  }
74 
75  void addEventMask (int m) { m_eventMask |= m; }
76  void clearEventMask (int m) { m_eventMask &= (~m); }
77  void setEventMask (int m) { m_eventMask = m; }
78 
79  void setCursor (MouseMode mode, std::string fallback,
80  QImage cdata, Matrix hotspot);
81 
82  virtual QWidget * qWidget (void) = 0;
83 
84  static Canvas *
86  const graphics_handle& handle, QWidget *parent,
87  const std::string& name);
88 
89  virtual uint8NDArray getPixels (void) { return do_getPixels (m_handle); };
90 
91  signals:
92 
95 
96  void gh_callback_event (const graphics_handle& h, const std::string& name);
97 
98  void gh_callback_event (const graphics_handle& h, const std::string& name,
99  const octave_value& data);
100 
101  void gh_set_event (const graphics_handle& h, const std::string& name,
102  const octave_value& value);
103 
104  void gh_set_event (const graphics_handle& h, const std::string& name,
105  const octave_value& value, bool notify_toolkit);
106 
107  void gh_set_event (const graphics_handle& h, const std::string& name,
108  const octave_value& value, bool notify_toolkit,
109  bool redraw_figure);
110  protected:
111  virtual void draw (const graphics_handle& handle) = 0;
112  virtual void drawZoomBox (const QPoint& p1, const QPoint& p2) = 0;
113  virtual void resize (int x, int y, int width, int height) = 0;
115  const QPoint& pt) = 0;
116  virtual uint8NDArray do_getPixels (const graphics_handle& handle) = 0;
117  virtual void do_print (const QString& file_cmd, const QString& term,
118  const graphics_handle& handle) = 0;
119 
120  protected:
122  const graphics_handle& handle)
123  : m_octave_qobj (oct_qobj),
124  m_interpreter (interp),
125  m_handle (handle),
126  m_redrawBlocked (false),
128  m_clickMode (false),
129  m_eventMask (0),
130  m_rectMode (false)
131  { }
132 
133  void canvasToggleAxes (const graphics_handle& handle);
134  void canvasToggleGrid (const graphics_handle& handle);
135  void canvasAutoAxes (const graphics_handle& handle);
136  void canvasPaintEvent (void);
137  void canvasMouseDoubleClickEvent (QMouseEvent *event);
138  void canvasMouseMoveEvent (QMouseEvent *event);
139  void canvasMousePressEvent (QMouseEvent *event);
140  void canvasMouseReleaseEvent (QMouseEvent *event);
141  void canvasWheelEvent (QWheelEvent *event);
142  bool canvasKeyPressEvent (QKeyEvent *event);
143  bool canvasKeyReleaseEvent (QKeyEvent *event);
144 
145  void updateCurrentPoint (const graphics_object& fig,
146  const graphics_object& obj, QMouseEvent *event);
147  void updateCurrentPoint (const graphics_object& fig,
148  const graphics_object& obj);
149 
150  void select_object (graphics_object obj, QMouseEvent *event,
151  graphics_object& currentObj, graphics_object& axesObj,
152  bool axes_only = false,
153  std::vector<std::string> omit = std::vector<std::string> ());
154 
155  protected:
158 
159  private:
160 
161  QCursor make_cursor (const QString& name, int hot_x = -1, int hot_y = -1);
162 
166  bool m_clickMode; // True: ZoomIn, False: ZoomOut
172  };
173 
174 }
175 
176 #endif
Definition: dMatrix.h:42
static Canvas * create(octave::base_qobject &oct_qobj, octave::interpreter &interp, const graphics_handle &handle, QWidget *parent, const std::string &name)
Definition: Canvas.cc:1097
void print(const QString &file_cmd, const QString &term)
Definition: Canvas.h:70
void addEventMask(int m)
Definition: Canvas.h:75
void canvasMousePressEvent(QMouseEvent *event)
Definition: Canvas.cc:583
virtual QWidget * qWidget(void)=0
virtual void draw(const graphics_handle &handle)=0
void setCursor(MouseMode mode, std::string fallback, QImage cdata, Matrix hotspot)
Definition: Canvas.cc:88
bool canvasKeyReleaseEvent(QKeyEvent *event)
Definition: Canvas.cc:1073
void canvasMouseReleaseEvent(QMouseEvent *event)
Definition: Canvas.cc:796
void gh_set_event(const graphics_handle &h, const std::string &name, const octave_value &value, bool notify_toolkit)
bool canvasKeyPressEvent(QKeyEvent *event)
Definition: Canvas.cc:1042
void canvasAutoAxes(const graphics_handle &handle)
void updateCurrentPoint(const graphics_object &fig, const graphics_object &obj, QMouseEvent *event)
Definition: Canvas.cc:181
void clearEventMask(int m)
Definition: Canvas.h:76
QPoint m_mouseCurrent
Definition: Canvas.h:168
bool m_clickMode
Definition: Canvas.h:166
bool m_redrawBlocked
Definition: Canvas.h:164
void canvasToggleGrid(const graphics_handle &handle)
virtual void do_print(const QString &file_cmd, const QString &term, const graphics_handle &handle)=0
void canvasMouseDoubleClickEvent(QMouseEvent *event)
Definition: Canvas.cc:550
void canvasPaintEvent(void)
Definition: Canvas.cc:276
MouseMode m_mouseMode
Definition: Canvas.h:165
void gh_set_event(const graphics_handle &h, const std::string &name, const octave_value &value)
graphics_handle m_mouseAxes
Definition: Canvas.h:169
virtual void drawZoomBox(const QPoint &p1, const QPoint &p2)=0
virtual uint8NDArray getPixels(void)
Definition: Canvas.h:89
Canvas(octave::base_qobject &oct_qobj, octave::interpreter &interp, const graphics_handle &handle)
Definition: Canvas.h:121
void interpreter_event(const octave::meth_callback &meth)
void redraw(bool sync=false)
Definition: Canvas.cc:58
octave::interpreter & m_interpreter
Definition: Canvas.h:157
virtual graphics_object selectFromAxes(const graphics_object &ax, const QPoint &pt)=0
QPoint m_mouseAnchor
Definition: Canvas.h:167
virtual uint8NDArray do_getPixels(const graphics_handle &handle)=0
void gh_callback_event(const graphics_handle &h, const std::string &name)
void setEventMask(int m)
Definition: Canvas.h:77
graphics_handle m_handle
Definition: Canvas.h:163
virtual ~Canvas(void)=default
void canvasMouseMoveEvent(QMouseEvent *event)
Definition: Canvas.cc:448
QCursor make_cursor(const QString &name, int hot_x=-1, int hot_y=-1)
Definition: Canvas.cc:78
void blockRedraw(bool block=true)
Definition: Canvas.cc:72
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:340
void canvasToggleAxes(const graphics_handle &handle)
virtual void resize(int x, int y, int width, int height)=0
void gh_callback_event(const graphics_handle &h, const std::string &name, const octave_value &data)
void canvasWheelEvent(QWheelEvent *event)
Definition: Canvas.cc:906
octave::base_qobject & m_octave_qobj
Definition: Canvas.h:156
void interpreter_event(const octave::fcn_callback &fcn)
void gh_set_event(const graphics_handle &h, const std::string &name, const octave_value &value, bool notify_toolkit, bool redraw_figure)
Base class for Octave interfaces that use Qt.
QString name
F77_RET_T const F77_DBLE * x
T octave_idx_type m
Definition: mx-inlines.cc:773
MouseMode
Definition: Figure.h:50
@ NoMode
Definition: Figure.h:51
std::function< void(octave::interpreter &)> meth_callback
Definition: event-manager.h:47
std::function< void(void)> fcn_callback
Definition: event-manager.h:46