-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewcurve.cpp
More file actions
194 lines (153 loc) · 7.52 KB
/
viewcurve.cpp
File metadata and controls
194 lines (153 loc) · 7.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include "viewcurve.h"
ViewCurve::ViewCurve(QWidget *w_parent) : QWidget(w_parent){
//setAttribute(Qt::WA_OpaquePaintEvent); // to bych pak musel nastavovat barvy
mainwindow = (MainWindow *)w_parent;
shift_page_left_shortcut = NULL;
shift_page_right_shortcut = NULL;
next_page_shortcut = NULL;
previous_page_shortcut = NULL;
arrowkeys_shortcuts_global_set_enabled(true);
QScreen *screen = QGuiApplication::primaryScreen();
qDebug() << "QScreen geometry height in px: " << screen->geometry().height();
qDebug() << "QScreen geometry width in px" << screen->geometry().width();
qDebug() << "Screen's physical size in mm: " << screen->physicalSize();
qDebug() << "Screen's physical height in mm: " << screen->physicalSize().height(); // screen's physical size (in millimeters)
qDebug() << "Screen's physical width in mm: " << screen->physicalSize().width();
qDebug() << "Physical dots per mm X: " << screen->geometry().width()/screen->physicalSize().width();
qDebug() << "Physical dots per mm Y: " << screen->geometry().height()/screen->physicalSize().height();
qDebug() << "Physical dots per inch: " << screen->physicalDotsPerInch(); //number of physical dots or pixels per inch
qDebug() << "Physical dots per mm: " << screen->physicalDotsPerInch()*0.0393701; //number of physical dots or pixels per inch
// BrainLab window 310x260 mm
//qDebug() << "window height: " << mainwindow->size().height();
//qDebug() << "window width: " << mainwindow->size().width();
//qDebug() <<"Foo ve viewcurve: " << mainwindow->foo;
}
void ViewCurve::setDataManager(EegDataManager* manager, const std::vector<read_signal_file::Channel>& channels) {
m_dataManager = manager;
m_channels = channels;
}
void ViewCurve::setTimeWindow(double startTimeSec, double durationSec) {
m_startTime = startTimeSec;
m_duration = durationSec;
this->update(); // Force a redraw whenever the time changes
}
void ViewCurve::arrowkeys_shortcuts_global_set_enabled(bool enabled)
{
// if(shift_page_left_shortcut != NULL)
// {
// QObject::disconnect(shift_page_left_shortcut, 0, 0, 0);
// delete shift_page_left_shortcut;
// }
// if(shift_page_right_shortcut != NULL)
// {
// QObject::disconnect(shift_page_right_shortcut, 0, 0, 0);
// delete shift_page_right_shortcut;
// }
// if(next_page_shortcut != NULL)
// {
// QObject::disconnect(next_page_shortcut, 0, 0, 0);
// delete next_page_shortcut;
// }
// if(previous_page_shortcut != NULL)
// {
// QObject::disconnect(previous_page_shortcut, 0, 0, 0);
// delete previous_page_shortcut;
// }
// TO DO - switching between BrainLab and NicOne style
if(enabled == true)
{
shift_page_left_shortcut = new QShortcut(QKeySequence::MoveToPreviousChar, mainwindow);
shift_page_right_shortcut = new QShortcut(QKeySequence::MoveToNextChar, mainwindow);
next_page_shortcut = new QShortcut(QKeySequence::MoveToNextPage, mainwindow);
previous_page_shortcut = new QShortcut(QKeySequence::MoveToPreviousPage, mainwindow);
first_page_shortcut = new QShortcut(QKeySequence::MoveToStartOfLine, mainwindow);
last_page_shortcut = new QShortcut(QKeySequence::MoveToEndOfLine, mainwindow);
}
else
{
shift_page_left_shortcut = new QShortcut(QKeySequence::MoveToPreviousChar, this, 0, 0, Qt::WidgetShortcut);
shift_page_right_shortcut = new QShortcut(QKeySequence::MoveToNextChar, this, 0, 0, Qt::WidgetShortcut);
next_page_shortcut = new QShortcut(QKeySequence::MoveToNextPage, this, 0, 0, Qt::WidgetShortcut);
previous_page_shortcut = new QShortcut(QKeySequence::MoveToPreviousPage, this, 0, 0, Qt::WidgetShortcut);
first_page_shortcut = new QShortcut(QKeySequence::MoveToStartOfLine, this, 0, 0, Qt::WidgetShortcut);
last_page_shortcut = new QShortcut(QKeySequence::MoveToEndOfLine, this, 0, 0, Qt::WidgetShortcut);
}
QObject::connect(shift_page_left_shortcut, SIGNAL(activated()), mainwindow, SLOT(shift_page_left()));
QObject::connect(shift_page_right_shortcut, SIGNAL(activated()), mainwindow, SLOT(shift_page_right()));
QObject::connect(next_page_shortcut, SIGNAL(activated()), mainwindow, SLOT(next_page()));
QObject::connect(previous_page_shortcut, SIGNAL(activated()), mainwindow, SLOT(previous_page()));
QObject::connect(first_page_shortcut, SIGNAL(activated()), mainwindow, SLOT(first_page()));
QObject::connect(last_page_shortcut, SIGNAL(activated()), mainwindow, SLOT(last_page()));
}
//
void ViewCurve::paintEvent(QPaintEvent *event){
if (!m_dataManager) return; // No file loaded
//create a QPainter and pass a pointer to the device.
//A paint device can be a QWidget, a QPixmap or a QImage
QPainter painter(this);
// couple of variables to use when drawing
int fromTop = 50;
int offset = 30;
int second2draw = mainwindow->pagetime;
std::string label;
QString qstr;
int LeftMargin = 50;
//float pixelFactor = 0.005;
int scaleY = 50;
// viewbuf
double endTime = m_startTime + m_duration;
std::vector<std::vector<double>> viewbuf = m_dataManager->getProcessedData(m_startTime, endTime);
// ====== LOAD DATA TO VIEWBUF ======
// ====== painter definition ======
QPen signal_pen(Qt::black, 1, Qt::SolidLine,Qt::SquareCap, Qt::BevelJoin);
QPen grid_pen(Qt::gray, 1, Qt::SolidLine,Qt::SquareCap, Qt::BevelJoin);
// and some font
QFont font = painter.font();
font.setPixelSize(12);
painter.setFont(font);
// TO DO - split grid, signals and labels to different processes
// ====== DRAW GRIDS ======
for (int i = 1; i < second2draw; i++){
// TO DO - replace 250 with variable - e.g. signal.recorder_info.channels[i].sampling_rate
painter.setPen(grid_pen);
painter.drawLine(LeftMargin + i*250,0,LeftMargin + i*250,1000);
}
// ====== DRAW SIGNALS =======
for (int i = 0; i < (int)viewbuf.size(); i++){
painter.setPen(grid_pen);
painter.drawLine(LeftMargin,fromTop + offset*i,1000+LeftMargin,fromTop + offset*i);
painter.setPen(signal_pen);
label = mainwindow->signal.recorder_info.channels[i].channel_desc;
qstr = QString::fromStdString(label);
painter.drawText(1, fromTop+offset*i, qstr);
int fromX = LeftMargin;
int fromY = fromTop + offset*i;
// draw signals from viewbuf
if (viewbuf[i].size() > 1) {
for (int j = 0; j < (int)viewbuf[i].size() - 1; j++){
painter.drawLine(fromX+j, fromY-viewbuf[i][j]*scaleY, fromX+j+1, fromY-viewbuf[i][j+1]*scaleY);
}
}
}
//draw time!
// TO DO - move it to separate widget
painter.drawText(1, fromTop+offset*mainwindow->signal.recorder_info.numberOfChannelsUsed, QString::fromStdString("Time:"));
}
void ViewCurve::wheelEvent(QWheelEvent *wheel_event)
{
if(mainwindow->file_open == 0) return;
//qDebug() << wheel_event->angleDelta().y();
if(wheel_event->angleDelta().y() > 0){
if (mainwindow->mouseWheelMode == 1) mainwindow->shift_page_left();
if (mainwindow->mouseWheelMode == 0) mainwindow->previous_page();
}
if(wheel_event->angleDelta().y() < 0){
if (mainwindow->mouseWheelMode == 1) mainwindow->shift_page_right();
if (mainwindow->mouseWheelMode == 0) mainwindow->next_page();
}
}
ViewCurve::~ViewCurve()
{
delete signal_pen;
delete grid_pen;
}