• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

rocs/RocsCore

  • sources
  • kde-4.12
  • kdeedu
  • rocs
  • RocsCore
  • DataStructures
  • RootedTree
RootedTreeNodeItem.cpp
Go to the documentation of this file.
1 /*
2  This file is part of RootedTree (Rocs Plugin).
3  Copyright 2012 Wagner Reck <wagner.reck@gmail.com>
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License as
7  published by the Free Software Foundation; either version 2 of
8  the License, or (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include "RootedTreeNodeItem.h"
20 #include "RootedTreeNode.h"
21 #include <boost/shared_ptr.hpp>
22 #include <QPainter>
23 #include <QGraphicsScene>
24 #include "DataStructure.h"
25 
26 
27 RootedTreeNodeItem::RootedTreeNodeItem(DataPtr n) : DataItem(n){
28 
29 
30 }
31 
32 RootedTreeNodeItem::~RootedTreeNodeItem(){};
33 
34 QRectF RootedTreeNodeItem::boundingRect() const
35 {
36  if (data() && data()->dataStructure()){
37  const qreal size = data()->dataStructure()->property("NodeSize").toReal();
38  if (data()->dataStructure()->property("ShowAllPointers").toBool()) {
39  RootedTreeNode* node = qobject_cast<RootedTreeNode*>(data().get());
40  const qreal pointersSize = data()->dataStructure()->property("PointersRegion").toReal();
41  const qint16 childCount = node->numberOfChilds();
42  return QRectF(0,0,(childCount * pointersSize) > 1 ?
43  childCount * pointersSize * size:
44  size,
45  size * 1.6);
46  } else {
47  return DataItem::boundingRect(); /*QRectF(0,0,size, size );*/
48  }
49 
50  }
51  return QRectF();
52 }
53 
54 
55 void RootedTreeNodeItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
56 {
57  RootedTreeNode * node = qobject_cast< RootedTreeNode* >(data().get());
58  if (!node || !node->dataStructure()) {
59  return;
60  }
61 
62  const qreal size = node->dataStructure()->property("NodeSize").toReal();
63  qDebug() << "multipointer? " << data()->dataStructure()->property("ShowAllPointers").toBool();
64  if (data()->dataStructure()->property("ShowAllPointers").toBool()){
65 
66  const qreal pointersSize = node->dataStructure()->property("PointersRegion").toReal();
67  qint16 childCount = node->numberOfChilds();
68 
69  const qreal width = (childCount * pointersSize) > 1 ?
70  childCount * pointersSize * size:
71  size;
72 
73  painter->drawRoundedRect(0,0, width, size * 1.6, width*0.01,size *0.01);
74  painter->drawLine(0,size*pointersSize, width, size*pointersSize);
75  painter->drawLine(0,size*(1+pointersSize), width, size*(1+pointersSize));
76 
77  const qreal division = width / childCount;
78  if (!node->child(0)){
79  painter->drawLine(division*0.2, size*1.55, division*0.8, size*(1+pointersSize+0.05));
80  }
81  for (int i = 1; i < childCount; ++i){
82  painter->drawLine(division*i,size*(1+pointersSize), division*i, size*1.6);
83  if (!node->child(i))
84  painter->drawLine(division*i+division*0.2, size*1.55, division*i+division*0.9, size*(1+pointersSize+0.05));
85  }
86  if (!(node->nodeParent().get())) {
87  painter->drawLine(width*0.3, size*0.25, width*0.7, size*0.05);
88  }
89  } else {
90  DataItem::paint(painter,option, widget);
91  }
92 // painter->drawEllipse(boundingRect());
93 }
Data::dataStructure
DataStructurePtr dataStructure() const
Definition: Data.cpp:150
RootedTreeNodeItem::boundingRect
QRectF boundingRect() const
Definition: RootedTreeNodeItem.cpp:34
RootedTreeNodeItem::paint
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Definition: RootedTreeNodeItem.cpp:55
DataStructure.h
RootedTreeNode::numberOfChilds
quint32 numberOfChilds
Definition: RootedTreeNode.h:29
RootedTreeNode::nodeParent
QScriptValue nodeParent
Definition: RootedTreeNode.h:32
RootedTreeNodeItem::RootedTreeNodeItem
RootedTreeNodeItem(DataPtr n)
Definition: RootedTreeNodeItem.cpp:27
RootedTreeNodeItem::~RootedTreeNodeItem
~RootedTreeNodeItem()
Definition: RootedTreeNodeItem.cpp:32
DataPtr
boost::shared_ptr< Data > DataPtr
Definition: CoreTypes.h:34
DataItem
RootedTreeNode.h
RootedTreeNode
Definition: RootedTreeNode.h:25
RootedTreeNode::child
DataPtr child(const quint32 i) const
return the i (0 to n-1) child
Definition: RootedTreeNode.cpp:125
RootedTreeNodeItem.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:42:26 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

rocs/RocsCore

Skip menu "rocs/RocsCore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal