MNE-CPP  beta 1.0
tmsiimpedancescene.cpp
1 //=============================================================================================================
37 //*************************************************************************************************************
38 //=============================================================================================================
39 // INCLUDES
40 //=============================================================================================================
41 
42 #include "tmsiimpedancescene.h"
43 
44 
45 //*************************************************************************************************************
46 //=============================================================================================================
47 // USED NAMESPACES
48 //=============================================================================================================
49 
50 using namespace TMSIPlugin;
51 using namespace std;
52 
53 
54 //*************************************************************************************************************
55 //=============================================================================================================
56 // DEFINE MEMBER METHODS
57 //=============================================================================================================
58 
59 TMSIImpedanceScene::TMSIImpedanceScene(QGraphicsView* view, QObject* parent)
60 : QGraphicsScene(parent)
61 , m_bRightMouseKeyPressed(false)
62 , m_qvView(view)
63 {
64 
65 }
66 
67 //*************************************************************************************************************
68 
69 void TMSIImpedanceScene::mousePressEvent(QGraphicsSceneMouseEvent* event)
70 {
71  if(event->button() == Qt::RightButton)
72  m_bRightMouseKeyPressed = true;
73 
74  QGraphicsScene::mousePressEvent(event);
75 }
76 
77 //*************************************************************************************************************
78 
79 void TMSIImpedanceScene::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
80 {
81  if(m_bRightMouseKeyPressed)
82  {
83  if(m_mousePosition.x()-event->scenePos().x() > 0) // user moved mouse to the left while pressing the right mouse key
84  scaleElectrodePositions(0.99);
85 
86  if(m_mousePosition.x()-event->scenePos().x() < 0) // user moved mouse to the right while pressing the right mouse key
87  scaleElectrodePositions(1.01);
88  }
89 
90  m_mousePosition = event->scenePos();
91 
92  QGraphicsScene::mouseMoveEvent(event);
93 }
94 
95 //*************************************************************************************************************
96 
97 void TMSIImpedanceScene::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
98 {
99  if(event->button() == Qt::RightButton)
100  m_bRightMouseKeyPressed = false;
101 
102  QGraphicsScene::mouseReleaseEvent(event);
103 }
104 
105 //*************************************************************************************************************
106 
107 void TMSIImpedanceScene::scaleElectrodePositions(double scaleFactor)
108 {
109  // Get scene items
110  QList< QGraphicsItem *> itemList = this->items();
111 
112  // Update position
113  for(int i = 0; i<itemList.size(); i++)
114  {
115  TMSIElectrodeItem* item = (TMSIElectrodeItem *) itemList.at(i);
116 
117  // Set both positions -> dunno why :-)
118  item->setPosition(item->getPosition()*scaleFactor);
119  item->setPos(item->pos()*scaleFactor);
120  }
121 
122  this->update(this->sceneRect());
123 }
124 
125 
Contains the implementation of the TMSIImpedanceScene class.
The TMSIElectrodeItem class provides a new data structure for impedance values.
void setPosition(QPointF newPosition)
TMSIImpedanceScene(QGraphicsView *view, QObject *parent=0)