Beispiel #1
0
void KoPatternBackground::paint(QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &/*context*/, const QPainterPath &fillPath) const
{
    Q_D(const KoPatternBackground);
    if (! d->imageData)
        return;

    painter.save();

    if (d->repeat == Tiled) {
        // calculate scaling of pixmap
        QSizeF targetSize = d->targetSize();
        QSizeF imageSize = d->imageData->imageSize();
        qreal scaleX = targetSize.width() / imageSize.width();
        qreal scaleY = targetSize.height() / imageSize.height();

        QRectF targetRect = fillPath.boundingRect();
        // undo scaling on target rectangle
        targetRect.setWidth(targetRect.width() / scaleX);
        targetRect.setHeight(targetRect.height() / scaleY);

        // determine pattern offset
        QPointF offset = d->offsetFromRect(targetRect, imageSize);

        // create matrix for pixmap scaling
        QTransform matrix;
        matrix.scale(scaleX, scaleY);

        painter.setClipPath(fillPath);
        painter.setWorldTransform(matrix, true);
        painter.drawTiledPixmap(targetRect, d->imageData->pixmap(imageSize.toSize()), -offset);
    } else if (d->repeat == Original) {
        QRectF sourceRect(QPointF(0, 0), d->imageData->imageSize());
        QRectF targetRect(QPoint(0, 0), d->targetSize());
        targetRect.moveCenter(fillPath.boundingRect().center());
        painter.setClipPath(fillPath);
        painter.drawPixmap(targetRect, d->imageData->pixmap(sourceRect.size().toSize()), sourceRect);
    } else if (d->repeat == Stretched) {
        painter.setClipPath(fillPath);
        // undo conversion of the scaling so that we can use a nicely scaled image of the correct size
        qreal zoomX, zoomY;
        converter.zoom(&zoomX, &zoomY);
        zoomX = zoomX ? 1 / zoomX : zoomX;
        zoomY = zoomY ? 1 / zoomY : zoomY;
        painter.scale(zoomX, zoomY);

        QRectF targetRect = converter.documentToView(fillPath.boundingRect());
        painter.drawPixmap(targetRect.topLeft(), d->imageData->pixmap(targetRect.size().toSize()));
    }

    painter.restore();
}
void KPrClockWipeStrategy::paintStep( QPainter &p, int currPos, const KPrPageEffect::Data &data )
{
    QRect rect( 0, 0, data.m_widget->width(), data.m_widget->height() );
    p.drawPixmap( QPoint( 0, 0 ), data.m_oldPage, rect );

    QPainterPath clipPath;
    for(int i = 0; i < m_bladeCount; i++) {

        double bladeStartAngle;
        double bladeEndAngle;

        double angle = static_cast<double>(currPos)/m_bladeCount/180 * M_PI;

        if(!reverse()) {
            bladeEndAngle = 2*M_PI/m_bladeCount*i + m_startAngle;
            bladeStartAngle = bladeEndAngle - angle;
        }
        else {
            bladeStartAngle = 2*M_PI/m_bladeCount*(i+1) + m_startAngle;
            bladeEndAngle = bladeStartAngle + angle;
        }
        KPrClockWipeSubpathHelper::addSubpathForCircularArc(&clipPath, rect, bladeStartAngle, bladeEndAngle);
    }
    p.setClipPath(clipPath);

    p.drawPixmap( QPoint( 0, 0 ), data.m_newPage, rect );
}
QPixmap ImageProcessor::drawPiece(int i, int j, const QPainterPath &shape, const Puzzle::Creation::Correction &corr)
{
    QPainter p;
    QPixmap px(_p->descriptor.unitSize.width() + corr.widthCorrection + 1,
               _p->descriptor.unitSize.height() + corr.heightCorrection + 1);
    px.fill(Qt::transparent);

    p.begin(&px);
    p.setRenderHint(QPainter::SmoothPixmapTransform);
    p.setRenderHint(QPainter::Antialiasing);
    p.setRenderHint(QPainter::HighQualityAntialiasing);
    p.setClipping(true);
    p.setClipPath(shape);

    p.drawPixmap(_p->descriptor.tabFull + corr.xCorrection + corr.sxCorrection,
                 _p->descriptor.tabFull + corr.yCorrection + corr.syCorrection,
                 _p->pixmap,
                 i * _p->descriptor.unitSize.width() + corr.sxCorrection,
                 j * _p->descriptor.unitSize.height() + corr.syCorrection,
                 _p->descriptor.unitSize.width() * 2,
                 _p->descriptor.unitSize.height() * 2);

    p.end();
    return px;
}
void GraphicsContext::clipPath(WindRule clipRule)
{
    if (paintingDisabled())
        return;

    QPainter *p = m_data->p();
    QPainterPath newPath = m_data->currentPath;
    newPath.setFillRule(clipRule == RULE_EVENODD ? Qt::OddEvenFill : Qt::WindingFill);
    p->setClipPath(newPath);
}
void KPrIrisWipeEffectStrategyBase::paintStep( QPainter &p, int currPos, const KPrPageEffect::Data &data )
{
    const int width = data.m_widget->width();
    const int height = data.m_widget->height();
    qreal scaleStep;
    qreal fullScale = findMaxScaling( data );
    if( width > height )
    {
        scaleStep = 1 / m_shape.boundingRect().width();
    }
    else
    {
        scaleStep = 1 / m_shape.boundingRect().height();
    }

    QPoint pointZero( 0, 0 );
    if( !reverse() )
    {
        QRect rect( 0, 0, width, height );
        p.drawPixmap( pointZero, data.m_oldPage, rect );

        QTransform matrix;
        matrix.translate( width/2, height/2 );
        matrix.scale( currPos*scaleStep, currPos*scaleStep );

        p.setClipPath( matrix.map(m_shape) );
        p.drawPixmap( pointZero, data.m_newPage, rect );
    }
    else
    {
        QRect rect( 0, 0, width, height );
        p.drawPixmap( pointZero, data.m_newPage, rect );

        QTransform matrix;
        matrix.translate( width/2, height/2 );
        matrix.scale( ( fullScale - currPos )*scaleStep, ( fullScale - currPos )*scaleStep );

        p.setClipPath( matrix.map(m_shape) );
        p.drawPixmap( pointZero, data.m_oldPage, rect );
    }
}
void AbstractAreaBase::paintBackground( QPainter& painter, const QRect& rect )
{
    Q_ASSERT_X ( d != 0, "AbstractAreaBase::paintBackground()",
                "Private class was not initialized!" );

    PainterSaver painterSaver( &painter );

    const qreal radius = d->frameAttributes.cornerRadius();
    QPainterPath path;
    path.addRoundedRect( rect.adjusted( 0, 0, -1, -1 ), radius, radius );
    painter.setClipPath(path);

    paintBackgroundAttributes( painter, rect, d->backgroundAttributes );
}
void GraphicsContext::clipOutEllipseInRect(const IntRect& rect)
{
    if (paintingDisabled())
        return;

    QPainter *p = m_data->p();
    QRectF clipBounds = p->clipPath().boundingRect();
    QPainterPath newClip;
    newClip.setFillRule(Qt::OddEvenFill);
    newClip.addRect(clipBounds);
    newClip.addEllipse(QRect(rect));

    p->setClipPath(newClip, Qt::IntersectClip);
}
Beispiel #8
0
 /**
  * Makes the corners of the image rounded
  */
 QImage polishImage(const QImage &img)
 {
     const int sz = 48 * 4;
     QImage roundedImage = QImage(QSize(sz, sz), QImage::Format_ARGB32_Premultiplied);
     roundedImage.fill(Qt::transparent);
     QPainter p;
     p.begin(&roundedImage);
     QPainterPath clippingPath;
     QRectF imgRect = QRectF(QPoint(0, 0), roundedImage.size());
     clippingPath.addRoundedRect(imgRect, 24, 24);
     p.setClipPath(clippingPath);
     p.setClipping(true);
     p.drawImage(QRectF(QPointF(0, 0), roundedImage.size()), img);
     return roundedImage;
 }
