本文整理汇总了C++中QPainter::viewport方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainter::viewport方法的具体用法?C++ QPainter::viewport怎么用?C++ QPainter::viewport使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainter
的用法示例。
在下文中一共展示了QPainter::viewport方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: printPage
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);
}
示例2: paintGrid
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);
}
示例3: print
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());
}
示例4: inv_transform
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);
}
示例5: paintTo
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();
}
示例6: createTaintedPixmapMacOnly
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;
}
示例7: createTaintedPixmapNotMac
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;
}
示例8: Draw
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;
}
示例9: print
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();
}
示例10: paint
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);
}
}
}
示例11: paintCameraBorder
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 );
}
}
}
示例12: printPdf
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;
}
示例13: slotPrint
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
}
示例14: drawDecoration
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();
}
}
示例15: save
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;
}