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(); }
void Main::addText() { QCanvasText* i = new QCanvasText(&canvas); i->setText("QCanvasText"); i->move(rand()%canvas.width(),rand()%canvas.height()); i->setZ(rand()%256); i->show(); }
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(); } }
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); }
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; }