当前位置: 首页>>代码示例>>C++>>正文


C++ QPainter::drawImage方法代码示例

本文整理汇总了C++中QPainter::drawImage方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainter::drawImage方法的具体用法?C++ QPainter::drawImage怎么用?C++ QPainter::drawImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QPainter的用法示例。


在下文中一共展示了QPainter::drawImage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: QPainter

void AuGrid::drawCrossGrid2(GridContext &gridGC)
{
    AuViewportGC *vpgc = gridGC.m_gc;
    QPainter *gc = new QPainter(vpgc->getGC());

    Device device = Display.getCurrent();
    Image pixelArray = new Image(device, gridGC.m_truexur - gridGC.m_truexll, 1);
    Image pixelArrayCross = new Image(device, gridGC.m_truexur - gridGC.m_truexll, 1);

    GC pixelArrayGC = new GC(pixelArray);
    GC pixelArrayCrossGC = new GC(pixelArrayCross);
    try {
        org.eclipse.swt.graphics.Color foregroundColor = new org.eclipse.swt.graphics.Color(device,
                m_color.getRed(), m_color.getGreen(), m_color.getBlue());
        Color vpBackgroundColor = gc.getBackground();
        org.eclipse.swt.graphics.Color backgroundColor = new org.eclipse.swt.graphics.Color(device,
            vpBackgroundColor.getRed(),	vpBackgroundColor.getGreen(), vpBackgroundColor.getBlue());

        pixelArrayGC.setForeground(foregroundColor);
        pixelArrayGC.setBackground(backgroundColor);
        pixelArrayGC.setLineStyle(STYLE_DOT);
        pixelArrayGC.fillRectangle(0, 0, gridGC.m_truexur - gridGC.m_truexll, 1);

        pixelArrayCrossGC.setForeground(foregroundColor);
        pixelArrayCrossGC.setBackground(backgroundColor);
        pixelArrayCrossGC.setLineStyle(STYLE_DOT);
        pixelArrayCrossGC.fillRectangle(0, 0, gridGC.m_truexur - gridGC.m_truexll, 1);
    } catch (Exception ex)
    {
        System.out.println("Unable to draw cross: " +
                ex.getMessage());
    }

    for (int i = 0; i <= gridGC.m_xnum; i++)
    {
        int x = gridGC.m_xll + (i * gridGC.m_dx);
        int y = gridGC.m_yll;

        // Convert world coordinates to device coordinates.
        VpCoord coord = ((VpGraphics2D)gc.m_viewport).worldToDev(x, y);

        if (((coord.m_x - 1) >= gridGC.m_truexll) && ((coord.m_x + 1) <= gridGC.m_truexur))
        {
            pixelArrayGC.drawOval(coord.m_x - gridGC.m_truexll - 1, 0, 1, 1);
            pixelArrayGC.drawOval(coord.m_x - gridGC.m_truexll, 0, 1, 1);
            pixelArrayGC.drawOval(coord.m_x - gridGC.m_truexll + 1, 0, 1, 1);
            pixelArrayCrossGC.drawOval(coord.m_x - gridGC.m_truexll, 0, 1, 1);
        }
    }

    for (int j = 0; j <= gridGC.m_ynum; j++)
    {
        int x = gridGC.m_xll;
        int y = gridGC.m_yll + (j * gridGC.m_dy);

        // Convert world coordinates to device coordinates.
        VpCoord coord = ((VpGraphics2D)gc.m_viewport).worldToDev(x, y);

        if (((coord.m_y - 1) >= gridGC.m_trueyll) && ((coord.m_y + 1) <= gridGC.m_trueyur))
        {
            try {
                gc.drawImage(pixelArrayCross, gridGC.m_truexll, coord.m_y - 1);
                gc.drawImage(pixelArray, gridGC.m_truexll, coord.m_y);
                gc.drawImage(pixelArrayCross, gridGC.m_truexll, coord.m_y + 1);
            } catch (Exception ex) {
                System.out.println("Unable to draw cross: " +
                    ex.getMessage());
            }
        }
    }

    // Flush graphics to display.
    //gc.flush();

    // Dispose of the cross image resources.
    pixelArrayGC.dispose();
    pixelArrayCrossGC.dispose();
    pixelArray.dispose();
    pixelArrayCross.dispose();
}
开发者ID:WizzerWorks,项目名称:QtVp,代码行数:80,代码来源:vpgrid.cpp

示例2: main

