本文整理汇总了C++中QPainter::setViewport方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainter::setViewport方法的具体用法?C++ QPainter::setViewport怎么用?C++ QPainter::setViewport使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainter
的用法示例。
在下文中一共展示了QPainter::setViewport方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void CMeter2DGraphView::InitializeRasterRenderer( QPainter& aPainter, QImage& anImage )
{
anImage.fill( 0x00000000 );
aPainter.begin( &anImage );
aPainter.setViewport( 0, 0, anImage.width(), anImage.height() );
aPainter.setWindow( 0, anImage.height(), anImage.width(), -anImage.height() );
aPainter.setRenderHint( QPainter::HighQualityAntialiasing );
}
示例2: paintEvent
void SVGFrame::paintEvent ( QPaintEvent* event )
{
if ( repaint && !drawImg && !empty )
{
QPainter p ( this );
p.setViewport ( 0, 0, width(), height() );
p.eraseRect ( 0, 0, width(), height() );
renderer->render ( &p );
}
QFrame::paintEvent ( event );
}
示例3: pixmap
QPixmap
GuitarChordSelectorDialog::getFingeringPixmap(const Guitar::Fingering& fingering) const
{
// RG_DEBUG << "GuitarChordSelectorDialog::getFingeringPixmap()";
QPixmap pixmap(FINGERING_PIXMAP_WIDTH, FINGERING_PIXMAP_HEIGHT);
pixmap.fill();
QPainter pp(&pixmap);
QPainter *p = &pp;
p->setViewport(FINGERING_PIXMAP_H_MARGIN, FINGERING_PIXMAP_W_MARGIN,
FINGERING_PIXMAP_WIDTH - FINGERING_PIXMAP_W_MARGIN,
FINGERING_PIXMAP_HEIGHT - FINGERING_PIXMAP_H_MARGIN);
Guitar::NoteSymbols::drawFingeringPixmap(fingering, m_fingeringBox->getNoteSymbols(), p);
return pixmap;
}
示例4: render
void ModelIndexLayer::render(QPainter& painter)
{
if (mItemModel == NULL)
{
qDebug() << "Model == NULL";
// Nothing to do. return.
return;
}
foreach(QModelIndex index, mCulled)
{
QGeoCoordinate coord = mItemModel->data(index, ModelIndexLayer::GeoCoordinateRole).value<QGeoCoordinate>();
if (!coord.isValid())
continue;
// prepare the viewport for the delegate
QRect vp = markerPosition(coord);
painter.save();
painter.setClipRect(vp);
painter.setWindow(QRect(0, 0, vp.width(), vp.height()));
painter.setViewport(vp);
MarkerInfo markerInfo;
markerInfo.coord = coord;
markerInfo.modelIndex = index;
markerInfo.x = vp.left();
markerInfo.y = vp.top();
markerInfo.width = vp.width();
markerInfo.height = vp.height();
if (mSelectionModel != NULL)
markerInfo.markerState = mSelectionModel->selection().contains(index)
? MarkerInfo::MarkerStateSelected : MarkerInfo::MarkerStateNone;
QVariant v = mItemModel->data(index, ModelIndexLayer::DataRole);
mDelegate->paint(painter, markerInfo, v);
painter.restore();
} // else skip, this coord is not in view
示例5: Draw
void Draw(){
QPixmap *pixmap = new QPixmap(pixelx,pixely);
QPainter *painter = new QPainter(pixmap);
painter->begin(pixmap);
painter->setViewport(0,0,pixelx,pixely);
painter->setWindow(0,0,n+1,n+1);
painter->setPen(Qt::NoPen);
painter->setBrush(QBrush(Qt::white,Qt::SolidPattern));
painter->drawRect(0,0,pixelx,pixely);
painter->setBrush(Qt::NoBrush);
painter->setPen(Qt::blue);
painter->setWindow(0,0,pixelx,pixely);
painter->setFont(QFont("Times", 10));
for (int i=1;i<=n*n;i++){
char ts[5];
sprintf(ts,"%d",i);
QString num(ts);
QRect rect;
double x,y,l;
x = (location[i][0]*1.0)*pixelx/(n+1);
y = (location[i][1]*1.0)*pixely/(n+1);
l = pixelx*0.5/(n+1);
rect.setRect(x-l,y-l,l*2,l*2);
painter->drawText(rect,Qt::AlignCenter,num);
}
painter->setWindow(0,0,n+1,n+1);
painter->setPen(Qt::lightGray);
for (int i=0;i<=n;i++) painter->drawLine(QPointF(0.5,i+0.5),QPointF(n+0.5,i+0.5));
for (int i=0;i<=n;i++) painter->drawLine(QPointF(i+0.5,0.5),QPointF(i+0.5,n+0.5));
painter->setPen(Qt::black);
for (int i=1;i<n*n;i++){
painter->drawLine(location[i][0],location[i][1],location[i+1][0],location[i+1][1]);
}
painter->end();
char temp[20];
sprintf(temp,"../picture/%d.jpg",count);
pixmap->save(temp,0,100);
}
示例6: printPosReport
bool MReportViewer::printPosReport()
{
if (report == 0)
return false;
posprinter = new FLPosPrinter();
posprinter->setPaperWidth((FLPosPrinter::PaperWidth) report->pageSize());
posprinter->setPrinterName(printerName_);
QPicture *page;
QPainter painter;
bool printRev = false;
int viewIdx = report->getCurrentIndex();
int printCopies = numCopies_;
painter.begin(posprinter);
QPaintDeviceMetrics pdm(posprinter);
QSize dim(report->pageDimensions());
painter.setWindow(0, 0, dim.width(), dim.height());
painter.setViewport(0, 0, pdm.width(), pdm.height());
for (int j = 0; j < printCopies; j++) {
report->setCurrentPage(1);
page = report->getCurrentPage();
page->play(&painter);
}
painter.end();
report->setCurrentPage(viewIdx);
delete posprinter;
return true;
}
示例7: print
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;
}
示例8: drawContents
void CorrelationView::drawContents(QPainter *p){
if((drawContentsMode == UPDATE || drawContentsMode == REDRAW) && dataReady){
QRect contentsRec = contentsRect();
//Set the window (part of the world I want to show)
QRect r((QRect)window);
//If the border is not visible (the user zoomed without taking it in his selection), the viewport and the contentsRec
//have the same size.
if(r.left() != 0) viewport = QRect(contentsRec.left(),contentsRec.top(),contentsRec.width(),contentsRec.height() -10);
else viewport = QRect(contentsRec.left() + XMARGIN,contentsRec.top(),contentsRec.width() - XMARGIN,contentsRec.height() -10);
//Resize the double buffer with the width and the height of the widget(QFrame)
doublebuffer.resize(contentsRec.width(),contentsRec.height());
//Create a painter to paint on the double buffer
QPainter painter;
painter.begin(&doublebuffer);
painter.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.
painter.setViewport(viewport);
if(drawContentsMode == REDRAW){
//Fill the double buffer with the background
doublebuffer.fill(backgroundColor());
//Paint all the correlograms in the pairs list (in the double buffer)
drawCorrelograms(painter,pairs);
}
//The update mode applies only when the color of a cluster has changed.
if(drawContentsMode == UPDATE){
//Paint the correlograms contained in clusterUpdateList
drawCorrelograms(painter,pairUpdateList);
//Reset the pairUpdateList list for the next call.
pairUpdateList.clear();
}
//reset transformation due to setWindow and setViewport
painter.resetXForm() ;
//Draw the cluster Ids along the correlograms.
drawClusterIds(painter);
//Closes the painter on the double buffer
painter.end();
//Back to the default
drawContentsMode = REFRESH;
}
//if drawContentsMode == REFRESH, we reuse the double buffer (pixmap)
//Draw the double buffer (pixmap) by copying it into the widget device.
p->drawPixmap(0, 0, doublebuffer);
setCursor(zoomCursor);
}
示例9: printReport
//.........这里部分代码省略.........
QMessageBox::critical(this, "Kugar", tr("No hay páginas en el\ninforme para."), QMessageBox::Ok,
QMessageBox::NoButton, QMessageBox::NoButton);
return false;
}
// Set the printer dialog
printer = new QPrinter(QPrinter::HighResolution);
printer->setPageSize((QPrinter::PageSize) report->pageSize());
if ((QPrinter::PageSize) report->pageSize() == QPrinter::Custom)
printer->setCustomPaperSize(report->pageDimensions());
printer->setOrientation((QPrinter::Orientation) report->pageOrientation());
printer->setMinMax(1, cnt);
printer->setFromTo(1, cnt);
printer->setFullPage(true);
printer->setColorMode((QPrinter::ColorMode) colorMode_);
printer->setNumCopies(numCopies_);
printer->setResolution(dpi_);
if (!printerName_.isEmpty())
printer->setPrinterName(printerName_);
QString printProg(aqApp->printProgram());
if (!printProg.isEmpty())
printer->setPrintProgram(aqApp->printProgram());
bool printNow = true;
if (!printerName_.isNull())
printNow = true;
else
printNow = printer->setup(qApp->focusWidget());
if (printNow) {
QPicture *page;
QPainter painter;
bool printRev = false;
// Save the viewer's page index
int viewIdx = report->getCurrentIndex();
// Check the order we are printing the pages
if (printer->pageOrder() == QPrinter::LastPageFirst)
printRev = true;
// Get the count of pages and copies to print
int printFrom = printer->fromPage() - 1;
int printTo = printer->toPage();
int printCnt = (printTo - printFrom);
int printCopies = printer->numCopies();
int totalSteps = printCnt * printCopies;
int currentStep = 1;
// Set copies to 1, QPrinter copies does not appear to work ...
printer->setNumCopies(1);
// Setup the progress dialog
QProgressDialog progress(tr("Imprimiendo Informe..."), tr("Cancelar"), totalSteps, this, tr("progreso"), true);
progress.setMinimumDuration(M_PROGRESS_DELAY);
QObject::connect(&progress, SIGNAL(cancelled()), this, SLOT(slotCancelPrinting()));
progress.setProgress(0);
qApp->processEvents();
// Start the printer
painter.begin(printer);
QPaintDeviceMetrics pdm(printer);
QSize dim(report->pageDimensions());
painter.setWindow(0, 0, dim.width(), dim.height());
painter.setViewport(0, 0, pdm.width(), pdm.height());
// Print each copy
for (int j = 0; j < printCopies; j++) {
// Print each page in the collection
for (int i = printFrom; i < printTo; i++, currentStep++) {
if (!printer->aborted()) {
progress.setProgress(currentStep);
qApp->processEvents();
if (printRev)
report->setCurrentPage((printCnt == 1) ? i : (printCnt - 1) - i);
else
report->setCurrentPage(i);
page = report->getCurrentPage();
page->play(&painter);
if ((i - printFrom) < printCnt - 1)
printer->newPage();
} else {
j = printCopies;
break;
}
}
if (j < printCopies - 1)
printer->newPage();
}
// Cleanup printing
painter.end();
report->setCurrentPage(viewIdx);
delete printer;
return true;
}
delete printer;
return false;
}
示例10: PrintPixmap
/* 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;
}
}
示例11: printGhostReportToPS
bool MReportViewer::printGhostReportToPS(const QString &outPsFile)
{
if (report == 0)
return false;
int cnt = report->pageCount();
if (cnt == 0)
return false;
psprinter = new PSPrinter(PSPrinter::HighResolution);
psprinter->setPageSize((PSPrinter::PageSize) report->pageSize());
if ((PSPrinter::PageSize) report->pageSize() == PSPrinter::Custom)
psprinter->setCustomPaperSize(report->pageDimensions());
psprinter->setOrientation((PSPrinter::Orientation) report->pageOrientation());
psprinter->setMinMax(1, cnt);
psprinter->setFromTo(1, cnt);
psprinter->setFullPage(true);
psprinter->setColorMode((PSPrinter::ColorMode) colorMode_);
psprinter->setNumCopies(numCopies_);
psprinter->setResolution(dpi_);
QPicture *page;
QPainter painter;
bool printRev = false;
int viewIdx = report->getCurrentIndex();
if (psprinter->pageOrder() == QPrinter::LastPageFirst)
printRev = true;
int printFrom = psprinter->fromPage() - 1;
int printTo = psprinter->toPage();
int printCnt = (printTo - printFrom);
int printCopies = psprinter->numCopies();
int totalSteps = printCnt * printCopies;
int currentStep = 1;
psprinter->setNumCopies(1);
psprinter->setOutputToFile(true);
psprinter->setOutputFileName(outPsFile);
QProgressDialog progress(tr("Imprimiendo Informe..."), tr("Cancelar"), totalSteps, this, tr("progreso"), true);
progress.setMinimumDuration(M_PROGRESS_DELAY);
QObject::connect(&progress, SIGNAL(cancelled()), this, SLOT(slotCancelPrinting()));
progress.setProgress(0);
qApp->processEvents();
painter.begin(psprinter);
QPaintDeviceMetrics pdm(psprinter);
QSize dim(report->pageDimensions());
painter.setWindow(0, 0, dim.width(), dim.height());
painter.setViewport(0, 0, pdm.width(), pdm.height());
for (int j = 0; j < printCopies; j++) {
for (int i = printFrom; i < printTo; i++, currentStep++) {
if (!psprinter->aborted()) {
progress.setProgress(currentStep);
qApp->processEvents();
if (printRev)
report->setCurrentPage((printCnt == 1) ? i : (printCnt - 1) - i);
else
report->setCurrentPage(i);
page = report->getCurrentPage();
page->play(&painter);
if ((i - printFrom) < printCnt - 1)
psprinter->newPage();
} else {
j = printCopies;
break;
}
}
if (j < printCopies - 1)
psprinter->newPage();
}
painter.end();
report->setCurrentPage(viewIdx);
delete psprinter;
return true;
}
示例12: print
//.........这里部分代码省略.........
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();
}
}
示例13: drawCordinate
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 );
}
}
示例14: createImage
QImage createImage(int width, int height)
{
QImage image(width, height, QImage::Format_RGB16);
QPainter painter;
QPen pen;
pen.setStyle(Qt::NoPen);
QBrush brush(Qt::blue);
painter.begin(&image);
painter.fillRect(image.rect(), brush);
brush.setColor(Qt::white);
painter.setPen(pen);
painter.setBrush(brush);
static const QPointF points1[3] = {
QPointF(4, 4),
QPointF(7, 4),
QPointF(5.5, 1)
};
static const QPointF points2[3] = {
QPointF(1, 4),
QPointF(7, 4),
QPointF(10, 10)
};
static const QPointF points3[3] = {
QPointF(4, 4),
QPointF(10, 4),
QPointF(1, 10)
};
painter.setWindow(0, 0, 10, 10);
int x = 0;
int y = 0;
int starWidth = image.width()/3;
int starHeight = image.height()/3;
QRect rect(x, y, starWidth, starHeight);
for (int i = 0; i < 9; ++i) {
painter.setViewport(rect);
painter.drawPolygon(points1, 3);
painter.drawPolygon(points2, 3);
painter.drawPolygon(points3, 3);
if (i % 3 == 2) {
y = y + starHeight;
rect.moveTop(y);
x = 0;
rect.moveLeft(x);
} else {
x = x + starWidth;
rect.moveLeft(x);
}
}
painter.end();
return image;
}
示例15: printReportToPS
/** Imprime directamente sobre formato PS */
bool MReportViewer::printReportToPS(const QString &outPsFile)
{
// Check for a report
if (report == 0)
return false;
#if defined(Q_OS_WIN32) || defined(Q_OS_MACX)
return printGhostReportToPS(outPsFile);
#endif
// Get the page count
int cnt = report->pageCount();
// Check if there is a report or any pages to print
if (cnt == 0) {
QMessageBox::critical(this, "Kugar", tr("No hay páginas en el\ninforme para."), QMessageBox::Ok,
QMessageBox::NoButton, QMessageBox::NoButton);
return false;
}
// Set the printer dialog
printer = new QPrinter(QPrinter::HighResolution);
printer->setPageSize((QPrinter::PageSize) report->pageSize());
if ((QPrinter::PageSize) report->pageSize() == QPrinter::Custom)
printer->setCustomPaperSize(report->pageDimensions());
printer->setOrientation((QPrinter::Orientation) report->pageOrientation());
printer->setMinMax(1, cnt);
printer->setFromTo(1, cnt);
printer->setFullPage(true);
printer->setColorMode((QPrinter::ColorMode) colorMode_);
printer->setNumCopies(numCopies_);
printer->setOutputToFile(true);
printer->setOutputFileName(outPsFile);
QPicture *page;
QPainter painter;
bool printRev = false;
// Save the viewer's page index
int viewIdx = report->getCurrentIndex();
// Check the order we are printing the pages
if (printer->pageOrder() == QPrinter::LastPageFirst)
printRev = true;
// Get the count of pages and copies to print
int printFrom = printer->fromPage() - 1;
int printTo = printer->toPage();
int printCnt = (printTo - printFrom);
int printCopies = printer->numCopies();
int totalSteps = printCnt * printCopies;
int currentStep = 1;
// Set copies to 1, QPrinter copies does not appear to work ...
printer->setNumCopies(numCopies_);
printer->setResolution(dpi_);
// Setup the progress dialog
QProgressDialog progress(tr("Imprimiendo Informe..."), tr("Cancelar"), totalSteps, this, tr("progreso"), true);
progress.setMinimumDuration(M_PROGRESS_DELAY);
QObject::connect(&progress, SIGNAL(cancelled()), this, SLOT(slotCancelPrinting()));
progress.setProgress(0);
qApp->processEvents();
// Start the printer
painter.begin(printer);
QPaintDeviceMetrics pdm(printer);
QSize dim(report->pageDimensions());
painter.setWindow(0, 0, dim.width(), dim.height());
painter.setViewport(0, 0, pdm.width(), pdm.height());
// Print each page in the collection
for (int j = 0; j < printCopies; j++) {
for (int i = printFrom; i < printTo; i++, currentStep++) {
if (!printer->aborted()) {
progress.setProgress(currentStep);
qApp->processEvents();
if (printRev)
report->setCurrentPage((printCnt == 1) ? i : (printCnt - 1) - i);
else
report->setCurrentPage(i);
page = report->getCurrentPage();
page->play(&painter);
if ((i - printFrom) < printCnt - 1)
printer->newPage();
} else {
j = printCopies;
break;
}
}
if (j < printCopies - 1)
printer->newPage();
}
// Cleanup printing
painter.end();
report->setCurrentPage(viewIdx);
delete printer;
//.........这里部分代码省略.........