GNU Octave  4.4.1
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-2018 Michael Goffioul
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include <QChildEvent>
28 #include <QVBoxLayout>
29 
30 #include "graphics.h"
31 
32 #include "Canvas.h"
33 #include "Container.h"
34 #include "Object.h"
35 #include "QtHandlesUtils.h"
36 
37 namespace QtHandles
38 {
39 
41  : ContainerBase (xparent), m_canvas (nullptr)
42  {
43  setFocusPolicy (Qt::ClickFocus);
44  }
45 
47  { }
48 
49  Canvas*
50  Container::canvas (const graphics_handle& gh, bool xcreate)
51  {
52  if (! m_canvas && xcreate)
53  {
56 
57  if (go)
58  {
59  graphics_object fig = go.get_ancestor ("figure");
60 
61  m_canvas = Canvas::create (fig.get ("renderer").string_value (),
62  this, gh);
63 
64  QWidget *canvasWidget = m_canvas->qWidget ();
65 
66  canvasWidget->lower ();
67  canvasWidget->show ();
68  canvasWidget->setGeometry (0, 0, width (), height ());
69  }
70  }
71 
72  return m_canvas;
73  }
74 
75  void
76  Container::resizeEvent (QResizeEvent* /* event */)
77  {
78  if (m_canvas)
79  m_canvas->qWidget ()->setGeometry (0, 0, width (), height ());
80 
82 
83  foreach (QObject *qObj, children ())
84  {
85  if (qObj->isWidgetType ())
86  {
87  Object *obj = Object::fromQObject (qObj);
88 
89  if (obj)
90  {
91  graphics_object go = obj->object ();
92 
93  if (go.valid_object ())
94  {
95  Matrix bb = go.get_properties ().get_boundingbox (false);
96 
97  obj->qWidget<QWidget> ()->setGeometry (
99  octave::math::round (bb(2)), octave::math::round (bb(3)));
100  }
101  }
102  }
103  }
104  }
105 
106  void
107  Container::childEvent (QChildEvent *xevent)
108  {
109  // Enable mouse tracking in child widgets as they are added if the
110  // container also has mouse tracking enabled. There is no need to
111  // do this when child objects are removed.
112 
113  if (xevent->added ())
114  {
115  QObject *obj = xevent->child ();
116 
117  if (obj && obj->isWidgetType ())
118  {
119  QWidget *widget = qobject_cast<QWidget *> (obj);
120 
121  if (widget)
122  widget->setMouseTracking (hasMouseTracking ());
123  }
124  }
125  }
126 }
virtual QWidget * qWidget(void)=0
std::string string_value(bool force=false) const
Definition: ov.h:955
void resizeEvent(QResizeEvent *event)
Definition: Container.cc:76
graphics_handle gh
Definition: graphics.cc:11812
virtual Matrix get_boundingbox(bool=false, const Matrix &=Matrix()) const
Definition: graphics.in.h:2257
void childEvent(QChildEvent *event)
Definition: Container.cc:107
bool valid_object(void) const
Definition: graphics.in.h:2806
octave_value get(bool all=false) const
Definition: graphics.in.h:2711
T * qWidget(void)
Definition: Object.h:74
static Object * fromQObject(QObject *obj)
Definition: Object.cc:176
base_properties & get_properties(void)
Definition: graphics.in.h:2788
Definition: dMatrix.h:36
graphics_object object(void) const
Definition: Object.cc:72
static Canvas * create(const std::string &name, QWidget *parent, const graphics_handle &handle)
Definition: Canvas.cc:1057
static graphics_object get_object(double val)
Definition: graphics.in.h:6098
double round(double x)
Definition: lo-mappers.h:145
Canvas * canvas(const graphics_handle &handle, bool create=true)
Definition: Container.cc:50
Container(QWidget *parent)
Definition: Container.cc:40
graphics_object get_ancestor(const std::string &type) const
Definition: graphics.cc:3613