12 GLWidget::GLWidget(QWidget *parent)
13 : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
15 qtGreen = QColor::fromCmykF(0.40, 0.0, 1.0, 0.0);
16 qtPurple = QColor::fromCmykF(0.0, 0.0, 0.0, 0.0);
38 QSize GLWidget::minimumSizeHint()
const
43 QSize GLWidget::sizeHint()
const
48 return QSize(this->width(), this->height());
52 void GLWidget::initializeGL()
55 glClearColor(1.0f, 1.0f, 1.0f, 0.0);
59 void GLWidget::paintGL()
61 glClear(GL_COLOR_BUFFER_BIT);
64 glScalef(1.0, 1.0, 1.0);
66 glColor3f(0.0f,0.0,0.0);
67 glCallList(LINES_MORE);
70 glColor3f(1.0f,0.0,0.0);
71 glCallList(BOXES_MORE);
80 void GLWidget::DrawLabels()
82 for (
int i = 0; i< mlabels.size(); i++)
84 renderText(xCoordScale*mx[i],yCoordScale*my[i],0.0,mlabels[i]);
97 void GLWidget::SetBoxMode(
bool boxmode)
102 void GLWidget::SetLabelMode(
bool labelmode)
104 NeedLabel = labelmode;
106 void GLWidget::SetLabels(QList <QString> labels,QVector <float> x,QVector <float> y)
113 void GLWidget::SetOnset(
float ons)
118 void GLWidget::SetXYScales(
float xScale,
float yScale)
120 xCoordScale = xScale;
121 yCoordScale = yScale;
124 void GLWidget::SetVScale(
float v)
129 void GLWidget::drawBoxes(QVector <float> x, QVector <float> y,
float w,
float h)
131 if(x.size()!= y.size()) {NumBoxes = 0; qDebug()<<
"Error: box coordinates";}
134 qDebug()<<
"NumBoxes"<<NumBoxes;
137 glNewList(BOXES_MORE, GL_COMPILE);
138 for (
int chanIndx=0; chanIndx < NumBoxes; chanIndx++)
141 glBegin(GL_LINE_STRIP);
142 glColor3f(1.0f,0.0,0.0);
143 glVertex2f(xCoordScale*x[chanIndx], yCoordScale*y[chanIndx]);
144 glVertex2f(xCoordScale*x[chanIndx]+w,yCoordScale*y[chanIndx]);
145 glVertex2f(xCoordScale*x[chanIndx]+w,yCoordScale*y[chanIndx]-h);
146 glVertex2f(xCoordScale*x[chanIndx], yCoordScale*y[chanIndx]-h);
147 glVertex2f(xCoordScale*x[chanIndx], yCoordScale*y[chanIndx]);
151 glBegin(GL_LINE_STRIP);
152 glColor3f(1.0f,0.0,0.0);
153 glVertex2f(xCoordScale*x[chanIndx], yCoordScale*y[chanIndx]-h/2);
154 glVertex2f(xCoordScale*x[chanIndx]+w,yCoordScale*y[chanIndx]-h/2);
158 glBegin(GL_LINE_STRIP);
159 glColor3f(1.0f,0.0,0.0);
160 glVertex2f(xCoordScale*x[chanIndx]+Onset, yCoordScale*y[chanIndx]);
161 glVertex2f(xCoordScale*x[chanIndx]+Onset,yCoordScale*y[chanIndx]-h);
165 glBegin(GL_LINE_STRIP);
166 glColor3f(1.0f,0.0,0.0);
171 qDebug()<<
"scale mark"<<xl<<w<<yd<<h;
175 void GLWidget::drawLines(
float * samples,
int row,
int col,
int wise_type,
176 QVector <float> x, QVector <float> y,
float w,
float h)
182 if((x.size()!=row) && (y.size()!=row)) NumLines = 0;
184 glNewList(LINES_MORE, GL_COMPILE);
185 for (
int chanIndx=0; chanIndx < row; chanIndx++)
186 drawOneLine(samples, row, col, wise_type, chanIndx, xCoordScale*x[chanIndx], yCoordScale*y[chanIndx], w, h);
192 void GLWidget::drawOneLine(
float * samples,
int row,
int col,
int wise_type,
int chanIndx,
193 float x,
float y,
float w,
float h)
198 float wscale = w/col;
199 float hscale = h/VScale;
200 glBegin(GL_LINE_STRIP);
202 for(
int i=0;i<col;i++){
203 glVertex2f(i*wscale+x,y-h/2+hscale*samples[i*row+chanIndx]);
208 for(
int i=0;i<col;i++){
209 glVertex2f(i*wscale+x,y-h/2+hscale*samples[i+chanIndx*col]);
215 void GLWidget::resizeGL(
int width,
int height)
217 glViewport( 0, 0, (GLint)width, (GLint)height );
218 glMatrixMode( GL_PROJECTION );
220 glOrtho( xl, xr, yd, yt, -1.0, 1.0 );
221 glMatrixMode( GL_MODELVIEW );
224 void GLWidget::SetGLView(
float xleft,
float xright,
float ydown,
float ytop)
232 glMatrixMode( GL_PROJECTION );
234 glOrtho( xl, xr, yd, yt, -1.0, 1.0 );
235 glMatrixMode( GL_MODELVIEW );
238 void GLWidget::mousePressEvent(QMouseEvent *event)
240 startPos =
event->pos();
245 void GLWidget::mouseMoveEvent(QMouseEvent *event)
247 MovePos =
event->pos();
251 void GLWidget::mouseReleaseEvent(QMouseEvent *event)
253 lastPos =
event->pos();
258 QPoint CenterPos(this->width()/2,this->height()/2);
260 startPos = startPos - CenterPos;
261 lastPos = lastPos - CenterPos;
263 QPoint NewStartPos(((xr-xl)/this->width())*startPos.x()+(xr+xl)/2, (yt-yd)*startPos.y()/this->height()+(yt+yd)/2);
265 QPoint NewLastPos(((xr-xl)/this->width())*lastPos.x()+(xr+xl)/2, (yt-yd)*lastPos.y()/this->height()+(yt+yd)/2);
267 float xsl = NewStartPos.x();
268 float xsr = NewLastPos.x();
269 float yst = NewStartPos.y();
270 float ysd = NewLastPos.y();
272 if (xsl > xsr) {
float t = xsr; xsr = xsl; xsl = t;}
273 if (ysd > yst) {
float t = yst; yst = ysd; ysd = t;}
275 qDebug()<<
"Width"<<this->width();
276 qDebug()<<xsl<<xsr<<ysd<<yst;
278 SetGLView(xsl, xsr, ysd, yst);