GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Container.cc
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 (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include <QChildEvent>
31#include <QVBoxLayout>
32
33#include "Canvas.h"
34#include "Container.h"
35#include "Object.h"
36#include "QtHandlesUtils.h"
37
38#include "graphics.h"
39#include "interpreter.h"
40
41namespace octave
42{
43
45 octave::interpreter& interp)
46 : ContainerBase (xparent), m_octave_qobj (oct_qobj),
47 m_interpreter (interp), m_canvas (nullptr)
48 {
49 setFocusPolicy (Qt::ClickFocus);
50 }
51
53 { }
54
55 Canvas *
56 Container::canvas (const graphics_handle& gh, bool xcreate)
57 {
58 if (! m_canvas && xcreate)
59 {
60 gh_manager& gh_mgr = m_interpreter.get_gh_manager ();
61
62 octave::autolock guard (gh_mgr.graphics_lock ());
63
64 graphics_object go = gh_mgr.get_object (gh);
65
66 if (go)
67 {
68 graphics_object fig = go.get_ancestor ("figure");
69
71 fig.get ("renderer").string_value ());
72
75
78
79 connect (m_canvas,
80 SIGNAL (gh_callback_event (const graphics_handle&,
81 const std::string&)),
82 this,
83 SIGNAL (gh_callback_event (const graphics_handle&,
84 const std::string&)));
85
86 connect (m_canvas,
87 SIGNAL (gh_callback_event (const graphics_handle&,
88 const std::string&,
89 const octave_value&)),
90 this,
91 SIGNAL (gh_callback_event (const graphics_handle&,
92 const std::string&,
93 const octave_value&)));
94
95 connect (m_canvas,
96 SIGNAL (gh_set_event (const graphics_handle&,
97 const std::string&,
98 const octave_value&)),
99 this,
100 SIGNAL (gh_set_event (const graphics_handle&,
101 const std::string&,
102 const octave_value&)));
103
104 connect (m_canvas,
105 SIGNAL (gh_set_event (const graphics_handle&,
106 const std::string&,
107 const octave_value&, bool)),
108 this,
109 SIGNAL (gh_set_event (const graphics_handle&,
110 const std::string&,
111 const octave_value&, bool)));
112
113 connect (m_canvas,
114 SIGNAL (gh_set_event (const graphics_handle&,
115 const std::string&,
116 const octave_value&, bool, bool)),
117 this,
118 SIGNAL (gh_set_event (const graphics_handle&,
119 const std::string&,
120 const octave_value&, bool, bool)));
121
122 QWidget *canvasWidget = m_canvas->qWidget ();
123
124 canvasWidget->lower ();
125 canvasWidget->show ();
126 canvasWidget->setGeometry (0, 0, width (), height ());
127 }
128 }
129
130 return m_canvas;
131 }
132
133 void
134 Container::resizeEvent (QResizeEvent * /* event */)
135 {
136 if (m_canvas)
137 m_canvas->qWidget ()->setGeometry (0, 0, width (), height ());
138
139 gh_manager& gh_mgr = m_interpreter.get_gh_manager ();
140
141 octave::autolock guard (gh_mgr.graphics_lock ());
142
143 for (auto *qObj : children ())
144 {
145 if (qObj->isWidgetType ())
146 {
147 Object *obj = Object::fromQObject (qObj);
148
149 if (obj)
150 {
151 graphics_object go = obj->object ();
152
153 if (go.valid_object ())
154 {
155 Matrix bb = go.get_properties ().get_boundingbox (false);
156
157 obj->qWidget<QWidget> ()->setGeometry
158 (octave::math::round (bb(0)),
159 octave::math::round (bb(1)),
160 octave::math::round (bb(2)),
161 octave::math::round (bb(3)));
162 }
163 }
164 }
165 }
166 }
167
168 void
169 Container::childEvent (QChildEvent *xevent)
170 {
171 // Enable mouse tracking in child widgets as they are added if the
172 // container also has mouse tracking enabled. There is no need to
173 // do this when child objects are removed.
174
175 if (xevent->added ())
176 {
177 QObject *obj = xevent->child ();
178
179 if (obj && obj->isWidgetType ())
180 {
181 QWidget *widget = qobject_cast<QWidget *> (obj);
182
183 if (widget)
184 widget->setMouseTracking (hasMouseTracking ());
185 }
186 }
187 }
188}
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:1089
void interpreter_event(const octave::fcn_callback &fcn)
virtual QWidget * qWidget(void)=0
void childEvent(QChildEvent *event)
Definition: Container.cc:169
octave::base_qobject & m_octave_qobj
Definition: Container.h:84
void interpreter_event(const octave::fcn_callback &fcn)
Canvas * m_canvas
Definition: Container.h:86
void gh_callback_event(const graphics_handle &h, const std::string &name)
Container(QWidget *parent, octave::base_qobject &oct_qobj, octave::interpreter &interp)
Definition: Container.cc:44
void resizeEvent(QResizeEvent *event)
Definition: Container.cc:134
octave::interpreter & m_interpreter
Definition: Container.h:85
void gh_set_event(const graphics_handle &h, const std::string &name, const octave_value &value)
Canvas * canvas(const graphics_handle &handle, bool create=true)
Definition: Container.cc:56
T * qWidget(void)
Definition: Object.h:85
static Object * fromQObject(QObject *obj)
Definition: Object.cc:214
graphics_object object(void) const
Definition: Object.cc:83
Base class for Octave interfaces that use Qt.
double round(double x)
Definition: lo-mappers.h:136