Ejemplo n.º 1
0
void ReportCanvas::contentsMouseMoveEvent( QMouseEvent* e ) {
	QPoint p = inverseWorldMatrix().map( e->pos() );

	/*    QCanvasItemList l=canvas()->collisions(p);
	  setCursor(QCursor(Qt::ArrowCursor));
	    unsetCursor();
	    for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
	    { 
		if ((*it)->rtti() > 2000)
		{
		    CanvasReportItem *item = (CanvasReportItem*)(*it);
		    if (item->bottomRightResizableRect().contains(e->pos()))
			setCursor(QCursor(Qt::SizeFDiagCursor));
		}
	    }*/

	if ( moving ) {
		moving->moveBy( p.x() - moving_start.x(),
		                p.y() - moving_start.y() );
		/*	attempt to prevent item collisions
		        QCanvasItemList l=canvas()->collisions(moving->rect());
			if (l.count() > 2)
			{
			    moving->moveBy(-(p.x() - moving_start.x()),
					   -(p.y() - moving_start.y()));
			    canvas()->update();
			    return;
			}*/
		moving_start = p;
		moving->updateGeomProps();
		canvas() ->update();
	}
	if ( resizing ) {
		QCanvasRectangle * r = ( QCanvasRectangle * ) resizing;
		int w = r->width() + p.x() - moving_start.x();
		int h = r->height() + p.y() - moving_start.y();
		if ( ( w > 10 ) && ( h > 10 ) )
			r->setSize( w, h );
		moving_start = p;
		resizing->updateGeomProps();
		canvas() ->update();
	}
}
Ejemplo n.º 2
0
void ScheduleDialog::drawTimings(DrawProperties *p, BlockNode* node)
{
    int line = blocks_.findIndex(node);
    int y = p->y + line * (BOX_HEIGHT + BOX_YSPACING) + RULER_HEIGHT;
    // if nameWidth is set the name should be drawn within the graph canvas
    if (p->nameWidth == 0) {
        // draw labels
        QCanvasText* text = new QCanvasText(node->model()->name(), labelCanvas);
        text->move(WIDGET_SPACING, y);
        text->show();

        // resize canvas if label doesn't fit.
        if ((int)(text->boundingRect().width() + 2 * WIDGET_SPACING)
            > labelCanvas->width())
        {
            labelCanvas->resize(text->boundingRect().width()
                                + (2 * WIDGET_SPACING), labelCanvas->height());
            labelCanvasView->setFixedWidth(labelCanvas->width() + 4);
        }
    } else {
        // draw labels
        QCanvasText* text = new QCanvasText(node->model()->name(), p->canvas);
        text->move(p->x, y);
        text->show();
    }

    // check if block is configured correctly
    if (node->clock() <= 0) {
        // draw info and skip
        QCanvasRectangle *box = new QCanvasRectangle(p->canvas);
        box->setSize(p->width - p->nameWidth, BOX_HEIGHT + BOX_YSPACING);
        box->setBrush(white);
        box->setPen(lightGray);
        box->move(p->x + p->nameWidth, RULER_HEIGHT - BOX_YSPACING
                  / 2 + line * (BOX_YSPACING + BOX_HEIGHT));
        box->setZ(2);
        box->show();

        QCanvasText *text = new QCanvasText(tr("Missing clock value."),
            p->canvas);
        text->move(p->x + p->nameWidth, y);
        text->setColor(black);
        text->setZ(3);
        text->show();
        return;
    }

    // draw blocks
    int t = node->offset();
    double X = t * p->pixPerNs;
    while (X < p->width - p->nameWidth) {
        // draw block
        QRect thisBlock = calcBlockPosition(p, node, t);
        QCanvasRectangle* box = new FancyRectangle(thisBlock, p->canvas);
        //        box->setBrush(QBrush(white));
        box->setBrush(QBrush(colormanager_->color(node->model())));
        box->setZ(2);
        box->show();

        // draw lines for all connected 'children'
        QPtrList<BlockNode> neighbours = node->neighbours();
        for (QPtrListIterator<BlockNode> it(neighbours); it != 0; ++it) {
            BlockNode *target = *it;

            // skip if child has no clock
            if (target->clock() <= 0) {
                continue;
            }

            // find next start time for the target block
            unsigned int targetTime = target->offset();
            while (targetTime <= t + node->runtime()) {
                targetTime += target->clock();
            }

            // check if this block is the next source for the target block
            if (t + (2 * node->runtime()) + node->clock() < targetTime) {
                continue;
            }

            // calculate position of the target block
            QRect targetBlock = calcBlockPosition(p, target, targetTime);

            // draw a line with arrowhead between this block and the next
            // target block.
            QCanvasLine *line = new ArrowLine(p->canvas);
            int start = thisBlock.x() + (int)rint(node->runtime() * p->pixPerNs * zoom_);
            line->setPoints(start,
                            thisBlock.y() + thisBlock.height(),
                            targetBlock.x(),
                            targetBlock.y());
            line->setZ(1);
            line->show();
        }

        t += node->clock();
        X = rint(t * p->pixPerNs);
    }

    return;
}