コード例 #1
0
ファイル: canvas.cpp プロジェクト: Albermg7/boost
void Canvas::redraw()
{
    QCanvasItemList l = m_canvas->allItems();    
    for(QCanvasItemList::iterator i = l.begin(),
            e = l.end(); i != e; ++i)
    {
        delete *i;
    }
    
    unsigned count = 0;
    for (unsigned x = 10; x < 4*1600; x += 20)
        for (unsigned y = 10; y < 600; y += 20) {
            QCanvasRectangle* r = new QCanvasRectangle(x, y, 10, 10, m_canvas);
            r->setPen(m_pen);
            r->setBrush(m_brushes[m_current_brush]);
            r->show();  
            ++count;  
            QCanvasText* t = new QCanvasText("D", m_canvas);
            t->move(x, y);
            t->show();
            ++count;
        }
    
    (new QCanvasText(QString::number(count), m_canvas))->show();
    m_canvas->setAllChanged();

}
コード例 #2
0
QCanvasRectangle * KGrCanvas::drawRectangle (int z, int x, int y, int w, int h)
{
    QCanvasRectangle * r = new QCanvasRectangle (x, y, w, h, field);

    r->setBrush (QBrush (colour));
    r->setPen (QPen (NoPen));
    r->setZ (z);
    r->show();

    return (r);
}
コード例 #3
0
ファイル: cv.cpp プロジェクト: Miguel-J/eneboo-core
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();
	}
}
コード例 #4
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;
}