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(); }
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; } } } }
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; }