Ejemplo n.º 1
0
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 );
}
Ejemplo n.º 2
0
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 );
}
Ejemplo n.º 3
0
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;
}
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
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);
}
Ejemplo n.º 6
0
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;
}
Ejemplo n.º 7
0
void AccountsView::print( QPrinter &printer, QPrintDialog &printDialog )
{
    //kDebug(planDbg());
    uint top, left, bottom, right;
    printer.margins( &top, &left, &bottom, &right );
    //kDebug(planDbg())<<m.width()<<"x"<<m.height()<<" :"<<top<<","<<left<<","<<bottom<<","<<right<<" :"<<size();
    QPainter p;
    p.begin( &printer );
    p.setViewport( left, top, printer.width() - left - right, printer.height() - top - bottom );
    p.setClipRect( left, top, printer.width() - left - right, printer.height() - top - bottom );
    QRect preg = p.clipRegion().boundingRect();
    //kDebug(planDbg())<<"p="<<preg;
    //p.drawRect(preg.x(), preg.y(), preg.width()-1, preg.height()-1);
    double scale = qMin( ( double ) preg.width() / ( double ) size().width(), ( double ) preg.height() / ( double ) ( size().height() ) );
    //kDebug(planDbg())<<"scale="<<scale;
    if ( scale < 1.0 ) {
        p.scale( scale, scale );
}
    QPixmap labelPixmap = QPixmap::grabWidget( m_label );
    p.drawPixmap( m_label->pos(), labelPixmap );
    p.translate( 0, m_label->size().height() );
    m_dlv->paintContents( &p );
    p.end();
}
Ejemplo n.º 8
0
void DetailledPrintStyle::print( const KABC::Addressee::List &contacts, PrintProgress *progress )
{
  mPrintProgress = progress;

  progress->addMessage( i18n( "Setting up fonts and colors" ) );
  progress->setProgress( 0 );

  bool useKDEFonts;
  QFont font;
  QColor foreColor = Qt::black;
  QColor headerColor = Qt::white;
  bool useHeaderColor = true;
  QColor backColor = Qt::black;
  bool useBGColor;

  // save, always available defaults:
  QFont header = QFont("Helvetica", 12, QFont::Normal);
  QFont headlines = QFont("Helvetica", 12, QFont::Normal, true);
  QFont body = QFont("Helvetica", 12, QFont::Normal);
  QFont fixed = QFont("Courier", 12, QFont::Normal);
  QFont comment = QFont("Helvetica", 10, QFont::Normal);

  // store the configuration settings:
  KConfig *config = kapp->config();
  config->setGroup( ConfigSectionName );
  useKDEFonts = mPageAppearance->cbStandardFonts->isChecked();
  config->writeEntry( UseKDEFonts, useKDEFonts );

  // read the font and color selections from the wizard pages:
  useBGColor=mPageAppearance->cbBackgroundColor->isChecked();
  config->writeEntry( ColoredContactHeaders, useBGColor );

  // use colored contact headers, otherwise use plain black and white):
  if ( useBGColor ) {
    headerColor = mPageAppearance->kcbHeaderTextColor->color();
    backColor = mPageAppearance->kcbHeaderBGColor->color();
    config->writeEntry( ContactHeaderForeColor, headerColor );
    config->writeEntry( ContactHeaderBGColor, backColor );
  }

  if ( mPageAppearance->cbStandardFonts->isChecked() ) {
    QFont standard = KGlobalSettings::generalFont();
    header = standard;
    headlines = standard;
    body = standard;
    fixed = KGlobalSettings::fixedFont();
    comment = standard;
  } else {
    header.setFamily( mPageAppearance->kfcHeaderFont->currentText() );
    header.setPointSize( mPageAppearance->kisbHeaderFontSize->value() );
    config->writeEntry( HeaderFont, header );

    // headlines:
    headlines.setFamily( mPageAppearance->kfcHeadlineFont->currentText() );
    headlines.setPointSize( mPageAppearance->kisbHeadlineFontSize->value() );
    config->writeEntry( HeadlinesFont, headlines );

    // body:
    body.setFamily( mPageAppearance->kfcBodyFont->currentText() );
    body.setPointSize( mPageAppearance->kisbBodyFontSize->value() );
    config->writeEntry( BodyFont, body );

    // details:
    comment.setFamily( mPageAppearance->kfcDetailsFont->currentText() );
    comment.setPointSize( mPageAppearance->kisbDetailsFontSize->value() );
    config->writeEntry( DetailsFont, comment );

    // fixed:
    fixed.setFamily( mPageAppearance->kfcFixedFont->currentText() );
    fixed.setPointSize( mPageAppearance->kisbFixedFontSize->value() );
    config->writeEntry( FixedFont, fixed );
  }

  mPainter = new KABEntryPainter;
  mPainter->setForegroundColor( foreColor );
  mPainter->setHeaderColor( headerColor );
  mPainter->setBackgroundColor( backColor );
  mPainter->setUseHeaderColor( useHeaderColor );
  mPainter->setHeaderFont( header );
  mPainter->setHeadLineFont( headlines );
  mPainter->setBodyFont( body );
  mPainter->setFixedFont( fixed );
  mPainter->setCommentFont( comment );

  KPrinter *printer = wizard()->printer();

  QPainter painter;
  progress->addMessage( i18n( "Setting up margins and spacing" ) );
  int marginTop = 0,
      marginLeft = 64, // to allow stapling, need refinement with two-side prints
      marginRight = 0,
      marginBottom = 0;

  register int left, top, width, height;

  painter.begin( printer );
  printer->setFullPage( true ); // use whole page

  QPaintDeviceMetrics metrics( printer );

  left = QMAX( printer->margins().width(), marginLeft );
  top = QMAX( printer->margins().height(), marginTop );
  width = metrics.width() - left - QMAX( printer->margins().width(), marginRight );
  height = metrics.height() - top - QMAX( printer->margins().height(), marginBottom );

  painter.setViewport( left, top, width, height );
  progress->addMessage( i18n( "Printing" ) );

  printEntries( contacts, printer, &painter,
                QRect( 0, 0, metrics.width(), metrics.height() ) );

  progress->addMessage( i18n( "Done" ) );
  painter.end();

  config->sync();
}
Ejemplo n.º 9
0
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;
}
Ejemplo n.º 10
0
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);
}
Ejemplo n.º 11
0
/** Prints the rendered report to the selected printer - displays Qt print dialog */
bool MReportViewer::printReport()
{
  // Check for a report
  if (report == 0)
    return false;

  report->setPrintToPos(printToPos_);

  if (report->printToPos())
    return printPosReport();

#if defined(Q_OS_WIN32)
  bool gsOk = false;
  QProcess *procTemp = new QProcess();
  procTemp->addArgument(aqApp->gsExecutable());
  procTemp->addArgument("--version");
  gsOk = procTemp->start();
  delete procTemp;
  if (gsOk) {
    if (printGhostReport())
      return true;
  }

  QMessageBox *m = new QMessageBox(tr("Sugerencia"),
                                   tr("Si instala Ghostscript (http://www.ghostscript.com) y añade\n"
                                      "el directorio de instalación a la ruta de búsqueda de programas\n"
                                      "del sistema (PATH), Eneboo podrá utilizarlo para optimizar\n"
                                      "sustancialmente la calidad de impresión y para poder generar códigos\nde barras.\n\n"),
                                   QMessageBox::Information, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton, this, 0, false);
  m->show();
#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->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;
}
Ejemplo n.º 12
0
/* 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;
   }
}
Ejemplo n.º 13
0
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;
}
Ejemplo n.º 14
0
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();
    }
}
Ejemplo n.º 15
0
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 );                     
  }

}
Ejemplo n.º 16
0
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;
}
Ejemplo n.º 17
0
/** 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;
  return true;
}