void GraphicsContext::clipOut(const Path& path)
{
    if (paintingDisabled())
        return;

    QPainter *p = m_data->p();
    QRectF clipBounds = p->clipPath().boundingRect();
    QPainterPath clippedOut = *path.platformPath();
    QPainterPath newClip;
    newClip.setFillRule(Qt::OddEvenFill);
    newClip.addRect(clipBounds);
    newClip.addPath(clippedOut);

    p->setClipPath(newClip, Qt::IntersectClip);
}
void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSymbolV2RenderContext& context )
{
  QPainter* p = context.renderContext().painter();
  if ( !p )
  {
    return;
  }

  double offset = 0.0;
  applyDataDefinedSymbology( context, mPen, mSelPen, offset );

  p->setPen( context.selected() ? mSelPen : mPen );

  // Disable 'Antialiasing' if the geometry was generalized in the current RenderContext (We known that it must have least #2 points).
  if ( points.size() <= 2 && context.layer() && context.layer()->simplifyDrawingCanbeApplied( context.renderContext(), QgsVectorLayer::AntialiasingSimplification ) && QgsAbstractGeometrySimplifier::canbeGeneralizedByDeviceBoundingBox( points, context.layer()->simplifyMethod().threshold() ) && ( p->renderHints() & QPainter::Antialiasing ) )
  {
    p->setRenderHint( QPainter::Antialiasing, false );
    p->drawPolyline( points );
    p->setRenderHint( QPainter::Antialiasing, true );
    return;
  }

  if ( mDrawInsidePolygon )
  {
    //only drawing the line on the interior of the polygon, so set clip path for painter
    p->save();
    QPainterPath clipPath;
    clipPath.addPolygon( points );
    p->setClipPath( clipPath, Qt::IntersectClip );
  }

  if ( offset == 0 )
  {
    p->drawPolyline( points );
  }
  else
  {
    double scaledOffset = offset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
    p->drawPolyline( ::offsetLine( points, scaledOffset ) );
  }

  if ( mDrawInsidePolygon )
  {
    //restore painter to reset clip path
    p->restore();
  }
}
void QgsSimpleLineSymbolLayerV2::renderPolygonOutline( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context )
{
  QPainter* p = context.renderContext().painter();
  if ( !p )
  {
    return;
  }

  if ( mDrawInsidePolygon )
  {
    //only drawing the line on the interior of the polygon, so set clip path for painter
    p->save();
    QPainterPath clipPath;
    clipPath.addPolygon( points );

    if ( rings != NULL )
    {
      //add polygon rings
      QList<QPolygonF>::const_iterator it = rings->constBegin();
      for ( ; it != rings->constEnd(); ++it )
      {
        QPolygonF ring = *it;
        clipPath.addPolygon( ring );
      }
    }

    //use intersect mode, as a clip path may already exist (eg, for composer maps)
    p->setClipPath( clipPath, Qt::IntersectClip );
  }

  renderPolyline( points, context );
  if ( rings )
  {
    mOffset = -mOffset; // invert the offset for rings!
    foreach ( const QPolygonF& ring, *rings )
      renderPolyline( ring, context );
    mOffset = -mOffset;
  }

  if ( mDrawInsidePolygon )
  {
    //restore painter to reset clip path
    p->restore();
  }

}
void UIPopupPane::configureClipping(const QRect &rect, QPainter &painter)
{
    /* Configure clipping: */
    QPainterPath path;
    int iDiameter = 6;
    QSizeF arcSize(2 * iDiameter, 2 * iDiameter);
    path.moveTo(rect.x() + iDiameter, rect.y());
    path.arcTo(QRectF(path.currentPosition(), arcSize).translated(-iDiameter, 0), 90, 90);
    path.lineTo(path.currentPosition().x(), rect.y() + rect.height() - iDiameter);
    path.arcTo(QRectF(path.currentPosition(), arcSize).translated(0, -iDiameter), 180, 90);
    path.lineTo(rect.x() + rect.width() - iDiameter, path.currentPosition().y());
    path.arcTo(QRectF(path.currentPosition(), arcSize).translated(-iDiameter, -2 * iDiameter), 270, 90);
    path.lineTo(path.currentPosition().x(), rect.y() + iDiameter);
    path.arcTo(QRectF(path.currentPosition(), arcSize).translated(-2 * iDiameter, -iDiameter), 0, 90);
    path.closeSubpath();
    painter.setClipPath(path);
}
    void GraphQtInteractiveRenderer::clipRegionAddRect(Rectangle *rect)
    {
        GraphQtRenderer *renderer = m_data->renderer;
        QRegion *clip = renderer->clipRegion();

        QRect clipRect;
        clipRect.setX(rect->x());
        clipRect.setY(rect->y());
        clipRect.setWidth(rect->width());
        clipRect.setHeight(rect->height());


        *clip = clip->united(clipRect);


        QPainterPath path;
        path.addRegion(*clip);
        QPainter *painter = m_data->renderer->painter();
        painter->setClipping(true);
        painter->setClipPath(path);
    }
    void PreviewContentWidget::applyClippingPath(QPainter &p)
    {
        const auto minExtent = (Ui::MessageStyle::getBorderRadius() * 2);

        const auto isPreviewTooSmall = (
            (PreviewGenuineSize_.width() <= minExtent) ||
            (PreviewGenuineSize_.height() <= minExtent)
        );

        if (isPreviewTooSmall)
        {
            return;
        }

        if (ClippingPath_.isEmpty())
        {
            ClippingPath_ = evaluateClippingPath();
            assert(!ClippingPath_.isEmpty());
        }

        p.setClipPath(ClippingPath_);
    }
