本文整理汇总了C++中QPainter::scale方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainter::scale方法的具体用法?C++ QPainter::scale怎么用?C++ QPainter::scale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainter
的用法示例。
在下文中一共展示了QPainter::scale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: qMin
QImage *createImage(const QMatrix &matrix) const
{
float sx = qMin(matrix.m11(), matrix.m22());
float sy = matrix.m22() < sx ? sx : matrix.m22();
// qWarning("ButtonForeground createImage painter debug. 1");
QRect scaledRect;
scaledRect = matrix.mapRect(QRect(0, 0, this->textSize.width(), this->textSize.height()));
QPainter *painter;
QImage *imagetext = new QImage(int(scaledRect.width()), int(scaledRect.height()), QImage::Format_ARGB32_Premultiplied);
imagetext->fill(QColor(0, 0, 0, 0).rgba());
painter = new QPainter(imagetext);
// painter->scale(sx, sy);
QStyleOptionGraphicsItem style;
this->textItem->paint(painter, &style, 0);
// qWarning("ButtonForeground createImage painter debug. 2");
delete painter;
// qWarning("ButtonForeground createImage painter debug. 3");
scaledRect = matrix.mapRect(QRect(0, 0, this->logicalSize.width(), this->logicalSize.height()));
QImage *image = new QImage(int(scaledRect.width()), int(scaledRect.height()), QImage::Format_ARGB32_Premultiplied);
image->fill(QColor(0, 0, 0, 0).rgba());
painter = new QPainter(image);
painter->scale(sx, sy);
if (this->iconShow)
{
// qWarning() << "Icon Size " << this->iconSize << " Pos " << this->iconpos;
painter->drawImage(this->iconpos*sx, this->icon);
}
if (this->textShow)
{
// qWarning() << "Text Size " << this->textSize << " Pos " << this->textpos;
painter->drawImage(this->textpos, *imagetext);
}
// qWarning("ButtonForeground createImage painter debug. 4");
delete imagetext;
delete painter;
// qWarning("ButtonForeground createImage painter debug. 5");
return image;
}
示例2: generatePixmap
void PluckerGenerator::generatePixmap( Okular::PixmapRequest * request )
{
const QSizeF size = mPages[ request->pageNumber() ]->size();
QPixmap *pixmap = new QPixmap( request->width(), request->height() );
pixmap->fill( Qt::white );
QPainter p;
p.begin( pixmap );
qreal width = request->width();
qreal height = request->height();
p.scale( width / (qreal)size.width(), height / (qreal)size.height() );
mPages[ request->pageNumber() ]->drawContents( &p );
p.end();
request->page()->setPixmap( request->id(), pixmap );
if ( !mLinkAdded.contains( request->pageNumber() ) ) {
QLinkedList<Okular::ObjectRect*> objects;
for ( int i = 0; i < mLinks.count(); ++i ) {
if ( mLinks[ i ].page == request->pageNumber() ) {
QTextDocument *document = mPages[ request->pageNumber() ];
QRectF rect;
calculateBoundingRect( document, mLinks[ i ].start,
mLinks[ i ].end, rect );
objects.append( new Okular::ObjectRect( rect.left(), rect.top(), rect.right(), rect.bottom(), false, Okular::ObjectRect::Action, mLinks[ i ].link ) );
}
}
if ( !objects.isEmpty() )
request->page()->setObjectRects( objects );
mLinkAdded.insert( request->pageNumber() );
}
signalPixmapRequestDone( request );
}
示例3: publishedImage
void StInterp2::draw(ImageView *view, QPainter &p, int pass) {
Module::draw(view, p, pass);
QRectF R = p.clipBoundingRect();
QRect aR = R.toAlignedRect().intersected(view->image().rect());
double pt = view->pt2px(1);
if (view->zoom() > 10) {
p.save();
p.scale(1.0/nx, 1.0/ny);
p.setPen(QPen(Qt::red, nx*0.25*pt));
cpu_image st2 = publishedImage("st2");
draw_minor_eigenvector_field(p, st2, QRect(aR.x()*nx, aR.y()*ny, aR.width()*nx, aR.height()*ny));
p.restore();
p.setPen(QPen(Qt::blue, 0.5*pt));
cpu_image st = publishedImage("st");
draw_minor_eigenvector_field(p, st, aR);
}
}
示例4: paintBorder
void KWCanvasBase::paintBorder(QPainter &painter, KWViewMode::ViewMap &viewMap)
{
painter.save();
const QRectF pageRect = viewMap.page.rect();
const KoPageLayout pageLayout = viewMap.page.pageStyle().pageLayout();
qreal zoomX, zoomY;
viewConverter()->zoom(&zoomX, &zoomY);
painter.scale(zoomX, zoomY);
QPointF topLeftCorner = QPointF(pageRect.topLeft() + QPointF(pageLayout.leftMargin,
pageLayout.topMargin));
QPointF bottomRightCorner = QPointF(pageRect.bottomRight() + QPointF(-pageLayout.rightMargin,
-pageLayout.bottomMargin));
QRectF borderRect = QRectF(topLeftCorner, bottomRightCorner);
pageLayout.border.paint(painter, borderRect);
painter.restore();
}
示例5: paintDab
void BrushEngine::paintDab(const QPointF& point, QPainter& painter) {
painter.save();
painter.translate(point);
painter.rotate(angle);
painter.scale(1, roundness / 100.0);
QRectF rect(-size / 2.0, -size / 2.0, size, size);
painter.drawEllipse(rect);
painter.restore();
rect.moveTo(point.x() - size / 2.0, point.y() - size / 2.0);
if (eraser > 50) {
canvasItem->update(rect.toRect());
} else {
canvasBuffer->update(rect.toRect());
}
// Detect a min and max corner positions
bottomright.setX(qMax(bottomright.x(), qRound(point.x())));
bottomright.setY(qMax(bottomright.y(), qRound(point.y())));
topleft.setX(qMin(topleft.x(), qRound(point.x())));
topleft.setY(qMin(topleft.y(), qRound(point.y())));
}
示例6: exportPainter
void MultiLayer::exportPainter(QPainter &painter, bool keepAspect, QRect rect,
QSize size) {
if (size == QSize()) size = canvas->size();
if (rect == QRect()) rect = canvas->rect();
if (keepAspect) {
QSize scaled = rect.size();
scaled.scale(size, Qt::KeepAspectRatio);
size = scaled;
}
painter.scale((double)size.width() / (double)rect.width(),
(double)size.height() / (double)rect.height());
painter.fillRect(rect, backgroundBrush()); // FIXME workaround for background
for (int i = 0; i < (int)graphsList.count(); i++) {
Graph *gr = (Graph *)graphsList.at(i);
Plot *myPlot = (Plot *)gr->plotWidget();
QPoint pos = QPoint(gr->pos().x(), gr->pos().y());
gr->exportPainter(painter, false, QRect(pos, myPlot->size()));
}
}
示例7: printSixDives
// experimental
void PrintLayout::printSixDives() const
{
ProfileGraphicsView *profile = mainWindow()->graphics();
QPainter painter;
painter.begin(printer);
painter.setRenderHint(QPainter::Antialiasing);
// painter.setRenderHint(QPainter::HighQualityAntialiasing);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
painter.scale(scaleX, scaleY);
profile->clear();
profile->setPrintMode(true, !printOptions->color_selected);
QSize originalSize = profile->size();
profile->resize(scaledPageW, scaledPageH);
int i;
struct dive *dive;
bool firstPage = true;
for_each_dive(i, dive) {
if (!dive->selected && printOptions->print_selected)
continue;
// don't create a new page if still on first page
if (!firstPage)
printer->newPage();
else
firstPage = false;
profile->plot(dive, true);
QPixmap pm = QPixmap::grabWidget(profile);
QTransform transform;
transform.rotate(270);
pm = QPixmap(pm.transformed(transform));
painter.drawPixmap(0, 0, pm);
}
painter.end();
profile->setPrintMode(false);
profile->resize(originalSize);
profile->clear();
profile->plot(current_dive, true);
}
示例8: RenderPage
QImage DocumentAdapter::RenderPage (int page, double xScale, double yScale)
{
const auto& size = Doc_->pageSize ();
auto imgSize = size.toSize ();
imgSize.rwidth () *= xScale;
imgSize.rheight () *= yScale;
QImage image (imgSize, QImage::Format_ARGB32);
image.fill (Qt::white);
QRectF rect (QPointF (0, 0), size);
rect.moveTop (rect.height () * page);
QPainter painter;
painter.begin (&image);
painter.scale (xScale, yScale);
painter.translate (0, rect.height () * (-page));
Doc_->drawContents (&painter, rect);
painter.end ();
return image;
}
示例9: createPairIcon
QIcon SCgAlphabet::createPairIcon(const QSize &size, QString type)
{
QIcon icon;
SCgPair *pair = new SCgPair;
pair->setTypeAlias(type);
QVector<QPointF> points;
points.push_back(QPointF(-size.width() / 2.f, 0.f));
points.push_back(QPointF(size.width() / 2.f, 0.f));
pair->setPoints(points);
QPixmap pixmap(size);
QPainter painter;
pixmap.fill(Qt::transparent);
painter.begin(&pixmap);
painter.setRenderHint(QPainter::Antialiasing, true);
pair->setColor(QColor(0, 0, 0, 255));//(state == QIcon::On) ? 255 : 128));
painter.translate(size.width() / 2.f, size.height() / 2.f);
painter.scale(0.9f, 0.9f);
paintPair(&painter, pair);
painter.end();
for (int mode = QIcon::Normal; mode <= QIcon::Selected; mode++)
for (int state = QIcon::On; state <= QIcon::Off; state++)
icon.addPixmap(pixmap, (QIcon::Mode)mode, (QIcon::State)state);
delete pair;
return icon;
}
示例10: on_pushButton_clicked
void MainWindow::on_pushButton_clicked()
{
int current_tab = this->ui->tabWidget->currentIndex();
QPrinter printer;
QTableView *myWidget;
switch(current_tab)
{
case TABLE::StudentsTableTab:
myWidget = this->ui->StudentsTableView;
break;
case TABLE::TeachersTableTab:
myWidget = this->ui->TeachersTableView;
break;
default:
return;
}
QPixmap pix = myWidget->grab();
QPainter painter;
printer.setResolution(QPrinter::HighResolution);
printer.setPageMargins (15,15,15,15,QPrinter::Millimeter);
painter.begin(&printer);
double xscale = printer.pageRect().width()/double(myWidget->width() + 50);
double yscale = printer.pageRect().height()/double(myWidget->height() + 50);
double scale = qMin(xscale, yscale);
painter.scale(scale, scale);
painter.drawPixmap(0, 0, pix);
painter.end();
myWidget->render(&painter);
}
示例11: draw
void QgsLayoutItemLegend::draw( QgsLayoutItemRenderContext &context )
{
QPainter *painter = context.renderContext().painter();
painter->save();
// painter is scaled to dots, so scale back to layout units
painter->scale( context.renderContext().scaleFactor(), context.renderContext().scaleFactor() );
painter->setPen( QPen( QColor( 0, 0, 0 ) ) );
if ( !mSizeToContents )
{
// set a clip region to crop out parts of legend which don't fit
QRectF thisPaintRect = QRectF( 0, 0, rect().width(), rect().height() );
painter->setClipRect( thisPaintRect );
}
QgsLegendRenderer legendRenderer( mLegendModel.get(), mSettings );
legendRenderer.setLegendSize( mSizeToContents ? QSize() : rect().size() );
legendRenderer.drawLegend( painter );
painter->restore();
}
示例12: QSizeF
QSizeF QgsSymbolV2LegendNode::drawSymbol( const QgsLegendSettings& settings, ItemContext* ctx, double itemHeight ) const
{
QgsSymbolV2* s = mItem.symbol();
if ( !s )
{
return QSizeF();
}
// setup temporary render context
QgsRenderContext context;
context.setScaleFactor( settings.dpi() / 25.4 );
context.setRendererScale( settings.mapScale() );
context.setMapToPixel( QgsMapToPixel( 1 / ( settings.mmPerMapUnit() * context.scaleFactor() ) ) );
context.setForceVectorOutput( true );
context.setPainter( ctx ? ctx->painter : 0 );
//Consider symbol size for point markers
double height = settings.symbolSize().height();
double width = settings.symbolSize().width();
double size = 0;
//Center small marker symbols
double widthOffset = 0;
double heightOffset = 0;
if ( QgsMarkerSymbolV2* markerSymbol = dynamic_cast<QgsMarkerSymbolV2*>( s ) )
{
// allow marker symbol to occupy bigger area if necessary
size = markerSymbol->size() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context, s->outputUnit(), s->mapUnitScale() ) / context.scaleFactor();
height = size;
width = size;
if ( width < settings.symbolSize().width() )
{
widthOffset = ( settings.symbolSize().width() - width ) / 2.0;
}
if ( height < settings.symbolSize().height() )
{
heightOffset = ( settings.symbolSize().height() - height ) / 2.0;
}
}
if ( ctx )
{
double currentXPosition = ctx->point.x();
double currentYCoord = ctx->point.y() + ( itemHeight - settings.symbolSize().height() ) / 2;
QPainter* p = ctx->painter;
//setup painter scaling to dots so that raster symbology is drawn to scale
double dotsPerMM = context.scaleFactor();
int opacity = 255;
if ( QgsVectorLayer* vectorLayer = dynamic_cast<QgsVectorLayer*>( layerNode()->layer() ) )
opacity = 255 - ( 255 * vectorLayer->layerTransparency() / 100 );
p->save();
p->setRenderHint( QPainter::Antialiasing );
p->translate( currentXPosition + widthOffset, currentYCoord + heightOffset );
p->scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM );
if ( opacity != 255 && settings.useAdvancedEffects() )
{
//semi transparent layer, so need to draw symbol to an image (to flatten it first)
//create image which is same size as legend rect, in case symbol bleeds outside its alloted space
QSize tempImageSize( width * dotsPerMM, height * dotsPerMM );
QImage tempImage = QImage( tempImageSize, QImage::Format_ARGB32 );
tempImage.fill( Qt::transparent );
QPainter imagePainter( &tempImage );
context.setPainter( &imagePainter );
s->drawPreviewIcon( &imagePainter, tempImageSize, &context );
context.setPainter( ctx->painter );
//reduce opacity of image
imagePainter.setCompositionMode( QPainter::CompositionMode_DestinationIn );
imagePainter.fillRect( tempImage.rect(), QColor( 0, 0, 0, opacity ) );
imagePainter.end();
//draw rendered symbol image
p->drawImage( 0, 0, tempImage );
}
else
{
s->drawPreviewIcon( p, QSize( width * dotsPerMM, height * dotsPerMM ), &context );
}
p->restore();
}
return QSizeF( qMax( width + 2 * widthOffset, ( double ) settings.symbolSize().width() ),
qMax( height + 2 * heightOffset, ( double ) settings.symbolSize().height() ) );
}
示例13: if
QColor VQMCSimpleChannelRenderer<ShapeDraw>::
renderChannel(unsigned camera, unsigned ncameras,
const VQMCChannelData& data,
const VQMCCameraDataLimits& limits,
bool clip, QPainter& painter, bool draw_fast)
{
QColor background_color = painter.background().color();
QColor return_color = background_color;
if(data.fNoDraw)return return_color;
if((!data.fNoData)&&(!data.fSuppress))
{
double lim = qMax(fabs(limits.fLimitLo.fValue),
fabs(limits.fLimitHi.fValue));
double x = data.fValue/lim;
if(clip)
{
if(x>1)x=1;
else if(x<-1)x=-1;
}
double radius = 0;
QColor color = background_color;
bool found_color = getChannelBaseColor(color, camera, data, limits);
if((draw_fast)&&(color.alphaF()<1.0))
blendColors(1.0-color.alphaF(),color,background_color);
QBrush brush(color,Qt::SolidPattern);
switch(fValueMode)
{
case VM_RADIUS:
radius = fabs(x);
if(x<0)brush.setStyle(Qt::NoBrush);
else return_color = color;
break;
case VM_AREA:
radius = sqrt(fabs(x));
if(x<0)brush.setStyle(Qt::NoBrush);
else return_color = color;
break;
case VM_ALPHA:
if(x>=1)
{
return_color = color;
radius = 1;
}
else if(x>0)
{
if(draw_fast)blendColors(x,color,background_color);
else color.setAlphaF(color.alphaF()*x);
brush.setColor(color);
return_color = color;
radius = 1;
}
else
{
radius = 0;
}
break;
case VM_COLOR:
radius = 1;
return_color = color;
break;
}
if((found_color)&&(radius>0))
{
QPen saved_pen = painter.pen();
QBrush saved_brush = painter.brush();
QPen pen(saved_pen);
pen.setWidth(0);
if((radius<=1.0)||(!fDrawOutline))pen.setColor(color);
else pen.setColor(fOutlineColor);
painter.setPen(pen);
painter.setBrush(brush);
painter.scale(radius,radius);
ShapeDraw::draw(camera,ncameras,painter,draw_fast);
if((fDrawOutline)&&(radius<=1.0))
{
const qreal rescale = 1.0/radius;
painter.scale(rescale,rescale);
pen.setColor(fOutlineColor);
painter.setPen(pen);
painter.setBrush(QBrush());
ShapeDraw::draw(camera,ncameras,painter,draw_fast);
}
painter.setBrush(saved_brush);
painter.setPen(saved_pen);
}
else if(fDrawOutline)
{
QPen saved_pen = painter.pen();
QPen pen = painter.pen();
pen.setWidth(0);
//.........这里部分代码省略.........
示例14: plotPathsToPainter
void plotPathsToPainter(QPainter& painter, QPainterPath& path,
const Numpy1DObj& x, const Numpy1DObj& y,
const Numpy1DObj* scaling,
const QRectF* clip,
const QImage* colorimg,
bool scaleline)
{
QRectF cliprect( QPointF(-32767,-32767), QPointF(32767,32767) );
if( clip != 0 )
{
qreal x1, y1, x2, y2;
clip->getCoords(&x1, &y1, &x2, &y2);
cliprect.setCoords(x1, y1, x2, y2);
}
QRectF pathbox = path.boundingRect();
cliprect.adjust(pathbox.left(), pathbox.top(),
pathbox.bottom(), pathbox.right());
// keep track of duplicate points
QPointF lastpt(-1e6, -1e6);
// keep original transformation for restoration after each iteration
QTransform origtrans(painter.worldTransform());
// number of iterations
int size = min(x.dim, y.dim);
// if few color points, trim down number of paths
if( colorimg != 0 )
size = min(size, colorimg->width());
// too few scaling points
if( scaling != 0 )
size = min(size, scaling->dim);
// draw each path
for(int i = 0; i < size; ++i)
{
const QPointF pt(x(i), y(i));
if( cliprect.contains(pt) && ! smallDelta(lastpt, pt) )
{
painter.translate(pt);
if( colorimg != 0 )
{
// get color from pixel and create a new brush
QBrush b( QColor::fromRgba(colorimg->pixel(i, 0)) );
painter.setBrush(b);
}
if( scaling == 0 )
{
painter.drawPath(path);
}
else
{
// scale point if requested
const qreal s = (*scaling)(i);
if( scaleline )
{
painter.scale(s, s);
painter.drawPath(path);
}
else
{
QPainterPath scaled;
scalePath(path, s, scaled);
painter.drawPath(scaled);
}
}
painter.setWorldTransform(origtrans);
lastpt = pt;
}
}
}
示例15: render
void QgsLayoutTable::render( QgsLayoutItemRenderContext &context, const QRectF &, const int frameIndex )
{
bool emptyTable = mTableContents.length() == 0;
if ( emptyTable && mEmptyTableMode == QgsLayoutTable::HideTable )
{
//empty table set to hide table mode, so don't draw anything
return;
}
if ( !mLayout->renderContext().isPreviewRender() )
{
//exporting composition, so force an attribute refresh
//we do this in case vector layer has changed via an external source (e.g., another database user)
refreshAttributes();
}
//calculate which rows to show in this frame
QPair< int, int > rowsToShow = rowRange( frameIndex );
double gridSizeX = mShowGrid && mVerticalGrid ? mGridStrokeWidth : 0;
double gridSizeY = mShowGrid && mHorizontalGrid ? mGridStrokeWidth : 0;
double cellHeaderHeight = QgsLayoutUtils::fontAscentMM( mHeaderFont ) + 2 * mCellMargin;
double cellBodyHeight = QgsLayoutUtils::fontAscentMM( mContentFont ) + 2 * mCellMargin;
QRectF cell;
//calculate whether a header is required
bool drawHeader = ( ( mHeaderMode == QgsLayoutTable::FirstFrame && frameIndex < 1 )
|| ( mHeaderMode == QgsLayoutTable::AllFrames ) );
//calculate whether drawing table contents is required
bool drawContents = !( emptyTable && mEmptyTableMode == QgsLayoutTable::ShowMessage );
int numberRowsToDraw = rowsToShow.second - rowsToShow.first;
int numberEmptyRows = 0;
if ( drawContents && mShowEmptyRows )
{
numberRowsToDraw = rowsVisible( frameIndex, rowsToShow.first, true );
numberEmptyRows = numberRowsToDraw - rowsToShow.second + rowsToShow.first;
}
bool mergeCells = false;
if ( emptyTable && mEmptyTableMode == QgsLayoutTable::ShowMessage )
{
//draw a merged row for the empty table message
numberRowsToDraw++;
rowsToShow.second++;
mergeCells = true;
}
QPainter *p = context.renderContext().painter();
p->save();
// painter is scaled to dots, so scale back to layout units
p->scale( context.renderContext().scaleFactor(), context.renderContext().scaleFactor() );
//draw the text
p->setPen( Qt::SolidLine );
double currentX = gridSizeX;
double currentY = gridSizeY;
if ( drawHeader )
{
//draw the headers
int col = 0;
for ( const QgsLayoutTableColumn *column : qgis::as_const( mColumns ) )
{
//draw background
p->save();
p->setPen( Qt::NoPen );
p->setBrush( backgroundColor( -1, col ) );
p->drawRect( QRectF( currentX, currentY, mMaxColumnWidthMap[col] + 2 * mCellMargin, cellHeaderHeight ) );
p->restore();
currentX += mCellMargin;
Qt::TextFlag textFlag = static_cast< Qt::TextFlag >( 0 );
if ( column->width() <= 0 )
{
//automatic column width, so we use the Qt::TextDontClip flag when drawing contents, as this works nicer for italicised text
//which may slightly exceed the calculated width
//if column size was manually set then we do apply text clipping, to avoid painting text outside of columns width
textFlag = Qt::TextDontClip;
}
cell = QRectF( currentX, currentY, mMaxColumnWidthMap[col], cellHeaderHeight );
//calculate alignment of header
Qt::AlignmentFlag headerAlign = Qt::AlignLeft;
switch ( mHeaderHAlignment )
{
case FollowColumn:
headerAlign = column->hAlignment();
break;
case HeaderLeft:
headerAlign = Qt::AlignLeft;
break;
case HeaderCenter:
headerAlign = Qt::AlignHCenter;
break;
case HeaderRight:
headerAlign = Qt::AlignRight;
break;
}
//.........这里部分代码省略.........