Esempio n. 1
0
void LinePath::setLineWidth( uint width ) {
    QCanvasLine * line = 0;
    QColor linecolor;
    LineListIt it( m_LineList );
    while( ( line = it.current() ) ) {
        linecolor = line->pen().color();
        line -> setPen( QPen( linecolor, width ) );
        ++it;
    }
    LineListIt hit( m_HeadList );
    while( ( line = hit.current() ) ) {
        linecolor = line->pen().color();
        line -> setPen( QPen( linecolor, width ) );
        ++hit;
    }
    LineListIt pit( m_ParallelList );
    while( ( line = pit.current() ) ) {
        linecolor = line->pen().color();
        line -> setPen( QPen( linecolor, width ) );
        ++pit;
    }

    if( m_pCircle ) {
        linecolor = m_pCircle->pen().color();
        m_pCircle->setPen( QPen(linecolor, width) );
    }
}
Esempio n. 2
0
void LinePath::setLineColor( const QColor &color ) {
    QCanvasLine * line = 0;
    uint linewidth = 0;
    LineListIt it( m_LineList );
    while( ( line = it.current() ) ) {
        linewidth = line->pen().width();
        line -> setPen( QPen( color, linewidth ) );
        ++it;
    }
    LineListIt hit( m_HeadList );
    while( ( line = hit.current() ) ) {
        linewidth = line->pen().width();
        line -> setPen( QPen( color, linewidth ) );
        ++hit;
    }
    LineListIt pit( m_ParallelList );
    while( ( line = pit.current() ) ) {
        linewidth = line->pen().width();
        line -> setPen( QPen( color, linewidth ) );
        ++pit;
    }

    if( getAssocType() == Uml::at_Aggregation )
        if (m_pClearPoly) m_pClearPoly -> setBrush( QBrush( Qt::white ) );
        else if( getAssocType() == Uml::at_Composition )
            if (m_pClearPoly) m_pClearPoly -> setBrush( QBrush( color ) );

    if( m_pCircle ) {
        linewidth = m_pCircle->pen().width();
        m_pCircle->setPen( QPen(color, linewidth) );
    }
}
Esempio n. 3
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();
}
Esempio n. 4
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;
			}
		}
	}
}
Esempio n. 5
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();

    }
}
Esempio n. 6
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);
}
Esempio n. 7
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;
}
Esempio n. 8
0
void LinePath::updateHead() {
    int count = m_HeadList.count();
    QCanvasLine * line = 0;

    switch( getAssocType() ) {
    case Uml::at_State:
    case Uml::at_Activity:
    case Uml::at_UniAssociation:
    case Uml::at_Dependency:
        if( count < 2)
            return;
        line = m_HeadList.at( 0 );
        line -> setPoints( m_EgdePoint.x(), m_EgdePoint.y(), m_ArrowPointA.x(), m_ArrowPointA.y() );

        line = m_HeadList.at( 1 );
        line -> setPoints( m_EgdePoint.x(), m_EgdePoint.y(), m_ArrowPointB.x(), m_ArrowPointB.y() );
        break;

    case Uml::at_Relationship:
        if (count < 2) {
            return;
        }
        {
            int xoffset = 0;
            int yoffset = 0;
            if( m_DockRegion == TopBottom )
                xoffset = 8;
            else
                yoffset = 8;
            line = m_HeadList.at( 0 );
            line->setPoints( m_PointArray[2].x(), m_PointArray[2].y(),
                             m_PointArray[0].x()-xoffset, m_PointArray[0].y()-yoffset );

            line = m_HeadList.at( 1 );
            line->setPoints( m_PointArray[2].x(), m_PointArray[2].y(),
                             m_PointArray[0].x()+xoffset, m_PointArray[0].y()+yoffset );
        }

    case Uml::at_Generalization:
    case Uml::at_Realization:
        if( count < 3)
            return;
        line = m_HeadList.at( 0 );
        line -> setPoints( m_EgdePoint.x(), m_EgdePoint.y(), m_ArrowPointA.x(), m_ArrowPointA.y() );

        line = m_HeadList.at( 1 );
        line -> setPoints( m_EgdePoint.x(), m_EgdePoint.y(), m_ArrowPointB.x(), m_ArrowPointB.y() );

        line = m_HeadList.at( 2 );
        line -> setPoints( m_ArrowPointA.x(), m_ArrowPointA.y(), m_ArrowPointB.x(), m_ArrowPointB.y() );
        m_pClearPoly -> setPoints( m_PointArray );
        break;

    case Uml::at_Composition:
    case Uml::at_Aggregation:
        if( count < 4)
            return;
        line = m_HeadList.at( 0 );
        line -> setPoints( m_PointArray[ 0 ].x(), m_PointArray[ 0 ].y(), m_PointArray[ 1 ].x(), m_PointArray[ 1 ].y() );

        line = m_HeadList.at( 1 );
        line -> setPoints( m_PointArray[ 1 ].x(), m_PointArray[ 1 ].y(), m_PointArray[ 2 ].x(), m_PointArray[ 2 ].y() );

        line = m_HeadList.at( 2 );
        line -> setPoints( m_PointArray[ 2 ].x(), m_PointArray[ 2 ].y(), m_PointArray[ 3 ].x(), m_PointArray[ 3 ].y() );

        line = m_HeadList.at( 3 );
        line -> setPoints( m_PointArray[ 3 ].x(), m_PointArray[ 3 ].y(), m_PointArray[ 0 ].x(), m_PointArray[ 0 ].y() );
        m_pClearPoly -> setPoints( m_PointArray );
        break;

    case Uml::at_Containment:
        if (count < 1)
            return;
        line = m_HeadList.at( 0 );
        line->setPoints( m_PointArray[ 1 ].x(), m_PointArray[ 1 ].y(),
                         m_PointArray[ 3 ].x(), m_PointArray[ 3 ].y() );
        m_pCircle -> setX( m_MidPoint.x() );
        m_pCircle -> setY( m_MidPoint.y() );
        break;
    default:
        break;
    }
}