GNU Octave  4.0.0
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-2015 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 #ifdef 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 
50 Canvas*
51 Container::canvas (const graphics_handle& gh, bool xcreate)
52 {
53  if (! m_canvas && xcreate)
54  {
57 
58  if (go)
59  {
60  graphics_object fig = go.get_ancestor ("figure");
61 
62  m_canvas = Canvas::create (fig.get("renderer").string_value (),
63  this, gh);
64 
65  QWidget* canvasWidget = m_canvas->qWidget ();
66 
67  canvasWidget->lower ();
68  canvasWidget->show ();
69  canvasWidget->setGeometry (0, 0, width (), height ());
70  }
71  }
72 
73  return m_canvas;
74 }
75 
76 void
77 Container::resizeEvent (QResizeEvent* /* event */)
78 {
79  if (m_canvas)
80  m_canvas->qWidget ()->setGeometry (0, 0, width (), height ());
81 
83 
84  foreach (QObject* qObj, children ())
85  {
86  if (qObj->isWidgetType ())
87  {
88  Object* obj = Object::fromQObject (qObj);
89 
90  if (obj)
91  {
92  Matrix bb = obj->properties ().get_boundingbox (false);
93 
94  obj->qWidget<QWidget> ()
95  ->setGeometry (xround (bb(0)), xround (bb(1)),
96  xround (bb(2)), xround (bb(3)));
97  }
98  }
99  }
100 }
101 
102 void
103 Container::childEvent (QChildEvent* xevent)
104 {
105  if (xevent->child ()->isWidgetType ())
106  qobject_cast<QWidget*> (xevent->child ())->setMouseTracking (hasMouseTracking ());
107 }
108 
109 }; // namespace QtHandles
virtual QWidget * qWidget(void)=0
double xround(double x)
Definition: lo-mappers.cc:63
virtual Matrix get_boundingbox(bool=false, const Matrix &=Matrix()) const
Definition: graphics.h:2553
void resizeEvent(QResizeEvent *event)
Definition: Container.cc:77
octave_value get(bool all=false) const
Definition: graphics.h:3300
void childEvent(QChildEvent *event)
Definition: Container.cc:103
std::string string_value(bool force=false) const
Definition: ov.h:897
T * qWidget(void)
Definition: Object.h:74
static Object * fromQObject(QObject *obj)
Definition: Object.cc:181
Definition: dMatrix.h:35
graphics_object get_ancestor(const std::string &type) const
Definition: graphics.cc:3394
static Canvas * create(const std::string &name, QWidget *parent, const graphics_handle &handle)
Definition: Canvas.cc:966
static graphics_object get_object(double val)
Definition: graphics.h:13212
Canvas * canvas(const graphics_handle &handle, bool create=true)
Definition: Container.cc:51
Container(QWidget *parent)
Definition: Container.cc:40
base_properties & properties(void)
Definition: Object.h:49