コード例 #1
0
void ListItemCache::draw(QPainter * painter) 
{
    QRectF irect = sourceBoundingRect(Qt::LogicalCoordinates);
    QRectF vrect = painter->clipPath().boundingRect();

    if (vrect.intersects(irect)) {
        QRectF newVisibleRect = irect.intersected(vrect);
        QPixmap pixmap;

        if (!QPixmapCache::find(m_cacheKey, &pixmap) ||
            m_visibleRect.toRect() != newVisibleRect.toRect()) {
            //qDebug() << "ListItemCache: caching" << m_visibleRect
            //    << "->" << newVisibleRect;

            pixmap = QPixmap(sourceBoundingRect().toRect().size());
            pixmap.fill(Qt::transparent);

            QPainter pixmapPainter(&pixmap);
            drawSource(&pixmapPainter);
            pixmapPainter.end();
            m_cacheKey = QPixmapCache::insert(pixmap);

            m_visibleRect = newVisibleRect;
        }

        //qDebug() << "ListItemCache: blitting" << m_visibleRect;
        painter->drawPixmap(0, 0, pixmap);
    } 
}
コード例 #2
0
ファイル: kstartuplogo.cpp プロジェクト: CGenie/kmymoney
KStartupLogo::KStartupLogo() :
    QObject(0),
    m_splash(0)
{
  // splash screen setting
  if (!KMyMoneyGlobalSettings::showSplash())
    return;

  QString filename = KGlobal::dirs()->findResource("appdata", "pics/startlogo.png");
  QString localeFilename = KGlobal::locale()->localizedFilePath(filename);
  QPixmap logoOverlay(localeFilename);

  QPixmap logoPixmap(logoOverlay.size());
  logoPixmap.fill(KColorScheme(QPalette::Active, KColorScheme::Selection).background(KColorScheme::NormalBackground).color());
  QPainter pixmapPainter(&logoPixmap);
  pixmapPainter.drawPixmap(0, 0, logoOverlay, 0, 0, logoOverlay.width(), logoOverlay.height());

  if (!logoOverlay.isNull()) {
    const KAboutData *aboutData = KCmdLineArgs::aboutData();
    KSplashScreen* splash = new KSplashScreen(logoPixmap);
    splash->setFixedSize(logoPixmap.size());

    splash->show();
    splash->showMessage(i18n("Loading %1...", aboutData->version()),  //krazy:exclude=qmethods
                        Qt::AlignLeft | Qt::AlignBottom,
                        KColorScheme(QPalette::Active, KColorScheme::Selection)
                        .foreground(KColorScheme::NormalText).color());
    m_splash = splash;
  }
}
コード例 #3
0
void ColorWidget::drawThumbnail(QPainter *painter, const QColor &color, const QPalette &palette, const QRect &rectangle)
{
	painter->save();

	if (color.alpha() < 255)
	{
		QPixmap pixmap(10, 10);
		pixmap.fill(Qt::white);

		QPainter pixmapPainter(&pixmap);
		pixmapPainter.setBrush(Qt::gray);
		pixmapPainter.setPen(Qt::NoPen);
		pixmapPainter.drawRect(0, 0, 5, 5);
		pixmapPainter.drawRect(5, 5, 5, 5);
		pixmapPainter.end();

		painter->setBrush(pixmap);
		painter->setPen(Qt::NoPen);
		painter->drawRoundedRect(rectangle, 2, 2);
	}

	painter->setBrush(color);
	painter->setPen(palette.color(QPalette::Button));
	painter->drawRoundedRect(rectangle, 2, 2);
	painter->restore();
}
コード例 #4
0
ファイル: EarthquakeItem.cpp プロジェクト: MChemodanov/marble
void EarthquakeItem::paint( GeoPainter *painter, ViewportParams *viewport,
                            const QString& renderPos, GeoSceneLayer * layer )
{
    Q_UNUSED( viewport )
    Q_UNUSED( renderPos )
    Q_UNUSED( layer )

    // Save the old painter state.
    painter->save();
    painter->autoMapQuality();

    // Draw the arch into the given rect.
    qreal width = magnitude() * 10;
    qreal height = magnitude() * 10;

    // Draws the circle with circles' center as rectangle's top-left corner.
    QRect arcRect( 0, 0, width, height );
    QColor color = oxygenBrickRed4;
    if ( magnitude() < 5.0 ) {
        color = oxygenSunYellow6;
    } else if ( magnitude() < 6.0 ) {
        color = oxygenHotOrange4;
    }
    painter->setPen( QPen( Qt::NoPen ) );
    QBrush brush( color );
    brush.setColor( color );
    painter->setBrush( brush );
    painter->drawEllipse( arcRect );

    // Draws the seismograph
    if ( m_seismograph.isNull() ) {
        m_seismograph = QPixmap( width, height );
        QSvgRenderer renderer( QString( ":/seismograph.svg" ) );
        m_seismograph.fill( Qt::transparent );
        QPainter pixmapPainter( &m_seismograph );
        renderer.render( &pixmapPainter, QRectF( 0.0, 0.0, width, height ) );
    }
    painter->drawPixmap( 0, 0, m_seismograph );

    // Draws magnitude of the earthquake
    QFontMetrics metrics( s_font );
    QString magnitudeText = QString::number( magnitude() );
    QRect magnitudeRect = metrics.boundingRect( magnitudeText );
    painter->setBrush( QBrush() );
    painter->setPen( QPen() );
    painter->setFont( s_font );
    painter->drawText( QPoint( (arcRect.width() - magnitudeRect.width()) / 2, (arcRect.height() - magnitudeRect.height()) / 2 + metrics.ascent() ), magnitudeText );

    // Restore the old painter state.
    painter->restore();
}
コード例 #5
0
ファイル: kitemlistwidget.cpp プロジェクト: stream009/dolphin
void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
    Q_UNUSED(option);

    if (m_alternateBackground) {
        const QColor backgroundColor = m_styleOption.palette.color(QPalette::AlternateBase);
        const QRectF backgroundRect(0, 0, size().width(), size().height());
        painter->fillRect(backgroundRect, backgroundColor);
    }

    if (m_selected && m_editedRole.isEmpty()) {
        const QStyle::State activeState(isActiveWindow() ? QStyle::State_Active : 0);
        drawItemStyleOption(painter, widget, activeState |
                                             QStyle::State_Enabled |
                                             QStyle::State_Selected |
                                             QStyle::State_Item);
    }

    if (m_current && m_editedRole.isEmpty()) {
        QStyleOptionFocusRect focusRectOption;
        focusRectOption.initFrom(widget);
        focusRectOption.rect = textFocusRect().toRect();
        focusRectOption.state = QStyle::State_Enabled | QStyle::State_Item | QStyle::State_KeyboardFocusChange;
        if (m_selected) {
            focusRectOption.state |= QStyle::State_Selected;
        }

        style()->drawPrimitive(QStyle::PE_FrameFocusRect, &focusRectOption, painter, widget);
    }

    if (m_hoverOpacity > 0.0) {
        if (!m_hoverCache) {
            // Initialize the m_hoverCache pixmap to improve the drawing performance
            // when fading the hover background
            m_hoverCache = new QPixmap(size().toSize());
            m_hoverCache->fill(Qt::transparent);

            QPainter pixmapPainter(m_hoverCache);
            const QStyle::State activeState(isActiveWindow() ? QStyle::State_Active : 0);
            drawItemStyleOption(&pixmapPainter, widget, activeState |
                                                        QStyle::State_Enabled |
                                                        QStyle::State_MouseOver |
                                                        QStyle::State_Item);
        }

        const qreal opacity = painter->opacity();
        painter->setOpacity(m_hoverOpacity * opacity);
        painter->drawPixmap(0, 0, *m_hoverCache);
        painter->setOpacity(opacity);
    }
}
コード例 #6
0
ファイル: TFWidget.cpp プロジェクト: VMML/Livre
void TFWidget::_createCheckersBackground()
{
    QPixmap pixmap( 20, 20 );
    QPainter pixmapPainter( &pixmap );
    pixmapPainter.fillRect( 0, 0, 10, 10, Qt::lightGray );
    pixmapPainter.fillRect( 10, 10, 10, 10, Qt::lightGray );
    pixmapPainter.fillRect( 0, 10, 10, 10, Qt::darkGray );
    pixmapPainter.fillRect( 10, 0, 10, 10, Qt::darkGray );
    pixmapPainter.end();
    QPalette colorPalette = palette();
    colorPalette.setBrush( backgroundRole(), QBrush( pixmap ));
    setAutoFillBackground( true );
    setPalette( colorPalette );
}
コード例 #7
0
ファイル: LabeledSection.cpp プロジェクト: Siddharthk/opticks
void LabeledSection::updateIndicator()
{
   if (mpSectionWidget != NULL)
   {
      bool bVisible = mpSectionWidget->isVisible();

      // Show the indicator
      mpExpandLabel->show();

      // Update the indicator pixmap
      QStyle* pStyle = style();
      if (pStyle != NULL)
      {
         QPixmap labelPixmap(9, 9);
         labelPixmap.fill(Qt::white);

         QStyleOption option;
         option.rect = labelPixmap.rect();
         option.state = QStyle::State_Children;
         if (bVisible == true)
         {
            option.state |= QStyle::State_Open;
         }

         QPainter pixmapPainter(&labelPixmap);
         pStyle->drawPrimitive(QStyle::PE_IndicatorBranch, &option, &pixmapPainter);

         mpExpandLabel->setPixmap(labelPixmap);
      }

      // Emit the signal
      if (bVisible == true)
      {
         emit expanded();
      }
      else
      {
         emit collapsed();
      }
   }
   else
   {
      // Hide the indicator
      mpExpandLabel->hide();
   }
}
コード例 #8
0
ファイル: qgraphicseffect.cpp プロジェクト: AtlantisCD9/Qt
/*!
    \reimp
*/
void QGraphicsOpacityEffect::draw(QPainter *painter)
{
    Q_D(QGraphicsOpacityEffect);

    // Transparent; nothing to draw.
    if (d->isFullyTransparent)
        return;

    // Opaque; draw directly without going through a pixmap.
    if (d->isFullyOpaque && !d->hasOpacityMask) {
        drawSource(painter);
        return;
    }

    QPoint offset;
    Qt::CoordinateSystem system = sourceIsPixmap() ? Qt::LogicalCoordinates : Qt::DeviceCoordinates;
    QPixmap pixmap = sourcePixmap(system, &offset, QGraphicsEffect::NoPad);
    if (pixmap.isNull())
        return;

    painter->save();
    painter->setOpacity(d->opacity);

    if (d->hasOpacityMask) {
        QPainter pixmapPainter(&pixmap);
        pixmapPainter.setRenderHints(painter->renderHints());
        pixmapPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
        if (system == Qt::DeviceCoordinates) {
            QTransform worldTransform = painter->worldTransform();
            worldTransform *= QTransform::fromTranslate(-offset.x(), -offset.y());
            pixmapPainter.setWorldTransform(worldTransform);
            pixmapPainter.fillRect(sourceBoundingRect(), d->opacityMask);
        } else {
            pixmapPainter.translate(-offset);
            pixmapPainter.fillRect(pixmap.rect(), d->opacityMask);
        }
    }

    if (system == Qt::DeviceCoordinates)
        painter->setWorldTransform(QTransform());

    painter->drawPixmap(offset, pixmap);
    painter->restore();
}
コード例 #9
0
void LegendItem::paint(QPainter *painter) {
  if (!isVisible()) {
    return;
  }

  RelationList legendItems;
  if (_auto) {
    legendItems = plot()->renderItem(PlotRenderItem::Cartesian)->relationList();
  } else {
    legendItems = _relations;
  }

  int count = legendItems.count();
  if (count <= 0) { // no legend or box if there are no legend items
    return;
  }


  QList<DrawnLegendItem> legendPixmaps;
  QSize legendSize(0, 0);

  QFont font(_font);
  font.setPointSizeF(view()->viewScaledFontSize(_fontScale));

  // generate string list of relation names
  QStringList names;
  bool allAuto = true;
  bool sameX = true;
  bool sameYUnits = true;

  LabelInfo label_info = legendItems.at(0)->xLabelInfo();
  QString yUnits =  legendItems.at(0)->yLabelInfo().units;

  for (int i = 0; i<count; i++) {
    RelationPtr relation = legendItems.at(i);
    if (relation->descriptiveNameIsManual()) {
      allAuto = false;
    }
    if (relation->xLabelInfo() != label_info) {
      sameX = false;
    }
    // sameYUnits is false if any non empty units are defined differently.
    if (yUnits.isEmpty()) {
      yUnits = relation->yLabelInfo().units;
    } else if (relation->yLabelInfo().units != yUnits) {
      if (!relation->yLabelInfo().units.isEmpty()) {
        sameYUnits = false;
      }
    }
  }

  if (!allAuto) {
    for (int i = 0; i<count; i++) {
      names.append(legendItems.at(i)->descriptiveName());
    }
  } else {
    for (int i = 0; i<count; i++) {
      RelationPtr relation = legendItems.at(i);
      QString label = relation->titleInfo().singleRenderItemLabel();
      if (label.isEmpty()) {
        label_info = relation->yLabelInfo();
        QString y_label = label_info.name;
        if (!sameYUnits) {
          if (!label_info.units.isEmpty()) {
            y_label = i18n("%1 \\[%2\\]").arg(y_label).arg(label_info.units);
          }
        }
        if (!y_label.isEmpty()) {
          LabelInfo xlabel_info = relation->xLabelInfo();
          if (!sameX) {
            label = i18n("%1 vs %2").arg(y_label).arg(xlabel_info.name);
          } else if (xlabel_info.quantity.isEmpty()) {
            label = y_label;
          } else if (xlabel_info.quantity != xlabel_info.name) {
            label = i18n("%1 vs %2").arg(y_label).arg(xlabel_info.name);
          } else {
            label = y_label;
          }
        } else {
          label = relation->descriptiveName();
        }
      }
      int i_dup = names.indexOf(label);
      if (i_dup<0) {
        names.append(label);
      } else {
        RelationPtr dup_relation = legendItems.at(i_dup);
        if (!dup_relation->yLabelInfo().file.isEmpty()) {
          names.replace(i_dup, label + " (" + dup_relation->yLabelInfo().file + ')');
        }
        if (!relation->yLabelInfo().file.isEmpty()) {
          names.append(label + " (" + relation->yLabelInfo().file + ')');
        }
      }
    }
  }

  for (int i = 0; i<count; i++) {
    RelationPtr relation = legendItems.at(i);
    DrawnLegendItem item;
    item.pixmap = QPixmap(LEGENDITEMMAXWIDTH, LEGENDITEMMAXHEIGHT);
    item.size = paintRelation(names.at(i), relation, &item.pixmap, font);

    if (_verticalDisplay) {
      legendSize.setWidth(qMax(legendSize.width(), item.size.width()));
      legendSize.setHeight(legendSize.height() + item.size.height());
    } else {
      legendSize.setHeight(qMax(legendSize.height(), item.size.height()));
      legendSize.setWidth(legendSize.width() + item.size.width());
    }

    legendPixmaps.append(item);
  }

  int x = rect().left();
  int y = rect().top();

  painter->save();

  if (!_title.isEmpty()) {
    // Paint the title
    Label::Parsed *parsed = Label::parse(_title);

    if (parsed) {
      painter->save();

      QPixmap pixmap(400, 100);
      pixmap.fill(Qt::transparent);
      QPainter pixmapPainter(&pixmap);

      Label::RenderContext rc(font, &pixmapPainter);
      QFontMetrics fm(font);
      rc.y = fm.ascent();
      Label::renderLabel(rc, parsed->chunk, false);

      int startPoint = qMax(0, (legendSize.width() / 2) - (rc.x / 2));
      int paddingValue = fm.height() / 4;
    
      setViewRect(viewRect().x(), viewRect().y(), qMax(rc.x, legendSize.width()), rc.y + legendSize.height() + paddingValue * 3);
      painter->drawRect(rect());

      painter->drawPixmap(QPoint(x + startPoint, y + paddingValue), pixmap, QRect(0, 0, rc.x, fm.height()));
      painter->restore();
      y += fm.height() + (paddingValue *2);
      delete parsed;
      parsed = 0;
    }
  } else {
    // No Title
    setViewRect(viewRect().x(), viewRect().y(), legendSize.width(), legendSize.height());
    painter->drawRect(rect());
  }


  foreach(const DrawnLegendItem &item, legendPixmaps) {
    painter->drawPixmap(QPoint(x, y), item.pixmap, QRect(0, 0, item.size.width(), item.size.height()));
    if (_verticalDisplay) {
      y += item.size.height();
    } else {
      x += item.size.width();
    }
  }
コード例 #10
0
void MapBox::testDateline()
{
    m_mapWidget->setCenter(QGeoCoordinate(0.0, 180.0));
    m_mapWidget->setZoomLevel(5.0);

    QList<QGeoCoordinate> dateline;

    dateline << QGeoCoordinate(-15.0, 180.0);
    dateline << QGeoCoordinate(15.0, 180.0);

    QGeoMapPolylineObject *datelineObject = new QGeoMapPolylineObject();
    datelineObject->setPath(dateline);
    QPen p(Qt::DashLine);
    p.setColor(Qt::black);
    p.setWidth(2);
    //p.setCosmetic(true);
    datelineObject->setPen(p);

    m_mapWidget->addMapObject(datelineObject);

    addRectangle(QGeoCoordinate(-5.0, 179.0), QGeoCoordinate(-6.0, -179.0));
    addCircle(QGeoCoordinate(-7.0, 180.0), 50000.0);

    QList<QGeoCoordinate> polyline;

    polyline << QGeoCoordinate(-3.0, 180.0);
    polyline << QGeoCoordinate(-4.0, 179.0);
    polyline << QGeoCoordinate(-4.0, -179.0);

    addPolyline(polyline);

    QList<QGeoCoordinate> polygon;

    polygon << QGeoCoordinate(0.0, 180.0);
    polygon << QGeoCoordinate(-2.0, 179.0);
    polygon << QGeoCoordinate(-2.0, -179.0);

    addPolygon(polygon);

    QPixmap pixmap(48, 48);
    QPainter pixmapPainter(&pixmap);
    pixmapPainter.fillRect(pixmap.rect(), Qt::yellow);
    pixmapPainter.setPen(QPen(Qt::black));
    pixmapPainter.setBrush(QBrush(Qt::black));

    QFont font = pixmapPainter.font();
    font.setPointSize(8);
    pixmapPainter.setFont(font);

    pixmapPainter.drawText(pixmap.rect(), Qt::AlignCenter, "Pixmap");

    addPixmap(QGeoCoordinate(6.0, 180.0), QPoint(-1 * pixmap.width() / 2, -1 * pixmap.width() / 2), pixmap);

    addText(QGeoCoordinate(4.0, 180.0), QString("Text"));

    QList<QGeoCoordinate> route;

    route << QGeoCoordinate(3.0, 180.0);
    route << QGeoCoordinate(2.5, 179.0);
    route << QGeoCoordinate(1.5, 179.0);
    route << QGeoCoordinate(1.0, 180.0);
    route << QGeoCoordinate(1.5, -179.0);
    route << QGeoCoordinate(2.5, -179.0);

    addFakeRoute(route, 3);

    QGraphicsEllipseItem *ellipseItem = new QGraphicsEllipseItem(QRectF(0.0, 0.0, 96.0, 48.0));
    ellipseItem->setBrush(Qt::red);

    addCustom(QGeoCoordinate(10.0, 180.0), QPoint(-48, -24), ellipseItem);
}
コード例 #11
0
//-----------------------------------------------------------------------------
void vktraceviewer_QTimelineView::paint(QPainter *painter, QPaintEvent *event)
{
    m_threadHeight = event->rect().height();
    if (m_threadIdList.count() > 0)
    {
        m_threadHeight /= m_threadIdList.count();
    }

    int arrowHeight = 12;
    int arrowTop = 2;
    int arrowHalfWidth = 4;

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

    QList<uint32_t> threadList = getModelThreadList();

    calculateRectsIfNecessary();

    if (m_pPixmap == NULL)
    {
        int pixmapHeight = event->rect().height();
        int pixmapWidth = event->rect().width();

        m_pPixmap = new QPixmap(pixmapWidth, pixmapHeight);

        for (int t = 0; t < m_threadIdList.size(); t++)
        {
            m_threadMask[m_threadIdList[t]] = QVector<int>(pixmapWidth, 0);
        }

        QPainter pixmapPainter(m_pPixmap);

        // fill entire background with background color
        pixmapPainter.fillRect(event->rect(), m_background);
        drawBaseTimelines(&pixmapPainter, event->rect(), threadList);

        if (model() != NULL)
        {
            int numRows = model()->rowCount();

            for (int r = 0; r < numRows; r++)
            {
                QModelIndex index = model()->index(r, vktraceviewer_QTraceFileModel::Column_EntrypointName);

                drawTimelineItem(&pixmapPainter, index);
            }
        }
    }
    painter->drawPixmap(event->rect(), *m_pPixmap, m_pPixmap->rect());

    if (model() == NULL)
    {
        return;
    }

    // draw current api call marker
    int currentIndexRow = currentIndex().row();
    if (currentIndexRow >= 0)
    {
        // Overlay a black rectangle around the current item.
        // For more information on how rects are drawn as outlines,
        // see here: http://qt-project.org/doc/qt-4.8/qrectf.html#rendering
        int penWidth = 2;
        int penWidthHalf = 1;
        QPen blackPen(Qt::black);
        blackPen.setWidth(penWidth);
        blackPen.setJoinStyle(Qt::MiterJoin);
        painter->setPen(blackPen);

        // Don't fill the rectangle
        painter->setBrush(Qt::NoBrush);

        QModelIndex index = model()->index(currentIndexRow, vktraceviewer_QTraceFileModel::Column_EntrypointName);
        QRectF rect = visualRect(index);
        rect.adjust(-penWidthHalf, -penWidthHalf, penWidthHalf, penWidthHalf);
        painter->drawRect(rect);

        // Draw marker underneath the current rect
        painter->save();
        QPainter::RenderHints hints = painter->renderHints();
        painter->setRenderHints(QPainter::Antialiasing);
        painter->setPen(m_trianglePen);
        painter->setBrush(QColor(Qt::yellow));
        painter->translate(rect.center().x(), rect.bottom());
        painter->drawPolygon(triangle);
        painter->setRenderHints(hints, false);
        painter->restore();
    }
}
コード例 #12
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();
        }
    }
}
コード例 #13
0
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();
    }
}