Beispiel #15
0
void ZigZagWipeStrategy::paintStep(QPainter &p, int currPos, const SCPageEffect::Data &data)
{
    p.drawPixmap(QPoint(0, 0), data.m_oldPage, data.m_widget->rect());
    p.setClipPath(clipPath(currPos, data.m_widget->rect()));
    p.drawPixmap(QPoint(0, 0), data.m_newPage, data.m_widget->rect());
}
Beispiel #16
0
void LightMaps::paintEvent(QPaintEvent *event)
{
    QPainter p;
    p.begin(this);
    m_normalMap->render(&p, event->rect());
    p.setPen(Qt::black);
    p.drawText(rect(),  Qt::AlignBottom | Qt::TextWordWrap,
                "Map data CCBYSA 2009 OpenStreetMap.org contributors");
    p.end();

    if (zoomed) {
        int dim = qMin(width(), height());
        int magnifierSize = qMin(MAX_MAGNIFIER, dim * 2 / 3);
        int radius = magnifierSize / 2;
        int ring = radius - 15;
        QSize box = QSize(magnifierSize, magnifierSize);

        // reupdate our mask
        if (maskPixmap.size() != box) {
            maskPixmap = QPixmap(box);
            maskPixmap.fill(Qt::transparent);

            QRadialGradient g;
            g.setCenter(radius, radius);
            g.setFocalPoint(radius, radius);
            g.setRadius(radius);
            g.setColorAt(1.0, QColor(255, 255, 255, 0));
            g.setColorAt(0.5, QColor(128, 128, 128, 255));

            QPainter mask(&maskPixmap);
            mask.setRenderHint(QPainter::Antialiasing);
            mask.setCompositionMode(QPainter::CompositionMode_Source);
            mask.setBrush(g);
            mask.setPen(Qt::NoPen);
            mask.drawRect(maskPixmap.rect());
            mask.setBrush(QColor(Qt::transparent));
            mask.drawEllipse(g.center(), ring, ring);
            mask.end();
        }

        QPoint center = dragPos - QPoint(0, radius);
        center = center + QPoint(0, radius / 2);
        QPoint corner = center - QPoint(radius, radius);

        QPoint xy = center * 2 - QPoint(radius, radius);

        // only set the dimension to the magnified portion
        if (zoomPixmap.size() != box) {
            zoomPixmap = QPixmap(box);
            zoomPixmap.fill(Qt::lightGray);
        }
        if (true) {
            QPainter p(&zoomPixmap);
            p.translate(-xy);
            m_largeMap->render(&p, QRect(xy, box));
            p.end();
        }

        QPainterPath clipPath;
        clipPath.addEllipse(center, ring, ring);

        QPainter p(this);
        p.setRenderHint(QPainter::Antialiasing);
        p.setClipPath(clipPath);
        p.drawPixmap(corner, zoomPixmap);
        p.setClipping(false);
        p.drawPixmap(corner, maskPixmap);
        p.setPen(Qt::gray);
        p.drawPath(clipPath);
    }
    if (invert) {
        QPainter p(this);
        p.setCompositionMode(QPainter::CompositionMode_Difference);
        p.fillRect(event->rect(), Qt::white);
        p.end();
    }
}
Beispiel #17
0
int main(int argc, char **argv)
{
  if (argc < 4) {
    fprintf(stderr, "import <maps.json> <map id> <file.tif>\n");
    return -1;
  }

  OGRRegisterAll();
  GDALAllRegister();

  QFile rootFile(argv[1]);
  QString mapId(argv[2]);
  QFileInfo filename(argv[3]);

  RootData rootData(NULL);
  Map *map = rootData.maps()[mapId];

  Projection *pjGeo = Geographic::getProjection(NAD27);
  Projection *pj = map->projection();


  readQuadIndex(0, "/Users/hawkinsp/geo/drg/index/drg100.shp", "drg100", pj);
  readQuadIndex(1, "/Users/hawkinsp/geo/drg/index/drg24.shp", "drg24", pj);

  // Index information seems buggy for these quads -- just use the regular grid.
  quads.remove("o37122g4"); // San Francisco North
  quads.remove("o37122g5"); // Point Bonita




  GDALDataset *ds = (GDALDataset *)GDALOpen(filename.filePath().toLatin1().data(),
                                            GA_ReadOnly);
  if (!ds) {
    fprintf(stderr, "ERROR: Could not open dataset.\n");
    return -1;
  }

  const char *proj = ds->GetProjectionRef();

  Quad quad;
  getQuadInfo(filename, pj, quad);

  // Read projection
  OGRSpatialReference srs;
  srs.importFromWkt((char **)&proj);

  // Size of the DRG
  QSize drgSize = QSize(ds->GetRasterXSize(), ds->GetRasterYSize());
  printf("DRG id: %s, name %s, size %dx%d\n", quad.id.toLatin1().data(),
         quad.name.toLatin1().data(), drgSize.width(), drgSize.height());

  // ------------------------------------------
  // Read geotransform coefficients. The geotransform describe the mapping from
  // DRG image space to projection space.
  double geoTransformCoeff[6];
  ds->GetGeoTransform(geoTransformCoeff);

  // Top left coordinate of the drg in projection space
  QPointF fProjTopLeft = QPointF(geoTransformCoeff[0], geoTransformCoeff[3]);

  // Size of a drg pixel in projection space
  QSizeF fPixelSize = QSizeF(geoTransformCoeff[1], geoTransformCoeff[5]);

  // Check Y pixel size is the negation of the X pixel size
  if (fabs(fPixelSize.width() + fPixelSize.height()) >= epsilon) {
    fprintf(stderr, "Invalid pixel sizes\n");
    return -1;
  }

  // We assume the geotransform consists of only translation and scaling. 
  // We'd need to do a more general image transformation to handle shearing.
  if (fabs(geoTransformCoeff[2]) >= epsilon 
      || fabs(geoTransformCoeff[4]) >= epsilon) {
    fprintf(stderr, "ERROR: DRG geotransform has shear component.\n");
    return -1;
  }

  // Transforms from drg space to projection space and vice versa
  QTransform drgProjTransform;
  drgProjTransform.translate(fProjTopLeft.x(), fProjTopLeft.y());
  drgProjTransform.scale(fPixelSize.width(), fPixelSize.height());
  QTransform projDrgTransform = drgProjTransform.inverted();


  // Size of the DRG in projection space
  QSizeF fProjSize = QSizeF(qreal(ds->GetRasterXSize()) * fPixelSize.width(),
                            qreal(ds->GetRasterYSize()) * fPixelSize.height());
  QRectF projRect = QRectF(fProjTopLeft, fProjSize);

  // Rectangle covered by the entire map image
  QRectF mapRect = map->projToMap().mapRect(projRect);

  printf("Map Rect: %lf %lf %lf %lf\n", mapRect.left(), mapRect.top(),
         mapRect.right(), mapRect.bottom());


  // Compute the initial scale factor and tile level
  QSizeF mapPixelSize = map->mapPixelSize();
  assert(mapPixelSize.width() + mapPixelSize.height() < epsilon);

  QSizeF scale(fPixelSize.width() / mapPixelSize.width(),
               fPixelSize.height() / mapPixelSize.height());
  int maxLevel = map->maxLevel();

  while (scale.width() >= 1.1) {
    maxLevel--;
    scale /= 2.0;
  }

  //  printf("scale %lf %lf\n", scale.width(), scale.height());
  //return 0;

  // Compute the quad boundary
  QPolygonF projQuad(quad.boundary);


  QPolygonF geoQuad = pjGeo->transformFrom(pj, projQuad);
  QRectF geoQuadBounds(geoQuad.boundingRect());
  printf("Series: %d %s\n", quad.series, map->layer(quad.series).name().toLatin1().data());
  printf("Geographic quad boundary: %lf %lf %lf %lf\n", geoQuadBounds.left(),
         geoQuadBounds.top(), geoQuadBounds.right(), geoQuadBounds.bottom());


  // Quad bounding rectangle in map space
  QRectF projQuadBounds = projQuad.boundingRect();
  QRectF mapQuadBounds = map->projToMap().mapRect(projQuadBounds);
  printf("Quad bounding rectangle in map space: %lf %lf %lf %lf\n", 
         mapQuadBounds.left(), mapQuadBounds.top(),
         mapQuadBounds.right(), mapQuadBounds.bottom());


  // Quad bounding rectangle in drg space
  QPolygonF drgBounds = projDrgTransform.map(projQuad);
  QRectF drgQuadBounds = drgBounds.boundingRect();
  printf("Quad bounding rectangle in drg space: %lf %lf %lf %lf\n", 
         drgQuadBounds.left(), drgQuadBounds.top(),
         drgQuadBounds.right(), drgQuadBounds.bottom());


  // Read the image
  QImage drg(filename.filePath());

  if (drgQuadBounds.left() < -drgQuadSlackPixels ||
      drgQuadBounds.right() > drgSize.width() + drgQuadSlackPixels ||
      drgQuadBounds.top() < -drgQuadSlackPixels ||
      drgQuadBounds.bottom() > drgSize.height() + drgQuadSlackPixels) {
    QString mfile("misalign-" + filename.baseName() + ".png");
    fprintf(stderr, "WARNING: DRG and quadrangle boundaries are misaligned; diagnostic saved to '%s'!\n", mfile.toLatin1().data());

    QImage image = drg.convertToFormat(QImage::Format_RGB32);
    QPainter p;
    p.begin(&image);
    QPainterPath pp;
    pp.addPolygon(drgBounds);
    p.setPen(QPen(Qt::blue, 2));
    p.drawPath(pp);
    p.end();
    image.save(mfile, "png");
  }

  /*printf("top left %lf %lf\n", fProjTopLeft.x(), fProjTopLeft.y());*/
  /*for (int i = 0; i< projectedQuad.size(); i++) {
    printf("quad proj %lf %lf\n", projectedQuad[i].x(), projectedQuad[i].y());
    }*/



  QDir dir;

  //  for (int level = maxLevel; level >= 0; level--, scale /= 2.0) {
  int level = maxLevel;
    QSizeF rasterSizeF = QSizeF(ds->GetRasterXSize() * scale.width(),
                               ds->GetRasterYSize() * scale.height());
    QSize rasterSize = rasterSizeF.toSize();
    printf("level %d size %dx%d\n", level, rasterSize.width(), rasterSize.height());
    QImage drgScaled = drg.scaled(rasterSize, Qt::IgnoreAspectRatio,
                                   Qt::SmoothTransformation);

    QPolygonF imageQuad;
    for (int i = 0; i < projQuad.size(); i++) {
      QPointF p = projQuad[i] - fProjTopLeft;
      imageQuad << QPointF(p.x() * scale.width() / fPixelSize.width(), 
                           p.y() * scale.height() / fPixelSize.height());
    }

    QSizeF baseTileSize(map->baseTileSize(), map->baseTileSize());
    int tileSize = map->tileSize(level);

    QRectF tileRectF = QRectF(mapQuadBounds.topLeft() / qreal(tileSize),
                              mapQuadBounds.bottomRight() / qreal(tileSize));
    QRect tileRect(QPoint(int(floor(tileRectF.left())), int(floor(tileRectF.top()))),
                   QPoint(int(ceil(tileRectF.right())), 
                          int(ceil(tileRectF.bottom()))));
    /*    printf("tile rect %d %d %d %d\n", tileRect.left(), tileRect.top(), 
          tileRect.right(), tileRect.bottom());*/
    for (int tileY = tileRect.top(); tileY <= tileRect.bottom(); tileY++) {
      for (int tileX = tileRect.left(); tileX <= tileRect.right(); tileX++) {
        Tile key(tileX, tileY, level, quad.series);

        QPointF tileTopLeft(tileX * tileSize, tileY * tileSize);
        QPointF deltaTileTopLeft = tileTopLeft - mapRect.topLeft();
        qreal s = qreal(1 << (map->maxLevel() - level));
        QPointF topLeft(deltaTileTopLeft.x() / s,
                        deltaTileTopLeft.y() / s);
        QRectF src(topLeft, baseTileSize);
        
        QFileInfo tilePath(map->tilePath(key));
        dir.mkpath(tilePath.path());
        QImage image;
        if (tilePath.exists()) {
          QImage idxImage = QImage(tilePath.filePath());
          image = idxImage.convertToFormat(QImage::Format_RGB32);
        } else {
          image = QImage(256, 256, QImage::Format_RGB32);
          image.setColorTable(drg.colorTable());
          image.fill(QColor(255, 255, 255).rgb());
        }

        QPainterPath pp;
        pp.addPolygon(imageQuad.translated(-topLeft));
        QPainter painter;
        painter.begin(&image);
        painter.setClipPath(pp);
        painter.drawImage(-topLeft, drgScaled);
        // painter.setPen(QPen(QColor(0, 0, 255)));
        // painter.drawPath(pp);
        painter.end();

        QImage tile = image.convertToFormat(QImage::Format_Indexed8, 
                                            drg.colorTable(), Qt::ThresholdDither);
        tile.save(tilePath.filePath(), "png");
        // printf("tile: %s\n", tilePath.filePath().toLatin1().data());
      }
    }

    //  }
  return 0;
}
Beispiel #18
0
void ArthurFrame::paintEvent(QPaintEvent *e)
{
#ifdef Q_WS_QWS
    static QPixmap *static_image = 0;
#else
    static QImage *static_image = 0;
#endif
    QPainter painter;
    if (preferImage()
#ifdef QT_OPENGL_SUPPORT
        && !m_use_opengl
#endif
        ) {
        if (!static_image || static_image->size() != size()) {
            delete static_image;
#ifdef Q_WS_QWS
            static_image = new QPixmap(size());
#else
            static_image = new QImage(size(), QImage::Format_RGB32);
#endif
        }
        painter.begin(static_image);

        int o = 10;

        QBrush bg = palette().brush(QPalette::Background);
        painter.fillRect(0, 0, o, o, bg);
        painter.fillRect(width() - o, 0, o, o, bg);
        painter.fillRect(0, height() - o, o, o, bg);
        painter.fillRect(width() - o, height() - o, o, o, bg);
    } else {
#ifdef QT_OPENGL_SUPPORT
        if (m_use_opengl) {
            painter.begin(glw);
            painter.fillRect(QRectF(0, 0, glw->width(), glw->height()), palette().color(backgroundRole()));
        } else {
            painter.begin(this);
        }
#else
        painter.begin(this);
#endif
    }

    painter.setClipRect(e->rect());

    painter.setRenderHint(QPainter::Antialiasing);

    QPainterPath clipPath;

    QRect r = rect();
    qreal left = r.x() + 1;
    qreal top = r.y() + 1;
    qreal right = r.right();
    qreal bottom = r.bottom();
    qreal radius2 = 8 * 2;

    clipPath.moveTo(right - radius2, top);
    clipPath.arcTo(right - radius2, top, radius2, radius2, 90, -90);
    clipPath.arcTo(right - radius2, bottom - radius2, radius2, radius2, 0, -90);
    clipPath.arcTo(left, bottom - radius2, radius2, radius2, 270, -90);
    clipPath.arcTo(left, top, radius2, radius2, 180, -90);
    clipPath.closeSubpath();

    painter.save();
    painter.setClipPath(clipPath, Qt::IntersectClip);

    painter.drawTiledPixmap(rect(), m_tile);

    // client painting

    paint(&painter);

    painter.restore();

    painter.save();
    if (m_show_doc)
        paintDescription(&painter);
    painter.restore();

    int level = 180;
    painter.setPen(QPen(QColor(level, level, level), 2));
    painter.setBrush(Qt::NoBrush);
    painter.drawPath(clipPath);

    if (preferImage()
#ifdef QT_OPENGL_SUPPORT
        && !m_use_opengl
#endif
        ) {
        painter.end();
        painter.begin(this);
#ifdef Q_WS_QWS
        painter.drawPixmap(e->rect(), *static_image, e->rect());
#else
        painter.drawImage(e->rect(), *static_image, e->rect());
#endif
    }

#ifdef QT_OPENGL_SUPPORT
    if (m_use_opengl && (inherits("PathDeformRenderer") || inherits("PathStrokeRenderer") || inherits("CompositionRenderer") || m_show_doc))
        glw->swapBuffers();
#endif
}
void FadePedal::paintEvent(QPaintEvent* /*event*/)
{
	float lastValue = (m_Ticks.empty() ? 0 : m_Ticks.back().value);
	float angle = (35 * lastValue);

	QRectF r( rect() );
	r.adjust(1, 1, -1, -1);
	
	QPainter painter;
	m_Canvas.fill(0);
	if( painter.begin(&m_Canvas) )
	{
		painter.setRenderHints(QPainter::Antialiasing);
	
		float brightness = m_Click;
		if(m_Hover > 0)
			brightness += (m_Hover*0.2f);

		if( !m_Image.isNull() )
		{
			painter.setOpacity(1.0-(brightness*0.5));
			painter.drawPixmap(	r.x() + qRound((r.width()-m_Image.width())*0.5),
								r.y() + qRound((r.height()-m_Image.height())*0.5),
								m_Image );
			painter.setOpacity(1.0);
		}
	
		QColor brushColor( palette().color(QPalette::Button) );
		if(m_Hover > 0)
		{
			qreal t = (brightness * BUTTON_BRIGHTESS);
			brushColor.setRedF( qMin(brushColor.redF()+t,1.0) );
			brushColor.setGreenF( qMin(brushColor.greenF()+t,1.0) );
			brushColor.setBlueF( qMin(brushColor.blueF()+t,1.0) );
		}
		
		QColor lineColor(brushColor);
		Utils::MakeContrastingColor(1.0f, lineColor);
	
		if( !m_Image.isNull() )
		{
			QPainterPath clip;
			clip.addRoundedRect(r, ROUNDED, ROUNDED);
			painter.setClipPath(clip);

			painter.drawPixmap(	r.x() + qRound((r.width()-m_Image.width())*0.5),
								r.y() + qRound((r.height()-m_Image.height())*0.5),
								m_Image );

			painter.setClipping(false);
		}

		painter.setBrush(brushColor);
		painter.setPen( QPen(lineColor,BORDER) );
		painter.drawRoundedRect(r, ROUNDED, ROUNDED);
	
		if( m_Ticks.empty() )
			m_Points.clear();
		else
			m_Points.resize(m_Ticks.size() + 1);	// end point
	
		if( !m_Points.empty() )
		{
			float lineHeight = (r.height() * 0.8f);
			float lineX = (r.right() + HALF_BORDER);
			float lineY = (r.bottom() - 0.5f*(r.height()-lineHeight));
			float lineWidth = (r.width() + BORDER);
		
			float toPercent = 1.0f/PEDAL_TIMEFRAME;

			for(size_t i=0; i<m_Ticks.size(); i++)
			{
				const sTick &t = m_Ticks[i];
				QPointF &p = m_Points[i];	// end point
			
				float percent = (t.elapsed * toPercent);
				p.setX(lineX - lineWidth*percent);
				p.setY(lineY - lineHeight*t.value);
			}
		
			// end point
			m_Points[m_Points.size()-1] = QPointF(lineX, m_Points[m_Points.size()-2].y());
		
			painter.drawPolyline(m_Points);
		}
	
		if(m_Hover > 0)
		{
			qreal dy = (-m_Hover * BUTTON_RAISE);
			if(dy != 0)
				r.adjust(0, 0, 0, dy);
		}
	
		QColor textColor( palette().color(QPalette::ButtonText) );
		if( !isEnabled() )
			textColor = textColor.darker(150);

		if( !text().isEmpty() )
		{
			if( m_Label.isEmpty() )
			{
				// just text centered
				painter.setFont( font() );
				painter.setPen(textColor);
				painter.drawText(r, Qt::AlignCenter|Qt::TextWordWrap, text());
			}
			else
			{
				// both text and label text
				QRectF textRect;
				painter.setFont( font() );
				painter.setPen(textColor);
				painter.drawText(r, Qt::AlignCenter|Qt::TextWordWrap|Qt::TextDontPrint, text(), &textRect);

				QRectF labelRect;
				painter.drawText(r, Qt::AlignCenter|Qt::TextWordWrap|Qt::TextDontPrint, m_Label, &labelRect);

				qreal h = (r.height() * 0.5 * (textRect.height()/labelRect.height()));
				painter.drawText(QRectF(r.x(),r.y(),r.width(),h), Qt::AlignCenter|Qt::TextWordWrap, text());
				painter.drawText(QRectF(r.x(),r.y()+h,r.width(),r.height()-h), Qt::AlignCenter|Qt::TextWordWrap, m_Label);
			}
		}
		else if( !m_Label.isEmpty() )
		{
			// just label text centered
			painter.setFont( font() );
			painter.setPen(textColor);
			painter.drawText(r, Qt::AlignCenter|Qt::TextWordWrap, m_Label);
		}

		painter.end();
	}

	if( painter.begin(this) )
	{
		if(angle > 0.00001)
		{
			qreal center = (m_Canvas.width() * 0.5);
			QMatrix4x4 matrix;
			matrix.translate(-center, m_Canvas.height());
			matrix.rotate(angle, 1.0, 0, 0);

			painter.translate(center, 0);
			painter.setTransform(matrix.toTransform(300.0), /*combine*/true);
			painter.setRenderHint(QPainter::SmoothPixmapTransform);
			painter.drawImage(0, -m_Canvas.height(), m_Canvas);
		}
		else
			painter.drawImage(0, 0, m_Canvas);

		painter.end();
	}
}
Beispiel #20
0
void ArthurFrame::paintEvent(QPaintEvent *e)
{

    static QImage *static_image = 0;
    QPainter painter;
    if (preferImage()) {
        if (!static_image) {
            static_image = new QImage(size(), QImage::Format_RGB32);
        } else if (static_image->size() != size()) {
            delete static_image;
            static_image = new QImage(size(), QImage::Format_RGB32);
        }
        painter.begin(static_image);

        int o = 10;

        QBrush bg = palette().brush(QPalette::Background);
        painter.fillRect(0, 0, o, o, bg);
        painter.fillRect(width() - o, 0, o, o, bg);
        painter.fillRect(0, height() - o, o, o, bg);
        painter.fillRect(width() - o, height() - o, o, o, bg);
    } else {
        painter.begin(this);
    }

    painter.setClipRect(e->rect());

    painter.setRenderHint(QPainter::Antialiasing);

    QPainterPath clipPath;

    QRect r = rect();
    double left = r.x() + 1;
    double top = r.y() + 1;
    double right = r.right();
    double bottom = r.bottom();
    double radius2 = 8 * 2;

    clipPath.moveTo(right - radius2, top);
    clipPath.arcTo(right - radius2, top, radius2, radius2, 90, -90);
    clipPath.arcTo(right - radius2, bottom - radius2, radius2, radius2, 0, -90);
    clipPath.arcTo(left, bottom - radius2, radius2, radius2, 270, -90);
    clipPath.arcTo(left, top, radius2, radius2, 180, -90);
    clipPath.closeSubpath();

    painter.save();
    painter.setClipPath(clipPath, Qt::IntersectClip);

    painter.drawTiledPixmap(rect(), m_tile);

    // client painting

    paint(&painter);

    painter.restore();

    painter.save();
    if (m_show_doc)
        paintDescription(&painter);
    painter.restore();

    int level = 180;
    painter.setPen(QPen(QColor(level, level, level), 2));
    painter.setBrush(Qt::NoBrush);
    painter.drawPath(clipPath);

    if (preferImage()) {
        painter.end();
        painter.begin(this);
        painter.drawImage(e->rect(), *static_image, e->rect());
    }
}