Пример #1
0
CaptionObject
CaptionGrabber::caption()
{
  CaptionObject co;
  co.set(position(),
	 text(),
	 font(),
	 color(),
	 haloColor(),
	 angle());
  return co;
}
Пример #2
0
void
CaptionObject::setCaption(CaptionObject co)
{
  m_pos = co.position();
  m_text = co.text();
  m_font = co.font();
  m_color = co.color();
  m_haloColor = co.haloColor();
  m_angle = co.m_angle;

  QFontMetrics metric(m_font);
  m_height = metric.height();
  m_width = metric.width(m_text);

  createImage();
}
Пример #3
0
CaptionObject
CaptionObject::interpolate(CaptionObject& cap1,
			   CaptionObject& cap2,
			   float frc)
{
  bool ok = false;

  QString finalText = cap1.text();


  QStringList regExprs;
  regExprs << "\\$[n|N]\\(\\d*\\.*\\d*\\)";
  regExprs << "\\$[d|D]\\(\\d*\\.*\\d*\\)";
  for (int nr=0; nr<regExprs.count(); nr++)
    {
      QRegExp rx(regExprs[nr]);
      QStringList rem;
      QString txt;

      float val1;
      rx.indexIn(cap1.text());      
      txt = rx.cap();
      rem = txt.split(QRegExp("\\(|\\)"));
      if (rem.count() > 1) val1 = rem[1].toFloat();

      float val2;
      rx.indexIn(cap2.text());      
      txt = rx.cap();
      rem = txt.split(QRegExp("\\(|\\)"));
      if (rem.count() > 1) val2 = rem[1].toFloat();

      float val = (1-frc)*val1 + frc*val2;

      QString ftxt = QString("%1").arg(val, 0, 'f', Global::floatPrecision());
      if (Global::floatPrecision() > 0)
	{
	  QStringList frem = ftxt.split(".");
	  float fraction = frem[1].toFloat();
	  if (fraction < 0.00001)
	    ftxt = frem[0];
	}

      if (nr == 0)
	finalText.replace(rx, ftxt);
      else
	finalText.replace(rx, "$d("+ftxt+")");
      ok = true;
    }

  if (!ok &&
      cap1.text() != cap2.text())
    {
      // apply fadein-fadeout
      CaptionObject cap;

      if (frc <= 0.5)
	cap.setCaption(cap1);
      else
	cap.setCaption(cap2);
      
//      QColor c = cap.color();
//      float r = c.redF();
//      float g = c.greenF();
//      float b = c.blueF();
//      float a;
//
//      if (frc <= 0.5)
//	a = (1-frc)*c.alphaF();
//      else
//	a = frc*c.alphaF();      
//      c = QColor::fromRgbF(r,g,b,a);      
//      cap.setColor(c);
//
//      QColor hc = cap.haloColor();
//      r = hc.redF();
//      g = hc.greenF();
//      b = hc.blueF();
//      if (frc <= 0.5)
//	a = (1-frc)*hc.alphaF();
//      else
//	a = frc*hc.alphaF();
//      hc = QColor::fromRgbF(r,g,b,a);      
//      cap.setHaloColor(hc);

      return cap;
    }

  // interpolate position, color and font

  CaptionObject cap;

  QFont fnt = cap1.font();
  QFont fnt2 = cap2.font();

  if (fnt.family() == fnt2.family())
    {
      // interpolate pointsize
      int pt1 = fnt.pointSize();
      int pt2 = fnt2.pointSize();
      int pt = (1-frc)*pt1 + frc*pt2;
      fnt.setPointSize(pt);
    }

  // interpolate position
  QPointF pos1 = cap1.position();
  QPointF pos2 = cap2.position();
  QPointF pos = pos1-pos2;  
  if (fabs(pos.x()) > 5 || fabs(pos.y()) > 5 ) // more than 5 pixel change
    pos = (1-frc)*pos1 + frc*pos2;
  else
    {
      if (frc <0.5)
	pos = pos1;
      else
	pos = pos2;
    }

  // interpolate color
  QColor c = cap1.color();
  float r1 = c.redF();
  float g1 = c.greenF();
  float b1 = c.blueF();
  float a1 = c.alphaF();
  c = cap2.color();
  float r2 = c.redF();
  float g2 = c.greenF();
  float b2 = c.blueF();
  float a2 = c.alphaF();
  float r = (1-frc)*r1 + frc*r2;
  float g = (1-frc)*g1 + frc*g2;
  float b = (1-frc)*b1 + frc*b2;
  float a = (1-frc)*a1 + frc*a2;
  c = QColor(r*255, g*255, b*255, a*255);

  // interpolate halocolor
  QColor hc = cap1.haloColor();
  r1 = hc.redF();
  g1 = hc.greenF();
  b1 = hc.blueF();
  a1 = hc.alphaF();
  hc = cap2.haloColor();
  r2 = hc.redF();
  g2 = hc.greenF();
  b2 = hc.blueF();
  a2 = c.alphaF();
  r = (1-frc)*r1 + frc*r2;
  g = (1-frc)*g1 + frc*g2;
  b = (1-frc)*b1 + frc*b2;
  a = (1-frc)*a1 + frc*a2;
  hc = QColor(r*255, g*255, b*255, a*255);

  float angle = (1-frc)*cap1.angle() + frc*cap2.angle();
  cap.set(pos,
	  finalText,
	  fnt,
	  c, hc,
	  angle);

  return cap;
}