GNU Octave 7.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-2022 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
37class QKeyEvent;
38class QMouseEvent;
39class QWheelEvent;
40class QWidget;
41
43
44namespace octave
45{
46 class base_qobject;
47 class interpreter;
48}
49
50namespace octave
51{
52
53 class Canvas : public QObject
54 {
55 Q_OBJECT
56
57 public:
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 *
85 create (octave::base_qobject& oct_qobj, octave::interpreter& interp,
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;
114 virtual graphics_object selectFromAxes (const graphics_object& ax,
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:
121 Canvas (octave::base_qobject& oct_qobj, octave::interpreter& interp,
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:
157 octave::interpreter& m_interpreter;
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
bool canvasKeyPressEvent(QKeyEvent *event)
Definition: Canvas.cc:1034
virtual void do_print(const QString &file_cmd, const QString &term, const graphics_handle &handle)=0
void canvasMouseReleaseEvent(QMouseEvent *event)
Definition: Canvas.cc:788
void gh_set_event(const graphics_handle &h, const std::string &name, const octave_value &value, bool notify_toolkit, bool redraw_figure)
bool canvasKeyReleaseEvent(QKeyEvent *event)
Definition: Canvas.cc:1065
void gh_callback_event(const graphics_handle &h, const std::string &name)
void canvasPaintEvent(void)
Definition: Canvas.cc:276
void updateCurrentPoint(const graphics_object &fig, const graphics_object &obj, QMouseEvent *event)
Definition: Canvas.cc:181
void canvasToggleAxes(const graphics_handle &handle)
static Canvas * create(octave::base_qobject &oct_qobj, octave::interpreter &interp, const graphics_handle &handle, QWidget *parent, const std::string &name)
Definition: Canvas.cc:1089
bool m_rectMode
Definition: Canvas.h:171
void blockRedraw(bool block=true)
Definition: Canvas.cc:72
virtual uint8NDArray getPixels(void)
Definition: Canvas.h:89
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 ~Canvas(void)=default
virtual graphics_object selectFromAxes(const graphics_object &ax, const QPoint &pt)=0
void canvasToggleGrid(const graphics_handle &handle)
void print(const QString &file_cmd, const QString &term)
Definition: Canvas.h:70
void canvasMouseMoveEvent(QMouseEvent *event)
Definition: Canvas.cc:440
void canvasAutoAxes(const graphics_handle &handle)
void canvasMousePressEvent(QMouseEvent *event)
Definition: Canvas.cc:575
graphics_handle m_handle
Definition: Canvas.h:163
virtual uint8NDArray do_getPixels(const graphics_handle &handle)=0
QPoint m_mouseAnchor
Definition: Canvas.h:167
void addEventMask(int m)
Definition: Canvas.h:75
void gh_set_event(const graphics_handle &h, const std::string &name, const octave_value &value, bool notify_toolkit)
octave::interpreter & m_interpreter
Definition: Canvas.h:157
QPoint m_mouseCurrent
Definition: Canvas.h:168
octave::base_qobject & m_octave_qobj
Definition: Canvas.h:156
void setEventMask(int m)
Definition: Canvas.h:77
void setCursor(MouseMode mode, std::string fallback, QImage cdata, Matrix hotspot)
Definition: Canvas.cc:88
void redraw(bool sync=false)
Definition: Canvas.cc:58
QCursor make_cursor(const QString &name, int hot_x=-1, int hot_y=-1)
Definition: Canvas.cc:78
MouseMode m_mouseMode
Definition: Canvas.h:165
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 clearEventMask(int m)
Definition: Canvas.h:76
virtual void drawZoomBox(const QPoint &p1, const QPoint &p2)=0
Canvas(octave::base_qobject &oct_qobj, octave::interpreter &interp, const graphics_handle &handle)
Definition: Canvas.h:121
virtual void draw(const graphics_handle &handle)=0
int m_eventMask
Definition: Canvas.h:170
void interpreter_event(const octave::meth_callback &meth)
void gh_callback_event(const graphics_handle &h, const std::string &name, const octave_value &data)
virtual void resize(int x, int y, int width, int height)=0
void interpreter_event(const octave::fcn_callback &fcn)
void canvasMouseDoubleClickEvent(QMouseEvent *event)
Definition: Canvas.cc:542
bool m_redrawBlocked
Definition: Canvas.h:164
virtual QWidget * qWidget(void)=0
bool m_clickMode
Definition: Canvas.h:166
void canvasWheelEvent(QWheelEvent *event)
Definition: Canvas.cc:898
Base class for Octave interfaces that use Qt.
OCTAVE_NAMESPACE_BEGIN typedef std::function< void(void)> fcn_callback
Definition: event-manager.h:47
std::function< void(interpreter &)> meth_callback
Definition: event-manager.h:48
QString name
F77_RET_T const F77_DBLE * x
MouseMode
Definition: Figure.h:50
@ NoMode
Definition: Figure.h:51