Пример #1
0
QPrinter::ColorMode QPrinterProto::colorMode() const
{
  QPrinter *item = qscriptvalue_cast<QPrinter*>(thisObject());
  if (item)
    return item->colorMode();
  return QPrinter::Color;
}
Пример #2
0
void ProRataGraphPane::print()
{
	if ( !(qtwGraphTab->currentWidget()) )
	{
		return ;
	}

/*
	QString qsSaveFileName = QFileDialog::getSaveFileName(
                    this,
                    "ProRata - Choose a file name to save",
                    ".",
                    "Images (*.png *.jpg)");

	if (qsSaveFileName.isEmpty())
	{
		return;
	}
	*/

	ProRataGraph *clickedGraph = (ProRataGraph *)qtwGraphTab->currentWidget();

	QPrinter printer;
    //printer.setOutputToFile(true);
    //printer.setOutputFileName(qsSaveFileName);
    printer.setDocName(QString("ProRata_Graph"));

    printer.setCreator("ProRata Graph");
    printer.setOrientation(QPrinter::Landscape);

	QPrintDialog dialog(&printer);
    if ( dialog.exec() )
    {
		QwtPlotPrintFilter filter;
		if ( printer.colorMode() == QPrinter::GrayScale )
        {
            filter.setOptions(QwtPlotPrintFilter::PrintAll 
                & ~QwtPlotPrintFilter::PrintCanvasBackground);
        }
		clickedGraph->print( printer, filter );
	}
	
	

/*
	//QPixmap *qpPic = new QPixmap( qsSaveFileName );
	//QPainter * qpntrPainter = new QPainter( qpPic );
	QPixmap qpPic( qsSaveFileName );
	qpPic.save( qsSaveFileName );
	//QPainter * qpntrPainter = new QPainter( qpPic );

	//clickedGraph->print( qpntrPainter, clickedGraph->frameGeometry() );
	clickedGraph->print( qpPic );
*/
	//QMessageBox::information( this, "Printing done.", QString( "Saved \"") + qsSaveFileName + QString( "\"" ) );

}
Пример #3
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);
	}
}
Пример #4
0
int Printer::colorMode(lua_State * L) // const : ColorMode 
{
	QPrinter* lhs = ValueBinding<MyQPrinter>::check( L, 1 );
	Util::push( L, lhs->colorMode() );
	return 1; 
}