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 #ifndef MODELNODE_H
00021 #define MODELNODE_H
00022 
00023 #include "warptreeview.h"
00024 #include "warpcoord.h"
00025 #include <QtCore/QThread>
00026 #include <QtGui/QIcon>
00027 #include <QtCore/QModelIndex>
00028 #include <QtCore/QLine>
00029 #include <QtCore/QVector>
00030 
00031 class ParentModelNode;
00032 class ModelNode {
00033 public:
00034     // the public part of the node (QModelIndex, QRect and depth)
00035     WarpTreeNode node;
00036     // the coordinate as originally layed out
00037     WarpCoord original;
00038     // the original coordinate translated with respect to the views origin
00039     WarpCoord translated;
00040     // the parent of the node
00041     ParentModelNode* parent;
00042     // the weight of the node. this depends on the number of children
00043     double weight;
00044     // whether to show the line connecting this node to its parent
00045     bool showLine;
00046     // whether to draw the label
00047     bool showText;
00048 
00049     ModelNode(int d) :node(d), parent(0), weight(1), showLine(false),
00050         showText(false) {}
00051     virtual ~ModelNode() {}
00052     // lay out a node with respect to its parent
00053     virtual void layout(double angle, double width, double length);
00054     // update the screen coordinates from the translated coordinates
00055     void updateScreenCoords(double halfw, double halfh);
00056     // move the node with respect to the views origin and zoomfactor
00057     void translate(const WarpCoord& m, double zoomFactor);
00058     void setShowLine();
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     double globalWeight;
00066     // the number of children in this node
00067     int count;
00068     // the width (angle) of this node
00069     double width;
00070     // the length of the connection of this node to its parent
00071     double length;
00072     // the angle of this node
00073     double 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(double angle, double width, double length);
00080 };
00081 
00082 #endif

Generated on Sun Jun 3 19:54:02 2007 for WarpTree by  doxygen 1.5.0