Esempio n. 1
0
void vogleditor_QTimelineView::paint(QPainter *painter, QPaintEvent *event)
{
    int gap = 10;
    int arrowHeight = 10;
    int arrowTop = event->rect().height()/2-gap-arrowHeight;
    int arrowHalfWidth = 3;
     m_lineLength = event->rect().width()-2*gap;

    QPolygon triangle(3);
    triangle.setPoint(0, 0, arrowTop);
    triangle.setPoint(1, -arrowHalfWidth, arrowTop+arrowHeight);
    triangle.setPoint(2, arrowHalfWidth, arrowTop+arrowHeight);

    drawBaseTimeline(painter, event->rect(), gap);

    if (m_pModel == NULL)
    {
        return;
    }

    if (m_pModel->get_root_item() == NULL)
    {
        return;
    }

    if (m_pPixmap != NULL)
    {
        int rectHeight = event->rect().height();
        int rectWidth = event->rect().width();
        int pmHeight = m_pPixmap->height();
        int pmWidth = m_pPixmap->width();

        float widthPctDelta = (float)(rectWidth - pmWidth) / (float)pmWidth;
        float heightPctDelta = (float)(rectHeight - pmHeight) / (float)pmHeight;

        // If the resize is of a 'signficant' amount, then delete the pixmap so that it will be regenerated at the new size.
        if (fabs(widthPctDelta) > 0.2 ||
            fabs(heightPctDelta) > 0.2)
        {
            deletePixmap();
        }
    }

    if (m_pPixmap == NULL)
    {
        m_pPixmap = new QPixmap(event->rect().width(), event->rect().height());
        QPainter pixmapPainter(m_pPixmap);
        drawBaseTimeline(&pixmapPainter, event->rect(), gap);

        // translate drawing to vertical center of rect
        // everything will have a small gap on the left and right sides
        pixmapPainter.translate(gap, event->rect().height()/2);

        if (m_pModel->get_root_item()->getBrush() == NULL)
        {
            m_pModel->get_root_item()->setBrush(&m_triangleBrush);
        }

        m_horizontalScale = (float)m_lineLength / (float)m_pModel->get_root_item()->getDuration();

        // we don't want to draw the root item, but all of its children
        int numChildren = m_pModel->get_root_item()->childCount();
        int height = event->rect().height()/2-2*gap;

        pixmapPainter.setBrush(m_triangleBrush);
        pixmapPainter.setPen(m_trianglePen);

        float minimumOffset = 0;
        for (int c = 0; c < numChildren; c++)
        {
            vogleditor_timelineItem* pChild = m_pModel->get_root_item()->child(c);
            drawTimelineItem(&pixmapPainter, pChild, height, minimumOffset);
        }
    }

    painter->drawPixmap(event->rect(), *m_pPixmap, m_pPixmap->rect());

    // translate drawing to vertical center of rect
    // everything will have a small gap on the left and right sides
    painter->translate(gap, event->rect().height()/2);

    painter->setBrush(m_triangleBrush);
    painter->setPen(m_trianglePen);

    int numChildren = m_pModel->get_root_item()->childCount();
    for (int c = 0; c < numChildren; c++)
    {
        vogleditor_timelineItem* pChild = m_pModel->get_root_item()->child(c);

        // draw current frame marker
        if (pChild->getFrameItem() != NULL && pChild->getFrameItem()->frameNumber() == m_curFrame)
        {
            painter->save();
            painter->translate(scalePositionHorizontally(pChild->getBeginTime()), 0);
            painter->drawPolygon(triangle);
            painter->restore();
        }

        // draw current api call marker
        if (pChild->getApiCallItem() != NULL && pChild->getApiCallItem()->globalCallIndex() == m_curApiCallNumber)
        {
            painter->save();
            painter->translate(scalePositionHorizontally(pChild->getBeginTime()), 0);
            painter->drawPolygon(triangle);
            painter->restore();
        }
    }
}
void vogleditor_QTimelineView::paint(QPainter *painter, QPaintEvent *event)
{
    m_gap = 10;
    int arrowHeight = 10;
    int arrowTop = height() / 2 - m_gap - arrowHeight;
    int arrowHalfWidth = 3;
    m_lineLength = (double)width()*(double)m_zoom - 2 * m_gap;

    QPolygon triangle(3);
    triangle.setPoint(0, 0, arrowTop);
    triangle.setPoint(1, -arrowHalfWidth, arrowTop + arrowHeight);
    triangle.setPoint(2, arrowHalfWidth, arrowTop + arrowHeight);

    painter->save();
    painter->translate(-m_scroll, 0);    
    drawBaseTimeline(painter, event->rect(), m_gap);
    //Go back to unscrolled coordinates to paint the pixmap to the widget.
    painter->restore();

    if (m_pModel == NULL)
    {
        return;
    }

    if (m_pModel->get_root_item() == NULL)
    {
        return;
    }

    if (m_pPixmap == NULL)
    {
        m_timelineItemPosCache.clear();
        m_pPixmap = new QPixmap(event->rect().width(), event->rect().height());
        m_pPixmap->fill(Qt::transparent);
        QPainter pixmapPainter(m_pPixmap);

        //Apply the scroll translation:
        pixmapPainter.translate(-m_scroll, 0);
        // translate drawing to vertical center of rect
        // everything will have a small gap on the left and right sides
        pixmapPainter.translate(m_gap, height() / 2);

        m_horizontalScale = (double)m_lineLength / (double)m_pModel->get_root_item()->getDuration();

        // we don't want to draw the root item, but all of its children
        int numChildren = m_pModel->get_root_item()->childCount();
        int i_height = height() / 2 - 2 * m_gap;

        pixmapPainter.setBrush(m_triangleBrushWhite);
        pixmapPainter.setPen(m_trianglePen);

        double minimumOffset = 0;
        vogleditor_timelineItem *rootItem = m_pModel->get_root_item();
        for (int c = 0; c < numChildren; c++)
        {
            vogleditor_timelineItem *pChild = rootItem->child(c);
            drawTimelineItem(&pixmapPainter, pChild, i_height, minimumOffset);
        }
    }

    painter->drawPixmap(event->rect(), *m_pPixmap, m_pPixmap->rect());

    painter->translate(-m_scroll, 0);
    painter->setBrush(m_triangleBrushWhite);
    painter->setPen(m_trianglePen);

    // translate drawing to vertical center of rect
    // everything will have a small gap on the left and right sides
    painter->translate(m_gap, height() / 2);

    if (m_curFrameTime!=-1)
    {
        painter->save();
        //translate to the point to draw marker
        painter->translate(scalePositionHorizontally(m_curFrameTime), 0);
        painter->setBrush(m_triangleBrushBlack);
        painter->drawPolygon(triangle);
        painter->restore();
    }

    // draw current api call marker
    if (m_curApiCallTime!=-1)
    {
        double xpos = scalePositionHorizontally(m_curApiCallTime);
        xpos -= m_roundoff;

        painter->save();
        //translate to the point to draw marker
        painter->translate(xpos, 0);
        painter->drawPolygon(triangle);
        painter->restore();
    }
}