int main(int argc, char **argv)
{
  if (argc < 5) {
    fprintf(stderr, "Usage: %s <maps.json> <map> <series> <max level> <base tile key>\n", argv[0]);
    return -1;
  }
  QFile rootFile(argv[1]);
  QString mapId(argv[2]);
  QString layerName(argv[3]);
  int maxLevel = atoi(argv[4]);
  QString rootTileKey("");
  if (argc == 5) {
    rootTileKey = QString(argv[5]);
  }

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


  int layer;
  if (!map->layerById(layerName, layer)) {
    fprintf(stderr, "Unknown layer %s\n", layerName.toLatin1().data());
    return -1;
  }
  Tile baseTile(layer, rootTileKey);
  int minLevel = baseTile.level();

  if (maxLevel <= baseTile.layer() || maxLevel > map->layer(layer).maxLevel()) {
    fprintf(stderr, "Invalid maximum level %d\n", maxLevel);
    return -1;    
  }

  printf("Merging layer %s from (%d, %d)@%d to %d\n", 
         map->layer(layer).name().toLatin1().data(),
         baseTile.x(), baseTile.y(), baseTile.level(), maxLevel);
         
  QRect baseRect(baseTile.x(), baseTile.y(), 1, 1);
  int tileSize = map->baseTileSize();
  
  for (int level = maxLevel - 1; level >= minLevel; level--) {
    printf("level %d\n", level);
    QRect tiles = map->rectAtLevel(baseRect, baseTile.level(), level);
    
    for (int y = tiles.top(); y <= tiles.bottom(); y++) {
      for (int x = tiles.left(); x <= tiles.right(); x++) {
        Tile to(x, y, level, layer);
        QImage image = QImage(256, 256, QImage::Format_RGB32);
        image.fill(QColor(255, 255, 255).rgb());
        QPainter p;
        bool isNull = true;
        QVector<QRgb> colorTable;
        p.begin(&image);
        p.setRenderHint(QPainter::SmoothPixmapTransform, true);
        for (int dy = 0; dy <= 1; dy++) {
          for (int dx = 0; dx <= 1; dx++) {
            Tile from(x * 2 + dx, y * 2 + dy, level + 1, layer);
            QString tilePath = map->tilePath(from);
            QImage tile(tilePath);
            if (!tile.isNull()) {
              isNull = false;
              QRect target(dx * tileSize / 2, dy * tileSize / 2, 
                           tileSize / 2, tileSize / 2);
              p.drawImage(target, tile);
              colorTable = tile.colorTable();
            }
          }
        }
        p.end();
        if (!isNull) {
          QImage indexImage = image.convertToFormat(QImage::Format_Indexed8, 
                                                    colorTable, Qt::ThresholdDither);
          indexImage.save(map->tilePath(to), "png");
        }
      }
    }

  }

  return 0;
}
开发者ID:djdarkbeat,项目名称:ZTopo,代码行数:80,代码来源:merge.cpp

示例3: print

void Matrix::print(const QString& fileName)
{
	QPrinter printer;
	printer.setColorMode (QPrinter::GrayScale);

	if (!fileName.isEmpty()){
	    printer.setCreator("QtiPlot");
	    printer.setOutputFormat(QPrinter::PdfFormat);
        printer.setOutputFileName(fileName);
	} else {
        QPrintDialog printDialog(&printer);
        if (printDialog.exec() != QDialog::Accepted)
            return;
    }
		printer.setFullPage( true );
		QPainter p;
		if ( !p.begin(&printer ) )
			return; // paint on printer
		int dpiy = printer.logicalDpiY();
		const int margin = (int) ( (1/2.54)*dpiy ); // 1 cm margins

        if (d_view_type == ImageView){
            p.drawImage (printer.pageRect(), d_matrix_model->renderImage());
            return;
        }

		QHeaderView *vHeader = d_table_view->verticalHeader();

		int rows = numRows();
		int cols = numCols();
		int height = margin;
		int i, vertHeaderWidth = vHeader->width();
		int right = margin + vertHeaderWidth;

		// print header
		p.setFont(QFont());
		QString header_label = d_matrix_model->headerData(0, Qt::Horizontal).toString();
		QRect br = p.boundingRect(br, Qt::AlignCenter, header_label);
		p.drawLine(right, height, right, height+br.height());
		QRect tr(br);

		for(i=0; i<cols; i++){
			int w = d_table_view->columnWidth(i);
			tr.setTopLeft(QPoint(right,height));
			tr.setWidth(w);
			tr.setHeight(br.height());
			header_label = d_matrix_model->headerData(i, Qt::Horizontal).toString();
			p.drawText(tr, Qt::AlignCenter, header_label,-1);
			right += w;
			p.drawLine(right, height, right, height+tr.height());

			if (right >= printer.width()-2*margin )
				break;
		}

		p.drawLine(margin + vertHeaderWidth, height, right-1, height);//first horizontal line
		height += tr.height();
		p.drawLine(margin, height, right-1, height);

		// print table values
		for(i=0;i<rows;i++){
			right = margin;
			QString cell_text = d_matrix_model->headerData(i, Qt::Horizontal).toString()+"\t";
			tr = p.boundingRect(tr, Qt::AlignCenter, cell_text);
			p.drawLine(right, height, right, height+tr.height());

			br.setTopLeft(QPoint(right,height));
			br.setWidth(vertHeaderWidth);
			br.setHeight(tr.height());
			p.drawText(br,Qt::AlignCenter,cell_text,-1);
			right += vertHeaderWidth;
			p.drawLine(right, height, right, height+tr.height());

			for(int j=0; j<cols; j++){
				int w = d_table_view->columnWidth (j);
				cell_text = text(i,j)+"\t";
				tr = p.boundingRect(tr,Qt::AlignCenter,cell_text);
				br.setTopLeft(QPoint(right,height));
				br.setWidth(w);
				br.setHeight(tr.height());
				p.drawText(br, Qt::AlignCenter, cell_text, -1);
				right += w;
				p.drawLine(right, height, right, height+tr.height());

				if (right >= printer.width()-2*margin )
					break;
			}
			height += br.height();
			p.drawLine(margin, height, right-1, height);

			if (height >= printer.height()-margin ){
				printer.newPage();
				height = margin;
				p.drawLine(margin, height, right, height);
			}
		}
}
开发者ID:BackupTheBerlios,项目名称:qtiplot-svn,代码行数:97,代码来源:Matrix.cpp

