00001
00002
00003
00004
00005
00006
00007 #include "DataKey.h"
00008 #include "EnumsToQt.h"
00009 #include "GraphicsItemType.h"
00010 #include "Logger.h"
00011 #include <QGraphicsScene>
00012 #include <QPen>
00013 #include "Segment.h"
00014 #include "SegmentLine.h"
00015 #include "ZValues.h"
00016
00017 SegmentLine::SegmentLine(QGraphicsScene &scene,
00018 const DocumentModelSegments &modelSegments,
00019 Segment *segment) :
00020 m_modelSegments (modelSegments),
00021 m_segment (segment)
00022 {
00023 LOG4CPP_DEBUG_S ((*mainCat)) << "SegmentLine::SegmentLine"
00024 << " address=0x" << std::hex << (quintptr) this;
00025
00026 setData (DATA_KEY_GRAPHICS_ITEM_TYPE, QVariant (GRAPHICS_ITEM_TYPE_SEGMENT));
00027
00028
00029 scene.addItem (this);
00030 setPen (QPen (Qt::transparent));
00031 setZValue (Z_VALUE_CURVE);
00032 setVisible (true);
00033 setAcceptHoverEvents (true);
00034 setHover (false);
00035 setFlags (QGraphicsItem::ItemIsFocusable);
00036
00037 connect (this, SIGNAL (signalHover (bool)), segment, SLOT (slotHover (bool)));
00038 }
00039
00040 SegmentLine::~SegmentLine ()
00041 {
00042 LOG4CPP_DEBUG_S ((*mainCat)) << "SegmentLine::~SegmentLine"
00043 << " address=0x" << std::hex << (quintptr) this;
00044 }
00045
00046 void SegmentLine::hoverEnterEvent(QGraphicsSceneHoverEvent * )
00047 {
00048 LOG4CPP_INFO_S ((*mainCat)) << "SegmentLine::hoverEnterEvent";
00049
00050 emit (signalHover (true));
00051 }
00052
00053 void SegmentLine::hoverLeaveEvent(QGraphicsSceneHoverEvent * )
00054 {
00055 LOG4CPP_INFO_S ((*mainCat)) << "SegmentLine::hoverLeaveEvent";
00056
00057 emit (signalHover (false));
00058 }
00059
00060 void SegmentLine::mousePressEvent(QGraphicsSceneMouseEvent * )
00061 {
00062 LOG4CPP_INFO_S ((*mainCat)) << "SegmentLine::mousePressEvent";
00063
00064 m_segment->forwardMousePress();
00065 }
00066
00067 Segment *SegmentLine::segment() const
00068 {
00069 return m_segment;
00070 }
00071
00072 void SegmentLine::setHover (bool hover)
00073 {
00074 if (hover) {
00075
00076 QColor color (ColorPaletteToQColor (m_modelSegments.lineColor()));
00077
00078 setPen (QPen (QBrush (color),
00079 m_modelSegments.lineWidth()));
00080
00081 } else {
00082
00083 setPen (QPen (Qt::transparent));
00084
00085 }
00086 }
00087
00088 void SegmentLine::updateModelSegment(const DocumentModelSegments &modelSegments)
00089 {
00090 LOG4CPP_INFO_S ((*mainCat)) << "SegmentLine::updateModelSegment";
00091
00092 m_modelSegments = modelSegments;
00093 }