MNE-CPP  beta 1.0
datamarker.cpp
1 //=============================================================================================================
37 //*************************************************************************************************************
38 //=============================================================================================================
39 // INCLUDES
40 //=============================================================================================================
41 
42 #include "datamarker.h"
43 
44 
45 //*************************************************************************************************************
46 //=============================================================================================================
47 // USED NAMESPACES
48 //=============================================================================================================
49 
50 using namespace MNEBrowseRawQt;
51 
52 
53 //*************************************************************************************************************
54 //=============================================================================================================
55 // DEFINE MEMBER METHODS
56 //=============================================================================================================
57 
58 DataMarker::DataMarker(QWidget *parent) :
59  QWidget(parent),
60  m_oldPos(QPoint(0,0)),
61  m_movableRegion(QRegion())
62 {
63  //Set background color
64  QPalette Pal(palette());
65 
66  QColor color = m_qSettings.value("DataMarker/data_marker_color", QColor(93,177,47)).value<QColor>();
67  color.setAlpha(DATA_MARKER_OPACITY);
68  Pal.setColor(QPalette::Background, color);
69 
70  setAutoFillBackground(true);
71  setPalette(Pal);
72 }
73 
74 
75 //*************************************************************************************************************
76 
78 {
79  m_movableRegion = rect;
80 }
81 
82 
83 //*************************************************************************************************************
84 
85 void DataMarker::mousePressEvent(QMouseEvent *event)
86 {
87  if(event->buttons() == Qt::LeftButton)
88  m_oldPos = event->globalPos();
89 }
90 
91 
92 //*************************************************************************************************************
93 
94 void DataMarker::mouseMoveEvent(QMouseEvent *event)
95 {
96  if(event->buttons() == Qt::LeftButton) {
97  const QPoint delta = event->globalPos() - m_oldPos;
98 
99  QRect newPosition(x()+delta.x(), y(),
100  this->geometry().width(), this->geometry().height());
101 
102  //Check if new position is inside the boundary
103  if(m_movableRegion.contains(newPosition.bottomLeft()) && m_movableRegion.contains(newPosition.bottomRight())) {
104  move(x()+delta.x(), y());
105  m_oldPos = event->globalPos();
106  }
107 
108  if(event->windowPos().x() < m_movableRegion.boundingRect().left())
109  move(m_movableRegion.boundingRect().left(), y());
110 
111  if(event->windowPos().x() > m_movableRegion.boundingRect().right())
112  move(m_movableRegion.boundingRect().right()-2, y());
113 
114 // qDebug()<<"globalPos"<<event->globalPos().x()<<event->globalPos().y();
115 // qDebug()<<"newPosition"<<newPosition.x()<<newPosition.y()<<newPosition.width()<<newPosition.height();
116 // qDebug()<<"m_movableRegion"<<m_movableRegion.boundingRect().x()<<m_movableRegion.boundingRect().y()<<m_movableRegion.boundingRect().width()<<m_movableRegion.boundingRect().height();
117  }
118 }
119 
120 
121 //*************************************************************************************************************
122 
123 void DataMarker::enterEvent(QEvent *event)
124 {
125  Q_UNUSED(event);
126  setCursor(QCursor(Qt::SizeHorCursor));
127 }
128 
129 
130 //*************************************************************************************************************
131 
132 void DataMarker::moveEvent(QMoveEvent *event)
133 {
134  Q_UNUSED(event);
135  emit markerMoved();
136 }
void setMovementBoundary(QRegion rect)
Definition: datamarker.cpp:77
DataMarker(QWidget *parent=0)
Definition: datamarker.cpp:58
Contains the declaration of the DataMarker class.