示例4: checkForUpdate

void NWaveformSlider::checkForUpdate()
{
    if (!m_waveBuilder)
        return;

    float builderPos;
    int builderIndex;
    m_waveBuilder->positionAndIndex(builderPos, builderIndex);

    if (m_oldSize != size() || m_oldBuilderIndex != builderIndex)
        m_needsUpdate = true;

    if ((builderPos != 0.0 && builderPos != 1.0) && m_timer->interval() != FAST_INTERVAL)
        m_timer->setInterval(FAST_INTERVAL);
    else
    if ((builderPos == 0.0 || builderPos == 1.0) && m_timer->interval() != IDLE_INTERVAL)
        m_timer->setInterval(IDLE_INTERVAL);

    if (m_needsUpdate) {
        QPainter painter;
        QImage waveImage;
        QImage backgroundImage;
        waveImage = backgroundImage = m_progressPlayingImage = m_progressPausedImage = m_remainingPlayingImage = m_remainingPausedImage = QImage(size(), QImage::Format_ARGB32_Premultiplied);

        m_oldBuilderPos = builderPos;
        m_oldBuilderIndex = builderIndex;
        m_oldSize = size();


        // waveform >>
        waveImage.fill(0);
        painter.begin(&waveImage);
        painter.setBrush(m_waveBackground);
        QPen wavePen;
        wavePen.setWidth(0);
        wavePen.setColor(m_waveBorderColor);
        painter.setPen(wavePen);

        painter.translate(1, 1);
        painter.scale((qreal)(width() - 1) / m_oldBuilderIndex * m_oldBuilderPos, (height() - 2) / 2);
        painter.translate(0, 1);

        QPainterPath pathPos;
        QPainterPath pathNeg;
        NWaveformPeaks *peaks = m_waveBuilder->peaks();
        for (int i = 0; i < m_oldBuilderIndex; ++i) {
            pathPos.lineTo(i, peaks->positive(i));
            pathNeg.lineTo(i, peaks->negative(i));
        }
        QPainterPath fullPath(pathNeg);
        fullPath.connectPath(pathPos.toReversed());
        fullPath.closeSubpath();
        painter.setRenderHint(QPainter::Antialiasing);
        painter.drawPath(fullPath);
        painter.end();
        // << waveform


        // main background >>
        painter.begin(&backgroundImage);
        backgroundImage.fill(0);
        painter.setPen(Qt::NoPen);
        painter.setBrush(m_background);
        painter.setRenderHint(QPainter::Antialiasing);
        painter.drawRoundedRect(rect(), m_radius, m_radius);
        painter.end();
        // << main background


        QList<QImage *> images; images << &m_progressPlayingImage << &m_progressPausedImage << &m_remainingPlayingImage << &m_remainingPausedImage;
        QList<QPainter::CompositionMode> modes; modes << m_playingComposition << m_pausedComposition << m_playingComposition << m_pausedComposition;
        QList<QBrush> brushes; brushes << m_progressPlayingBackground << m_progressPausedBackground << m_remainingPlayingBackground << m_remainingPausedBackground;
        for (int i = 0; i < images.size(); ++i) {
            painter.begin(images[i]);
            // background
            images[i]->fill(0);
            // + overlay
            painter.setPen(Qt::NoPen);
            painter.setBrush(brushes[i]);
            painter.setRenderHint(QPainter::Antialiasing);
            painter.drawRoundedRect(rect(), m_radius, m_radius);
            // + waveform
            painter.setCompositionMode(modes[i]);
            painter.drawImage(0, 0, waveImage);
            painter.setCompositionMode(QPainter::CompositionMode_DestinationOver);
            painter.drawImage(0, 0, backgroundImage);
            painter.end();
        }

        update();
        m_needsUpdate = false;
    }
}
开发者ID:chillin2,项目名称:nulloy,代码行数:93,代码来源:waveformSlider.cpp

示例5: paintImage

void BitmapImage::paintImage(QPainter& painter, QImage& image, QRect sourceRect, QRect destRect)
{
    painter.drawImage(QRect(mBounds.topLeft(), destRect.size()),
                      image,
                      sourceRect);
}
开发者ID:chchwy,项目名称:pencil2d,代码行数:6,代码来源:bitmapimage.cpp

示例6: placeImage

void FontRenderer::placeImage(QPainter& p,ushort symbol,int x,int y) {
    p.drawImage(x,y,m_rendered.chars[symbol].img);
}
开发者ID:chidean,项目名称:fontbuilder,代码行数:3,代码来源:fontrenderer.cpp

示例7: drawPixmap

  void drawPixmap(const QImage& sprite, const aw::coord& c, QPainter& painter) {
	QSize size = sprite.size();
	painter.drawImage(QPoint((c.x*16)+(16-size.width()), (c.y*16)+(16-size.height())), sprite);
  }
开发者ID:CoolCalmPete,项目名称:AdvanceWars2,代码行数:4,代码来源:PixmapDrawing.cpp

示例8: createArrowBackground

