GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Container.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2011-2017 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 the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 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 <http://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 (0)
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> ()
98  ->setGeometry (octave::math::round (bb(0)), octave::math::round (bb(1)),
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  if (xevent->child ()->isWidgetType ())
110  qobject_cast<QWidget*> (xevent->child ())->setMouseTracking (
111  hasMouseTracking ());
112  }
113 
114 }
virtual QWidget * qWidget(void)=0
virtual Matrix get_boundingbox(bool=false, const Matrix &=Matrix()) const
Definition: graphics.h:2499
void resizeEvent(QResizeEvent *event)
Definition: Container.cc:76
graphics_handle gh
Definition: graphics.cc:11209
octave_value get(bool all=false) const
Definition: graphics.h:3211
double round(double x)
Definition: lo-mappers.cc:333
void childEvent(QChildEvent *event)
Definition: Container.cc:107
std::string string_value(bool force=false) const
Definition: ov.h:908
T * qWidget(void)
Definition: Object.h:74
static Object * fromQObject(QObject *obj)
Definition: Object.cc:176
base_properties & get_properties(void)
Definition: graphics.h:3288
Definition: dMatrix.h:37
graphics_object get_ancestor(const std::string &type) const
Definition: graphics.cc:3404
graphics_object object(void) const
Definition: Object.cc:72
bool valid_object(void) const
Definition: graphics.h:3306
static Canvas * create(const std::string &name, QWidget *parent, const graphics_handle &handle)
Definition: Canvas.cc:1037
static graphics_object get_object(double val)
Definition: graphics.h:13794
Canvas * canvas(const graphics_handle &handle, bool create=true)
Definition: Container.cc:50
Container(QWidget *parent)
Definition: Container.cc:40