Esempio n. 1
0
int QPrinterProto::resolution() const
{
  QPrinter *item = qscriptvalue_cast<QPrinter*>(thisObject());
  if (item)
    return item->resolution();
  return 0;
}
Esempio n. 2
0
void PrintHelper::print(Document::Ptr doc)
{
    doc->startLoadingFullImage();
    doc->waitUntilLoaded();
    QPrinter printer;

    PrintOptionsPage* optionsPage = new PrintOptionsPage(doc->size());
    optionsPage->loadConfig();

    std::unique_ptr<QPrintDialog> dialog(
        KdePrint::createPrintDialog(&printer,
                                    QList<QWidget*>() << optionsPage,
                                    d->mParent)
    );
    dialog->setWindowTitle(i18n("Print Image"));
    bool wantToPrint = dialog->exec();

    optionsPage->saveConfig();
    if (!wantToPrint) {
        return;
    }

    QPainter painter(&printer);
    QRect rect = painter.viewport();
    QSize size = d->adjustSize(optionsPage, doc, printer.resolution(), rect.size());
    QPoint pos = d->adjustPosition(optionsPage, size, rect.size());
    painter.setViewport(pos.x(), pos.y(), size.width(), size.height());

    QImage image = doc->image();
    painter.setWindow(image.rect());
    painter.drawImage(0, 0, image);
}
/*!
  \param itemRow The row of the item for which to print the barcode lable.
  \see printLabelCurrent()
*/
void wndInventoryControl::printLabel( QVector<int> itemRow )
{
    QPrinter printer;

    // The labels used are 2.25"x0.75"
    // Set page size and margins accordingly
    qreal labelwidth = 2.25;
    qreal labelheight = 0.75;
    printer.setPaperSize( QSizeF( labelwidth, labelheight ), QPrinter::Inch );
    printer.setPageMargins( 0, 0, 0, 0, QPrinter::Inch );

    // PDF printing:
    //printer.setOutputFormat(QPrinter::PdfFormat);
    //printer.setOutputFileName("test.pdf");

    // Build the painter data which is printed
    QPainter painter;

    if ( !painter.begin( &printer ) ) // Link the painter to the printer
    {
        qWarning( "Printer Error: Could not link painter to printer." );
        return;
    }

    for ( int i = 0; i < itemRow.size(); i++ )
    {
        // Get the id column of the QTableView.
        QString codestring = "*" + _pUI->tblInventory->model()->data( _pUI->tblInventory->model()->index( itemRow[i] ,0 ) ).toString() + "*";

        // Draw the plaintext id centered at the top of the label
        painter.setFont( QFont( "Verdana", 10 ) );
        painter.drawText( 0 ,0, (int)( labelwidth * printer.resolution() ), (int)( labelheight * printer.resolution() ),
                          Qt::AlignHCenter, codestring );

        // Switch to the barcode font and do the same
        painter.setFont( QFont( "Free 3 of 9 Extended", 32 ) );
        painter.drawText( 0, 15, (int)( labelwidth * printer.resolution() ), (int)( labelheight * printer.resolution() ),
                          Qt::AlignHCenter, codestring );

        if ( i < itemRow.size() - 1 )
            printer.newPage();
    }

    painter.end(); // Send output
}
Esempio n. 4
0
//--------------------------------------------------------------------
float GDeviceQt::GetDPITag()const
{  
#ifndef IOS
	QPrinter * device = dynamic_cast<QPrinter *>( mQPainter->device() );
	if ( device != 0 )
	{
		return device->resolution ();
	}
#endif
	return -1;
}
Esempio n. 5
0
void Printer::print()
{
	// we can only print if "PRINT" mode is selected
	if (printMode != Printer::PRINT) {
		return;
	}


	QPrinter *printerPtr;
	printerPtr = static_cast<QPrinter*>(paintDevice);

	TemplateLayout t(printOptions, templateOptions);
	connect(&t, SIGNAL(progressUpdated(int)), this, SLOT(templateProgessUpdated(int)));
	dpi = printerPtr->resolution();
	//rendering resolution = selected paper size in inchs * printer dpi
	pageSize.setHeight(qCeil(printerPtr->pageRect(QPrinter::Inch).height() * dpi));
	pageSize.setWidth(qCeil(printerPtr->pageRect(QPrinter::Inch).width() * dpi));
	webView->page()->setViewportSize(pageSize);
	webView->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);

	// export border width with at least 1 pixel
	// templateOptions->borderwidth = std::max(1, pageSize.width() / 1000);
	if (printOptions->type == print_options::DIVELIST) {
		webView->setHtml(t.generate());
	} else if (printOptions->type == print_options::STATISTICS ) {
		webView->setHtml(t.generateStatistics());
	}
	if (printOptions->color_selected && printerPtr->colorMode()) {
		printerPtr->setColorMode(QPrinter::Color);
	} else {
		printerPtr->setColorMode(QPrinter::GrayScale);
	}
	// apply user settings
	int divesPerPage;

	// get number of dives per page from data-numberofdives attribute in the body of the selected template
	bool ok;
	divesPerPage = webView->page()->mainFrame()->findFirstElement("body").attribute("data-numberofdives").toInt(&ok);
	if (!ok) {
		divesPerPage = 1; // print each dive in a single page if the attribute is missing or malformed
		//TODO: show warning
	}
	int Pages;
	if (divesPerPage == 0) {
		flowRender();
	} else {
		Pages = qCeil(getTotalWork(printOptions) / (float)divesPerPage);
		render(Pages);
	}
}
Esempio n. 6
0
/// Writes all the relevant data into the tdf file.
void ExportEPS::doExport()
{
  using namespace std;

  // code adapted from Umbrello
  bool exportSuccessful;
  QRect textrect;

  //out->close();

    // print the image to a normal postscript file,
    // do not clip so that everything ends up in the file
    // regardless of "paper size"

    // because we want to work with postscript
    // user-coordinates, set to the resolution
    // of the printer (which should be 72dpi here)
    QPrinter *printer;

    printer = new QPrinter(QPrinter::ScreenResolution);

    printer->setOutputToFile(true);
    printer->setOutputFormat(QPrinter::PostScriptFormat);
    printer->setOutputFileName(fileName);
    printer->setColorMode(QPrinter::Color);
	printer->setFontEmbeddingEnabled(true);

    // do not call printer.setup(); because we want no user
    // interaction here
    QPainter *painter = new QPainter(printer);

    // make sure the widget sizes will be according to the
    // actually used printer font, important for getDiagramRect()
    // and the actual painting
    //view->forceUpdateWidgetFontMetrics(painter);

    if (!scrollview)
    {
      delete painter;
      delete printer;
      exportSuccessful = FALSE;
    }
    Draw* draw = new Draw(scrollview, options);
    QRect rect = draw->getBoundingBox(machine, painter);
	rect.setWidth(rect.width()+10);
	rect.setHeight(rect.height()+10);
    painter->translate(-rect.x(),-rect.y());
    //view->getDiagram(rect,*painter);

    int resolution = printer->resolution();


    if (scrollview)
      scrollview->getDrawArea()->getSelection()->deselectAll(machine);
    draw->drawStates(machine, painter, 0, 0, 1.0);
    draw->drawTransitions(machine, painter, 0, 0, 1.0);
    if (machine->getDrawITrans())
      draw->drawInitialTransition(machine, machine->getInitialTransition(), painter, 0, 0, 1.0, textrect, FALSE);

    // delete painter and printer before we try to open and fix the file
    delete painter;
    delete printer;
    delete draw;
    
    // modify bounding box from screen to eps resolution.
    rect.setWidth( int(ceil(rect.width() * 72.0/resolution)) );
    rect.setHeight( int(ceil(rect.height() * 72.0/resolution)) );
    exportSuccessful = fixEPS(fileName,rect);
	
    // next painting will most probably be to a different device (i.e. the screen)
    //view->forceUpdateWidgetFontMetrics(0);

    if (scrollview)
      scrollview->getDrawArea()->reset();
    //return exportSuccessful;
}
Esempio n. 7
0
void TSController::printReport()
{
    //    qDebug()<<"TSController::printReport";
    QPrinter printer;
    QPrintDialog *dialog = new QPrintDialog(&printer, this);
    dialog->setWindowTitle(tr("Предварительный просмотр"));

    int endIndex=curveBuffer->lenght;

    float listh=printer.widthMM()*printer.resolution()/25.4-60;
    float listw=printer.heightMM()*printer.resolution()/25.4-60;
    printer.setPageMargins(5,5,5,5,QPrinter::Millimeter);
    printer.setOrientation(QPrinter::Landscape);
    printer.setResolution(QPrinter::HighResolution);
    printer.setPaperSize(QPrinter::A4);
    Ui::Form pf;

    pf.setupUi(&wpf);
    pf.mainBox->setMaximumSize((int)listw,(int)listh);
    pf.mainBox->setMinimumSize((int)listw,(int)listh);
    pf.resultsTable->setMinimumWidth(40+(int)listw/3);
    pf.resultsTable->setRowCount(13);
    pf.resultsTable->setColumnCount(2);
    pf.resultsTable->verticalHeader()->setVisible(false);
    pf.resultsTable->setHorizontalHeaderLabels(QString(tr("Параметр; Значение")).split(";"));
    pf.resultsTable->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
    int i=0,j=0;
    for(i=0;i<ui->resultsTable->rowCount();i++){
        for(j=0;j<2;j++){
            pf.resultsTable->setItem(i,j,getQTableWidgetItem(ui->resultsTable->item(i,j)->text()));
        }
    }
    int myH=0,myW=0;
    wpf.resize(pf.mainBox->size());
    wpf.show();

    myH = pf.gVolume->height();
    myW = pf.gVolume->width();

    QPixmap pmTempIn(myW,myH);
    QPixmap pmTempOut(myW,myH);
    QPixmap pmVolume(myW,myH);

    QPainter prTempIn;
    QPainter prTempOut;
    QPainter prVolume;
    prTempIn.begin(&pmTempIn);
    prTempOut.begin(&pmTempOut);
    prVolume.begin(&pmVolume);

    int h = pf.gVolume->height()/2;
    int step = h/10;
    if(h%10>=5)
    {
        h+=step/2;
    }
    prVolume.fillRect(0,0,myW,myH,Qt::white);
    prTempIn.fillRect(0,0,myW,myH,Qt::white);
    prTempOut.fillRect(0,0,myW,myH,Qt::white);

    prVolume.setPen(QColor(225,225,225));
    prTempIn.setPen(QColor(225,225,225));
    prTempOut.setPen(QColor(225,225,225));
    for(i=step;i<h;i+=step)
    {
        prVolume.drawLine(0,h+i,myW,h+i);
        prTempIn.drawLine(0,h+i,myW,h+i);
        prTempOut.drawLine(0,h+i,myW,h+i);
        prVolume.drawLine(0,h-i,myW,h-i);
        prTempIn.drawLine(0,h-i,myW,h-i);
        prTempOut.drawLine(0,h-i,myW,h-i);
    }
    for(i=10;i<myW;i+=10)
    {
        prVolume.drawLine(i,0,i,h<<1);
        prTempIn.drawLine(i,0,i,h<<1);
        prTempOut.drawLine(i,0,i,h<<1);
    }
    prVolume.setPen(QColor(0,0,0));
    prTempIn.setPen(QColor(0,0,0));
    prTempOut.setPen(curveBuffer->toutColor);
    prVolume.setPen(QColor(255,0,0));
    int* tinInt = curveBuffer->getTempInInterval();
    int* toutInt = curveBuffer->getTempOutInterval();
    int* volInt = curveBuffer->getVolumeInterval();
    float tempInK = 1;
    float tempOutK = 1;
    float tempInZ = h;
    float tempOutZ = h;
    tempInAdaptive = (float)myH/(tinInt[1]-tinInt[0]);
    tempOutAdaptive = (float)myH/(toutInt[1]-toutInt[0]);
    volumeAdaptive = (float)myH/(volInt[1]-volInt[0]);
    tempInZ = h + ceil((float)(tinInt[1]+tinInt[0])*tempInAdaptive*tempInK/2);
    tempOutZ = h + ceil((float)(toutInt[1]+toutInt[0])*tempOutAdaptive*tempOutK/2);
    float volumeK =1;

    i=0;
    int k=ceil((float)curveBuffer->lenght/pf.gTempIn->width());
    for(j=0;j<myW-35;j+=1)
    {
        if(i>=k*endIndex)break;
        prVolume.drawLine(
                    j,h-volumeK*volumeAdaptive*volume[i],j+1,h-volumeK*volumeAdaptive*volume[i+k]
                );
        prTempIn.drawLine(j,tempInZ-tempInK*tempInAdaptive*tempIn[i]
                          ,j+1,tempInZ-tempInK*tempInAdaptive*tempIn[i+k]);
        prTempOut.drawLine(j,tempOutZ-tempOutK*tempOutAdaptive*tempOut[i]
                           ,j+1,tempOutZ-tempOutK*tempOutAdaptive*tempOut[i+k]);
        i+=k;
    }
    pf.gVolume->setPixmap(pmVolume);
    pf.gTempIn->setPixmap(pmTempIn);
    pf.gTempOut->setPixmap(pmTempOut);
    pf.PatientName->setText(patientsModel->record(0).value("sname").toString()+" "+patientsModel->record(0).value("fname").toString());

    wpf.hide();
    if (dialog->exec() == QDialog::Accepted){
        QPainter painter;
        painter.begin(&printer);
        int i=0;
        pf.mainBox->render(&painter);
    }
}
Esempio n. 8
0
int Printer::resolution(lua_State * L) // const : int 
{
	QPrinter* lhs = ValueBinding<MyQPrinter>::check( L, 1 );
	Util::push( L, lhs->resolution() );
	return 1;
}