void  QmaxButton::createArrowBackground(QPainter &painter)
{
   // printf("Arrow BackGround2\n");
    QRect scaledRect;
    scaledRect = matrix.mapRect(QRect(0, 0, this->logicalSize.width(), this->logicalSize.height()));

    QImage image(scaledRect.width(), scaledRect.height(), QImage::Format_ARGB32_Premultiplied);
    image.fill(QColor(0, 0, 0, 0).rgba());
    //QPainter painter(image);
    painter.setRenderHint(QPainter::SmoothPixmapTransform);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setPen(Qt::NoPen);
    painter.drawImage(0, 0, image);

    if(Colors::useEightBitPalette)
    {
        painter.setPen(QColor(120,120,120));
        if(this->m_nPressed)
            painter.setBrush(QColor(60,60,60));
        else if(this->m_nHighlight)
            painter.setBrush(QColor(100,100,100));
        else
            painter.setBrush(QColor(80,80,80));
    }
    else
    {
        QLinearGradient outlinebrush(0,0,0,scaledRect.height());
        QLinearGradient brush(0,0,0,scaledRect.height());

        brush.setSpread(QLinearGradient::PadSpread);
        QColor highlight(255,255,255,128);
        QColor shadow(0,0,0,70);
        QColor sunken(220,220,220,30);
        QColor normal1(88,88,89,255);
        QColor normal2(88,88,89,255);
        QColor normal3(0,0,200,10);
        QColor normal4(255,255,250,255);

         if(m_nType==3 || m_nType == 4)
         {
            normal1 = QColor(100,180,189,55);
            normal2 = QColor(100,180,189,255);
         }
        if(m_nPressed)
        {
            outlinebrush.setColorAt(0.0f,shadow);
            outlinebrush.setColorAt(1.0f,highlight);
            brush.setColorAt(1.0f,sunken);
            painter.setPen(Qt::NoPen);

        }
        else
        {
            outlinebrush.setColorAt(0.75f,shadow);
            outlinebrush.setColorAt(0.0f,highlight);
            brush.setColorAt(0.0f,normal2);
            if(m_nHighlight)
                brush.setColorAt(1.0f,normal1);
            painter.setPen(QPen(outlinebrush,1));
        }
        if(this->isEnabled()==false )
        {
            outlinebrush.setColorAt(1.0f,shadow);
            outlinebrush.setColorAt(0.0f,highlight);
            brush.setColorAt(0.0f,normal3);
            painter.setPen(QPen(outlinebrush,2));

        }
        if(m_nStatus )
        {
            outlinebrush.setColorAt(1.0f,shadow);
            outlinebrush.setColorAt(0.0f,highlight);
            brush.setColorAt(0.0f,normal2);
            painter.setPen(QPen(outlinebrush,1));
        }
        painter.setBrush(brush);

    }

    
   // painter.drawRect(0, 0, scaledRect.width(), scaledRect.height());

    float xOff = scaledRect.width() / 2;
    float yOff = scaledRect.height() / 2;
    float sizex = 5.0f * matrix.m11();
    float sizey = 3.5f * matrix.m22();
    if (m_nType == 3)
        sizey *= -1;
    QPainterPath path;
    path.moveTo(xOff, yOff + (5 * sizey));
    path.lineTo(xOff - (4 * sizex), yOff - (3 * sizey));
    path.lineTo(xOff + (4 * sizex), yOff - (3 * sizey));
    path.lineTo(xOff, yOff + (5 * sizey));
    painter.drawPath(path);

}
开发者ID:Qmax,项目名称:PT6,代码行数:96,代码来源:qmaxbutton.cpp

示例9: paint

void ItemFoundAnimation::paint(QPainter& painter)
{
	painter.drawImage(currentX(), m_item->position().y(), m_item->image());
}
开发者ID:alexei-sch,项目名称:hidden_object_game,代码行数:4,代码来源:itemfoundanimation.cpp

示例10: paint

void paint(QPaintDevice* pd) {
    QPainter p;
    if (!p.begin(pd)) return;
    QPen pe(QColor("black"));
    pe.setWidthF(6.0);
    pe.setStyle(Qt::DashLine);
    p.setPen(pe);
    p.drawLine(QPointF(0,0),QPointF(100.0,100.0));
    pe.setColor("red");
    pe.setStyle(Qt::DotLine);
    p.setPen(pe);
    p.drawLine(QPointF(0,0),QPointF(50.0,25.0));
    pe.setColor("green");
    pe.setStyle(Qt::SolidLine);
    p.setPen(pe);
    p.drawLine(QPointF(0,0),QPointF(25.0,50.0));
    pe.setColor("blue");
    p.setPen(pe);
    p.drawText(50,10, QString("Hello World!"));
    p.drawLine(50,10,55,15);
    QFont f;
    QImage img(QString("qfe_plotterexportercairo.png"));
    pe.setWidthF(0.5);
    p.setPen(pe);
    p.drawImage(QRectF(50,25,50,50), img);
    //p.drawRect(QRectF(50,25,50,50));
    p.drawImage(QRectF(25,50,15,10), img);
    //p.drawRect(QRectF(25,50,15,10));
    p.drawImage(QRectF(225,50,100,100), img, QRect(5,5,12,12));
    p.drawRect(QRectF(125,50,15,10));
    pe.setWidthF(2);
    pe.setColor("red");
    p.setPen(pe);
    f.setFamily("Times New Roman");
    f.setPointSizeF(10);
    p.setFont(f);
    p.drawText(50,30, QString("Hello World!"));
    p.drawLine(50,30,55,35);

    f.setFamily("Arial");
    f.setPointSizeF(16);
    p.setFont(f);
    p.drawText(250,30, QString("Unicode-test: ")+QChar(0x2190)+QChar(0x2591)+QChar(0x2665)+QChar(0x039B)+QChar(0x03B6));
    p.drawLine(250,30,255,35);

    pe.setWidthF(1);
    p.setPen(pe);
    QBrush b(QColor("salmon"));
    p.fillRect(QRectF(100,10,50,50), b);
    p.drawRect(QRectF(100,10,50,50));
    QColor c=b.color();
    c.setAlphaF(0.5);
    b.setColor(c);
    pe.setWidthF(5);
    p.setPen(pe);
    p.setBrush(b);
    p.drawEllipse(QRectF(130,40,50,30));
    //p.drawRect(QRectF(130,40,50,30));
    QPolygonF poly;
    for (int phi=0; phi<60; phi++) {
        double p=double(phi)/20.0*M_PI;
        poly<<QPointF(50.0+cos(p)*35.0*double(phi)/60.0, 50.0-sin(p)*35.0*double(phi)/60.0);
    }

    p.setClipRect(0,0,200,50);

    pe.setWidthF(1);
    p.setPen(pe);
    p.drawPolygon(poly);
    pe.setColor("red");
    pe.setStyle(Qt::DashDotDotLine);
    p.setPen(pe);
    p.setClipping(false);
    p.drawPolyline(poly);


    p.end();
}
开发者ID:jkriege2,项目名称:cairoQPaintDevice,代码行数:78,代码来源:cairoQPaintDevice_test.cpp

示例11: createButton

void  QmaxButton::createButton(QPainter &painter)
{
    QRect scaledRect;
    scaledRect = matrix.mapRect(QRect(0,0,this->logicalSize.width(),this->logicalSize.height()));
    QImage bg(this->m_strImage);
    painter.setRenderHint(QPainter::SmoothPixmapTransform);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setPen(Qt::NoPen);
    QLinearGradient brush1(0,0,0,scaledRect.height());
    painter.drawImage(-2, -2, bg);


    if(Colors::useEightBitPalette)
    {
        painter.setPen(QColor(120,120,120));
        if(this->m_nPressed)
            painter.setBrush(QColor(60,60,60));
        else if(this->m_nHighlight)
            painter.setBrush(QColor(100,100,100));
        else
            painter.setBrush(QColor(80,80,80));
    }
    else
    {
        QLinearGradient outlinebrush(0,0,0,scaledRect.height());
        QLinearGradient brush(0,0,0,scaledRect.height());

        brush.setSpread(QLinearGradient::PadSpread);
        QColor highlight(255,255,255,128);
        QColor shadow(0,0,0,70);
        QColor sunken(220,220,220,30);
        QColor normal1(255,255,245,60);
        QColor normal2(255,255,235,10);
        QColor normal3(200,200,200,10);
        QColor normal4(255,255,250,255);

         if(m_nType && m_nType != 5  )
         {
            normal1 = QColor(200,170,160,50);
            normal2 = QColor(50,10,0,50);
         }
        if(m_nPressed)
        {
            outlinebrush.setColorAt(0.0f,shadow);
            outlinebrush.setColorAt(1.0f,highlight);
            brush.setColorAt(1.0f,sunken);
            painter.setPen(Qt::NoPen);

        }
        else
        {
            outlinebrush.setColorAt(1.0f,shadow);
            outlinebrush.setColorAt(0.0f,highlight);
            brush.setColorAt(0.0f,normal1);
            if(m_nHighlight)
                brush.setColorAt(1.0f,normal2);
            painter.setPen(QPen(outlinebrush,1));
        }
        if(this->isEnabled()==false )
        {
            outlinebrush.setColorAt(1.0f,shadow);
            outlinebrush.setColorAt(0.0f,highlight);
            brush.setColorAt(0.0f,normal3);
            painter.setPen(QPen(outlinebrush,1));

        }
        if(m_nStatus )
        {
            outlinebrush.setColorAt(1.0f,shadow);
            outlinebrush.setColorAt(0.0f,highlight);
            brush.setColorAt(0.0f,normal4);
            painter.setPen(QPen(outlinebrush,1));
        }
        painter.setBrush(brush);

    }


    if(m_nType == 1)
        painter.drawRect(0,0,scaledRect.width(),scaledRect.height());
    else if(m_nType == 0)
        painter.drawRoundedRect(0,0,scaledRect.width(),scaledRect.height(),40.0,40.0,Qt::RelativeSize);
    else if(m_nType == 5)
        painter.drawEllipse(0,0,scaledRect.width(),scaledRect.height());
    QFont font( "DejaVu Sans" );
    font.setPointSize( 12 );
    painter.setFont( font );
    brush1.setColorAt(1.0f,QColor(255,255,255,255));
    if(this->isEnabled()==false)
    {
        brush1.setColorAt(1.0f,QColor(200,200,200,100));
    }
    painter.setPen(QPen(brush1,1));
    painter.setBrush(brush1);
    QFontMetrics fMetrics = painter.fontMetrics();
    QSize sz = fMetrics.size( Qt::TextWordWrap, m_strText );
    QRectF txtRect( scaledRect.center(), sz );
    int xPoint = (scaledRect.width()/2)- ((m_strText.count()/2)*10);
    int yPoint = scaledRect.height()/2;
    painter.drawText(xPoint,yPoint,m_strText);
//.........这里部分代码省略.........
开发者ID:Qmax,项目名称:PT6,代码行数:101,代码来源:qmaxbutton.cpp

示例12: ASSERT

void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* canvas, const FloatRect& srcRect,
    const FloatRect& dstRect, ExceptionCode& ec)
{
    ASSERT(canvas);

    ec = 0;

    FloatRect srcCanvasRect = FloatRect(FloatPoint(), canvas->size());
    if (!(srcCanvasRect.contains(srcRect) && srcRect.width() >= 0 && srcRect.height() >= 0 
            && dstRect.width() >= 0 && dstRect.height() >= 0)) {
        ec = INDEX_SIZE_ERR;
        return;
    }

    if (srcRect.isEmpty() || dstRect.isEmpty())
        return;

    GraphicsContext* c = drawingContext();
    if (!c)
        return;
        
    FloatRect sourceRect = c->roundToDevicePixels(srcRect);
    FloatRect destRect = c->roundToDevicePixels(dstRect);
        
    // FIXME: Do this through platform-independent GraphicsContext API.
#if PLATFORM(CG)
    CGImageRef platformImage = canvas->createPlatformImage();
    if (!platformImage)
        return;

    willDraw(destRect);

    float iw = CGImageGetWidth(platformImage);
    float ih = CGImageGetHeight(platformImage);
    if (sourceRect.x() == 0 && sourceRect.y() == 0 && iw == sourceRect.width() && ih == sourceRect.height()) {
        // Fast path, yay!
        CGContextDrawImage(c->platformContext(), destRect, platformImage);
    } else {
        // Slow path, boo!
        // Create a new bitmap of the appropriate size and then draw that into our context.

        size_t csw = static_cast<size_t>(ceilf(sourceRect.width()));
        size_t csh = static_cast<size_t>(ceilf(sourceRect.height()));

        CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
        size_t bytesPerRow = csw * 4;
        void* buffer = fastMalloc(csh * bytesPerRow);

        CGContextRef clippedSourceContext = CGBitmapContextCreate(buffer, csw, csh,
            8, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast);
        CGColorSpaceRelease(colorSpace);
        CGContextTranslateCTM(clippedSourceContext, -sourceRect.x(), -sourceRect.y());
        CGContextDrawImage(clippedSourceContext, CGRectMake(0, 0, iw, ih), platformImage);

        CGImageRef clippedSourceImage = CGBitmapContextCreateImage(clippedSourceContext);
        CGContextRelease(clippedSourceContext);

        CGContextDrawImage(c->platformContext(), destRect, clippedSourceImage);
        CGImageRelease(clippedSourceImage);
        
        fastFree(buffer);
    }

    CGImageRelease(platformImage);
#elif PLATFORM(QT)
    QImage px = canvas->createPlatformImage();
    if (px.isNull())
        return;
    willDraw(dstRect);
    QPainter* painter = static_cast<QPainter*>(c->platformContext());
    painter->drawImage(dstRect, px, srcRect);
#elif PLATFORM(CAIRO)
    cairo_surface_t* image = canvas->createPlatformImage();
    willDraw(dstRect);
    cairo_t* cr = c->platformContext();
    cairo_save(cr);
    cairo_set_source_surface(cr, image, srcRect.x(), srcRect.y());
    cairo_rectangle(cr, dstRect.x(), dstRect.y(), dstRect.width(), dstRect.height());
    cairo_fill(cr);
    cairo_restore(cr);
#endif
}
开发者ID:FilipBE,项目名称:qtextended,代码行数:82,代码来源:CanvasRenderingContext2D.cpp

示例13: GenPreview

