Ejemplo n.º 1
0
void StarView::drawState(HostItem *node)
{
    delete node->stateItem();
    QGraphicsLineItem *newItem = 0;

    unsigned int client = node->client();
    QColor color = client ? hostColor(client) : Qt::green;

    if (node->isCompiling() || node->isActiveClient()) {
        newItem = new QGraphicsLineItem(qRound(node->centerPosX()),
                                        qRound(node->centerPosY()),
                                        qRound(m_schedulerItem->centerPosX()),
                                        qRound(m_schedulerItem->centerPosY()));
        if (node->isCompiling()) {
            newItem->setPen(QPen(color, 0));
            newItem->setZValue(-301);
        } else if (node->isActiveClient()) {
            newItem->setPen(QPen(color, 1, Qt::DashLine));
            newItem->setZValue(-300);
        }
        m_canvas->addItem(newItem);
    }

    node->setStateItem(newItem);
}
Ejemplo n.º 2
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);

}
Ejemplo n.º 3
0
void MonitorGraphicsView::updateGrid()
{
    int itemsCount = m_gridItems.count();
    for (int i = 0; i < itemsCount; i++)
        m_scene->removeItem((QGraphicsItem *)m_gridItems.takeLast());

    if (m_gridEnabled == true)
    {
        m_xOffset = 0;
        m_yOffset = 0;
        int xInc = this->width() / m_gridSize.width();
        int yInc = this->height() / m_gridSize.height();
        if (yInc < xInc)
        {
            m_cellPixels = yInc;
            m_xOffset = (this->width() - (m_cellPixels * m_gridSize.width())) / 2;
        }
        else if (xInc < yInc)
        {
            m_cellPixels = xInc;
            m_yOffset = (this->height() - (m_cellPixels * m_gridSize.height())) / 2;
        }
        int xPos = m_xOffset;
        int yPos = m_yOffset;
        for (int i = 0; i < m_gridSize.width() + 1; i++)
        {
            QGraphicsLineItem *item = m_scene->addLine(xPos, m_yOffset, xPos, this->height() - m_yOffset,
                                                       QPen( QColor(40, 40, 40, 255) ));
            item->setZValue(1);
            xPos += m_cellPixels;
            m_gridItems.append(item);
        }

        for (int i = 0; i < m_gridSize.height() + 1; i++)
        {
            QGraphicsLineItem *item = m_scene->addLine(m_xOffset, yPos, this->width() - m_xOffset, yPos,
                                                       QPen( QColor(40, 40, 40, 255) ));
            item->setZValue(1);
            yPos += m_cellPixels;
            m_gridItems.append(item);
        }
        if (m_bgItem != NULL)
        {
            m_bgItem->setX(m_xOffset);
            m_bgItem->setY(m_yOffset);
            m_bgItem->setPixmap(m_bgPixmap.scaled(xPos - m_cellPixels - m_xOffset, yPos - m_cellPixels - m_yOffset));
        }
    }
}
Ejemplo n.º 4
0
void ClsDiagConnectionHandleStart::refresh(){
    qrectParentBR.setSize(parentItem()->boundingRect().size());

    qrectParentBR.setX(0);
    qrectParentBR.setY(0);

    setPos(qrectParentBR.center());
    if(dynamic_cast<ClsDiagItemAP*>(parentItem())){
	iOrientation = dynamic_cast<ClsDiagItemAP*>(parentItem())->getOrientation();
	setOrientation(iOrientation);
    }
    QPointF qpHere = parentItem()->scenePos() + qrectParentBR.center();	    
    
    QGraphicsLineItem *qlinePost = parentConnection->getFirstSegment();
    if(qlinePost!=NULL){
	if(iOrientation == ClsDiagConnection::WEST_EAST){
	    qlinePost->setLine(qpHere.x() - qrectMyBR.height(), qpHere.y() - 1, qlinePost->line().p2().x(), qlinePost->line().p2().y()); /* height because we are rotated! */
	} else if(iOrientation == ClsDiagConnection::EAST_WEST){
	    qlinePost->setLine(qpHere.x() + qrectMyBR.height(), qpHere.y(), qlinePost->line().p2().x(), qlinePost->line().p2().y()); /* height because we are rotated! */
	} else if(iOrientation == ClsDiagConnection::NORTH_SOUTH){
	    qlinePost->setLine(qpHere.x(), qpHere.y() - qrectMyBR.height(), qlinePost->line().p2().x(), qlinePost->line().p2().y());
	} else if(iOrientation == ClsDiagConnection::SOUTH_NORTH){
	    qlinePost->setLine(qpHere.x() - 1, qpHere.y() + qrectMyBR.height(), qlinePost->line().p2().x(), qlinePost->line().p2().y());
	}
    }
    qlinePost->setZValue(0);	    
    setZValue(10);	    
}
Ejemplo n.º 5
0
void
ConfigurationSpaceScene::drawConfigurationPath(const rl::plan::VectorList& path)
{
	this->resetPath();
	
	rl::plan::VectorList::const_iterator i = path.begin();
	rl::plan::VectorList::const_iterator j = ++path.begin();
	
	while (i != path.end() && j != path.end())
	{
		QGraphicsLineItem* line = this->addLine(
			(*i)(this->x),
			-(*i)(this->y),
			(*j)(this->x),
			-(*j)(this->y),
			QPen(QBrush(QColor(0, 255, 0)), 0.0f)
		);
		
		line->setZValue(3);
		
		this->path.push_back(line);
		
		++i;
		++j;
	}
}
Ejemplo n.º 6
0
void Wall::ShowStructure(QGraphicsScene *c) {

  Vector offset = Cell::Offset();
  double factor = Cell::Factor();

  Vector startpoint ( ((offset.x+n1->x)*factor),((offset.y+n1->y)*factor)),
    endpoint (((offset.x+n2->x)*factor),((offset.y+n2->y)*factor));

  Vector linevec = endpoint - startpoint;
  Vector midline = startpoint + linevec/2.;
  Vector perpvec = linevec.Normalised().Perp2D();
  Vector textpos1 = midline + 100 * perpvec;
  Vector textpos2 = midline - 100 * perpvec;

  QGraphicsLineItem *line = new QGraphicsLineItem(0,c);

  line->setPen( QPen(QColor(par.arrowcolor),2) );
  line->setLine(startpoint.x, startpoint.y, endpoint.x, endpoint.y );
  line->setZValue(10);
  line->show();

  QGraphicsSimpleTextItem *text1 = new QGraphicsSimpleTextItem( QString("%1").arg(c2->Index()),0,c);
  QGraphicsSimpleTextItem *text2 = new QGraphicsSimpleTextItem( QString("%1").arg(c1->Index()),0,c);

  text1 -> setPos( textpos1.x, textpos1.y );
  text2 -> setPos( textpos2.x, textpos2.y );
  text1->setZValue(20); text2->setZValue(20);

  text1->setFont( QFont( "Helvetica", par.nodenumsize, QFont::Bold) );
  text2->setFont( QFont( "Helvetica", par.nodenumsize, QFont::Bold) );

  text1->setPen ( QColor(par.textcolor) );
  text2->setPen ( text1->pen() );
  text1->show(); text2->show();
}
void CSharedPainterScene::drawLineTo( const QPointF &pt1, const QPointF &pt2, const QColor &clr, int width )
{
	QGraphicsLineItem *item = addLine( pt1.x(), pt1.y(), pt2.x(), pt2.y(), QPen(clr, width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin) );
	item->setZValue( currentLineZValue_ );

	tempLineItemList_.push_back( item );
}
Ejemplo n.º 8
0
std::vector<QGraphicsLineItem*> GraphRenderer::addLines(
        const repo::core::model::RepoNode *node,
        const QGraphicsItem *nodeItem)
{
    std::vector<QGraphicsLineItem*> lines(node->getParentIDs().size());
    if (node)
    {
        QPen pen(Qt::lightGray);
        pen.setWidthF(penWidth);

        qreal halfDiameter = nodeDiameter/2;
        qreal halfPen = penWidth/2;

        int i = 0;
        for (repo::lib::RepoUUID parentID : node->getParentIDs())
        {
            QGraphicsItem *parentItem = painted[uuidToQString(parentID)];
            QGraphicsLineItem *line = addLine(
                        parentItem->scenePos().x() + halfDiameter,
                        parentItem->scenePos().y() + halfDiameter + halfPen,
                        nodeItem->scenePos().x() + halfDiameter,
                        nodeItem->scenePos().y() + halfDiameter + halfPen,
                        pen);
            line->setZValue(0.0f);
            lines[i++] = line;
        }
    }
    return lines;
}
Ejemplo n.º 9
0
void Main::addLine()
{
    QGraphicsLineItem* i = canvas.addLine(QLineF( qrand()%int(canvas.width()), qrand()%int(canvas.height()),
                                                  qrand()%int(canvas.width()), qrand()%int(canvas.height()) ));
    i->setFlag(QGraphicsItem::ItemIsMovable);
    i->setPen( QPen(QColor(qrand()%32*8,qrand()%32*8,qrand()%32*8), 6) );
    i->setZValue(qrand()%256);
}
Ejemplo n.º 10
0
void GameBoardScene::drawLine(int index, const QColor &colour)
{
	QGraphicsLineItem* line = new QGraphicsLineItem(lineFromIndex(index));
	line->setZValue(10);
	line->setPen(QPen(QBrush(colour), 2.5));
	addItem(line);	//draw new line
	lineList[index] = true;	//keep this table in sync
	indicatorLine->hide();
	update(line->boundingRect());
}
Ejemplo n.º 11
0
// -----------------------------------------------------------------------------
// General.
// -----------------------------------------------------------------------------
ReAnimGraphicsScene::ReAnimGraphicsScene( ReAnimModel* _model, QObject* _parent /* = NULL */ )
: TSuper( _parent )
, m_editMenu( NULL )
{
	const int width = 2000;
	const int height = 2000;
	QColor penColor( 190, 190, 190 );
	setSceneRect( -width / 2, -height / 2, width, height );
	setBackgroundBrush( QBrush( Qt::gray ) );
	QGraphicsLineItem* lineA = addLine( -width / 2, 0, width / 2, 0, QPen( penColor ) );
	lineA->setZValue( -999.0f );
	QGraphicsLineItem* lineB = addLine( 0, -height / 2, 0, height / 2, QPen( penColor ) );
	lineA->setZValue( -999.0f );

	m_editMenu = new QMenu();
	m_createItemAction = m_editMenu->addAction( tr( "&Add Item" ) );
	connect( m_createItemAction, SIGNAL( triggered() ), this, SLOT( OnAddItem() ) );
	m_deleteItemAction = m_editMenu->addAction( tr( "&Delete Item" ) );
	connect( m_deleteItemAction, SIGNAL( triggered() ), this, SLOT( OnDeleteItem() ) );
}
Ejemplo n.º 12
0
void ItemConnection::CreateConnection()
{	// create lines to draw connections
	QPen pen(Qt::red, 2, Qt::SolidLine);
	QGraphicsLineItem* line;
	for (int i = 0; i < 4 ; ++i)
	{
		line = new QGraphicsLineItem(this, scene());
		line->setPen(pen);
		line->setZValue(1.0);
		mChildrens.push_back(line);
	}
}
Ejemplo n.º 13
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);
    }
  }
}
Ejemplo n.º 14
0
// Plugin Interface
void
dmz::QtPluginGraph::update_plugin_state (
    const PluginStateEnum State,
    const UInt32 Level) {

    if (State == PluginStateInit) {

        QColor white (1.0f, 1.0f, 1.0f, 1.0f);
        QPen pen (white);
        QGraphicsLineItem *spacer = new QGraphicsLineItem (0.0f, 0.0f, -40.0f, 0.0f);
        spacer->setPen (pen);
        spacer->setZValue (-1.0f);
        _scene->addItem (spacer);

        spacer = new QGraphicsLineItem (0.0f, -_barHeight, 0.0f, -(_barHeight + 20.0f));
        spacer->setPen (pen);
        spacer->setZValue (-1.0f);
        _scene->addItem (spacer);

        _xAxis = new QGraphicsLineItem (0.0f, 0.0f, _barWidth + _spaceWidth, 0.0f);
        _xAxis->setZValue (1.0);
        _scene->addItem (_xAxis);

        _yAxis = new QGraphicsLineItem (0.0f, 0.0f, 0.0f, -_barHeight);
        _yAxis->setZValue (1.0);
        _scene->addItem (_yAxis);
    }
    else if (State == PluginStateStart) {

    }
    else if (State == PluginStateStop) {

    }
    else if (State == PluginStateShutdown) {

    }
}
Ejemplo n.º 15
0
void
ConfigurationSpaceScene::drawConfigurationEdge(const rl::math::Vector& u, const rl::math::Vector& v, const bool& free)
{
	QGraphicsLineItem* line = this->addLine(
		u(this->x),
		-u(this->y),
		v(this->x),
		-v(this->y),
		free ? QPen(QBrush(QColor(0, 128, 0)), 0.0f) : QPen(QBrush(QColor(128, 0, 0)), 0.0f)
	);
	
	line->setZValue(2);
	
	this->edges.push_back(line);
}
Ejemplo n.º 16
0
void PSV_CircularIndicatorItem::drawMark(int zValue)
{
    double colorCircleRadius = m_colorCircleRadiusRatio * m_outerRadius;
    double value= m_min;
    double dValue = (m_max - m_min) / m_numTicks;
    QString strValue;
    for(int i=0;i<=m_numTicks;i++)
    {
        QPointF topPot;
        QPointF bottomPot;

        if(i%10==0)
        {
            strValue=QObject::tr("%1").arg(value);
            bottomPot = QPointF(m_rect.center().x(), m_rect.center().y() - colorCircleRadius);
            topPot = QPointF(m_rect.center().x(), m_rect.center().y() - colorCircleRadius*1.05);
            value+=10 * dValue;
            QGraphicsTextItem* item = new QGraphicsTextItem(strValue, this);
            item->setDefaultTextColor(QColor(Qt::white));
            item->setFont(m_markFont);
            item->setZValue(zValue);
            QRectF rectF = item->boundingRect();
            QPointF movePointF = QPointF(m_rect.center().x() - 0.5 * rectF.width()
                                         , m_rect.center().y() - colorCircleRadius*1.05 - rectF.height());
            item->moveBy(movePointF.x(), movePointF.y());
            item->setTransform(QTransform().translate(m_rect.center().x() - movePointF.x(), m_rect.center().y() - movePointF.y()).rotate(270 * i / 100-135).translate(-(m_rect.center().x() - movePointF.x()), -(m_rect.center().y() - movePointF.y())));
        }
        else if(i%5==0)
        {
            bottomPot = QPointF(m_rect.center().x(), m_rect.center().y() - colorCircleRadius);
            topPot = QPointF(m_rect.center().x(), m_rect.center().y() - colorCircleRadius*1.03);
        }
        else
        {
            bottomPot = QPointF(m_rect.center().x(), m_rect.center().y() - colorCircleRadius);
            topPot = QPointF(m_rect.center().x(), m_rect.center().y() - colorCircleRadius*1.01);
        }
        QGraphicsLineItem* item = new QGraphicsLineItem(QLineF(topPot, bottomPot), this);
        item->setPen(QPen(Qt::white));
        item->setZValue(zValue);
        item->setTransform(QTransform().translate(m_rect.center().x(), m_rect.center().y()).rotate(270.0 * i / 100-135).translate(-m_rect.center().x(), -m_rect.center().y()));
    }
}
Ejemplo n.º 17
0
void EditorData::pushTargetNodeToRoute(TargetNodePtr tnode)
{
    Route & route = trackData()->route();

    if (route.numNodes())
    {
        TargetNodePtr prev = route.get(route.numNodes() - 1);

        prev->setNext(tnode);
        tnode->setPrev(prev);

        dynamic_cast<TargetNode *>(prev.get())->updateRouteLine();
    }

    const bool loopClosed = route.push(tnode);

    QGraphicsLineItem * routeLine = new QGraphicsLineItem;
    TargetNode * ptr = dynamic_cast<TargetNode *>(tnode.get());
    ptr->setRouteLine(routeLine);

    m_mainWindow->editorScene().addItem(ptr);
    m_mainWindow->editorScene().addItem(routeLine);

    const int routeLineZ = 10;
    ptr->setZValue(routeLineZ);
    routeLine->setZValue(routeLineZ);

    // Check if we might have a loop => end
    if (loopClosed)
    {
        setMode(EditorData::EM_NONE);
        m_mainWindow->endSetRoute();

        TargetNodePtr firstNode = route.get(0);
        route.get(route.numNodes() - 1)->setLocation(firstNode->location());

        tnode->setNext(firstNode);
        firstNode->setPrev(tnode);
    }
}
Ejemplo n.º 18
0
void PSV_CircularIndicatorItem::drawIndicator(int zValue)
{
    QPointF center(0, 0);
    QPointF topPot(center.x(), center.y() - m_colorCircleRadiusRatio * m_outerRadius/*m_coverBallRadius*/);
    QPointF bottomLeftPot(center.x() - m_outerRadius * m_indicatorWidthRatio, center.y());
    QPointF bottomRightPot(center.x() + m_outerRadius * m_indicatorWidthRatio, center.y());

    QLinearGradient indicatorGradient(topPot, bottomLeftPot);
    indicatorGradient.setColorAt(0.0, QColor(236, 187, 62));
    indicatorGradient.setColorAt(0.5, QColor(220, 147, 0));
    indicatorGradient.setColorAt(1.0, QColor(236, 187, 62));

    QPolygonF polygon;
    polygon.append(topPot);
    polygon.append(bottomLeftPot);
    polygon.append(bottomRightPot);
    //    if(m_polygonItem == NULL)
    {
        QGraphicsLineItem *item = new QGraphicsLineItem(this);
        item->setPos(m_rect.center().x(), m_rect.center().y());
        item->setZValue(zValue);
        m_polygonItem = new QGraphicsPolygonItem(item);
    }
    m_polygonItem->setPolygon(polygon);
    m_polygonItem->setPen(QPen(Qt::NoPen));
    m_polygonItem->setBrush(indicatorGradient);
    m_polygonItem->setZValue(zValue);
    qreal angle = (m_value - m_min) / (m_max - m_min) * 270 - 135;
    PSV_Public::printMes(angle,"angle");
#if QT_VERSION > QT_VERSION_CHECK(4, 6, 0)
    m_polygonItem->setRotation(angle);
#else
    m_polygonItem->rotate((m_value - m_min) / (m_max - m_min) * 270 - 135);
#endif

}
Ejemplo n.º 19
0
void NetworkGraphics::updateNetwork(){
	qDebug() << "NetworkGraphics::updateNetwork()";

	scene->clear();
	linkMap.clear();
	rebuildNetwork();

	QPointF position = QPointF(0.0, 0.0);
	QList<raw_address> rootAddrs = network->getTopLevelAddresses();

	for(int i=0; i<rootAddrs.size(); i++){
		if(positionBranch(rootAddrs[i], position)){
			QSizeF size = computeSize(rootAddrs[i]);

			QRectF rect = QRectF(position, size);
			//scene->addRect(rect);*/

			position.setX( position.x() + size.width() + (3.0*CLOUD_X_MARGIN) );

			//scene->update(rect);
		}
	}

	//Draw links
	QList<NetLink*> links = network->getLinks();

	QPen blackPen = QPen();
	blackPen.setColor(Qt::gray);
	blackPen.setWidth(2);


	for(int i=0; i<links.size(); i++){
		NetLink* link = links[i];

		GraphicNetCloud* firstCloud = cloudMap[nodeMap[link->getFirst()]];
		GraphicNetCloud* secondCloud = cloudMap[nodeMap[link->getSecond()]];

		if(firstCloud != secondCloud){

			QPointF startPoint = firstCloud->boundingRect().center();
			QPointF endPoint = secondCloud->boundingRect().center();

			startPoint.setX(firstCloud->pos().x() + startPoint.x());
			startPoint.setY(firstCloud->pos().y() + startPoint.y());

			endPoint.setX(secondCloud->pos().x() + endPoint.x());
			endPoint.setY(secondCloud->pos().y() + endPoint.y());

			QLineF line(startPoint, endPoint);

			QGraphicsLineItem* lineItem = new QGraphicsLineItem(line);
			lineItem->setPen(blackPen);
			lineItem->setZValue(1);
			lineItem->setOpacity(.8);

			scene->addItem(lineItem);

			//qDebug() << "Line: " << line ;

			linkMap.insert(link, lineItem);
		}
	}
}
Ejemplo n.º 20
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;
	}

      }
    }
  }
}
Ejemplo n.º 21
0
void
dmz::QtPluginGraph::_init (Config &local) {

    RuntimeContext *context (get_plugin_runtime_context ());
    Definitions defs (context);

    _scene = new QGraphicsScene;
    _view = new QGraphicsView (_scene);
    _view->setAlignment (Qt::AlignLeft); // | Qt::AlignBottom);

    _typeSet = config_to_object_type_set ("set", local, context);

    if (_typeSet.get_count () == 0) {

        _log.info << "No object types specified. Using root type." << endl;
        _typeSet.add_object_type (defs.get_root_object_type ());
    }

    activate_default_object_attribute (ObjectCreateMask | ObjectDestroyMask);

    Config attrList;

    if (local.lookup_all_config ("attribute", attrList)) {

        ConfigIterator it;

        Config attr;

        while (attrList.get_next_config (it, attr)) {

            const String Type = config_to_string ("type", attr).get_lower ();
            const String AttrName = config_to_string ("name", attr);

            if (AttrName) {

                if (Type == "link") {

                    activate_object_attribute (AttrName, ObjectLinkMask | ObjectUnlinkMask);
                }
                else if (Type == "counter") {

                    activate_object_attribute (AttrName, ObjectCounterMask);
                }
                else {

                    _log.error << "Unknown attribute type: " << Type << endl;
                }
            }
            else {

                _log.error << "Attribute missing name." << endl;
            }
        }
    }

    _ascendingOrder = config_to_boolean ("ascending.value", local, _ascendingOrder);

    _maxCount = config_to_int32 ("start.value", local, _maxCount);

    _showPowerLaw = config_to_boolean ("power-law.show", local, _showPowerLaw);
    _powerStroke = config_to_qpen ("power-law.stroke", local, _powerStroke);
    _barStroke = config_to_qpen ("bar.stroke", local, _barStroke);
    _barFill = config_to_qbrush ("bar.fill", local, _barFill);
    _barWidth = config_to_int32 ("bar.width", local, _barWidth);
    _barHeight = config_to_int32 ("bar.height", local, _barHeight);
    _spaceWidth = config_to_int32 ("bar.space", local, _spaceWidth);
    _steps = config_to_int32 ("bar.steps", local, _steps);

    _yDivisions = config_to_int32 ("bar.divisions", local, _yDivisions);

    _yLabels = new QGraphicsTextItem*[_yDivisions];

    for (Int32 ix = 0; ix < _yDivisions; ix++) {

        const Float32 Offset (-_barHeight * ((Float32)(ix + 1)) / (Float32)_yDivisions);

        _yLabels[ix] = new QGraphicsTextItem;

        _yLabels[ix]->setPlainText (
            QString::number (100 * (ix +1) / _yDivisions) + QString ("%"));
        _yLabels[ix]->setZValue (1.0f);

        QRectF rect = _yLabels[ix]->boundingRect ();

        _yLabels[ix]->setPos (-5.0 - rect.width (), Offset - (rect.height () * 0.5f));

        _scene->addItem (_yLabels[ix]);

        QGraphicsLineItem *line = new QGraphicsLineItem (-4.0, Offset, 0.0f, Offset);
        line->setZValue (1.0f);

        _scene->addItem (line);
    }
}
Ejemplo n.º 22
0
void Gui::createLaserScannerObjects()
{
	// the start position for the pos. calculation
	laserXPos = 0;
	laserYPos = 0;
	//laserFrontYPos = INITIALLASERYPOSFRONT;
	//laserRearYPos  = INITIALLASERYPOSREAR;

	// set some nice colors for some widgets
	colorLaserObstacle =  QColor(255, 50, 50); // light red
	colorLaserFreeWay = Qt::darkRed;
	colorLaserPreferredDrivingDirection = QColor(7, 68, 30); // green
	colorLaserCenterDrivingDirection = Qt::green;
	colorGraphicsSceneBackground = Qt::black;


	// the graphicsScene for the laser scanner
	scene = new LaserScene();

	// set some colors
	scene->setBackgroundBrush(colorGraphicsSceneBackground);

	// turn off moving of scene, when objects extend the scene									-> DISABLED to enable dragging the robot in the laserView!!
	// (set scene rect to size of GUI element)													-> DISABLED to enable dragging the robot in the laserView!!
	//scene->setSceneRect(0, 0, ui.graphicsViewLaser->width(), ui.graphicsViewLaser->height());	-> DISABLED to enable dragging the robot in the laserView!!

	// set scene to the GUI
	ui.graphicsViewLaser->setScene(scene);

	// enable OpenGL rendering with antialiasing (and direct hardware rendering (if supportet from the hardware))
	ui.graphicsViewLaser->setViewport(new QGLWidget(QGLFormat(QGL::DoubleBuffer | QGL::DirectRendering)));


	//=======================================================
	// add robot picture1
	//=======================================================
	// add items to the scene
	pixmapBot1 = new QGraphicsPixmapItem(QPixmap(":/images/images/bot_from_above.png"));

	// init the scale for the laser line / distances drawing stuff
	lastZoom = ui.sliderZoom->value();

	//--------------------------------------------------------------
	// set the start scale
	//--------------------------------------------------------------
	startScale = 10;

	// change scale of the robot pic to 1/10 to fit in the window and to fit on the size of the laser lines
	pixmapBot1->scale( (1.0 / startScale), (1.0 / startScale));

	// horizontal center
	pixmapBot1->setPos(laserXPos, laserYPos);

	// add the pixmap
	scene->addItem(pixmapBot1);

	// put one layer up (layer 2). All others share the same (unset) layer under the pixmap.
	pixmapBot1->setZValue(1);


	//=====================================================
	// create the laser line lists
	//=====================================================
	laserLineListFront = new QList <QGraphicsLineItem*>();
	laserLineListRear = new QList <QGraphicsLineItem*>();


	//-------------------------------------
	// create the FRONT laser line list
	//-------------------------------------
	// TODO: check if always 180 lines!
	// create 180 laser lines (0 to 179)
	for (int i=-90; i<90; i++)
	{
		QGraphicsLineItem *line = new QGraphicsLineItem();

		// the length (and position) of the laser line in pixel
		line->setLine(0,0,0,0);

		// FIXME doest not work: line->setPen(QPen(colorLaserFreeWay, 3));
		line->setPen(QPen(colorLaserFreeWay));

		// set position of each line
		line->rotate(i);

		// put one layer up (layer 2). All others share the same (unset) layer under the pixmap.
		line->setZValue(2);

		// add line to QList
		laserLineListFront->append(line);

		// add line to scene
		scene->addItem(line);
	}


	//-------------------------------------
	// create the REAR laser line list
	//-------------------------------------
	// TODO: check if always 180 lines!
	// create 180 laser lines (0 to 179)
	for (int i=90; i>-90; i--)
	{
		QGraphicsLineItem *line = new QGraphicsLineItem();

		// FIXME doest not work: line->setPen(QPen(colorLaserFreeWay, 3));
		line->setPen(QPen(colorLaserFreeWay));

		// the length (and position) of the laser line in pixel
		line->setLine(0,0,0,0);

		// set position of each line
		line->rotate(i);

		// put one layer up (layer 2). All others share the same (unset) layer under the pixmap.
		line->setZValue(2);

		// add line to QList
		laserLineListRear->append(line);

		// add line to scene
		scene->addItem(line);
	}


	//=======================================================
	// add robot picture2
	//=======================================================
	// add items to the scene
	pixmapBot2 = new QGraphicsPixmapItem(QPixmap(":/images/images/bot_from_above_TOP2.png"));

	// change scale of the robot pic to 1/10 to fit in the window and to fit on the size of the laser lines
	pixmapBot2->scale( (1.0 / startScale), (1.0 / startScale));

	// horizontal center
	pixmapBot2->setPos(laserXPos, laserYPos);

	// add the pixmap
	scene->addItem(pixmapBot2);

	// put one layer up (layer 2). All others share the same (unset) layer under the pixmap.
	pixmapBot2->setZValue(3);
}
Ejemplo n.º 23
0
void PSV_AxisDownItem::updateItem()
{
//    m_markFont.setPointSizeF(m_rect.width() * m_rect.height() * 0.0005);
    updateLabels();
    QPen linePen(QBrush(m_lineColor), m_lineWidth);
    QPen barPen(QBrush(m_markColor), m_markWidth);
    {
        QGraphicsLineItem* lineItem = new QGraphicsLineItem(this);
        lineItem->setPen(linePen);
        lineItem->setLine(m_rect.right() + 2 * m_arrowsLength, m_rect.top()
                          , m_rect.left(), m_rect.top());
        lineItem->setZValue(1);

        QGraphicsLineItem* arrowsItem_up = new QGraphicsLineItem(this);
        arrowsItem_up->setPen(linePen);
        arrowsItem_up->setLine(m_rect.right() + 2 * m_arrowsLength, m_rect.y()
                                 , m_rect.right() + m_arrowsLength, m_rect.y()- 0.5 * m_arrowsLength);
        arrowsItem_up->setZValue(1);

        QGraphicsLineItem* arrowsItem_right = new QGraphicsLineItem(this);
        arrowsItem_right->setPen(linePen);
        arrowsItem_right->setLine(m_rect.right() + 2 * m_arrowsLength, m_rect.y()
                                  , m_rect.right() + m_arrowsLength, m_rect.y() + 0.5 * m_arrowsLength);
        arrowsItem_right->setZValue(1);
    }
    int count = m_labelList.count();
    if(count <= 1)
    {
        return;
    }
    double dx = 0.0;
    double dy = 0.0;
    if(m_isCenter && m_isList)
    {
        dx = 0.5 * m_rect.width() / count;
    }
    else
    {
        count--;
    }

    double oneSpace = m_rect.width() / count;
    m_markPointList.clear();
    bool isRotate = false;
    qreal maxHeight = 0.0;;
    qreal maxWidth = 0.0;;
    if(m_isCenter && m_isList)
    {
        count = m_labelList.count() + 1;
    }
    else
    {
        count = m_labelList.count();
    }

    for(int index = 0; index < m_labelList.count(); ++index)
    {
        QPair<QVariant, QString> labelPair = m_labelList.at(index);
        QGraphicsTextItem* textItem = new QGraphicsTextItem(labelPair.second, this);
        textItem->setDefaultTextColor(m_defaultColor);
        textItem->setFont(m_markFont);
        qreal height = textItem->boundingRect().height();
        qreal width = textItem->boundingRect().width();
        if(index == 0)
        {
            if(width > oneSpace && height < 2*oneSpace)//ФЭК±ґ¦Ан
            {
               isRotate = true;
               maxHeight = width;
               maxWidth = height;
            }
            else
            {
                maxHeight = height;
                maxWidth = width;
            }
        }
        qreal x = m_rect.left() + (index * (m_rect.width())) / (count - 1);
        qreal y = m_rect.top() + m_markLength;
        if(isRotate)
        {
#if QT_VERSION > QT_VERSION_CHECK(4, 6, 0)
            textItem->setRotation(90);
#else
            textItem->rotate(90);
#endif

            textItem->setPos(x + 0.5 * height, y);
            if(maxHeight < width)
            {
                maxHeight = width;
            }
            if(maxWidth < height)
            {
                maxWidth = height;
            }
        }
        else
        {
            textItem->setPos(x - 0.5 * width, y);
            if(maxHeight < height)
            {
                maxHeight = height;
            }
            if(maxWidth < width)
            {
                maxWidth = width;
            }
        }
        textItem->moveBy(dx,dy);
        QGraphicsLineItem *lineItem = new QGraphicsLineItem(this);
        lineItem->setPen(barPen);
        if(index != 0 && index != count -1)
        {
            lineItem->setLine(x - 0.5 * barPen.width(), m_rect.top(), x - 0.5 * barPen.width(), m_rect.top() + m_markLength);
        }
        else
        {
            lineItem->setLine(x, m_rect.top(), x, m_rect.top() + m_markLength);
        }
        m_markPointList.append(QPointF(x - 0.5 * barPen.width(), m_rect.top()));
    }
    //=================
    m_validRect =  QRectF(m_rect.x() - 0.5 * maxWidth
                          ,m_rect.y()
                          ,m_rect.width() + maxWidth
                          ,m_markLength + maxHeight);
//    QGraphicsRectItem *item = new QGraphicsRectItem(m_validRect,this);
}
Ejemplo n.º 24
0
void TerrainProfileGraph::drawHoverCursor(const QPointF& position)
{
  if (_hoverLine)
  {
    _scene->removeItem(_hoverLine);
    delete _hoverLine;
    _hoverLine = 0L;
  }

  if (_graphField.width() < 2 || _graphField.height() < 2)
    return;

  double xPos = position.x() < _graphField.x() ? _graphField.x() : (position.x() > _graphField.x() + _graphField.width() ? _graphField.x() + _graphField.width() : position.x());

  QLineF vLine(xPos, _graphField.y(), xPos, _graphField.y() + _graphField.height());

  QPointF* intersect = new QPointF;
  bool foundIntersect = false;
  for (int i=0; i < _graphLines.count(); i++)
  {
    if (vLine.intersect(_graphLines[i], intersect) == QLineF::BoundedIntersection)
    {
      foundIntersect = true;
      break;
    }
  }

  if (foundIntersect)
  {
    // Draw the upper line segment.  Also serves as the parent item.
    _hoverLine = new QGraphicsLineItem(xPos, _graphField.y(), xPos, intersect->y() - 3);
    _hoverLine->setPen(_hoverPen);
    _hoverLine->setZValue(OVERLAY_Z);
    _scene->addItem(_hoverLine);

    // Draw the box around the intersect point
    QGraphicsRectItem* hoverBox = new QGraphicsRectItem(xPos - 3, intersect->y() - 3, 6, 6);
    hoverBox->setPen(_hoverPen);
    hoverBox->setBrush(Qt::NoBrush);
    hoverBox->setZValue(OVERLAY_Z);
    hoverBox->setParentItem(_hoverLine);

    // Draw the lower line segment
    QGraphicsLineItem* lowerLine = new QGraphicsLineItem(xPos, intersect->y() + 3, xPos, _graphField.y() + _graphField.height() + 5);
    lowerLine->setPen(_hoverPen);
    lowerLine->setZValue(OVERLAY_Z);
    lowerLine->setParentItem(_hoverLine);

    // Draw the text and background
    double y = (1.0 - ((intersect->y() - _graphField.y()) / _graphField.height())) * (_graphMaxY - _graphMinY) + _graphMinY;
    int textOffset = 10;

    QGraphicsSimpleTextItem* hoverText = new QGraphicsSimpleTextItem(QString::number(y) + tr("m"));
    hoverText->setBrush(QBrush(_axesColor));
    hoverText->setFont(_graphFont);
    hoverText->setZValue(OVERLAY_Z);

    if (intersect->x() + textOffset + hoverText->boundingRect().width() < _graphField.x() + _graphField.width())
      hoverText->setPos(intersect->x() + textOffset, intersect->y() - hoverText->boundingRect().height());
    else
      hoverText->setPos(intersect->x() - textOffset - hoverText->boundingRect().width(), intersect->y() - hoverText->boundingRect().height());

    QGraphicsRectItem* hoverTextBackground = new QGraphicsRectItem(hoverText->x() - 3, hoverText->y() - 1, 
                                                                   hoverText->boundingRect().width() + 6,
                                                                   hoverText->boundingRect().height() + 1);
    hoverTextBackground->setPen(_axesPen);
    hoverTextBackground->setBrush(QBrush(_graphColor));
    hoverTextBackground->setZValue(OVERLAY_Z);
    hoverTextBackground->setParentItem(_hoverLine);

    hoverText->setParentItem(_hoverLine);

    // Update callback
    if (_positionCallback.valid())
    {
      double distanceFactor = ((xPos - _graphField.x()) / (double)_graphField.width());

      osg::Vec3d worldStart, worldEnd;
      _calculator->getStart(ALTMODE_ABSOLUTE).toWorld(worldStart);
      _calculator->getEnd(ALTMODE_ABSOLUTE).toWorld(worldEnd);

      double worldX = (worldEnd.x() - worldStart.x()) * distanceFactor + worldStart.x();
      double worldY = (worldEnd.y() - worldStart.y()) * distanceFactor + worldStart.y();
      double worldZ = (worldEnd.z() - worldStart.z()) * distanceFactor + worldStart.z();

      GeoPoint mapPos;
      mapPos.fromWorld(_calculator->getStart().getSRS(), osg::Vec3d(worldX, worldY, worldZ));

      _positionCallback->updatePosition(mapPos.y(), mapPos.x(), hoverText->text().toStdString());
    }
  }
  else
  {
    // No intersect found so just draw the full line at xPos
    _hoverLine = new QGraphicsLineItem(xPos, _graphField.y(), xPos, _graphField.y() + _graphField.height() + 5);
    _hoverLine->setPen(_hoverPen);
    _hoverLine->setZValue(OVERLAY_Z);
    _scene->addItem(_hoverLine);
  }

  // Draw distance text
  double x = ((xPos - _graphField.x()) / _graphField.width()) * _totalDistance;

  BoxedSimpleTextItem* distanceText = new BoxedSimpleTextItem(QString::number(x / 1000.0, 'f', 2) + tr("km"), _backgroundColor);
  distanceText->setBrush(QBrush(_axesColor));
  distanceText->setFont(_graphFont);
  distanceText->setZValue(OVERLAY_Z);
  if(xPos - 2 - distanceText->boundingRect().width() > _graphField.x())
  {
      distanceText->setPos(xPos - 2 - distanceText->boundingRect().width(), _graphField.y() + _graphField.height() + 2);
  }
  else
  {
      distanceText->setPos(xPos + 2, _graphField.y() + _graphField.height() + 2);
  }
  distanceText->setParentItem(_hoverLine);

  // Draw selection box
  drawSelectionBox(xPos);

  delete intersect;
}
Ejemplo n.º 25
-1
    void WeekScene::addCalendar()
    {
        const KCalendarSystem* cal = KGlobal::locale()->calendar();

        QGraphicsTextItem* tmp = addText("Dinges");
        QFontMetricsF fm(tmp->font());
        removeItem(tmp);
        delete tmp;


        // first add 7 rectangles for each day of the week
        xoff = fm.width("00:00") + 10;
        yoff = 2 * fm.height() + 10;
        day_width = LongestDayWidth(fm) * 1.5;
        hour_height = fm.height() * 1.5;

        status = addText(i18n("Current schedule:"));
        status->setPos(QPointF(0, 0));
        status->setZValue(2);

        QPen pen(SchedulerPluginSettings::scheduleLineColor());
        QBrush brush(SchedulerPluginSettings::scheduleBackgroundColor());

        for (int i = 0; i < 7; i++)
        {
            QGraphicsRectItem* item = addRect(xoff + day_width * i, yoff, day_width, 24 * hour_height, pen, brush);
            item->setZValue(1);

            QString day = cal->weekDayName(i + 1);

            // make sure day is centered in the middle of the column
            qreal dlen = fm.width(day);
            qreal mid = xoff + day_width * (i + 0.5);
            qreal start = mid - dlen * 0.5;

            QGraphicsTextItem* t = addText(day);
            t->setPos(QPointF(start, fm.height() + 5));
            t->setZValue(2);

            rects.append(item);
        }

        // draw hour lines
        for (int i = 0; i <= 24; i++)
        {
            QGraphicsLineItem* item = addLine(0, yoff + i * hour_height, xoff + 7 * day_width, yoff + i * hour_height, pen);
            item->setZValue(2);

            if (i < 24)
            {
                QGraphicsTextItem* t = addText(QString("%1:00").arg(i));
                t->setPos(QPointF(0, yoff + i * hour_height));
                t->setZValue(2);
            }
            lines.append(item);
        }

        ;
        gline[0] = new GuidanceLine(xoff, yoff, xoff + 7 * day_width + 10);
        gline[0]->setVisible(false);
        gline[1] = new GuidanceLine(xoff, yoff, xoff + 7 * day_width + 10);
        gline[1]->setVisible(false);
        addItem(gline[0]);
        addItem(gline[1]);

        QRectF r = sceneRect();
        r.setHeight(r.height() + 10);
        setSceneRect(r);
    }