Example #1
0
void toPieChart::editPrint ( void )
{
    TOPrinter printer;
    printer.setMinMax ( 1, 1 );
    if ( printer.setup() ) {
        printer.setCreator ( "TOra" );
        QPainter painter ( &printer );
        QPaintDeviceMetrics metrics ( &printer );
        QRect rect ( 0, 0, metrics.width(), metrics.height() );
        paintChart ( &painter, rect );
    }
}
Example #2
0
void KoPictureEps::draw(QPainter& painter, int x, int y, int width, int height, int sx, int sy, int sw, int sh, bool fastMode)
{
    if ( !width || !height )
        return;

    QSize screenSize( width, height );
    //kdDebug() << "KoPictureEps::draw screenSize=" << screenSize.width() << "x" << screenSize.height() << endl;

    QPaintDeviceMetrics metrics (painter.device());
    kdDebug(30003) << "Metrics: X: " << metrics.logicalDpiX() << " x Y: " << metrics.logicalDpiX() << " (in KoPictureEps::draw)" << endl;

    if ( painter.device()->isExtDev() ) // Is it an external device (i.e. printer)
    {
        kdDebug(30003) << "Drawing for a printer (in KoPictureEps::draw)" << endl;
        // For printing, always re-sample the image, as a printer has never the same resolution than a display.
        QImage image( scaleWithGhostScript( screenSize, metrics.logicalDpiX(), metrics.logicalDpiY() ) );
        // sx,sy,sw,sh is meant to be used as a cliprect on the pixmap, but drawImage
        // translates it to the (x,y) point -> we need (x+sx, y+sy).
        painter.drawImage( x + sx, y + sy, image, sx, sy, sw, sh );
    }
    else // No, it is simply a display
    {
        scaleAndCreatePixmap(screenSize, fastMode, metrics.logicalDpiX(), metrics.logicalDpiY() );

        // sx,sy,sw,sh is meant to be used as a cliprect on the pixmap, but drawPixmap
        // translates it to the (x,y) point -> we need (x+sx, y+sy).
        painter.drawPixmap( x + sx, y + sy, m_cachedPixmap, sx, sy, sw, sh );
    }
}
Example #3
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;
}
Example #4
0
void ScheduleDialog::print()
{
    PrintManager printer(project_->name());
    if (!printer.setup()) return;

    QPaintDeviceMetrics *metrics = printer.getMetrics();
    int printCanvasWidth = metrics->width();
    delete metrics;

    int tableHeight = (blocks_.count() + 1) * PRINT_ITEM_HEIGHT;
    QCanvas *printCanvas = new QCanvas(printCanvasWidth,
        tableHeight + PRINT_ITEM_HEIGHT + canvas->height());

    // first draw timing table
    int y = 0;
    Q_ASSERT(timingTable->numCols() == 4);
    int xOfs[6] = {0,       // x offsets of the columns
                   printCanvasWidth * 1/20,
                   printCanvasWidth * 4/10,
                   printCanvasWidth * 6/10,
                   printCanvasWidth * 8/10,
                   printCanvasWidth - 1};

    QCanvasLine *line = new QCanvasLine(printCanvas);
    line->setPoints(xOfs[0], y, xOfs[5], y);
    line->setPen(gray);
    line->show();

    // print header and vertical lines
    for (int i = 0; i <= 5; i++) {
        if ((i > 0) && (i < 5)) {
            QCanvasText* text = new QCanvasText(
                timingTable->horizontalHeader()->label(i - 1), printCanvas);
            text->move(xOfs[i] + PRINT_SPACING, y + PRINT_SPACING);
            text->show();
        }

        line = new QCanvasLine(printCanvas);
        line->setPoints(xOfs[i], y, xOfs[i], y + tableHeight);
        line->setPen(gray);
        line->show();
    }
    y += PRINT_ITEM_HEIGHT;

    // now print contents
    int row = 0;
    QValueList<BlockNode*>::Iterator it;
    for (it = blocks_.begin(); it != blocks_.end(); ++it) {
        // number
        QCanvasText* text;
        text = new QCanvasText(QString::number(row + 1), printCanvas);
        text->move(xOfs[0] + PRINT_SPACING, y + PRINT_SPACING);
        text->show();

        // other contents
        for (int i = 1; i <= 4; i++) {
            text = new QCanvasText(timingTable->text(row, i - 1), printCanvas);
            text->move(xOfs[i] + PRINT_SPACING, y + PRINT_SPACING);
            text->show();
        }

        // horizontal line
        line = new QCanvasLine(printCanvas);
        line->setPoints(xOfs[0], y, xOfs[5], y);
        line->setPen(gray);
        line->show();

        y += PRINT_ITEM_HEIGHT;
        row++;
    }

    line = new QCanvasLine(printCanvas);
    line->setPoints(xOfs[0], y, xOfs[5], y);
    line->setPen(gray);
    line->show();
    y += PRINT_ITEM_HEIGHT;

    // properties for the graph
    DrawProperties p;
    p.nameWidth = PRINT_NAME_WIDTH;
    p.x = 0;
    p.y = y;
    p.width = printCanvasWidth;
    p.height = canvas->height();
    p.canvas = printCanvas;

    // now draw graph
    unsigned int max_clock = 0;
    for (it = blocks_.begin(); it != blocks_.end(); ++it) {
        max_clock = QMAX(max_clock, (*it)->clock());
    }
    p.pixPerNs = (max_clock > 0)
        ? (double)canvas->width() / (max_clock * BLOCKS_PER_CANVAS)
        : 1.0;
    drawRuler(&p);
    for (it = blocks_.begin(); it != blocks_.end(); ++it) {
        drawTimings(&p, *it);
    }

    // finally print canvas
    printer.print(printCanvas);
}