Пример #1
0
void Main::addLine()
{
    QCanvasLine* i = new QCanvasLine(&canvas);
    i->setPoints( rand()%canvas.width(), rand()%canvas.height(),
		  rand()%canvas.width(), rand()%canvas.height() );
    i->setPen( QPen(QColor(rand()%32*8,rand()%32*8,rand()%32*8), 6) );
    i->setZ(rand()%256);
    i->show();
}
Пример #2
0
void ScheduleDialog::drawRuler(DrawProperties *p)
{
    // draw ruler
    QFont font = QApplication::font();
    font.setPointSize(font.pointSize() - 2);

    int x = p->x + p->nameWidth;
    int currNs = 0;

    double nsPer100 = RULER_INTERVAL * (1.0 / (p->pixPerNs * zoom_));
    int rulerTick = (((int)nsPer100 / RULER_SNAP)+1) * RULER_SNAP;

    while (x < p->width) {
        x += (int)(p->pixPerNs * zoom_ * rulerTick);
        currNs += rulerTick;

        // draw short line
        QCanvasLine *tick = new QCanvasLine(p->canvas);
        tick->setPoints(x, p->y, x, p->y + 10);
        tick->setPen(gray);
        tick->show();

        // draw long line
        tick = new QCanvasLine(p->canvas);
        tick->setPoints(x, p->y + 10, x, p->y + p->height);
        tick->setPen(lightGray);
        tick->show();

        QCanvasText *text = new QCanvasText(formatTimeProperly(currNs),
                                            p->canvas);
        text->move(x + WIDGET_SPACING / 2, p->y + 1);
        text->setColor(gray);

        text->setFont(font);

        text->show();

    }
}
Пример #3
0
void View::contentsMousePressEvent(QMouseEvent *e)
{
	if (e->button()==LeftButton){
		if (!started){
			end = new QPoint(e->x(),e->y());
			started=true;
			#ifdef MYDEBUG	
			cout << end->x() << " and " << end->y() << endl;
			cout << "you are the first time" << endl;
			#endif
		}
		else
		{
			start = end;
			end = new QPoint(e->x(),e->y());
			#ifdef MYDEBUG
			cout << "start is (" << start->x() << "," << start->y() << ") and end is (" << end->x() << "," << end->y() << ")" << endl;
			#endif
			QCanvasLine *i = new QCanvasLine(canvas());
			i->setPoints(start->x(),start->y(),end->x(),end->y());
			i->setPen(blue);
			i->setZ(2);
			i->show();
		}
	}
	else if (e->button()==RightButton)
	{
		started=false;
		QCanvasItemList list=canvas()->allItems();
		for (QCanvasItemList::Iterator it=list.begin();it!=list.end();it++)
		{
			if (*it){
				delete *it;
			}
		}
	}
}
Пример #4
0
void ScheduleDialog::print()
{
    PrintManager printer(project_->name());
    if (!printer.setup()) return;

    QPaintDeviceMetrics *metrics = printer.getMetrics();
    int printCanvasWidth = metrics->width();
    delete metrics;

    int tableHeight = (blocks_.count() + 1) * PRINT_ITEM_HEIGHT;
    QCanvas *printCanvas = new QCanvas(printCanvasWidth,
        tableHeight + PRINT_ITEM_HEIGHT + canvas->height());

    // first draw timing table
    int y = 0;
    Q_ASSERT(timingTable->numCols() == 4);
    int xOfs[6] = {0,       // x offsets of the columns
                   printCanvasWidth * 1/20,
                   printCanvasWidth * 4/10,
                   printCanvasWidth * 6/10,
                   printCanvasWidth * 8/10,
                   printCanvasWidth - 1};

    QCanvasLine *line = new QCanvasLine(printCanvas);
    line->setPoints(xOfs[0], y, xOfs[5], y);
    line->setPen(gray);
    line->show();

    // print header and vertical lines
    for (int i = 0; i <= 5; i++) {
        if ((i > 0) && (i < 5)) {
            QCanvasText* text = new QCanvasText(
                timingTable->horizontalHeader()->label(i - 1), printCanvas);
            text->move(xOfs[i] + PRINT_SPACING, y + PRINT_SPACING);
            text->show();
        }

        line = new QCanvasLine(printCanvas);
        line->setPoints(xOfs[i], y, xOfs[i], y + tableHeight);
        line->setPen(gray);
        line->show();
    }
    y += PRINT_ITEM_HEIGHT;

    // now print contents
    int row = 0;
    QValueList<BlockNode*>::Iterator it;
    for (it = blocks_.begin(); it != blocks_.end(); ++it) {
        // number
        QCanvasText* text;
        text = new QCanvasText(QString::number(row + 1), printCanvas);
        text->move(xOfs[0] + PRINT_SPACING, y + PRINT_SPACING);
        text->show();

        // other contents
        for (int i = 1; i <= 4; i++) {
            text = new QCanvasText(timingTable->text(row, i - 1), printCanvas);
            text->move(xOfs[i] + PRINT_SPACING, y + PRINT_SPACING);
            text->show();
        }

        // horizontal line
        line = new QCanvasLine(printCanvas);
        line->setPoints(xOfs[0], y, xOfs[5], y);
        line->setPen(gray);
        line->show();

        y += PRINT_ITEM_HEIGHT;
        row++;
    }

    line = new QCanvasLine(printCanvas);
    line->setPoints(xOfs[0], y, xOfs[5], y);
    line->setPen(gray);
    line->show();
    y += PRINT_ITEM_HEIGHT;

    // properties for the graph
    DrawProperties p;
    p.nameWidth = PRINT_NAME_WIDTH;
    p.x = 0;
    p.y = y;
    p.width = printCanvasWidth;
    p.height = canvas->height();
    p.canvas = printCanvas;

    // now draw graph
    unsigned int max_clock = 0;
    for (it = blocks_.begin(); it != blocks_.end(); ++it) {
        max_clock = QMAX(max_clock, (*it)->clock());
    }
    p.pixPerNs = (max_clock > 0)
        ? (double)canvas->width() / (max_clock * BLOCKS_PER_CANVAS)
        : 1.0;
    drawRuler(&p);
    for (it = blocks_.begin(); it != blocks_.end(); ++it) {
        drawTimings(&p, *it);
    }

    // finally print canvas
    printer.print(printCanvas);
}
Пример #5
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;
}