MNE-CPP  beta 1.0
sensoritem.cpp
Go to the documentation of this file.
1 //=============================================================================================================
36 //*************************************************************************************************************
37 //=============================================================================================================
38 // INCLUDES
39 //=============================================================================================================
40 
41 #include "sensoritem.h"
42 
43 
44 //*************************************************************************************************************
45 //=============================================================================================================
46 // QT INCLUDES
47 //=============================================================================================================
48 
49 #include <QStaticText>
50 #include <QDebug>
51 
52 
53 //*************************************************************************************************************
54 //=============================================================================================================
55 // USED NAMESPACES
56 //=============================================================================================================
57 
58 using namespace XDISPLIB;
59 
60 
61 //*************************************************************************************************************
62 //=============================================================================================================
63 // DEFINE MEMBER METHODS
64 //=============================================================================================================
65 
66 SensorItem::SensorItem(const QString& dispChName, qint32 chNumber, const QPointF& coordinate, const QColor& channelColor, QGraphicsItem *parent)
67 : QGraphicsObject(parent)
68 , m_sDisplayChName(dispChName)
69 , m_iChNumber(chNumber)
70 , m_qPointFCoord(coordinate)
71 , m_qColorChannel(channelColor)
72 , m_bIsHighlighted(false)
73 , m_bIsChoosen(false)
74 {
75  setZValue(m_iChNumber);
76 
77  setFlags(ItemIsSelectable);// | ItemIsMovable);
78  setAcceptHoverEvents(true);
79 }
80 
81 
82 //*************************************************************************************************************
83 
85 {
86  return QRectF(-25, -30, 50, 50);//QRectF(QPointF(0,0), m_qSizeFDim);
87 }
88 
89 
90 //*************************************************************************************************************
91 
92 QPainterPath SensorItem::shape() const
93 {
94  QPainterPath path;
95  path.addRect(-25, -30, 50, 50);
96  return path;
97 }
98 
99 
100 //*************************************************************************************************************
101 
102 void SensorItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
103 {
104  Q_UNUSED(widget)
105 
106  // Plot shadow
107  painter->setPen(Qt::NoPen);
108  painter->setBrush(Qt::darkGray);
109  painter->drawEllipse(-12, -12, 30, 30);
110 
111  if (option->state & QStyle::State_MouseOver)
112  painter->setBrush(Qt::lightGray);
113  else
114  painter->setBrush(m_bIsChoosen ? Qt::yellow : m_qColorChannel);
115 
116  painter->setPen(Qt::black);
117  painter->drawEllipse(-15, -15, 30, 30);
118 
119  // Plot channel name
120  painter->setPen(QPen(Qt::black, 1));
121  QStaticText staticChName = QStaticText(m_sDisplayChName);
122  QSizeF sizeText = staticChName.size();
123  painter->drawStaticText(-15+((30-sizeText.width())/2), -32, staticChName);
124 }
125 
126 
127 //*************************************************************************************************************
128 
129 void SensorItem::setColor(const QColor& channelColor)
130 {
131  m_qColorChannel = channelColor;
132 }
133 
134 
135 //*************************************************************************************************************
136 
137 void SensorItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
138 {
139  QGraphicsItem::mousePressEvent(event);
140  update();
141 }
142 
143 
144 //*************************************************************************************************************
145 
146 void SensorItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
147 {
148 // if (event->modifiers() & Qt::ShiftModifier) {
149 // stuff << event->pos();
150 // update();
151 // return;
152 // }
153  QGraphicsItem::mouseMoveEvent(event);
154 }
155 
156 
157 //*************************************************************************************************************
158 
159 void SensorItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
160 {
161  QGraphicsItem::mouseReleaseEvent(event);
162  m_bIsChoosen = !m_bIsChoosen;
163  emit itemChanged(this);
164  update();
165 }
166 
167 
void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
Definition: sensoritem.cpp:146
void itemChanged(SensorItem *item)
void setColor(const QColor &channelColor)
Definition: sensoritem.cpp:129
Declaration of the SensorItem Class.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Definition: sensoritem.cpp:102
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
Definition: sensoritem.cpp:159
void mousePressEvent(QGraphicsSceneMouseEvent *event)
Definition: sensoritem.cpp:137
QRectF boundingRect() const
Definition: sensoritem.cpp:84
QPainterPath shape() const
Definition: sensoritem.cpp:92
SensorItem(const QString &dispChName, qint32 chNumber, const QPointF &coordinate, const QColor &channelColor, QGraphicsItem *parent=0)
Definition: sensoritem.cpp:66