TinkerCell Core 1.0
TinkerCell's Core library providing all basic functionalities
ControlPoint.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003 Copyright (c) 2008 Deepak Chandran
00004 Contact: Deepak Chandran (dchandran1@gmail.com)
00005 See COPYRIGHT.TXT
00006 
00007 One of the main classes in Tinkercell.
00008 
00009 There are two classes defined in this file: ControlPoint and NodeGraphicsItem
00010 
00011 The NodeGraphicsItem is a group made up of Shapes. Each Shape is a polygon item. 
00012 Each shape has a default color. The purpose of the default color is to allow plugins
00013 to change color temporarily and then revert back to the default.
00014 
00015 ControlPoint is a drawable item that is used by NodeGraphicsItem and ConnectionGraphicsItem
00016 to draw movable points.
00017 
00018 ****************************************************************************/
00019 
00020 #include "GraphicsScene.h"
00021 #include "MainWindow.h"
00022 #include "ControlPoint.h"
00023 #include "ItemHandle.h"
00024 
00025 namespace Tinkercell
00026 {
00027         ItemHandle * ControlPoint::handle() const
00028         {
00029                 return 0;
00030         }
00031 
00032         void ControlPoint::setHandle(ItemHandle *)
00033         {
00034                 
00035         }
00036 
00038         ControlPoint::ControlPoint(QGraphicsItem * parent) : 
00039         QAbstractGraphicsShapeItem(parent)
00040         {
00041                 setFlag(QGraphicsItem::ItemIsMovable, false);
00042                 setFlag(QGraphicsItem::ItemIsSelectable, false);
00043 
00044                 setPen(defaultPen = QPen( QColor(100,100,255) ));
00045                 setBrush(defaultBrush = QBrush( QColor(0,0,255,10)) );
00046                 setRect(QRectF(-10,-10,20,20));
00047                 setZValue(10);
00048                 shapeType = this->circle;
00049         }
00050 
00052         ControlPoint::ControlPoint(const ControlPoint& copy) : QAbstractGraphicsShapeItem(copy.parentItem())
00053         {       
00054                 setFlag(QGraphicsItem::ItemIsMovable, false);
00055                 setFlag(QGraphicsItem::ItemIsSelectable, false);
00056                 setVisible(copy.isVisible());
00057 
00058                 setPos(copy.pos());
00059                 setRect(copy.rect());
00060                 setPen(defaultPen = copy.defaultPen);
00061                 setBrush(defaultBrush = copy.defaultBrush);
00062                 //setTransform(copy.transform());
00063                 shapeType = copy.shapeType;
00064                 bounds = copy.bounds;
00065                 defaultSize = copy.defaultSize;
00066         }
00067 
00069         QRectF ControlPoint::boundingRect() const
00070         {
00071                 qreal w = pen().widthF();
00072                 return bounds.adjusted(-w,-w,w,w);
00073         }
00074 
00076         QRectF ControlPoint::rect() const
00077         {
00078                 return bounds;
00079         }
00080 
00082         void ControlPoint::setRect(const QRectF& rect)
00083         {
00084                 this->bounds = rect;
00085         }
00086 
00088         ControlPoint* ControlPoint::clone() const
00089         {
00090                 return new ControlPoint(*this);
00091         }
00092 
00094         void ControlPoint::sideEffect()
00095         {
00096         }
00097 
00098 
00100         void ControlPoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *,QWidget *)
00101         {
00102                 if (painter)
00103                 {
00104                         QRectF rect = boundingRect();
00105 
00106                         painter->setBrush(brush());
00107                         painter->setPen(pen());
00108 
00109                         if (shapeType == circle)
00110                                 painter->drawEllipse(rect);
00111                         else
00112                                 if (shapeType == square)
00113                                         painter->drawRect(rect);
00114                                 else
00115                                 {
00116                                         painter->drawLine(rect.bottomLeft(),rect.bottomRight());
00117                                         painter->drawLine(rect.bottomRight(),QPointF(rect.center().x(),rect.top()));
00118                                         painter->drawLine(QPointF(rect.center().x(),rect.top()),rect.bottomLeft());
00119                                 }
00120                 }
00121         }
00122 
00123 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines