void GraphicsScene::printPage(int index, int percentual , QPainter &painter, QPrinter * printer) { QPixmap pixmap(painter.viewport().width(),painter.viewport().height()); /* virtual paper */ bool portrait = printer->orientation() == QPrinter::Portrait ? true : false; const qreal wit = qMin(printer->pageRect().width(),printer->paperRect().width()); const qreal hei = qMin(printer->pageRect().height(),printer->paperRect().height()); const qreal faktor_print = qMax(wit,hei) / qMin(wit,hei); const QRect Paper_Rect = printer->pageRect(); qreal onepagescene_HI = sceneRect().width() * faktor_print; if (!portrait) { onepagescene_HI = sceneRect().width() / faktor_print; } QRectF rectScenePiece = QRectF (0.,0.,sceneRect().width(),onepagescene_HI); /* first slice from scene */ const qreal page = sceneRect().height() / onepagescene_HI; /* page need */ int PageSumm = page; if (page > PageSumm) { PageSumm++; /* float to next int */ } if ( index > PageSumm ) { return; /* not having this page */ } qreal InitOnYtop = 0; if (index != 0) { InitOnYtop = rectScenePiece.height() * index; } QRect pagepiece = QRect(0,InitOnYtop,rectScenePiece.width(),rectScenePiece.height()); //////////qDebug() << "### page " << index << "," << percentual << "," << printer->pageRect(); const qreal smallpart = qMax(pixmap.width(),pixmap.height()) / faktor_print; QRectF AFormatPaper; /* Paper dimension from printer Faktor run */ if (portrait) { AFormatPaper = QRect(0,0,smallpart,qMax(pixmap.width(),pixmap.height())); } else { AFormatPaper = QRect(0,0,qMax(pixmap.width(),pixmap.height()),smallpart); } QRectF ZoomFaktorPage = Reduce(AFormatPaper,percentual); /* zoom rect */ QRect WhitePaper = CenterRectSlaveFromMaster(pixmap.rect(),AFormatPaper).toRect(); QRect RenderPage = CenterRectSlaveFromMaster(pixmap.rect(),ZoomFaktorPage).toRect(); painter.fillRect(painter.viewport(),QBrush(Qt::lightGray)); /* device to cover */ painter.fillRect(WhitePaper,QBrush(Qt::white)); /* paper */ /////////painter.fillRect(RenderPage,QBrush(Qt::red)); /* page result */ render(&painter,RenderPage,pagepiece,Qt::KeepAspectRatio); }
void CanvasRenderer::paintGrid( QPainter& painter ) { int gridSize = mOptions.nGridSize; QRectF rect = painter.viewport(); QRectF boundingRect = mViewTransform.inverted().mapRect( rect ); int w = boundingRect.width(); int h = boundingRect.height(); //qDebug() << mViewTransform; //qDebug() << mViewTransform.inverted(); int left = round100( boundingRect.left(), gridSize ) - gridSize; int right = round100( boundingRect.right(), gridSize ) + gridSize; int top = round100( boundingRect.top(), gridSize ) - gridSize; int bottom = round100( boundingRect.bottom(), gridSize ) + gridSize; QPen pen( Qt::lightGray ); pen.setCosmetic( true ); painter.setPen( pen ); painter.setWorldMatrixEnabled( true ); painter.setBrush( Qt::NoBrush ); QPainter::RenderHints previous_renderhints = painter.renderHints(); painter.setRenderHint( QPainter::Antialiasing, false ); for ( int x = left; x < right; x += gridSize ) { painter.drawLine( x, top, x, bottom ); } for ( int y = top; y < bottom; y += gridSize ) { painter.drawLine( left, y, right, y ); } painter.setRenderHints(previous_renderhints); }
void ClusterView::print(QPainter& printPainter,QPaintDeviceMetrics& metrics,bool whiteBackground){ //Draw the double buffer (pixmap) by copying it into the printer device throught the painter. QRect viewportOld = QRect(viewport.left(),viewport.top(),viewport.width(),viewport.height()); viewport = QRect(printPainter.viewport().left(),printPainter.viewport().top(),printPainter.viewport().width(),printPainter.viewport().height()); QRect r = ((QRect)window); //Set the window (part of the world I want to show) printPainter.setWindow(r.left(),r.top(),r.width()-1,r.height()-1);//hack because Qt QRect is used differently in this function //Fill the background with the background color QRect back = QRect(r.left(),r.top(),r.width(),r.height()); QColor colorLegendTmp = colorLegend; QColor background= backgroundColor(); if(whiteBackground){ colorLegend = black; setPaletteBackgroundColor(white); } printPainter.fillRect(back,backgroundColor()); printPainter.setClipRect(back,QPainter::CoordPainter); //Draw the axes drawAxes(printPainter); //Paint all the clusters in the shownClusters list (in the double buffer) drawClusters(printPainter,view.clusters(),true); //reset transformation due to setWindow and setViewport printPainter.resetXForm(); //Draw the time axis information if the time is displayed drawTimeInformation(printPainter); printPainter.setClipping(false); //Restore the colors. if(whiteBackground){ colorLegend = colorLegendTmp; setPaletteBackgroundColor(background); } //Restore the previous state viewport = QRect(viewportOld.left(),viewportOld.top(),viewportOld.width(),viewportOld.height()); }
void PixmapRenderer::drawPixmapNoXRender(QPainter& painter, QPixmap const& pixmap) { QTransform const inv_transform(painter.worldTransform().inverted()); QRectF const src_rect(inv_transform.map(QRectF(painter.viewport())).boundingRect()); QRectF const bounded_src_rect(src_rect.intersected(pixmap.rect())); painter.drawPixmap(bounded_src_rect, pixmap, bounded_src_rect); }
void PaintWidget::paintTo(const QRect &dirtyRect, QPainter &painter) { painter.setRenderHint(QPainter::SmoothPixmapTransform, true); painter.setRenderHint(QPainter::Antialiasing, true); //painter.setRenderHint(QPainter::HighQualityAntialiasing, true); //draw screenshot if enabled if(drawScreenhot_) { painter.save(); auto size = painter.viewport().size(); QSize s = screenshot_.size(); QRect r = calcDrawArea(s, size); painter.drawPixmap(r,screenshot_); painter.restore(); } //draw pdf if available if(drawPdf_ && pdfDocument_) { QSize s(4, 3); QRect area = calcDrawArea(s, painter.viewport().size()); //std::cout << area.x() << ' ' << area.y() << ' ' << area.width() << ' ' << area.height() << std::endl; painter.drawImage(area, pdfImage_); } painter.save(); //draw the overlay image auto size = this->size(); painter.scale( (qreal)size.width() / (qreal)overlayImage_.width(), (qreal)size.height() / (qreal)overlayImage_.height()); painter.drawImage(dirtyRect, overlayImage_, dirtyRect); //draw temporary stuff if(isPainting_ && paintTool_ == PaintToolType::Rectangle) { QColor color(pen_.color()); color.setAlpha(100); painter.fillRect(rectTool, color); } painter.restore(); }
QPixmap TaintedPixmap::createTaintedPixmapMacOnly(const QString &pixmap_path, const QColor &tint_color) { QPixmap shape(pixmap_path); QPixmap result(shape); QPainter painter; painter.begin(&result); painter.drawPixmap(painter.viewport(), shape); // Create a color mask painter.setCompositionMode(QPainter::CompositionMode_SourceIn); painter.fillRect(painter.viewport(), tint_color); // Apply the shape on top of the mask painter.setCompositionMode(QPainter::CompositionMode_SourceOver); painter.drawPixmap(painter.viewport(), shape); painter.end(); return result; }
QPixmap TaintedPixmap::createTaintedPixmapNotMac(const QString &pixmap_path, const QColor &tint_color) { QPixmap shape(pixmap_path); QPixmap result(shape); QPainter painter; painter.begin(&result); painter.fillRect(painter.viewport(), tint_color); // Apply the shape on top of the tint painter.setCompositionMode(QPainter::CompositionMode_SourceOver); painter.drawPixmap(painter.viewport(), shape); // Remove unused background painter.setCompositionMode(QPainter::CompositionMode_DestinationIn); painter.drawPixmap(painter.viewport(), shape); painter.end(); return result; }
void ReinforcementPower::Draw(QPainter &painter) { int w = painter.viewport().width(), h = painter.viewport().height(); int graphW = 200, graphH = 100, graphPad = 10; int top = h - 10 - (graphH + 2*graphPad); int left = 10; QPainter::RenderHints hints = painter.renderHints(); painter.setRenderHint(QPainter::Antialiasing, false); QFont font = painter.font(); font.setPointSize(9); painter.setFont(font); // we draw the rectangle behind painter.setOpacity(1); painter.setBrush(Qt::NoBrush); painter.setPen(QPen(Qt::black, 2)); painter.drawRect(left, top, graphW + 2*graphPad, graphH + 2*graphPad); painter.setOpacity(0.6); painter.setPen(Qt::NoPen); painter.setBrush(Qt::white); painter.drawRect(left, top, graphW + 2*graphPad, graphH + 2*graphPad); painter.setOpacity(1); painter.setBrush(Qt::black); painter.setPen(Qt::black); // we draw the values double maxValue = -DBL_MAX; FOR(i, historyValue.size()) maxValue = max(maxValue, historyValue[i]); int valueLimit = 4; double upperBound = ((int)ceil(maxValue)/valueLimit + 1)*valueLimit; painter.setPen(QPen(Qt::black, 2)); QPointF oldPoint; FOR(i, graphW) { int index = i*historyValue.size()/graphW; QPointF point(i, graphH*(1.f - (historyValue[index]/upperBound))); point += QPointF(left + graphPad, top + graphPad); if(i) painter.drawLine(point, oldPoint); if(i==graphW-1) { painter.drawText(point + QPointF(-20,0), QString("%1").arg(historyValue.back(), 0, 'f', 2)); } oldPoint = point; }
void ProcessWidget::print(QPrinter *printer, const QString &filePath){ QPainter printPainter; const int height = printer->height(); const int width = printer->width(); const int Margin = 20; int yPos = 0; // y-position for each line printPainter.begin(printer); QRect textRec = QRect(printPainter.viewport().left() + 5 ,printPainter.viewport().height() - 20,printPainter.viewport().width() - 5,20); QFont f("Helvetica",8); printPainter.setFont(f); QFontMetrics fontMetrics = printPainter.fontMetrics(); for(int i = 0; i< count(); i++){ // no more room on the current page if(Margin + yPos > height - Margin) { printPainter.setPen(Qt::black); printPainter.drawText(Margin,Margin + yPos + fontMetrics.lineSpacing(),width,fontMetrics.lineSpacing(), Qt::AlignLeft | Qt::AlignVCenter,tr("File: %1").arg(filePath)); printer->newPage(); yPos = 0; // back to top of page } //Draw text ProcessListBoxItem* boxItem = static_cast<ProcessListBoxItem*>(item(i)); printPainter.setPen(boxItem->color()); printPainter.drawText(Margin,Margin + yPos, width,fontMetrics.lineSpacing(), Qt::TextExpandTabs | Qt::TextDontClip, boxItem->text()); yPos = yPos + fontMetrics.lineSpacing(); } //Print the name of the file printPainter.resetMatrix(); printPainter.setPen(Qt::black); printPainter.drawText(textRec,Qt::AlignLeft | Qt::AlignVCenter,tr("File: %1").arg(filePath)); printPainter.end(); }
void MazePainter::paint(MazeModel *pModel, QPainter &painter) { if (!pModel->hasMaze()) return; QRect rSize = painter.viewport(); int nMazeWidth = pModel->width(); int nMazeHeight = pModel->height(); float nCellSize = std::min((float)rSize.width()/nMazeWidth, (float)rSize.height()/nMazeHeight); //draw the big left and top walls of the maze QLineF wall; wall.setP1(QPointF(0, 0)); wall.setP2(QPointF(nCellSize, 0)); for (int col = 0; col < nMazeWidth; col++) { if (pModel->cellWalls(col, 0) & MazeModel::UP) painter.drawLine(wall); wall.translate(nCellSize, 0); } wall.setP1(QPointF(0, 0)); wall.setP2(QPointF(0, nCellSize)); for (int row = 0; row < nMazeHeight; row++) { if (pModel->cellWalls(0, row) & MazeModel::LEFT) painter.drawLine(wall); wall.translate(0, nCellSize); } //draw the rest of the maze's walls for (int row = 0; row < nMazeHeight; row++) { QLineF wallDown(0, (row+1)*nCellSize, nCellSize, (row+1)*nCellSize); QLineF wallRight(nCellSize, row*nCellSize, nCellSize, (row+1)*nCellSize); for (int col = 0; col < nMazeWidth; col++) { int walls = pModel->cellWalls(col, row); if (walls & MazeModel::RIGHT) painter.drawLine(wallRight); if (walls & MazeModel::DOWN) painter.drawLine(wallDown); wallDown.translate(nCellSize, 0); wallRight.translate(nCellSize, 0); } } }
void CanvasRenderer::paintCameraBorder(QPainter &painter) { for ( int i = 0; i < mObject->getLayerCount(); ++i ) { Layer* layer = mObject->getLayer( i ); if ( layer->type() == Layer::CAMERA && (i == mLayerIndex || mOptions.nShowAllLayers > 0) && layer->visible() ) { if ( i == mLayerIndex || mOptions.nShowAllLayers != 1 ) { painter.setOpacity( 1.0 ); } else { painter.setOpacity( 0.8 ); } QRectF viewRect = painter.viewport(); QRect boundingRect = mViewTransform.inverted().mapRect( viewRect ).toRect(); LayerCamera* cameraLayer = dynamic_cast< LayerCamera* >( layer ); QRect cameraRect = cameraLayer->getViewRect(); painter.setWorldMatrixEnabled( true ); painter.setPen( Qt::NoPen ); painter.setBrush( QColor( 0, 0, 0, 160 ) ); QRegion rg1(boundingRect); QRegion rg2(cameraRect); QRegion rg3=rg1.subtracted(rg2); painter.setClipRegion(rg3); painter.drawRect( boundingRect ); painter.setClipping(false); painter.setPen( Qt::black ); painter.setBrush( Qt::NoBrush ); painter.drawRect( cameraRect ); } } }
bool ExportWizard::printPdf() { // get dpi, compute printed size int printDpi = m_pdfPrinter->resolution(); QSizeF canvasPrintSize = canvasNatInches() * (qreal)printDpi; Qt::AspectRatioMode printAspect = Qt::KeepAspectRatio; // open the painter over the printer QPainter painter; if (!painter.begin(m_pdfPrinter)) { QMessageBox::warning(0, tr("PDF Error"), tr("Error saving to the PDF file, try to chose another one."), QMessageBox::Cancel); return false; } QRect paperRect = painter.viewport(); QRect targetRect(0, 0, (int)canvasPrintSize.width(), (int)canvasPrintSize.height()); // adapt rect Scale switch (m_ui->pdfScaleCombo->currentIndex()) { case 0: // Original break; case 1: { // Fit to page QSize targetSize = targetRect.size(); targetSize.scale(paperRect.size(), printAspect); targetRect.setSize(targetSize); } break; } // adapt Position switch (m_ui->pdfPosCombo->currentIndex()) { case 0: // Top Left targetRect.moveTopLeft(paperRect.topLeft()); break; case 1: // Center targetRect.moveCenter(paperRect.center()); break; } // render to PDF painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, true); RenderOpts::PDFExporting = true; m_canvas->renderVisible(&painter, targetRect, m_canvas->sceneRect(), Qt::IgnoreAspectRatio, true); RenderOpts::PDFExporting = false; painter.end(); return true; }
void MainWindow::slotPrint() { #ifndef NO_PRINTER if(opt.arg_debug) printf("slotPrint\n"); QWidget *w = centralWidget(); if(w == NULL) { QMessageBox::information (this, "pvbrowser", tr("no printable contents")); return; } QPixmap pm; QPrinter printer; printer.setOrientation(QPrinter::Landscape); printer.setColorMode(QPrinter::Color); snapshot(pm); QPrintDialog printDialog(&printer, this); if(printDialog.exec() == QDialog::Accepted) { // print ... QPainter painter; painter.begin(&printer); if(strlen(l_print_header.toUtf8()) > 0) { QString date_time; date_time = l_print_header; date_time += QDateTime::currentDateTime().toString(Qt::TextDate); date_time += " "; date_time += pvbtab[currentTab].url; painter.drawText(LEFT_PRINT_MARGIN,UPPER_PRINT_MARGIN-30,1280,100,Qt::TextExpandTabs, date_time); } QPixmap pmprint = pm.scaledToWidth(painter.viewport().width()-LEFT_PRINT_MARGIN*2, Qt::SmoothTransformation); painter.drawPixmap(LEFT_PRINT_MARGIN,UPPER_PRINT_MARGIN,pmprint); painter.end(); } #endif }
void KisMirrorAxis::drawDecoration(QPainter& gc, const QRectF& updateArea, const KisCoordinatesConverter* converter, KisCanvas2* canvas) { Q_UNUSED(updateArea); Q_UNUSED(converter); Q_UNUSED(canvas); gc.setPen(QPen(QColor(0, 0, 0, 128), 1)); gc.setBrush(Qt::white); gc.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); QOpenGLContext *ctx = QOpenGLContext::currentContext(); bool hasMultisample = ((gc.paintEngine()->type() == QPaintEngine::OpenGL2) && (ctx->hasExtension("GL_ARB_multisample"))); // QPainter cannot anti-alias the edges of circles etc. when using OpenGL // So instead, use native OpenGL anti-aliasing when available. if (hasMultisample) { gc.beginNativePainting(); ctx->functions()->glEnable(GL_MULTISAMPLE); gc.endNativePainting(); } float halfHandleSize = d->handleSize / 2; d->recomputeVisibleAxes(gc.viewport()); if(d->mirrorHorizontal) { if (!d->horizontalAxis.isNull()) { // QPointF horizontalIndicatorCenter = d->horizontalAxis.unitVector().pointAt(15); // QRectF horizontalIndicator = QRectF(horizontalIndicatorCenter.x() - halfHandleSize, horizontalIndicatorCenter.y() - halfHandleSize, d->handleSize, d->handleSize); float horizontalHandlePosition = qBound<float>(d->minHandlePosition, d->horizontalHandlePosition, d->horizontalAxis.length() - d->minHandlePosition); QPointF horizontalHandleCenter = d->horizontalAxis.unitVector().pointAt(horizontalHandlePosition); d->horizontalHandle = QRectF(horizontalHandleCenter.x() - halfHandleSize, horizontalHandleCenter.y() - halfHandleSize, d->handleSize, d->handleSize); gc.setPen(QPen(QColor(0, 0, 0, 64), 2, Qt::DashDotDotLine, Qt::RoundCap, Qt::RoundJoin)); gc.drawLine(d->horizontalAxis); // gc.drawEllipse(horizontalIndicator); // gc.drawPixmap(horizontalIndicator.adjusted(5, 5, -5, -5).toRect(), d->horizontalIcon); gc.setPen(QPen(QColor(0, 0, 0, 128), 2)); gc.drawEllipse(d->horizontalHandle); gc.drawPixmap(d->horizontalHandle.adjusted(5, 5, -5, -5).toRect(), d->horizontalIcon); } else { d->horizontalHandle = QRectF(); } } if(d->mirrorVertical) { if (!d->verticalAxis.isNull()) { gc.setPen(QPen(QColor(0, 0, 0, 64), 2, Qt::DashDotDotLine, Qt::RoundCap, Qt::RoundJoin)); gc.drawLine(d->verticalAxis); // QPointF verticalIndicatorCenter = d->verticalAxis.unitVector().pointAt(15); // QRectF verticalIndicator = QRectF(verticalIndicatorCenter.x() - halfHandleSize, verticalIndicatorCenter.y() - halfHandleSize, d->handleSize, d->handleSize); float verticalHandlePosition = qBound<float>(d->minHandlePosition, d->verticalHandlePosition, d->verticalAxis.length() - d->minHandlePosition); QPointF verticalHandleCenter = d->verticalAxis.unitVector().pointAt(verticalHandlePosition); d->verticalHandle = QRectF(verticalHandleCenter.x() - halfHandleSize, verticalHandleCenter.y() - halfHandleSize, d->handleSize, d->handleSize); // gc.drawEllipse(verticalIndicator); // gc.drawPixmap(verticalIndicator.adjusted(5, 5, -5, -5).toRect(), d->verticalIcon); gc.setPen(QPen(QColor(0, 0, 0, 128), 2)); gc.drawEllipse(d->verticalHandle); gc.drawPixmap(d->verticalHandle.adjusted(5, 5, -5, -5).toRect(), d->verticalIcon); } else { d->verticalHandle = QRectF(); } } if (hasMultisample) { gc.beginNativePainting(); ctx->functions()->glDisable(GL_MULTISAMPLE); gc.endNativePainting(); } }
void HeliCanvas::save(QString streamID, QString headline, QString date, QString filename, int xres, int yres, int dpi) { std::cerr << "Printing..." << std::flush; QPainter *painter; QFileInfo fi(filename); QPrinter *printer = NULL; QImage *pixmap = NULL; if ( fi.suffix().toLower() == "ps" ) { printer = new QPrinter(QPrinter::HighResolution); printer->setOutputFileName(filename); printer->setResolution(dpi); printer->setPageSize(QPrinter::A4); painter = new QPainter(printer); } else { pixmap = new QImage(xres,yres,QImage::Format_RGB32); painter = new QPainter(pixmap); painter->fillRect(painter->window(), _palette.color(QPalette::Base)); } painter->setFont(SCScheme.fonts.base); int fontHeight = painter->fontMetrics().height(); int headerHeight = fontHeight*120/100; if ( !headline.isEmpty() ) headerHeight += fontHeight*120/100; painter->translate(0, headerHeight); int offset = draw( *painter, QSize(painter->viewport().width(), painter->viewport().height()-headerHeight) ); painter->translate(0, -headerHeight); painter->drawText(offset, 0, painter->viewport().width()-offset, fontHeight, Qt::AlignLeft | Qt::AlignTop, streamID); painter->drawText(offset, 0, painter->viewport().width()-offset, fontHeight, Qt::AlignRight | Qt::AlignTop, date); if ( !headline.isEmpty() ) painter->drawText(offset, fontHeight*120/100, painter->viewport().width()-offset, fontHeight, Qt::AlignLeft | Qt::AlignTop, headline); painter->drawLine(0, headerHeight, painter->viewport().width(), headerHeight); if ( pixmap ) pixmap->save(filename); painter->end(); // Clean up if ( printer ) delete printer; if ( pixmap ) delete pixmap; if ( painter ) delete painter; std::cerr << "finished" << std::endl; }
void CorrelationView::print(QPainter& printPainter,QPaintDeviceMetrics& metrics,bool whiteBackground){ printState = true; //Draw the double buffer (pixmap) by copying it into the printer device throught the painter. QRect viewportOld = QRect(viewport.left(),viewport.top(),viewport.width(),viewport.height()); //If the left margin is not visible (the user zoomed without taking it in his selection), the viewport and the printer //have the same size. QRect r((QRect)window); if(r.left() != 0) viewport = QRect(printPainter.viewport().left(),printPainter.viewport().top(),printPainter.viewport().width(),printPainter.viewport().height()-10); else viewport = QRect(printPainter.viewport().left() + XMARGIN,printPainter.viewport().top(),printPainter.viewport().width() - XMARGIN,printPainter.viewport().height()-10); //Set the window (part of the world I want to show) printPainter.setWindow(r.left(),r.top(),r.width()-1,r.height()-1);//hack because Qt QRect is used differently in this function //Set the viewport (part of the device I want to write on). //By default, the viewport is the same as the device's rectangle (contentsRec), taking a smaller //one will ensure that the legends (cluster ids) will not ovelap a correlogram. printPainter.setViewport(viewport); //Fill the background with the background color and ensure we draw the same portion of the world than on the screen QRect back = QRect(r.left(),r.top(),r.width(),r.height()); float heightRatio = (static_cast<float>(back.height())/static_cast<float>(metrics.height())); back.setBottom(r.top() + r.height() - 1 + static_cast<long>(10 * heightRatio)); float widthRatio = (static_cast<float>(back.width())/static_cast<float>(metrics.width())); if(r.left() == 0) back.setLeft(r.left() - static_cast<long>(XMARGIN * widthRatio)); printRegion = QRegion(back); QColor colorLegendTmp = colorLegend; QColor background= backgroundColor(); if(whiteBackground){ colorLegend = black; setPaletteBackgroundColor(white); } printPainter.fillRect(back,backgroundColor()); printPainter.setClipRegion(printRegion,QPainter::CoordPainter); //Paint all the correlograms in the pairs list (in the double buffer) drawCorrelograms(printPainter,pairs); //reset transformation due to setWindow and setViewport printPainter.resetXForm(); //Draw the cluster Ids along the correlograms. drawClusterIds(printPainter); printPainter.setClipping(false); //Restore the colors. if(whiteBackground){ colorLegend = colorLegendTmp; setPaletteBackgroundColor(background); } //Restore the previous state viewport = QRect(viewportOld.left(),viewportOld.top(),viewportOld.width(),viewportOld.height()); printState = false; }
void NaZStackWidget::paintIntensityNumerals(QPainter& painter) { if (cur_z < 0) return; if (! zSliceColors) return; ZSliceColors::Reader zReader(*zSliceColors); if (! zReader.hasReadLock()) return; const QImage * displayImage = zReader.getImage(); if (! displayImage) return; if (! volumeData) return; NaVolumeData::Reader volumeReader(*volumeData); if (! volumeReader.hasReadLock()) return; const Image4DProxy<My4DImage>& imgProxy = volumeReader.getOriginalImageProxy(); // qDebug() << "numerals"; QPointF v_img_upleft = X_img_view * painter.viewport().topLeft(); QPointF v_img_downright = X_img_view * painter.viewport().bottomRight(); // qDebug() << v_img_upleft; // qDebug() << v_img_downright; // clear transform for text rendering, otherwise font size is harder to manage painter.resetTransform(); QFont font = painter.font(); float scale = defaultScale * cameraModel.scale(); font.setPixelSize(scale/4.0); font.setStyleStrategy(QFont::NoAntialias); // text rendering can be slow painter.setFont(font); // qDebug() << "nColumns = " << mipImage->originalData.nColumns(); // qDebug() << "nRows = " << mipImage->originalData.nRows(); // Iterate over only the image pixels that are visible int nC = imgProxy.sc; float lineHeight = scale / (nC + 1.0); for (int x = int(v_img_upleft.x() - 0.5); x <= int(v_img_downright.x() + 0.5); ++x) { // qDebug() << "x = " << x; if (x < 0) continue; if (x >= displayImage->width()) continue; for (int y = int(v_img_upleft.y() - 0.5); y <= int(v_img_downright.y() + 0.5); ++y) { // qDebug() << "y = " << y; if (y < 0) continue; if (y >= displayImage->height()) continue; // Transform image pixel coordinates back to viewport coordinates QPointF v = X_view_img * QPointF(x, y); // qDebug() << x << ", " << y << "; " << v.x() << ", " << v.y(); // Print original data intensity, not displayed intensity // But choose font color based on displayed intensity. unsigned int red = qRed(displayImage->pixel(x, y)); unsigned int green = qGreen(displayImage->pixel(x, y)); unsigned int blue = qBlue(displayImage->pixel(x, y)); // human color perception is important here float displayIntensity = 0.30 * red + 0.58 * green + 0.12 * blue; if (displayIntensity < 128) painter.setPen(Qt::white); else painter.setPen(Qt::black); // Write a neat little column of numbers inside each pixel for (int c = 0; c < nC; ++c) { double val = imgProxy.value_at(x, y, cur_z, c); painter.drawText(QRectF(v.x(), v.y() + (c + 0.5) * lineHeight, scale, lineHeight), Qt::AlignHCenter | Qt::AlignVCenter, QString("%1").arg(val)); } } } // restore coordinate system transformPainterToCurrentCamera(painter); }
/* Prints a QPixmap, optionally displaying the print setup dialog first */ void PrintPixmap(QPixmap pixmap, bool displayDialog, QWidget *pParent, QPrinter *pPrinter) { bool deletePrinter = false; if (pixmap.isNull() == true) { return; } // Create a printer device. Analogous to a Windows device context if (pPrinter == NULL) { deletePrinter = true; pPrinter = new QPrinter(); if (pPrinter == NULL) { return; } } bool bPrint = true; if (displayDialog) { QPrintDialog dlg(pPrinter, pParent); if (dlg.exec() == QDialog::Rejected) { bPrint = false; } } if (bPrint == true) { double dAspect = 1.0; // the aspect ratio of the pixmap = width / height dAspect = static_cast<double>(pixmap.width()) / static_cast<double>(pixmap.height()); // the QPainter provides an interface for drawing to a device, analogous // to Windows GDI, with the printer being the device context in this case QPainter p; if (p.begin(pPrinter) == false) { if (deletePrinter) { delete pPrinter; } return; } QRect rcViewport = p.viewport(); // the printable area in device coords // Determine how large we can make the pixmap on the paper without // losing any of it off the edges of the paper. iPrintWidth and iPrintHeight // will be the size of the pixmap on the paper, in printer device coords. int iPrintWidth = rcViewport.width(); int iPrintHeight = rcViewport.height(); double pAspect = static_cast<double>(iPrintWidth) / static_cast<double>(iPrintHeight); // aspect ratio of the paper // unless the aspect ratios of the paper and pixmap are equal, we will have unused // space above and below or left and right of the printed image. double ratioAspects = pAspect / dAspect; if (ratioAspects > 1.0) { // paper is wider than the image: empty space left and right // reduce iPrintWidth accordingly iPrintWidth = iPrintWidth / ratioAspects; } else { // paper is taller than the image: empty space above and below // reduce iPrintHeight accordingly iPrintHeight = iPrintHeight * ratioAspects; } // specify the pixel dimensions of the pixmap p.setWindow(pixmap.rect()); // specify the location and size to draw the pixmap on the paper p.setViewport(rcViewport.left() + (rcViewport.width() - iPrintWidth) / 2, rcViewport.top() + (rcViewport.height() - iPrintHeight) / 2, iPrintWidth, iPrintHeight); // draw the pixmap to the print device p.drawPixmap(0, 0, pixmap); // tell the printer that we are done; this will trigger a form feed p.end(); } if (deletePrinter) { delete pPrinter; } }
void FOV::draw( QPainter &p, float zoomFactor ) { p.setPen( QColor( color() ) ); p.setBrush( Qt::NoBrush ); p.setRenderHint( QPainter::Antialiasing, Options::useAntialias() ); float pixelSizeX = sizeX() * zoomFactor / 57.3 / 60.0; float pixelSizeY = sizeY() * zoomFactor / 57.3 / 60.0; float offsetXPixelSize = offsetX() * zoomFactor / 57.3 / 60.0; float offsetYPixelSize = offsetY() * zoomFactor / 57.3 / 60.0; p.save(); p.translate(p.viewport().center()); p.translate(offsetXPixelSize, offsetYPixelSize); p.rotate(rotation()); QPointF center(0,0); switch ( shape() ) { case SQUARE: p.drawRect( center.x() - pixelSizeX/2, center.y() - pixelSizeY/2, pixelSizeX, pixelSizeY); break; case CIRCLE: p.drawEllipse( center, pixelSizeX/2, pixelSizeY/2 ); break; case CROSSHAIRS: //Draw radial lines p.drawLine(center.x() + 0.5*pixelSizeX, center.y(), center.x() + 1.5*pixelSizeX, center.y()); p.drawLine(center.x() - 0.5*pixelSizeX, center.y(), center.x() - 1.5*pixelSizeX, center.y()); p.drawLine(center.x(), center.y() + 0.5*pixelSizeY, center.x(), center.y() + 1.5*pixelSizeY); p.drawLine(center.x(), center.y() - 0.5*pixelSizeY, center.x(), center.y() - 1.5*pixelSizeY); //Draw circles at 0.5 & 1 degrees p.drawEllipse( center, 0.5 * pixelSizeX, 0.5 * pixelSizeY); p.drawEllipse( center, pixelSizeX, pixelSizeY); break; case BULLSEYE: p.drawEllipse(center, 0.5 * pixelSizeX, 0.5 * pixelSizeY); p.drawEllipse(center, 2.0 * pixelSizeX, 2.0 * pixelSizeY); p.drawEllipse(center, 4.0 * pixelSizeX, 4.0 * pixelSizeY); break; case SOLIDCIRCLE: { QColor colorAlpha = color(); colorAlpha.setAlpha(127); p.setBrush( QBrush( colorAlpha ) ); p.drawEllipse(center, pixelSizeX/2, pixelSizeY/2 ); p.setBrush(Qt::NoBrush); break; } default: ; } p.restore(); }
void SXBSchView::print(QPrinter* pPrinter) { m_pDoc->resetSelect(); updateViewBuffer(true); QPainter paint; if(paint.begin(pPrinter ) ) { int dpi; #ifdef Q_WS_MACX int dpix,dpiy;; dpix = pPrinter->logicalDpiX(); dpiy = pPrinter->logicalDpiY(); dpi=((dpix < dpiy) ? dpix : dpiy); #else dpi = pPrinter->resolution(); #endif paint.setRenderHint(QPainter::Antialiasing, true); // QRect rcPaper = pPrinter->paperRect(); // printf("paperRect %d,%d,%d,%d\n",rcPaper.left(),rcPaper.top(),rcPaper.width(),rcPaper.height()); QRect rcVp = paint.viewport(); QRect rcPg = pPrinter->pageRect(); // printf("pageRect %d,%d,%d,%d\n",rcPg.left(),rcPg.top(),rcPg.width(),rcPg.height()); // int orientation = pPrinter->orientation(); // printf("orientation %d\n",orientation); int vpWidth, vpHeight; int pgLeft, pgTop, pgWidth, pgHeight; vpWidth =rcVp.width(); vpHeight = rcVp.height(); pgLeft =rcPg.left(); pgTop =rcPg.top(); pgWidth =rcPg.width(); pgHeight = rcPg.height(); //印刷時に印刷の向きを変えてもpageRect()の返す値が変わらないQtのバグ(?)の対策 if( (vpWidth > vpHeight && pgWidth < pgHeight) || (vpWidth < vpHeight && pgWidth > pgHeight) ) { int swapn; swapn = pgLeft; pgLeft = pgTop; pgTop = swapn; swapn = pgWidth; pgWidth = pgHeight; pgHeight = swapn; } QSettings *settings = g_cfg.getSettings(); int leftMargin = 15; int topMargin = 15; int rightMargin = 15; int bottomMargin = 15; settings->beginGroup("PrintOption"); bool color = settings->value("Color",true).toBool(); settings->endGroup(); settings->beginGroup("PrintMargin"); topMargin = settings->value("Top",15).toInt(); bottomMargin = settings->value("Bottom",15).toInt(); leftMargin = settings->value("Left",15).toInt(); rightMargin = settings->value("Right",15).toInt(); settings->endGroup(); if (topMargin < 0) topMargin = 0; else if (topMargin > 50) topMargin = 50; if (bottomMargin < 0) bottomMargin = 0; else if (bottomMargin > 50) bottomMargin = 50; if (leftMargin < 0) leftMargin = 0; else if (leftMargin > 50) leftMargin = 50; if (rightMargin < 0) rightMargin = 0; else if (rightMargin > 50) rightMargin = 50; topMargin = dpi * 10 * topMargin / 254; bottomMargin = dpi * 10 * bottomMargin / 254; leftMargin = dpi * 10 * leftMargin / 254; rightMargin = dpi * 10 * rightMargin / 254; // printf("SXBSchView::print() dpi:%d\n",dpi); paint.save(); paint.setViewTransformEnabled (true); paint.resetMatrix(); SSize size = m_pDoc->SheetSize(); int w = size.w(); int h = size.h(); int dw = w*10; int dh = h*10; // p->setWindow( 0,0, dw, dh ); // QRect rc = paint.viewport(); int rightWidth = vpWidth-(pgLeft+pgWidth); if(rightWidth < 0) rightWidth = 0; int bottomWidth = vpHeight-(pgTop+pgHeight); if(bottomWidth < 0) bottomWidth = 0; leftMargin -= pgLeft; if(leftMargin < 0)leftMargin = 0; topMargin -= pgTop; if(topMargin < 0) topMargin = 0; rightMargin -= rightWidth; if(rightMargin < 0) rightMargin = 0; bottomMargin -= bottomWidth; if(bottomMargin < 0) bottomMargin = 0; int vw = pgWidth-(leftMargin+rightMargin); int vh = pgHeight-(topMargin+bottomMargin); double sheetRatio=(double)w / (double)h; double viewRatio=(double)vw / (double)vh; int newW; int newH; if(sheetRatio > viewRatio) { newW = vw; newH = (int)(vw / sheetRatio); } else { newH = vh; newW = (int)(vh * sheetRatio); } // printf("newW,H=%d,%d\n",newW,newH); // p->setViewport( rc.left() + (vw-newW)/2, // rc.top() + (vh-newH)/2, // newW, newH ); // QRect rcvp = p->viewport(); // printf("x,y,w,h %d,%d,%d,%d\n",rcvp.x(),rcvp.y(),rcvp.width(),rcvp.height()); paint.setViewport( leftMargin+ (vw-newW)/2, topMargin + (vh-newH)/2, newW, newH ); paint.setWindow( 0,0, dw, dh ); // rcvp = p->viewport(); // printf("x,y,w,h %d,%d,%d,%d\n",rcvp.x(),rcvp.y(),rcvp.width(),rcvp.height()); QRect rcClip = QRect(0,0,dw,dh); SRect srcClip =SRect(0,0,w,h); paint.setBackground(Qt::white); paint.eraseRect(0,0,dw,dh); g_drawFrame(&paint,size,rcClip,Qt::black,1,10); drawMainXBSchObj(&paint,(color ? DRAW_ON : DRAW_MONO)|DRAW_FOR_PRINT,&srcClip,false,1,10); paint.restore(); paint.end(); } }
void Screen::drawCordinate(QPainter &painter) { if ( firstShow ) { int y0 = rectCordinate.bottom(); int x0 = rectCordinate.left(); int yText = 0; for (int j=0; j<=numYTicks; j++ ) { painter.setPen(QPen(Qt::blue,1,Qt::SolidLine) ); painter.drawLine( x0-BaseLineLenght, y0, x0, y0 ); if (j%Step==0) { painter.drawLine( x0-2*BaseLineLenght, y0, x0-BaseLineLenght, y0 ); if(j==0) { painter.drawLine( x0 , y0, rectCordinate.right(), y0 ); } if(j==numYTicks) { painter.drawLine( x0 , rectCordinate.top(), rectCordinate.right(), rectCordinate.top() );} else{ painter.setPen( QPen( Qt::blue, 1, Qt::DotLine) ); painter.drawLine( x0 , y0, rectCordinate.right(), y0 ); } painter.setPen( Qt::red ); painter.drawText( x0 - 3 * BaseLineLenght - BaseFontHeight , y0 -2* BaseFontHeight+ 3* Step , BaseFontHeight+3 , BaseFontHeight + Step , Qt::AlignCenter|Qt::AlignTop , QString::number( yText) ); yText ++; painter.setPen( Qt::blue ); } y0 -= Step; } painter.save(); QRect tempYText( rectYText.left(), rectYText.top(), rectYText.height(), rectYText.height() ); painter.setViewport( tempYText ); QRect rectYViewport = painter.viewport(); painter.setWindow( -(int)rectYViewport.width()/2, -(int)rectYViewport.height()/2, rectYViewport.width(), rectYViewport.height() ); QRect rectYWindow = painter.window(); QRect rectDrawText( rectYWindow.left(), -(int)rectYText.width()/2, rectYText.height(), rectYText.width() ); painter.rotate(-90.0); double dy = ( rectYWindow.width() - rectDrawText.height() ) / 2; dy = dy > 0 ? dy : ( -dy ); painter.translate( 0, -dy ); painter.drawText( rectDrawText.left(), rectDrawText.top(), rectDrawText.width()+5, rectDrawText.height()+5, Qt::AlignHCenter, stringYTitle ); painter.restore(); painter.setPen( Qt::blue ); y0=rectCordinate.bottom(); for ( int i = 0; i <= numXTicks; i ++ ) { painter.setPen(QPen(Qt::blue,1,Qt::SolidLine) ); painter.drawLine( x0 , y0, x0, y0 + BaseLineLenght ); if ( 0 == i % (2*Step) ) { if(i==0){ painter.drawLine( x0, y0, x0, rectCordinate.top());} if(i==numXTicks){ painter.drawLine( rectCordinate.right(),y0, rectCordinate.right(),rectCordinate.top());} else{ painter.setPen( QPen( Qt::blue, 1, Qt::DotLine) ); painter.drawLine( x0, rectCordinate.bottom(), x0, rectCordinate.top()); } } x0 += Step; } painter.drawText( rectXText.left(), rectXText.top(), rectXText.width(), rectXText.height()+5, Qt::AlignCenter, stringXTitle ); } }
void ORPrintRender::renderPage(ORODocument * pDocument, int pageNb, QPainter *painter, qreal xDpi, qreal yDpi, QSize margins, int printResolution) { OROPage * p = pDocument->page(pageNb); if(((!p->backgroundImage().isNull()) && (p->backgroundOpacity() != 0)) || ((!p->watermarkText().isEmpty()) && (p->watermarkOpacity() != 0))) { // Do some simple processing used by both Background and Watermark const int resolution = 100; bool doBgWm = false; int printMarginWidth = margins.width(); int printMarginHeight = margins.height(); QString pageSize = pDocument->pageOptions().getPageSize(); int pageWidth = 0; int pageHeight = 0; if(pageSize == "Custom") { // if this is custom sized sheet of paper we will just use those values pageWidth = (int)(pDocument->pageOptions().getCustomWidth() * resolution); pageHeight = (int)(pDocument->pageOptions().getCustomHeight() * resolution); } else { // lookup the correct size information for the specified size paper PageSizeInfo pi = PageSizeInfo::getByName(pageSize); if(!pi.isNull()) { pageWidth = (int)((pi.width() / 100.0) * resolution); pageHeight = (int)((pi.height() / 100.0) * resolution); } } if(!pDocument->pageOptions().isPortrait()) { int tmp = pageWidth; pageWidth = pageHeight; pageHeight = tmp; } if(pageWidth < 1 || pageHeight < 1) { // whoops we couldn't find it.... we will use the values from the painter // and add in the margins of the printer to get what should be the correct // size of the sheet of paper we are printing to. pageWidth = (int)(((painter->viewport().width() + printMarginWidth + printMarginWidth) / xDpi) * resolution); pageHeight = (int)(((painter->viewport().height() + printMarginHeight + printMarginHeight) / yDpi) * resolution); } QImage image = QImage(pageWidth, pageHeight, QImage::Format_RGB32); QPainter gPainter; if(gPainter.begin(&image)) gPainter.fillRect(gPainter.viewport(), QColor(Qt::white)); // Render Background if((!p->backgroundImage().isNull()) && (p->backgroundOpacity() != 0)) { doBgWm = true; QPointF ps = p->backgroundPosition(); QSizeF sz = p->backgroundSize(); QRectF rc = QRectF(ps.x() * resolution, ps.y() * resolution, sz.width() * resolution, sz.height() * resolution); renderBackground(image, p->backgroundImage(), rc.toRect(), p->backgroundScale(), p->backgroundScaleMode(), p->backgroundAlign(), p->backgroundOpacity()); } // Render Watermark if((!p->watermarkText().isEmpty()) && (p->watermarkOpacity() != 0)) { doBgWm = true; renderWatermark(image, p->watermarkText(), p->watermarkFont(), p->watermarkOpacity(), ((pDocument->pageOptions().getMarginLeft() + pDocument->pageOptions().getMarginRight()) * resolution), ((pDocument->pageOptions().getMarginTop() + pDocument->pageOptions().getMarginBottom()) * resolution), pDocument->pageOptions().getMarginLeft() * resolution, pDocument->pageOptions().getMarginTop() * resolution); } if(doBgWm) { QRectF target(-printMarginWidth, -printMarginHeight, (painter->viewport().width() + printMarginWidth + printMarginWidth), (painter->viewport().height() + printMarginHeight + printMarginHeight)); QRectF source(0, 0, image.width(), image.height()); painter->drawImage(target, image, source); } } // Render Page Objects for(int i = 0; i < p->primitives(); i++) { OROPrimitive * prim = p->primitive(i); QPen pen(prim->pen()); painter->save(); painter->setPen(pen); painter->setBrush(prim->brush()); QPointF ps = prim->position(); if(prim->rotationAxis().isNull()) { painter->translate(ps.x() * xDpi, ps.y() * yDpi); painter->rotate(prim->rotation()); // rotation around the origin of the primitive (not the center) } else { // rotation around the defined axis qreal xRot = prim->rotationAxis().x(); qreal yRot = prim->rotationAxis().y(); painter->translate(xRot * xDpi, yRot * yDpi); painter->rotate(prim->rotation()); painter->translate((ps.x() - xRot) * xDpi, (ps.y() - yRot) * yDpi); } if(prim->type() == OROTextBox::TextBox) { OROTextBox * tb = (OROTextBox*)prim; painter->setFont(tb->font()); QSizeF sz = tb->size(); QRectF rc = QRectF(0, 0, sz.width() * xDpi, sz.height() * yDpi); painter->drawText(rc, tb->flags(), tb->text()); } else if(prim->type() == OROLine::Line) { OROLine * ln = (OROLine*)prim; QPointF s = ln->startPoint(); QPointF e = ln->endPoint(); pen.setWidthF((ln->weight() / 100) * printResolution); painter->setPen(pen); painter->drawLine(QLineF(0, 0, (e.x()-s.x()) * xDpi, (e.y()-s.y()) * yDpi)); } else if(prim->type() == OROImage::Image) { OROImage * im = (OROImage*)prim; QSizeF sz = im->size(); QRectF rc = QRectF(0, 0, sz.width() * xDpi, sz.height() * yDpi); QImage img = im->image(); if(im->scaled()) img = img.scaled(rc.size().toSize(), (Qt::AspectRatioMode)im->aspectRatioMode(), (Qt::TransformationMode)im->transformationMode()); QRectF sr = QRectF(QPointF(0.0, 0.0), rc.size().boundedTo(img.size())); painter->drawImage(rc.topLeft(), img, sr); } else if(prim->type() == ORORect::Rect) { ORORect * re = (ORORect*)prim; QSizeF sz = re->size(); QRectF rc = QRectF(0, 0, sz.width() * xDpi, sz.height() * yDpi); pen.setWidthF((re->weight() / 100) * printResolution); painter->setPen(pen); painter->drawRect(rc); } else { qDebug("unrecognized primitive type"); } painter->restore(); } }
void ORPrintRender::renderPage(ORODocument * pDocument, int pageNb, QPainter *painter, qreal xDpi, qreal yDpi, QSize margins, int printResolution) { OROPage * p = pDocument->page(pageNb); if(((!p->backgroundImage().isNull()) && (p->backgroundOpacity() != 0)) || ((!p->watermarkText().isEmpty()) && (p->watermarkOpacity() != 0))) { // Do some simple processing used by both Background and Watermark const int resolution = 100; bool doBgWm = false; int printMarginWidth = margins.width() < 0 ? 0 : margins.width(); int printMarginHeight = margins.height() < 0 ? 0 : margins.height(); QString pageSize = pDocument->pageOptions().getPageSize(); int pageWidth = 0; int pageHeight = 0; if(pageSize == "Custom") { // if this is custom sized sheet of paper we will just use those values pageWidth = (int)(pDocument->pageOptions().getCustomWidth() * resolution); pageHeight = (int)(pDocument->pageOptions().getCustomHeight() * resolution); } else { // lookup the correct size information for the specified size paper PageSizeInfo pi = PageSizeInfo::getByName(pageSize); if(!pi.isNull()) { pageWidth = (int)((pi.width() / 100.0) * resolution); pageHeight = (int)((pi.height() / 100.0) * resolution); } } if(!pDocument->pageOptions().isPortrait()) { int tmp = pageWidth; pageWidth = pageHeight; pageHeight = tmp; } if(pageWidth < 1 || pageHeight < 1) { // whoops we couldn't find it.... we will use the values from the painter // and add in the margins of the printer to get what should be the correct // size of the sheet of paper we are printing to. pageWidth = (int)(((painter->viewport().width() + printMarginWidth + printMarginWidth) / xDpi) * resolution); pageHeight = (int)(((painter->viewport().height() + printMarginHeight + printMarginHeight) / yDpi) * resolution); } QImage image = QImage(pageWidth, pageHeight, QImage::Format_RGB32); QPainter gPainter; if(gPainter.begin(&image)) gPainter.fillRect(gPainter.viewport(), QColor(Qt::white)); // Render Background if((!p->backgroundImage().isNull()) && (p->backgroundOpacity() != 0)) { doBgWm = true; QPointF ps = p->backgroundPosition(); QSizeF sz = p->backgroundSize(); QRectF rc = QRectF(ps.x() * resolution, ps.y() * resolution, sz.width() * resolution, sz.height() * resolution); renderBackground(image, p->backgroundImage(), rc.toRect(), p->backgroundScale(), p->backgroundScaleMode(), p->backgroundAlign(), p->backgroundOpacity()); } // Render Watermark if((!p->watermarkText().isEmpty()) && (p->watermarkOpacity() != 0)) { doBgWm = true; renderWatermark(image, p->watermarkText(), p->watermarkFont(), p->watermarkOpacity(), pDocument->pageOptions().getMarginLeft() * resolution, pDocument->pageOptions().getMarginRight() * resolution, pDocument->pageOptions().getMarginTop() * resolution, pDocument->pageOptions().getMarginBottom() * resolution); } if(doBgWm) { QRectF target(0, 0, pageWidth, pageHeight); painter->save(); painter->scale(xDpi / resolution, yDpi / resolution); QRectF source(0, 0, image.width(), image.height()); painter->drawImage(target, image, source); painter->restore(); } } // Render Page Objects for(int i = 0; i < p->primitives(); i++) { OROPrimitive * prim = p->primitive(i); QPen pen(prim->pen()); painter->save(); painter->setPen(pen); painter->setBrush(prim->brush()); QPointF ps = prim->position(); if(prim->rotationAxis().isNull()) { painter->translate(ps.x() * xDpi, ps.y() * yDpi); painter->rotate(prim->rotation()); // rotation around the origin of the primitive (not the center) } else { // rotation around the defined axis qreal xRot = prim->rotationAxis().x(); qreal yRot = prim->rotationAxis().y(); painter->translate(xRot * xDpi, yRot * yDpi); painter->rotate(prim->rotation()); painter->translate((ps.x() - xRot) * xDpi, (ps.y() - yRot) * yDpi); } if(prim->type() == OROTextBox::TextBox) { OROTextBox * tb = (OROTextBox*)prim; QSizeF sz = tb->size(); QRectF rc = QRectF(0, 0, sz.width() * xDpi, sz.height() * yDpi); prim->drawRect(rc, painter, printResolution); painter->setFont(tb->font()); QString text = tb->text(); QString url; if(tb->text().startsWith("<http")) { int endOfUrl = tb->text().indexOf('>'); if(endOfUrl > 0) { url = tb->text().mid(1, endOfUrl-1); text = tb->text().mid(endOfUrl+1); if(text.isEmpty()) text = url; } } bool toPdf = painter->paintEngine()->type() == QPaintEngine::Pdf; if(toPdf && !url.isEmpty()) { QTextDocument doc; QTextCursor cursor(&doc); QTextCharFormat format; format.setFont(tb->font()); format.setFontPointSize(tb->font().pointSizeF()*printResolution/100.0); format.setAnchor(true); format.setAnchorHref(url); cursor.insertText(text, format); doc.drawContents(painter); } else { painter->drawText(rc, tb->flags(), text); } } else if(prim->type() == OROBarcode::Barcode) { OROBarcode * bc = (OROBarcode*)prim; QSizeF sz = bc->size(); QRectF rc = QRectF(0, 0, sz.width() * xDpi, sz.height() * yDpi); if(painter->paintEngine()->type() == QPaintEngine::User) { // label paint engine: the barcode parameters are encoded in a text item QString encodedData = ReportPrinter::barcodePrefix() + QString("%1;%2;%3;%4").arg(bc->format()).arg(sz.height()).arg(bc->narrowBarWidth()).arg(bc->data()); painter->drawText(rc, 0, encodedData); } else { if(bc->format() == "3of9") render3of9(painter, xDpi, rc, bc->data(), bc); else if(bc->format() == "3of9+") renderExtended3of9(painter, xDpi, rc, bc->data(), bc); else if(bc->format() == "128") renderCode128(painter, xDpi, rc, bc->data(), bc); else if(bc->format() == "i2of5") renderI2of5(painter, xDpi, rc, bc->data(), bc); else if(bc->format() == "ean13") renderCodeEAN13(painter, xDpi, rc, bc->data(), bc); else if(bc->format() == "ean8") renderCodeEAN8(painter, xDpi, rc, bc->data(), bc); else if(bc->format() == "upc-a") renderCodeUPCA(painter, xDpi, rc, bc->data(), bc); else if(bc->format() == "upc-e") renderCodeUPCE(painter, xDpi, rc, bc->data(), bc); else if(bc->format().contains("datamatrix")) renderCodeDatamatrix(painter, rc, bc->data(), bc); else if(bc->format().contains("PDF417")) renderPDF417(painter, xDpi, rc, bc->data(), bc); else if(bc->format().contains("QR")) renderQR(painter, xDpi, rc, bc->data(), bc); else { painter->drawText(rc, 0, "ERR: [" + bc->format() + "]" + bc->data()); } } } else if(prim->type() == OROLine::Line) { OROLine * ln = (OROLine*)prim; QPointF s = ln->startPoint(); QPointF e = ln->endPoint(); pen.setWidthF((pen.widthF() / 100.0) * printResolution); painter->setPen(pen); painter->drawLine(QLineF(0, 0, (e.x()-s.x()) * xDpi, (e.y()-s.y()) * yDpi)); } else if(prim->type() == OROImage::Image) { OROImage * im = (OROImage*)prim; QSizeF sz = im->size(); QRectF rc = QRectF(0, 0, sz.width() * xDpi, sz.height() * yDpi); prim->drawRect(rc, painter, printResolution); QImage img = im->image(); if(im->scaled()) img = img.scaled(rc.size().toSize(), (Qt::AspectRatioMode)im->aspectRatioMode(), (Qt::TransformationMode)im->transformationMode()); else img = img.scaled(QSize(img.width()*(int)xDpi/150, img.height()*(int)yDpi/150), Qt::KeepAspectRatio); QRectF sr = QRectF(QPointF(0.0, 0.0), rc.size().boundedTo(img.size())); painter->drawImage(rc.topLeft(), img, sr); } else if(prim->type() == ORORect::Rect) { QSizeF sz = ((OROTextBox*)prim)->size(); QRectF rc = QRectF(0, 0, sz.width() * xDpi, sz.height() * yDpi); prim->drawRect(rc, painter, printResolution); } else { qDebug("unrecognized primitive type"); } painter->restore(); } }