void FDialogPreview::GenPreview(QString name)
{
	QPixmap pm;
	QString Buffer = "";
	updtPix();
	if (name.isEmpty())
		return;
	QFileInfo fi = QFileInfo(name);
	if (fi.isDir())
		return;
	int w = pixmap()->width();
	int h = pixmap()->height();
	bool mode = false;
	QString ext = fi.suffix().toLower();
	QString formatD(FormatsManager::instance()->extensionListForFormat(FormatsManager::IMAGESIMGFRAME, 1));
 	QStringList formats = formatD.split("|");
	formats.append("pat");
	
	QStringList allFormatsV = LoadSavePlugin::getExtensionsForPreview(FORMATID_ODGIMPORT);
	if (ext.isEmpty())
		ext = getImageType(name);
	if (formats.contains(ext.toUtf8()))
	{
		ScImage im;
		//No doc to send data anyway, so no doc to get into scimage.
		CMSettings cms(0, "", Intent_Perceptual);
		cms.allowColorManagement(false);
		if (im.loadPicture(name, 1, cms, ScImage::Thumbnail, 72, &mode))
		{
			int ix,iy;
			if ((im.imgInfo.exifDataValid) && (!im.imgInfo.exifInfo.thumbnail.isNull()))
			{
				ix = im.imgInfo.exifInfo.width;
				iy = im.imgInfo.exifInfo.height;
			}
			else
			{
				ix = im.width();
				iy = im.height();
			}
			int xres = im.imgInfo.xres;
			int yres = im.imgInfo.yres;
			QString tmp = "";
			QString tmp2 = "";
			QImage im2 = im.scaled(w - 5, h - 44, Qt::KeepAspectRatio, Qt::SmoothTransformation);
			QPainter p;
			QBrush b(QColor(205,205,205), loadIcon("testfill.png"));
			// Qt4 FIXME imho should be better
			pm = *pixmap();
			p.begin(&pm);
			p.fillRect(0, 0, w, h-44, b);
			p.fillRect(0, h-44, w, 44, QColor(255, 255, 255));
			p.drawImage((w - im2.width()) / 2, (h - 44 - im2.height()) / 2, im2);
			p.drawText(2, h-29, tr("Size:")+" "+tmp.setNum(ix)+" x "+tmp2.setNum(iy));
			p.drawText(2, h-17, tr("Resolution:")+" "+tmp.setNum(xres)+" x "+tmp2.setNum(yres)+" "+ tr("DPI"));
			QString cSpace;
			if ((extensionIndicatesPDF(ext) || extensionIndicatesEPSorPS(ext)) && (im.imgInfo.type != ImageType7))
				cSpace = tr("Unknown");
			else
				cSpace=colorSpaceText(im.imgInfo.colorspace);
			p.drawText(2, h-5, tr("Colorspace:")+" "+cSpace);
			p.end();
			setPixmap(pm);
			repaint();
		}
	}
	else if (allFormatsV.contains(ext.toUtf8()))
	{
		FileLoader *fileLoader = new FileLoader(name);
		int testResult = fileLoader->TestFile();
		delete fileLoader;
		if ((testResult != -1) && (testResult >= FORMATID_ODGIMPORT))
		{
			const FileFormat * fmt = LoadSavePlugin::getFormatById(testResult);
			if( fmt )
			{
				QImage im = fmt->readThumbnail(name);
				if (!im.isNull())
				{
					QString desc = tr("Size:")+" ";
					desc += value2String(im.text("XSize").toDouble(), PrefsManager::instance()->appPrefs.docSetupPrefs.docUnitIndex, true, true);
					desc += " x ";
					desc += value2String(im.text("YSize").toDouble(), PrefsManager::instance()->appPrefs.docSetupPrefs.docUnitIndex, true, true);
					im = im.scaled(w - 5, h - 21, Qt::KeepAspectRatio, Qt::SmoothTransformation);
					QPainter p;
					QBrush b(QColor(205,205,205), loadIcon("testfill.png"));
					pm = *pixmap();
					p.begin(&pm);
					p.fillRect(0, 0, w, h-21, b);
					p.fillRect(0, h-21, w, 21, QColor(255, 255, 255));
					p.drawImage((w - im.width()) / 2, (h - 21 - im.height()) / 2, im);
					p.drawText(2, h-5, desc);
					p.end();
					setPixmap(pm);
					repaint();
				}
			}
		}
	}
	else if (ext.toUtf8() == "sml")
//.........这里部分代码省略.........
开发者ID:moceap,项目名称:scribus,代码行数:101,代码来源:customfdialog.cpp

示例14: main

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));


    QSqlDatabase db=QSqlDatabase::addDatabase("QMYSQL");

    //maBase=new QSqlDatabase(db);

    db.setHostName("172.16.63.111");
    db.setDatabaseName("dbtrouxNewWorld");
    db.setUserName("troux");
    db.setPassword("PscX57Q16");
    bool ok = db.open();
    if(!ok)
    {
        cout<<"Connection impossible"<<endl;
    }
    else
    {
        cout<<"Connection réussie"<<endl;
    }

    Connexion co;
    QVector<int> idUser = co.getTabIdUser();
    int nbUser = idUser.size();



    for(int comp=0; comp<nbUser; comp++)
    {
        QString userNom = co.getUserNom(idUser[comp]);
        QString userPrenom = co.getUserPrenom(idUser[comp]);
        QVector<int> numPDV = co.getUserTabPointDeVente(idUser[comp]);
        QVector<int> numProduit;
        for(int compPDV=0; compPDV<numPDV.size(); compPDV++)
        {
            QVector<int> tabInstNumProd = co.getProdByPDV(numPDV[compPDV]);
            for(int compProd=0; compProd < tabInstNumProd.size(); compProd++)
            {
                bool uniqueNumProd = true;
                for(int compVerifDoubleProd=0; compVerifDoubleProd < numProduit.size(); compVerifDoubleProd++)
                {
                    if(numProduit[compVerifDoubleProd] == tabInstNumProd[compProd])
                    {
                        uniqueNumProd = false;
                    }
                }
                if(uniqueNumProd){
                    numProduit.push_back(tabInstNumProd[compProd]);
                }
            }
        }
        QVector<int> numRayon = co.getTabRayon(numProduit);
        QVector<int> numCategorie = co.getTabCategorie(numRayon);

        QPrinter printer(QPrinter::HighResolution); //create your QPrinter (don't need to be high resolution, anyway)
        printer.setFullPage(QPrinter::A4);
        printer.setOutputFormat(QPrinter::NativeFormat);
        printer.setOutputFileName("pdfClient/"+ QString::number(idUser[comp]) +".pdf");


        QPen pen;
        int decalage = -100;
        int tailleImage = 1800;
        QPainter painter;
        painter.begin(&printer);
        QRectF rectangle(700, decalage,1000,900);
        QImage monImage;
        monImage.load("images/presentation/logoNw.jpg");
        painter.drawImage(rectangle, monImage);
        QRectF rectangle2(1200, decalage,8000,1000);
        QImage monImage2;
        monImage2.load("images/presentation/ecritureNw.png");
        painter.drawImage(rectangle2, monImage2);
        decalage += 2000;
        painter.setFont(QFont("Arial",15));
        painter.drawText(0, decalage, userNom +" "+ userPrenom +",");
        decalage += 250;
        painter.drawText(0, decalage,"Bienvenue sur votre catalogue personnalisé ");
        decalage += 400;
        painter.setFont(QFont("Arial",9));
        painter.drawText(0, decalage, "Liste des points de vente associés :");
        decalage += 200;
        pen.setWidth(10);
        painter.setPen(pen);
        for(int compNbPDV=0; compNbPDV<numPDV.size(); compNbPDV++)
        {
            painter.drawRect(0, decalage, 3000, 300);
            painter.drawText(100, decalage+200, QString::number(compNbPDV+1)+ " : " +co.getNomPDV(numPDV[compNbPDV]));
            painter.drawText(2000, decalage+200, QString::number(co.getProdByPDV(numPDV[compNbPDV]).size())+ " Produits");
            decalage += 300;
        }
        decalage += 1000;
        painter.setFont(QFont("Arial",12));
        painter.drawText(0, decalage,"Nous vous proposerons cette semaine "+QString::number(numProduit.size()) +" produits parmi les "+ QString::number(numPDV.size()) +" points de vente choisis.");
        decalage += 650;
//.........这里部分代码省略.........
开发者ID:rlesieur05,项目名称:newWorldTR-RL,代码行数:101,代码来源:main.cpp

示例15: off

void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context )
{
  QPainter *p = context.renderContext().painter();
  if ( !p )
  {
    return;
  }

  //offset
  double offsetX = 0;
  double offsetY = 0;
  markerOffset( context, offsetX, offsetY );
  QPointF off( offsetX, offsetY );

  //angle
  double angle = mAngle;
  if ( mAngleExpression )
  {
    angle = mAngleExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
  }
  if ( angle )
    off = _rotatedOffset( off, angle );

  //data defined shape?
  if ( mNameExpression )
  {
    QString name = mNameExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString();
    if ( !prepareShape( name ) ) // drawing as a polygon
    {
      preparePath( name ); // drawing as a painter path
    }
  }

  if ( mUsingCache )
  {
    // we will use cached image
    QImage &img = context.selected() ? mSelCache : mCache;
    double s = img.width() / context.renderContext().rasterScaleFactor();
    p->drawImage( QRectF( point.x() - s / 2.0 + off.x(),
                          point.y() - s / 2.0 + off.y(),
                          s, s ), img );
  }
  else
  {
    QMatrix transform;

    // move to the desired position
    transform.translate( point.x() + off.x(), point.y() + off.y() );

    QgsExpression *sizeExpression = expression( "size" );
    bool hasDataDefinedSize = context.renderHints() & QgsSymbolV2::DataDefinedSizeScale || sizeExpression;

    // resize if necessary
    if ( hasDataDefinedSize )
    {
      double scaledSize = mSize;
      if ( sizeExpression )
      {
        scaledSize = sizeExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
      }
      scaledSize *= QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mSizeUnit );

      switch ( mScaleMethod )
      {
        case QgsSymbolV2::ScaleArea:
          scaledSize = sqrt( scaledSize );
          break;
        case QgsSymbolV2::ScaleDiameter:
          break;
      }

      double half = scaledSize / 2.0;
      transform.scale( half, half );
    }

    bool hasDataDefinedRotation = context.renderHints() & QgsSymbolV2::DataDefinedRotation || mAngleExpression;
    if ( angle != 0 && hasDataDefinedRotation )
      transform.rotate( angle );

    QgsExpression* colorExpression = expression( "color" );
    QgsExpression* colorBorderExpression = expression( "color_border" );
    QgsExpression* outlineWidthExpression = expression( "outline_width" );
    if ( colorExpression )
    {
      mBrush.setColor( QgsSymbolLayerV2Utils::decodeColor( colorExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) );
    }
    if ( colorBorderExpression )
    {
      mPen.setColor( QgsSymbolLayerV2Utils::decodeColor( colorBorderExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) );
      mSelPen.setColor( QgsSymbolLayerV2Utils::decodeColor( colorBorderExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() ) );
    }
    if ( outlineWidthExpression )
    {
      double outlineWidth = outlineWidthExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
      mPen.setWidthF( outlineWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOutlineWidthUnit ) );
      mSelPen.setWidthF( outlineWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOutlineWidthUnit ) );
    }

    p->setBrush( context.selected() ? mSelBrush : mBrush );
    p->setPen( context.selected() ? mSelPen : mPen );
//.........这里部分代码省略.........
开发者ID:maggi,项目名称:QGIS,代码行数:101,代码来源:qgsmarkersymbollayerv2.cpp


注:本文中的QPainter::drawImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。