示例#1
0
void GData::setRightTime(double x)
{
  if(x != _rightTime) {
    _rightTime = x;
    emit timeRangeChanged(leftTime(), rightTime());
    emit rightTimeChanged(rightTime());
    //emit viewChanged();
  }
}
示例#2
0
Point GraphWidget::gridToWindow( Point p ) {

	int iWindowWidth = w();
	int iWindowHeight = h();
	const int k_iAvgLongMarkLen = 15;
	double dRange = rightTime() - leftTime();

	int iLongMarkCountX = iWindowWidth / k_iAvgLongMarkLen;
	double dLongMarkLengthX = dRange / (double)iLongMarkCountX;
	double dLongMarkLengthPowX = log10(dLongMarkLengthX);
	int iLongMarkLengthPowX = (int)ceil(dLongMarkLengthPowX);
	dLongMarkLengthX = pow(10.0, (double)iLongMarkLengthPowX);

	int iLongMarkCountY = iWindowHeight / k_iAvgLongMarkLen;
	double dLongMarkLengthY = dRange / (double)iLongMarkCountY;
	double dLongMarkLengthPowY = log10(dLongMarkLengthY);
	int iLongMarkLengthPowY = (int)ceil(dLongMarkLengthPowY);
	dLongMarkLengthY = pow(10.0, (double)iLongMarkLengthPowY);


	Point val;

	val.x = (int)(((double)p.x * dLongMarkLengthX - leftTime()) / dRange * (double)iWindowWidth + 0.5);
	val.y = (int)(((double)p.y * dLongMarkLengthY - leftTime()) / dRange * (double)iWindowHeight + 0.5);

	return val;
}
示例#3
0
Point GraphWidget::windowToGrid( Point p ) {

	double dRange = rightTime() - leftTime();
	int iWindowWidth = w();
	int iWindowHeight = h();
	const int k_iAvgLongMarkLen = 15;

	int iLongMarkCountX = iWindowWidth / k_iAvgLongMarkLen;
	int iLongMarkCountY = iWindowHeight / k_iAvgLongMarkLen;
	int iMarkX=0, iMarkY=0;

	if (iLongMarkCountX > 0 && iWindowWidth > 0) {
		// Computer the long mark length so that it's 10^i where i is an integer
		double dLongMarkLengthX = dRange / (double)iLongMarkCountX;
		double dLongMarkLengthPowX = log10(dLongMarkLengthX);
		int iLongMarkLengthPowX = (int)ceil(dLongMarkLengthPowX);
		dLongMarkLengthX = pow(10.0, (double)iLongMarkLengthPowX);

		iMarkX = ((int)(((p.x-.5) / ((double)iWindowWidth) ) * dRange ) - leftTime())/dLongMarkLengthX;

		double dLongMarkLengthY = dRange / (double)iLongMarkCountY;
		double dLongMarkLengthPowY = log10(dLongMarkLengthY);
		int iLongMarkLengthPowY = (int)ceil(dLongMarkLengthPowY);
		dLongMarkLengthY = pow(10.0, (double)iLongMarkLengthPowY);

		iMarkY = ((int)(((p.y-.5) / ((double)iWindowHeight) ) * dRange ) - leftTime())/dLongMarkLengthY;

	}

	p.x = iMarkX;
	p.y = iMarkY;
	return p;
}
示例#4
0
void AmplitudeWidget::drawVerticalRefLines()
{
  //Draw the vertical reference lines
  double timeStep = timeWidth() / double(width()) * 150.0; //time per 150 pixels
  double timeScaleBase = pow10(floor(log10(timeStep))); //round down to the nearest power of 10

  //choose a timeScaleStep which is a multiple of 1, 2 or 5 of timeScaleBase
  int largeFreq;
  if(timeScaleBase * 5.0 < timeStep) { largeFreq = 5; }
  else if (timeScaleBase * 2.0 < timeStep) { largeFreq = 2; }
  else { largeFreq = 2; timeScaleBase /= 2; }

  double timePos = floor(leftTime() / (timeScaleBase*largeFreq)) * (timeScaleBase*largeFreq); //calc the first one just off the left of the screen
  int x, largeCounter=-1;
  double ratio = double(width()) / timeWidth();
  double lTime = leftTime();

  for(; timePos <= rightTime(); timePos += timeScaleBase) {
    if(++largeCounter == largeFreq) {
      largeCounter = 0;
      glColor4ub(25, 125, 170, 128); //draw the darker lines
    } else {
      glColor4ub(25, 125, 170, 64); //draw the lighter lines
	}
    x = toInt((timePos-lTime) * ratio);
    mygl_line(x, 0, x, height()-1);
  }
}
示例#5
0
void GData::updateActiveChunkTime(double t)
{
  if((running != STREAM_STOP) && (soundMode & SOUND_REC)) return;

  Channel *active = getActiveChannel();
  t = bound(t, leftTime(), rightTime());
  if(active) {
    //t = active->timeAtChunk(active->chunkAtTime(t)); //align time to an integer sample step
    active->jumpToTime(t);
    if(gdata->doingActive()) {
	    active->lock();
      active->processChunk(active->currentChunk());
	    active->unlock();
    }
  }
  view->setCurrentTime(t);
  doChunkUpdate();
}
示例#6
0
void TimeAxis::paintEvent(QPaintEvent *)
{
  int frameWidth = 2;
  const int	h = height(), w = width() - 2*frameWidth;
  int fontSpace = _fontSize+2;
  
  beginDrawing(false);
  fillBackground(colorGroup().background());

  double timeStep = timeWidth() / double(w) * 150.0; //time per 150 pixels
  double timeScaleBase = pow10(floor(log10(timeStep))); //round down to the nearest power of 10

  //choose a timeScaleStep which is a multiple of 1, 2 or 5 of timeScaleBase
  int largeFreq;
  if(timeScaleBase * 5.0 < timeStep) { largeFreq = 5; }
  else if (timeScaleBase * 2.0 < timeStep) { largeFreq = 2; }
  else { largeFreq = 2; timeScaleBase /= 2; }
    
  // Draw Ruler Numbers
  p.setBrush(Qt::black);
  //p.setFont(QFont("AnyStyle", h / 2 - 7));
  p.setFont(_font);
  double timePos = floor(leftTime() / (timeScaleBase*largeFreq)) * (timeScaleBase*largeFreq); //calc the first one just off the left of the screen
  int x, largeCounter=-1;
  
  //precalculate line sizes (for efficiency)
  int smallLineTop = 0;
  int smallLineBottom = 0;
  if(_numbersOnTop) {
    smallLineTop = h - 1 - (h - 1 - fontSpace)/2;
    smallLineBottom = h - 1;
  } else {
    smallLineTop = 0;
    smallLineBottom = (h - 1 - fontSpace) / 2;
  }
  int bigLineTop = 0;
  int bigLineBottom = 0;
  if(_numbersOnTop) {
    bigLineTop = fontSpace;
    bigLineBottom = h - 1;
  } else {
    bigLineTop = 0;
    bigLineBottom = h - 1 - fontSpace;
  }
  int textBottom = 0;
  if(_numbersOnTop) textBottom = _fontSize;
  else textBottom = h - 1;
    
  for(; timePos <= rightTime(); timePos += timeScaleBase) {
    if(++largeCounter == largeFreq) {
      largeCounter = 0;
      //draw the bigger lines and the numbers
      //QString numString = QString::number(timePos);

      double newTime = myround(timePos / timeScaleBase) * timeScaleBase;
      QString mins;
      double secs = fmod(newTime, 60.0);

      if (timePos < 0) {
        mins = "-" + QString::number(int(ceil(newTime / 60)));
        secs *= -1;
      } else {
        mins = QString::number(int(floor(newTime / 60)));
      }

      QString seconds = QString::number(secs);
      if (secs < 10 && secs > -10) {
        seconds = "0" + seconds;
      }
      
      QString numString = mins + ":" + seconds;
      x = frameWidth + toInt((timePos-leftTime()) / (timeWidth() / double(w)));
      p.drawText(x - (p.fontMetrics().width(numString) / 2), textBottom, numString);
      p.drawLine(x, bigLineTop, x, bigLineBottom);
    } else {
      //draw the smaller lines
      x = frameWidth + toInt((timePos-leftTime()) / (timeWidth() / double(w)));
      p.drawLine(x, smallLineTop, x, smallLineBottom);
    }
  }
  //draw the horizontal line
  if(_numbersOnTop) {
    p.drawLine(0, h-1, width(), h-1);
  } else {
    p.drawLine(0, 0, width(), 0);
  }
  endDrawing();
}
示例#7
0
void GraphWidget::draw()
{
	if (!valid()) {
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();

		glViewport(0, 0, w(), h());

		glClearColor(GRID_BACKGROUND_INTENSITY, GRID_BACKGROUND_INTENSITY, GRID_BACKGROUND_INTENSITY, 0.0);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	}

	glClear(GL_COLOR_BUFFER_BIT);

	glColor3d(0,0,0);
	glBegin(GL_POLYGON);
		glVertex2d( -w(), -h()  );
		glVertex2d( -w(),  h()  );
		glVertex2d(  w(),  h()  );
		glVertex2d(  w(), -h()  );
	glEnd();

/************************************************************************************/

	//The grid.. We're copying this from rulerwindow class.
	//Really to two should have a single reference function.
	double dRangeX = rightTime() - leftTime();
	double dRangeY = (rightTime() - leftTime());
	int iWindowWidth = w();
	int iWindowHeight = h();
	const int k_iAvgLongMarkLen = 15;

	int iLongMarkCountX = iWindowWidth / k_iAvgLongMarkLen;
	int iLongMarkCountY = iWindowHeight / k_iAvgLongMarkLen;

	if (iLongMarkCountX > 0 && iWindowWidth > 0) {
		// Computer the long mark length so that it's 10^i where i is an integer
		double dLongMarkLengthX = dRangeX / (double)iLongMarkCountX;
		double dLongMarkLengthPowX = log10(dLongMarkLengthX);
		int iLongMarkLengthPowX = (int)ceil(dLongMarkLengthPowX);
		dLongMarkLengthX = pow(10.0, (double)iLongMarkLengthPowX);

		double dLongMarkLengthY = dRangeY / (double)iLongMarkCountY;
		double dLongMarkLengthPowY = log10(dLongMarkLengthY);
		int iLongMarkLengthPowY = (int)ceil(dLongMarkLengthPowY);
		dLongMarkLengthY = pow(10.0, (double)iLongMarkLengthPowY);


		int iStartX = (int)ceil(leftTime() / dLongMarkLengthX);

		int iMarkX, iMarkY;
		double x,y;

		glColor3d(1,1,1);
		glPointSize(0.5);
		glBegin(GL_POINTS);

			do {
				iMarkX = 2*(int)(((double)iStartX * dLongMarkLengthX - leftTime()) / dRangeX * (double)iWindowWidth + 0.5) - w();
				x = (double)iMarkX / w();
				
				int iStartY = (int)ceil(leftTime() / dLongMarkLengthY);
				do{
					iMarkY = 2*(int)(((double)iStartY * dLongMarkLengthY - leftTime()) / dRangeY * (double)iWindowHeight + 0.5) - h();
					y = (double)iMarkY / h();

					glVertex2d(x,y);

					++iStartY;
				} while (iMarkY < iWindowHeight);
				
				++iStartX;
			} while (iMarkX < iWindowWidth);
		glEnd();
	}

/************************************************************************************/
	
	if (m_bHasEvent) {
		m_bHasEvent = false;

		switch (m_iEventToDo) {
			case LEFT_MOUSE_DOWN:
				selectAddCtrlPt(m_iMouseX, m_iMouseY);
				break;
			case LEFT_MOUSE_DRAG:
				dragCtrlPt(m_iMouseX, m_iMouseY);
				break;
			case LEFT_MOUSE_UP:
				break;

			case ALT_LEFT_DOWN:
				startCtrlPtSelection(m_iMouseX, m_iMouseY);
				break;
			case ALT_LEFT_DRAG:
				doCtrlPtSelection(m_iMouseX, m_iMouseY);
				break;
			case ALT_LEFT_UP:
				endCtrlPtSelection(m_iMouseX, m_iMouseY);
				break;

			case CTRL_LEFT_DOWN:
				selectCurrCurve(m_iMouseX, m_iMouseY);
				break;

			case SHIFT_LEFT_DOWN:
				removeCtrlPt(m_iMouseX, m_iMouseY);
				break;

			case RIGHT_MOUSE_DOWN:
				break;
			case RIGHT_MOUSE_DRAG:
				doZoom(m_iMouseDX, m_iMouseDY);
				break;
			case RIGHT_MOUSE_UP:
				break;

			case SHIFT_RIGHT_DOWN:
				break;
			case SHIFT_RIGHT_DRAG:
				m_bPanning = true;
				doPan(m_iMouseDX, m_iMouseDY);
				break;
			case SHIFT_RIGHT_UP:
				m_bPanning = false;
				break;

			case CTRL_RIGHT_DOWN:
				startZoomSelection(m_iMouseX, m_iMouseY);
				break;
			case CTRL_RIGHT_DRAG:
				doZoomSelection(m_iMouseX, m_iMouseY);
				break;
			case CTRL_RIGHT_UP:
				endZoomSelection(m_iMouseX, m_iMouseY);
				break;

			default:
				break;
		}

		do_callback();
	}
	drawTimeBar();
	drawActiveCurves();
	drawZoomSelectionMap();
	drawSelectionRect();
}
示例#8
0
void GData::end()
{
  updateActiveChunkTime(rightTime());
  view->doSlowUpdate();
}