src/modelnode.h

00001 /* This file is part of WarpTree
00002  *
00003  * Copyright (C) 2007 Jos van den Oever <jos@vandenoever.info>
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Library General Public License
00016  * along with this library; see the file COPYING.LIB.  If not, write to
00017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019  */
00020 // parts of code for layout was adapted from HyperTree published under
00021 // MIT License 2001 www.bouthier.net
00022 #ifndef MODELNODE_H
00023 #define MODELNODE_H
00024 
00025 #include "warptreeview.h"
00026 #include "warpcoord.h"
00027 #include <QtCore/QThread>
00028 #include <QtGui/QIcon>
00029 #include <QtCore/QModelIndex>
00030 #include <QtCore/QLine>
00031 #include <QtCore/QVector>
00032 
00033 class ParentModelNode;
00034 class ModelNode {
00035 public:
00036     // the public part of the node (QModelIndex, QRect and depth)
00037     WarpTreeNode node;
00038     // the coordinate as originally layed out
00039     WarpCoord original;
00040     // the original coordinate translated with respect to the views origin
00041     WarpCoord translated;
00042     // the parent of the node
00043     ParentModelNode* parent;
00044     // the weight of the node. this depends on the number of children
00045     float weight;
00046     // whether to show the line connecting this node to its parent
00047     bool showLine;
00048     // whether to draw the label
00049     bool showText;
00050 
00051     ModelNode(int d) :node(d), parent(0), weight(1) {}
00052     virtual ~ModelNode() {}
00053     // lay out a node with respect to its parent
00054     virtual void layout(float angle, float width, float length);
00055     // update the screen coordinates from the translated coordinates
00056     void updateScreenCoords(float halfw, float halfh);
00057     // move the node with respect to the views origin and zoomfactor
00058     void translate(const WarpCoord& m, float zoomFactor);
00059 };
00060 class ParentModelNode : public ModelNode {
00061 public:
00062     // the children of this node
00063     QVector<ModelNode*> children;
00064     // the global weight of this node
00065     float globalWeight;
00066     // the number of children in this node
00067     int count;
00068     // the width (angle) of this node
00069     float width;
00070     // the length of the connection of this node to its parent
00071     float length;
00072     // the angle of this node
00073     float angle;
00074     // have the children of this node been loaded?
00075     bool complete;
00076 
00077     ParentModelNode(int d) :ModelNode(d), globalWeight(0), complete(false) {}
00078     // overloaded function for laying out this node
00079     void layout(float angle, float width, float length);
00080 };
00081 
00082 #endif

Generated on Sat Jun 2 19:18:06 2007 for WarpTree by  doxygen 1.5.0