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