Exemple #1
0
StitcherView::StitcherView(QWidget * parent)
  :ImageView(parent)
{
  imageViewPanel()->showSaveButton(true);
  setRenderHints(QPainter::Antialiasing);
  /*  QGraphicsLineItem * centerVerticalIndicator = new QGraphicsLineItem(0,-100000,0,100000);
  QGraphicsLineItem * centerHorizontalIndicator = new QGraphicsLineItem(-100000,0,100000,0);
  centerVerticalIndicator->setZValue(11);
  centerHorizontalIndicator->setZValue(11);
  graphicsScene->addItem(centerVerticalIndicator);
  graphicsScene->addItem(centerHorizontalIndicator);
  QPen pen = centerHorizontalIndicator->pen();  
  pen.setColor(Qt::white);
  pen.setStyle(Qt::SolidLine);
  centerHorizontalIndicator->setPen(pen);
  centerVerticalIndicator->setPen(pen);*/

  /* Solid background */
  setBackgroundBrush(QColor("#26466D"));
  _showIdentifiers = true;
  setBackgroundDraggable(false);
  QGraphicsLineItem * centerVerticalIndicator = new QGraphicsLineItem(0,-100,0,100);
  QGraphicsLineItem * centerHorizontalIndicator = new QGraphicsLineItem(-100,0,100,0);
  centerVerticalIndicator->setZValue(11);
  centerHorizontalIndicator->setZValue(11);
  graphicsScene->addItem(centerVerticalIndicator);
  graphicsScene->addItem(centerHorizontalIndicator);
  QPen pen = centerHorizontalIndicator->pen();  
  pen.setColor(Qt::white);
  pen.setStyle(Qt::SolidLine);
  centerHorizontalIndicator->setPen(pen);
  centerVerticalIndicator->setPen(pen);

}
Exemple #2
0
void StitcherView::drawConstraintFit(geometrically_constrained_system *gc){
  for(int i = 0;i<gc->n_constraints;i++){
    GeometryConstraintType type = gc->constraints[i].type;
    double fit = gc->constraints[i].best_fit;    
    if(type == RadialLineConstraint){
      qreal x1,x2,y1,y2;
      qreal scale = 10000;
      x1 = cos(fit)*scale;

      y1 = sin(fit)*scale;
      x2 = -x1;
      y2 = -y1;
      QGraphicsLineItem * item = new QGraphicsLineItem(x1,y1,x2,y2);
      QPen p = item->pen();
      p.setStyle(Qt::DashLine);
      QVector<qreal> dashes;
      dashes << 25 << 15;
      p.setDashPattern(dashes);
      p.setColor(Qt::white);
      item->setPen(p);
      item->setZValue(10000);
      scene()->addItem(item);
      constraintFit.append(item);
    }else if(type == CircleConstraint){
      double radius = fit;
      QGraphicsEllipseItem * item = new QGraphicsEllipseItem(-radius,-radius,2*radius,2*radius);
      QPen p = item->pen();
      p.setStyle(Qt::DashLine);
      QVector<qreal> dashes;
      dashes << 25 << 15;
      p.setDashPattern(dashes);
      p.setColor(Qt::white);
      item->setPen(p);
      item->setZValue(10000);
      scene()->addItem(item);
      constraintFit.append(item);
    }
    sp_vector ** cp_g = control_point_list_to_global(gc->constraints[i].points,gc->constraints[i].n_points);
    QColor color = QColor::fromHsvF(1.0/3+(double)i/gc->n_constraints,1,1,1);
    for(int j = 0;j<gc->constraints[i].n_points;j++){
      QGraphicsEllipseItem * point = new QGraphicsEllipseItem(-4,-4,8,8);
      point->setZValue(10001);
      point->setPos(sp_vector_get(cp_g[j],0),sp_vector_get(cp_g[j],1));
      point->setPen(QPen(color, 2));
      point->setFlags(point->flags() | QGraphicsItem::ItemIgnoresTransformations);
      scene()->addItem(point);
      constraintFit.append(point);
    }
  }
}
Exemple #3
0
void StitcherView::mouseReleaseEvent( QMouseEvent *  event){
  ImageView::mouseReleaseEvent(event);
  if(mode == Line && event->button() & Qt::LeftButton){
    setMode(Default);
    QGraphicsLineItem * line = new QGraphicsLineItem(QLineF(mapToScene(lineOrigin),mapToScene(lineEnd)));
    line->setData(0,QString("Helper"));
    line->setZValue(11);    
    QPen pen = line->pen();  
    pen.setColor(Qt::white);
    pen.setStyle(Qt::SolidLine);
    line->setPen(pen);
    graphicsScene->addItem(line);    
  }else if(mode == Circle && event->button() & Qt::LeftButton){
    setMode(Default);
    QPointF lineOriginF = mapToScene(lineOrigin);
    QPointF lineEndF = mapToScene(lineEnd);
    QPointF circleCenter = (lineOriginF+lineEndF)/2;    
    qreal circleRadius = sqrt((lineOriginF-lineEndF).x()* (lineOriginF-lineEndF).x()+
			      (lineOriginF-lineEndF).y()* (lineOriginF-lineEndF).y())/2;
    if(QApplication::keyboardModifiers() & Qt::ShiftModifier){
      circleCenter =  mapFromScene(QPointF(0,0));
      circleRadius = sqrt((circleCenter-lineEnd).x()* (circleCenter-lineEnd).x()+
			      (circleCenter-lineEnd).y()* (circleCenter-lineEnd).y());
      circleCenter =  QPointF(0,0);

    }
    QGraphicsEllipseItem * circle = new QGraphicsEllipseItem(QRect(circleCenter.x()-circleRadius,circleCenter.y()-circleRadius,circleRadius*2,circleRadius*2));
    circle->setData(0,QString("Helper"));
    circle->setZValue(11);    
    QPen pen = circle->pen();  
    pen.setColor(Qt::white);
    pen.setStyle(Qt::SolidLine);
    circle->setPen(pen);
    graphicsScene->addItem(circle);    
  }else if(mode == AddPoint && event->button() & Qt::LeftButton){
    QList<QGraphicsItem *> it = items(event->pos());
    for(int i = 0; i < it.size(); i++){
      if(ImageItem * item = qgraphicsitem_cast<ImageItem *>(it.at(i))){
	item->addControlPoint(item->mapFromScene(mapToScene(event->pos())));
      }
    }
  }else if(mode == DeletePoint && event->button() & Qt::LeftButton){
    QList<QGraphicsItem *> it = items(event->pos());
    for(int i = 0; i < it.size(); i++){
      if(ImageItem * item = qgraphicsitem_cast<ImageItem *>(it.at(i))){
	item->deleteControlPoint(item->mapFromScene(mapToScene(event->pos())));
      }
    }
  }else if(mode == DeleteGuide && event->button() & Qt::LeftButton){
    QList<QGraphicsItem *> it = items(event->pos());
    QPointF pos = mapToScene(event->pos());
    /* 10 px tolerance radius, delete the closest */
    for(int i = 0; i < it.size(); i++){
      if(QString("Helper") == it[i]->data(0)){
	QGraphicsEllipseItem * elipse = qgraphicsitem_cast<QGraphicsEllipseItem *>(it[i]);
	if(elipse){
	  // Check if click position close to the line
	  QPointF origin = elipse->rect().center();
	  qreal radius = elipse->rect().height()/2;
	  QPointF d = origin-pos;	  
	  if(abs(sqrt(d.x()*d.x()+d.y()*d.y())-radius) < 10){
	    delete elipse;
	  }
	}
	QGraphicsLineItem * line = qgraphicsitem_cast<QGraphicsLineItem *>(it[i]);
	if(line){
	  delete line;
	}

      }
    }
  }
}