void MultiLayer::exportVector(const QString &fileName, int res, bool color,
                              bool keepAspect, QPrinter::PageSize pageSize,
                              QPrinter::Orientation orientation) {
  Q_UNUSED(res);
  if (fileName.isEmpty()) {
    QMessageBox::critical(this, tr("Error"),
                          tr("Please provide a valid file name!"));
    return;
  }

  QPrinter printer;
  printer.setDocName(this->name());
  printer.setCreator("AlphaPlot");
  printer.setFullPage(true);
  printer.setOutputFileName(fileName);
  if (fileName.contains(".eps"))
    printer.setOutputFormat(QPrinter::PostScriptFormat);

  if (color)
    printer.setColorMode(QPrinter::Color);
  else
    printer.setColorMode(QPrinter::GrayScale);

  if (pageSize == QPrinter::Custom)
    printer.setPaperSize(canvas->size(), QPrinter::Point);
  else {
    printer.setOrientation(orientation);
    printer.setPaperSize(pageSize);
  }

  exportPainter(printer, keepAspect);
}
Example #2
0
void PageScreen::saveAsDocument(const QString &format)
{
    const QString &suffix = QLatin1Char('.') + format.toLower();

    QString pathWithoutSuffix = ui->location->text();
    if (pathWithoutSuffix.endsWith(suffix, Qt::CaseInsensitive)) {
        pathWithoutSuffix = pathWithoutSuffix.mid(0, pathWithoutSuffix.length() - suffix.length());
    }

    QPrinter printer;
    printer.setCreator(QupZilla::tr("QupZilla %1 (%2)").arg(QupZilla::VERSION, QupZilla::WWWADDRESS));
    printer.setOutputFileName(pathWithoutSuffix + suffix);
    printer.setOutputFormat(QPrinter::PdfFormat);
    printer.setPaperSize(m_pageImages.first().size(), QPrinter::DevicePixel);
    printer.setPageMargins(0, 0, 0, 0, QPrinter::DevicePixel);
    printer.setFullPage(true);

    QPainter painter;
    painter.begin(&printer);

    for (int i = 0; i < m_pageImages.size(); ++i) {
        const QImage &image = m_pageImages.at(i);
        painter.drawImage(0, 0, image);

        if (i != m_pageImages.size() - 1) {
            printer.newPage();
        }
    }

    painter.end();
}
Example #3
0
void Matrix::exportVector(const QString& fileName, int res, bool color)
{
	if ( fileName.isEmpty() ){
		QMessageBox::critical(this, tr("QtiPlot - Error"), tr("Please provide a valid file name!"));
        return;
	}

	QPrinter printer;
    printer.setCreator("QtiPlot");
	printer.setFullPage(true);
	if (res)
		printer.setResolution(res);

    printer.setOutputFileName(fileName);
    if (fileName.contains(".eps"))
    	printer.setOutputFormat(QPrinter::PostScriptFormat);

    if (color)
		printer.setColorMode(QPrinter::Color);
	else
		printer.setColorMode(QPrinter::GrayScale);

	printer.setOrientation(QPrinter::Portrait);

    int cols = numCols();
    int rows = numRows();
    QRect rect = QRect(0, 0, cols, rows);
    printer.setPaperSize(QSizeF(cols, rows), QPrinter::DevicePixel);

    QPainter paint(&printer);
    paint.drawImage(rect, d_matrix_model->renderImage());
    paint.end();
}
Example #4
0
/**
 * Methode permettant d'imprimer un document
 */
void ValidDocument::print(){

    QWebView webView;
    QPrinter printer ;

    printer.setPageSize(QPrinter::A4);
    printer.setFullPage(true);
    QString type=(docType==Document::Facture)?QObject::trUtf8("Facture"):QObject::trUtf8("Devis");
    printer.setDocName(type+"_"+QString::number(id) );
    printer.setCreator(QObject::trUtf8("QFacturation"));
    printer.setOutputFormat(QPrinter::NativeFormat);

    webView.setHtml(view);
    webView.show();
    QPrintDialog printDialog(&printer);
    if(printDialog.exec() == QDialog::Accepted) {
        qDebug("Ne fonctionne pas sous windows")<<" Hack ....";

        #if defined(Q_WS_WIN)
            QTextDocument text;
            text.setHtml(view);
            text.print(&printer);
        #endif
        #if defined(Q_WS_QWS)
            webView.print(&printer);
        #endif
        #if defined(Q_WS_X11)
            webView.print(&printer);
        #endif
    }

}
Example #5
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( "\"" ) );

}
Example #6
0
void data_plot::savePDF()
{
	if (save_file_name.length() > 0)
	{
		QPrinter printer;
		printer.setOutputFormat(QPrinter::PdfFormat);
		printer.setOrientation(QPrinter::Landscape);
		printer.setOutputFileName((save_file_name + ".pdf").c_str());
		printer.setCreator("Aluminizer2");

		myPlot.print(printer);
	}
}
Example #7
0
void PmChart::filePrint()
{
    QPrinter printer;
    QString creator = QString("pmchart Version ");

    creator.append(pmGetConfig("PCP_VERSION"));
    printer.setCreator(creator);
    printer.setOrientation(QPrinter::Portrait);
    printer.setDocName("pmchart.pdf");

    QPrintDialog print(&printer, (QWidget *)this);
    if (print.exec()) {
	QPainter qp(&printer);
	painter(&qp, printer.width(), printer.height(), false, false);
    }
}
Example #8
0
void Matrix::print(const QString& fileName)
{
	QPrinter printer;
	printer.setColorMode (QPrinter::GrayScale);

	if (!fileName.isEmpty()){
	    printer.setCreator("QtiPlot");
	    printer.setOutputFormat(QPrinter::PdfFormat);
        printer.setOutputFileName(fileName);
	} else {
        QPrintDialog printDialog(&printer, applicationWindow());
        if (printDialog.exec() != QDialog::Accepted)
            return;
    }
	printer.setFullPage( true );
	print(&printer);
}
Example #9
0
/*
*Function: Print
*Inputs:none
*Outputs:none
*Returns:none
*/
void GraphPaneData::Print()
{
	IT_IT("GraphPaneData::Print");
	
	QPrinter prt; 
	prt.setDocName(tr("Pen Trace"));
	prt.setCreator(tr(SYSTEM_NAME));
	prt.setOrientation(QPrinter::Landscape);
	prt.setOutputFileName("~out.ps");
	prt.setOutputToFile(false);
	//
	if(prt.setup(this))
	{
		//
		// Handle the case of no printer being selected
		//
		if(!prt.printerName().isEmpty())
		{
			QPainter p;
			p.begin(&prt);
			QPaintDeviceMetrics metrics(p.device());
			//
			int dpix = metrics.logicalDpiX() ; //  inch border
			int dpiy = metrics.logicalDpiY() ;
			//
			QRect body(dpix, dpiy,	metrics.width()  -  dpix*6,	metrics.height() -  dpiy*2);
			TheGraph.Plot(p,body,Qt::white);
			//
			QFont font("times", 8); 
			p.setFont(font);
			//
			p.drawText( body.left() ,body.top(), Title);
			//
			p.end();
			//
		}
		else
		{
			QMessageBox::information(this,tr("Print Graph Error"),tr("No Printer Selected!"));
		};
	};
};
Example #10
0
void PlotWindow::printPlot()
{
  QPrinter printer;

  QString docName = mpPlot->title().text();

  if (docName.isEmpty())
    {
      //docName.replace (QRegExp (QString::fromLatin1 ("\n")), tr (" -- "));
      docName = QString::fromLatin1("A plot of selected COPASI output");
      printer.setDocName(docName);
    }

  printer.setCreator("COPASI");
  printer.setOrientation(QPrinter::Landscape);

  QPrintDialog dialog(&printer);

  if (dialog.exec())
    mpPlot->print(printer, PrintFilter());
}
Example #11
0
/**
   Impression du livre des recettes
  */
void DialogInvoiceList::on_pushButton_print_clicked() {
	//Si on est pas connecte on sort
	if((!m_data->isConnected()) || (ui->tableWidget_Invoices->rowCount()<=0) )return;

	QPrinter printer;
	printer.setPageSize(QPrinter::A4);
	QString name = tr("LIVRERECETTES-")+ m_date.toString(tr("yyyyMM")) ;
	printer.setOutputFileName( name + ".pdf");
	printer.setDocName( name );
	printer.setCreator("mcercle");

	DialogPrintChoice *m_DialogPrintChoice = new DialogPrintChoice(&printer);
	m_DialogPrintChoice->setModal(true);
	m_DialogPrintChoice->exec();

	if(m_DialogPrintChoice->result() == QDialog::Accepted) {
		QWidget fenetre;
		QPrintPreviewDialog m_PreviewDialog(&printer,  &fenetre, Qt::Widget | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint);
		connect(&m_PreviewDialog, SIGNAL(paintRequested(QPrinter *)), this, SLOT(on_paintPrinter(QPrinter *)));
		m_PreviewDialog.setWindowState(Qt::WindowMaximized);
		m_PreviewDialog.exec();
	}
Example #12
0
void SimDialog::on_saveButton_clicked()
{
#if QT_VERSION >= 0x040100

#ifndef QT_NO_FILEDIALOG
  const QString fileName = QFileDialog::getSaveFileName(
      this, "Save File Name", QString(),
      "PDF Documents (*.pdf)");
#else
  const QString fileName = "similarity.pdf";
#endif

  if ( !fileName.isEmpty() )
  {
    QPrinter printer;
    printer.setOutputFormat(QPrinter::PdfFormat);
    printer.setOrientation(QPrinter::Landscape);
    printer.setOutputFileName(fileName);

    printer.setCreator("Octree Similarity");
    m_plot->print(printer);
  }
#endif
}
Example #13
0
void Clamp::print() {
#if 1
	QPrinter printer;
#else
	QPrinter printer(QPrinter::HighResolution);
#if QT_VERSION < 0x040000
	printer.setOutputToFile(true);
	printer.setOutputFileName("/tmp/FI.ps");
	printer.setColorMode(QPrinter::Color);
#else
	printer.setOutputFileName("/tmp/FI.pdf");
#endif
#endif

	QString docName = splot->title().text();
	if (!docName.isEmpty()) {
		docName.replace(QRegExp(QString::fromLatin1("\n")), tr(" -- "));
		printer.setDocName(docName);
	}

	printer.setCreator("RTXI");
	printer.setOrientation(QPrinter::Landscape);

#if QT_VERSION >= 0x040000
	QPrintDialog dialog(&printer);
	if ( dialog.exec() ) {
#else
		if (printer.setup())	{
#endif 
/*
		RTXIPrintFilter filter;
		if (printer.colorMode() == QPrinter::GrayScale) {
		 int options = QwtPlotPrintFilter::PrintAll;
		 filter.setOptions(options);
		 filter.color(QColor(29, 100, 141),
			  QwtPlotPrintFilter::CanvasBackground);
		 filter.color(Qt::white, QwtPlotPrintFilter::CurveSymbol);
		}
*/
//	splot->print(printer, filter);
	QwtPlotRenderer *renderer = new QwtPlotRenderer;
	renderer->renderTo(splot, printer);
	}
}

void Clamp::exportSVG() {
	QString fileName = "FI.svg";

std::cout<<"flag 0"<<std::endl;

#if QT_VERSION < 0x040000
std::cout<<"flag 1"<<std::endl;

#ifndef QT_NO_FILEDIALOG
std::cout<<"flag 2"<<std::endl;
	fileName = QFileDialog::getSaveFileName("FI.svg", "SVG Documents (*.svg)",	this);
#endif
std::cout<<"flag 3"<<std::endl;
	if (!fileName.isEmpty()) {
		// enable workaround for Qt3 misalignments
		QwtPainter::setSVGMode(true);
		QPicture picture;
		QPainter p(&picture);
//		splot->print(&p, QRect(0, 0, 800, 600));
		QwtPlotRenderer *renderer = new QwtPlotRenderer;
		renderer->renderTo(splot, p, QRect(0, 0, 800, 600));
		p.end();
		picture.save(fileName, "svg");
	}

#elif QT_VERSION >= 0x040300
std::cout<<"flag 4"<<std::endl;
#ifdef QT_SVG_LIB
std::cout<<"flag 5"<<std::endl;
#ifndef QT_NO_FILEDIALOG
std::cout<<"flag 6"<<std::endl;
		fileName = QFileDialog::getSaveFileName(this, "Export File Name", 
		                                        QString(), "SVG Documents (*.svg)");
#endif
std::cout<<"flag 7"<<std::endl;
	if ( !fileName.isEmpty() ) {
		QSvgGenerator generator;
		generator.setFileName(fileName);
		generator.setSize(QSize(800, 600));
//		splot->print(generator);
	}
#endif
#endif
}
Example #14
0
void CustRegister::printRegister()
{
    QDate       theDate;
    QPrinter    prn;
    QPainter    p;
    QRect       rect;
    ADBTable    cust;
    ADBTable    cont;
    ADB         DB;
    QString     tmpSt;
    char        tStr[1024];
    int         yPos;
    int         pageNo = 1;
    float       Balance = 0.00;
    float       EndingBalance;
    CustomersDB CDB;
    AddressesDB addrDB;
    
    CDB.get(myCustID);
    addrDB.get(REF_CUSTOMER, myCustID, "Billing");
    
    theDate = QDate::currentDate();
    
    // prn.setPrintProgram("ghostview");
    prn.setPrinterName("PostScript");
    // prn.setOutputFileName("/home/marc/test.ps");
    // prn.setOutputToFile(TRUE);
    prn.setPageSize(QPrinter::Letter);
    
    prn.setDocName("Register Listing");
    prn.setCreator("Blarg! Online Services, Inc.");
    
    if (!prn.setup()) return;
    
    p.begin(&prn);
    
    EndingBalance = DB.sumFloat("select SUM(Amount) from AcctsRecv where CustomerID = %ld", myCustID);
    
    // Put the Blarg header and contact information on the page.
    printHeader(&p, &CDB, &addrDB, EndingBalance);
    
    // Put the register header on the page.
    registerHeader(&p);
    
    // Now, get the register information from the database.
    DB.query("select TransDate, DueDate, LoginID, Memo, Amount from AcctsRecv where CustomerID = %ld order by TransDate, LoginID", myCustID);
    
    yPos = 165;
    p.setFont(QFont("courier", 8, QFont::Normal));
    while (DB.getrow()) {
        int Lines = (int) (strlen(DB.curRow["Memo"]) / 52) + 1;
        int RowHeight = 15 * Lines;
        
        // Check to see if we have enough room on the page left for this
        // line.
        if (yPos+RowHeight >= 740) {
            printFooter(&p, pageNo++);
            prn.newPage();
            printHeader(&p, &CDB, &addrDB, EndingBalance);
            registerHeader(&p);
            yPos = 165;
            p.setFont(QFont("courier", 8, QFont::Normal));
        } 
    
        // The transaction date.
        rect.setCoords(20, yPos, 79, yPos + RowHeight);
        p.drawRect(rect);
        p.drawText(rect, AlignVCenter|AlignHCenter, DB.curRow["TransDate"]);
        
        // The Due Date
        rect.setCoords(80, yPos, 139, yPos + RowHeight);
        p.drawRect(rect);
        p.drawText(rect, AlignVCenter|AlignHCenter, DB.curRow["DueDate"]);
        
        // The Login ID
        rect.setCoords(140, yPos, 199, yPos + RowHeight);
        p.drawRect(rect);
        p.drawText(rect, AlignVCenter|AlignHCenter, DB.curRow["LoginID"]);
        
        // The description...
        rect.setCoords(200, yPos, 419, yPos + RowHeight);
        p.drawRect(rect);
        rect.setCoords(203, yPos, 419, yPos + RowHeight);
        p.drawText(rect, WordBreak|AlignLeft|AlignVCenter, DB.curRow["Memo"]);
        
        // The amount.
        rect.setCoords(420, yPos, 479, yPos + RowHeight);
        p.drawRect(rect);
        p.drawText(rect, AlignRight|AlignVCenter, DB.curRow["Amount"]);
        
        // The balance.
        Balance += atof(DB.curRow["Amount"]);
        sprintf(tStr, "%.2f", Balance);
        if (Balance == 0.0) strcpy(tStr, "0.00");
        rect.setCoords(480, yPos, 539, yPos + RowHeight);
        p.drawRect(rect);
        p.drawText(rect, AlignRight|AlignVCenter, tStr);
        
        yPos += RowHeight;
    }

    // Put the footer on the page.
    printFooter(&p, pageNo);
    
    // prn.newPage();
    
    // p.drawText(300, 600, "Page 2");
    
    p.end();
}
Example #15
0
void Window::triggerAction(int identifier, const QVariantMap &parameters)
{
	switch (identifier)
	{
		case ActionsManager::CloneTabAction:
			if (canClone())
			{
				m_mainWindow->addWindow(clone(true, m_mainWindow));
			}

			break;
		case ActionsManager::PinTabAction:
			setPinned(!isPinned());

			break;
		case ActionsManager::DetachTabAction:
			if (m_mainWindow->getWindowCount() > 1)
			{
				m_mainWindow->moveWindow(this);
			}

			break;
		case ActionsManager::SuspendTabAction:
			if (!m_contentsWidget || m_contentsWidget->close())
			{
				m_session = getSession();

				setContentsWidget(nullptr);
			}

			break;
		case ActionsManager::CloseTabAction:
			if (!isPinned())
			{
				requestClose();
			}

			break;
		case ActionsManager::GoAction:
		case ActionsManager::ActivateAddressFieldAction:
		case ActionsManager::ActivateSearchFieldAction:
			{
				AddressWidget *addressWidget(findAddressWidget());
				SearchWidget *searchWidget(nullptr);

				for (int i = 0; i < m_searchWidgets.count(); ++i)
				{
					if (m_searchWidgets.at(i) && m_searchWidgets.at(i)->isVisible())
					{
						searchWidget = m_searchWidgets.at(i);

						break;
					}
				}

				if (identifier == ActionsManager::ActivateSearchFieldAction && searchWidget)
				{
					searchWidget->activate(Qt::ShortcutFocusReason);
				}
				else if (addressWidget)
				{
					if (identifier == ActionsManager::ActivateAddressFieldAction)
					{
						addressWidget->activate(Qt::ShortcutFocusReason);
					}
					else if (identifier == ActionsManager::ActivateSearchFieldAction)
					{
						addressWidget->setText(QLatin1String("? "));
						addressWidget->activate(Qt::OtherFocusReason);
					}
					else if (identifier == ActionsManager::GoAction)
					{
						addressWidget->handleUserInput(addressWidget->text(), SessionsManager::CurrentTabOpen);

						return;
					}
				}
				else if (identifier == ActionsManager::ActivateAddressFieldAction || identifier == ActionsManager::ActivateSearchFieldAction)
				{
					OpenAddressDialog dialog(this);

					if (identifier == ActionsManager::ActivateSearchFieldAction)
					{
						dialog.setText(QLatin1String("? "));
					}

					connect(&dialog, SIGNAL(requestedLoadUrl(QUrl,SessionsManager::OpenHints)), this, SLOT(handleOpenUrlRequest(QUrl,SessionsManager::OpenHints)));
					connect(&dialog, SIGNAL(requestedOpenBookmark(BookmarksItem*,SessionsManager::OpenHints)), this, SIGNAL(requestedOpenBookmark(BookmarksItem*,SessionsManager::OpenHints)));
					connect(&dialog, SIGNAL(requestedSearch(QString,QString,SessionsManager::OpenHints)), this, SLOT(handleSearchRequest(QString,QString,SessionsManager::OpenHints)));

					dialog.exec();
				}
			}

			break;
		case ActionsManager::PrintAction:
			{
				QPrinter printer;
				printer.setCreator(QStringLiteral("Otter Browser %1").arg(Application::getFullVersion()));

				QPrintDialog printDialog(&printer, this);
				printDialog.setWindowTitle(tr("Print Page"));

				if (printDialog.exec() != QDialog::Accepted)
				{
					break;
				}

				getContentsWidget()->print(&printer);
			}

			break;
		case ActionsManager::PrintPreviewAction:
			{
				QPrintPreviewDialog printPreviewDialog(this);
				printPreviewDialog.printer()->setCreator(QStringLiteral("Otter Browser %1").arg(Application::getFullVersion()));
				printPreviewDialog.setWindowFlags(printPreviewDialog.windowFlags() | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint);
				printPreviewDialog.setWindowTitle(tr("Print Preview"));

				if (QApplication::activeWindow())
				{
					printPreviewDialog.resize(QApplication::activeWindow()->size());
				}

				connect(&printPreviewDialog, SIGNAL(paintRequested(QPrinter*)), getContentsWidget(), SLOT(print(QPrinter*)));

				printPreviewDialog.exec();
			}

			break;
		case ActionsManager::BookmarkPageAction:
			{
				const QUrl url((parameters.contains(QLatin1String("url")) ? parameters[QLatin1String("url")].toUrl() : getUrl()).adjusted(QUrl::RemovePassword));

				if (url.isEmpty())
				{
					break;
				}

				const QVector<BookmarksItem*> bookmarks(BookmarksManager::getModel()->getBookmarks(url));

				if (bookmarks.isEmpty())
				{
					BookmarkPropertiesDialog dialog(url, (parameters.contains(QLatin1String("title")) ? parameters[QLatin1String("title")].toString() : getTitle()), parameters[QLatin1String("description")].toString(), nullptr, -1, true, this);
					dialog.exec();
				}
				else
				{
					BookmarkPropertiesDialog dialog(bookmarks.at(0), this);
					dialog.exec();
				}
			}

			break;
		case ActionsManager::FullScreenAction:
			if (m_addressBar)
			{
				m_addressBar->setVisible(m_addressBar->shouldBeVisible(m_mainWindow->isFullScreen()));
			}

			if (m_contentsWidget)
			{
				m_contentsWidget->triggerAction(identifier, parameters);
			}

			break;
		default:
			getContentsWidget()->triggerAction(identifier, parameters);

			break;
	}
Example #16
0
void PrintTool::print()
{
    const QString processTitle = i18nc( "@title:window", "Print Byte Array %1", mDocument->title() );

    QPrinter printer;

//     LayoutDialogPage* layoutPage = new LayoutDialogPage();
    QList<QWidget*> customDialogPages;
//     customDialogPages << layoutPage;
    QPrintDialog *printDialog = new QPrintDialog( &printer, 0 );
    // Disable PrintPageRange, this tells Qt we can't do client-side page selection,
    // so it will try do server-side page selection if supported
    printDialog->setOption(QPrintDialog::PrintPageRange, false);
//    printDialog->setOptionTabs(customDialogPages);

    printDialog->setWindowTitle( processTitle );
    if( printDialog->exec() )
    {
        QString creator = QString::fromLatin1( "Print Plugin for Okteta " ); // no i18n(), keep space at end as separator
//         creator += KDEUTILS_VERSION_STRING; // TODO: change to OKTETA_VERSION_STRING
        printer.setCreator( creator );

        FramesToPaperPrinter framesPrinter;
        framesPrinter.setPaperRect( printer.paperRect() );
        framesPrinter.setPageRect( printer.pageRect() );
        printer.setFullPage( true );


        PrintInfo info;
        const QRect pageRect = framesPrinter.pageRect();
        const int left = pageRect.left();
        const int width = pageRect.width();

        HeaderFooterFrameRenderer *headerFrameRenderer = new HeaderFooterFrameRenderer( &info );
        headerFrameRenderer->setTexts( QStringLiteral("%d"),
                                       QStringLiteral("%f"),
                                       i18nc("in the header of the printed page, e.g. Page 2 of 20","Page %p of %P") );
        headerFrameRenderer->setWidth( width );
        headerFrameRenderer->setPos( pageRect.topLeft() );

        HeaderFooterFrameRenderer *footerFrameRenderer = new HeaderFooterFrameRenderer( &info );
        footerFrameRenderer->setTexts( i18nc("in the footer of the printed page, e.g. Printed by: Joe User",
                                             "Printed by: %U"),
                                       QString(),
                                       QStringLiteral("%F") );
        footerFrameRenderer->setWidth( width );
        const int footerTop = pageRect.bottom() - footerFrameRenderer->height();
        footerFrameRenderer->setPos( left, footerTop );

        const int contentHeight = pageRect.height() - footerFrameRenderer->height() - headerFrameRenderer->height();
        const int contentTop = pageRect.top() + headerFrameRenderer->height();
        ByteArrayFrameRenderer *byteArrayFrameRenderer = new ByteArrayFrameRenderer;
        byteArrayFrameRenderer->setPos( left, contentTop );
        byteArrayFrameRenderer->setWidth( width );
        byteArrayFrameRenderer->setHeight( contentHeight );

        Okteta::AddressRange range = mByteArrayView->selection();
        if( ! range.isValid() )
            range.setByWidth( 0, mByteArrayModel->size() );
        byteArrayFrameRenderer->setByteArrayModel( mByteArrayModel, range.start(), range.width() );

        // TODO: use noOfBytesPerLine of view, scale resolution down if it does not fit the page
        const int noOfBytesPerLine = mByteArrayView->noOfBytesPerLine();
//         byteArrayFrameRenderer->setNoOfBytesPerLine( mByteArrayView->noOfBytesPerLine() );

        const Okteta::Address startOffset = mByteArrayView->startOffset() + range.start();
        const int line = startOffset / noOfBytesPerLine;
        const Okteta::Address firstLineOffset = mByteArrayView->firstLineOffset() + line*noOfBytesPerLine;
        byteArrayFrameRenderer->setFirstLineOffset( firstLineOffset );
        byteArrayFrameRenderer->setStartOffset( startOffset );

        byteArrayFrameRenderer->setCharCoding( mByteArrayView->charCodingName() );
        byteArrayFrameRenderer->setBufferSpacing( mByteArrayView->byteSpacingWidth(),
                                                  mByteArrayView->noOfGroupedBytes(),
                                                  mByteArrayView->groupSpacingWidth() );
        byteArrayFrameRenderer->setBinaryGapWidth( mByteArrayView->binaryGapWidth() );

        byteArrayFrameRenderer->setValueCoding( (Okteta::ValueCoding)mByteArrayView->valueCoding() );
        byteArrayFrameRenderer->setShowsNonprinting( mByteArrayView->showsNonprinting() );
        byteArrayFrameRenderer->setSubstituteChar( mByteArrayView->substituteChar() );
        byteArrayFrameRenderer->setUndefinedChar( mByteArrayView->undefinedChar() );
        byteArrayFrameRenderer->showByteArrayColumns( mByteArrayView->visibleByteArrayCodings() );

//     if( !confirmPrintPageNumber( byteArrayFrameRenderer->framesCount()) )
//         return;

        framesPrinter.addFrameRenderer( headerFrameRenderer );
        framesPrinter.addFrameRenderer( byteArrayFrameRenderer );
        framesPrinter.addFrameRenderer( footerFrameRenderer );

        info.setNoOfPages( byteArrayFrameRenderer->framesCount() );
        AbstractModelSynchronizer* synchronizer = mDocument->synchronizer();
        if (synchronizer) {
            info.setUrl( synchronizer->url() );
        }

        QApplication::setOverrideCursor( Qt::WaitCursor );

        PrintJob *printJob = new PrintJob( &framesPrinter, 0, byteArrayFrameRenderer->framesCount()-1, &printer );
        const bool success = printJob->exec();

        QApplication::restoreOverrideCursor();

        if( ! success )
        {
            const QString message = i18nc( "@info","Could not print." );

            KMessageBox::sorry( 0, message, processTitle );
        }
    }

    delete printDialog;
}
Example #17
0
void QPrinterProto::setCreator(const QString & creator)
{
  QPrinter *item = qscriptvalue_cast<QPrinter*>(thisObject());
  if (item)
    item->setCreator(creator);
}
Example #18
0
void Matrix::exportVector(const QString& fileName, int res, bool color, bool keepAspect, QPrinter::PageSize pageSize)
{
    if (d_view_type != ImageView)
        return;

	if ( fileName.isEmpty() ){
		QMessageBox::critical(this, tr("QtiPlot - Error"), tr("Please provide a valid file name!"));
        return;
	}

	QPrinter printer;
    printer.setCreator("QtiPlot");
	printer.setFullPage(true);
	if (res)
		printer.setResolution(res);

    printer.setOutputFileName(fileName);
    if (fileName.contains(".eps"))
    	printer.setOutputFormat(QPrinter::PostScriptFormat);

    if (color)
		printer.setColorMode(QPrinter::Color);
	else
		printer.setColorMode(QPrinter::GrayScale);

    int cols = numCols();
    int rows = numRows();
    QRect rect = QRect(0, 0, cols, rows);
    if (pageSize == QPrinter::Custom)
        printer.setPageSize(Graph::minPageSize(printer, rect));
    else
        printer.setPageSize(pageSize);

    double aspect = (double)cols/(double)rows;
	if (aspect < 1)
		printer.setOrientation(QPrinter::Portrait);
	else
		printer.setOrientation(QPrinter::Landscape);

    if (keepAspect){// export should preserve aspect ratio
        double page_aspect = double(printer.width())/double(printer.height());
        if (page_aspect > aspect){
            int margin = (int) ((0.1/2.54)*printer.logicalDpiY()); // 1 mm margins
            int height = printer.height() - 2*margin;
            int width = int(height*aspect);
            int x = (printer.width()- width)/2;
            rect = QRect(x, margin, width, height);
        } else if (aspect >= page_aspect){
            int margin = (int) ((0.1/2.54)*printer.logicalDpiX()); // 1 mm margins
            int width = printer.width() - 2*margin;
            int height = int(width/aspect);
            int y = (printer.height()- height)/2;
            rect = QRect(margin, y, width, height);
        }
	} else {
	    int x_margin = (int) ((0.1/2.54)*printer.logicalDpiX()); // 1 mm margins
        int y_margin = (int) ((0.1/2.54)*printer.logicalDpiY()); // 1 mm margins
        int width = printer.width() - 2*x_margin;
        int height = printer.height() - 2*y_margin;
        rect = QRect(x_margin, y_margin, width, height);
	}

    QPainter paint(&printer);
    paint.drawImage(rect, d_matrix_model->renderImage());
    paint.end();
}
Example #19
0
void Matrix::print(const QString& fileName)
{
	QPrinter printer;
	printer.setColorMode (QPrinter::GrayScale);

	if (!fileName.isEmpty()){
	    printer.setCreator("QtiPlot");
	    printer.setOutputFormat(QPrinter::PdfFormat);
        printer.setOutputFileName(fileName);
	} else {
        QPrintDialog printDialog(&printer, applicationWindow());
        if (printDialog.exec() != QDialog::Accepted)
            return;
    }
		printer.setFullPage( true );
		QPainter p;
		if ( !p.begin(&printer ) )
			return; // paint on printer
		int dpiy = printer.logicalDpiY();
		const int margin = (int) ( (1/2.54)*dpiy ); // 1 cm margins

        if (d_view_type == ImageView){
            p.drawImage (printer.pageRect(), d_matrix_model->renderImage());
            return;
        }

		QHeaderView *vHeader = d_table_view->verticalHeader();

		int rows = numRows();
		int cols = numCols();
		int height = margin;
		int i, vertHeaderWidth = vHeader->width();
		int right = margin + vertHeaderWidth;

		// print header
		p.setFont(QFont());
		QString header_label = d_matrix_model->headerData(0, Qt::Horizontal).toString();
		QRect br = p.boundingRect(br, Qt::AlignCenter, header_label);
		p.drawLine(right, height, right, height+br.height());
		QRect tr(br);

		for(i=0; i<cols; i++){
			int w = d_table_view->columnWidth(i);
			tr.setTopLeft(QPoint(right,height));
			tr.setWidth(w);
			tr.setHeight(br.height());
			header_label = d_matrix_model->headerData(i, Qt::Horizontal).toString();
			p.drawText(tr, Qt::AlignCenter, header_label,-1);
			right += w;
			p.drawLine(right, height, right, height+tr.height());

			if (right >= printer.width()-2*margin )
				break;
		}

		p.drawLine(margin + vertHeaderWidth, height, right-1, height);//first horizontal line
		height += tr.height();
		p.drawLine(margin, height, right-1, height);

		// print table values
		for(i=0;i<rows;i++){
			right = margin;
			QString cell_text = d_matrix_model->headerData(i, Qt::Horizontal).toString()+"\t";
			tr = p.boundingRect(tr, Qt::AlignCenter, cell_text);
			p.drawLine(right, height, right, height+tr.height());

			br.setTopLeft(QPoint(right,height));
			br.setWidth(vertHeaderWidth);
			br.setHeight(tr.height());
			p.drawText(br,Qt::AlignCenter,cell_text,-1);
			right += vertHeaderWidth;
			p.drawLine(right, height, right, height+tr.height());

			for(int j=0; j<cols; j++){
				int w = d_table_view->columnWidth (j);
				cell_text = text(i,j)+"\t";
				tr = p.boundingRect(tr,Qt::AlignCenter,cell_text);
				br.setTopLeft(QPoint(right,height));
				br.setWidth(w);
				br.setHeight(tr.height());
				p.drawText(br, Qt::AlignCenter, cell_text, -1);
				right += w;
				p.drawLine(right, height, right, height+tr.height());

				if (right >= printer.width()-2*margin )
					break;
			}
			height += br.height();
			p.drawLine(margin, height, right-1, height);

			if (height >= printer.height()-margin ){
				printer.newPage();
				height = margin;
				p.drawLine(margin, height, right, height);
			}
		}
}
Example #20
0
int Printer::setCreator(lua_State * L) // ( const QString & creator )
{
	QPrinter* lhs = ValueBinding<MyQPrinter>::check( L, 1 );
	lhs->setCreator( QtValueBase::toString( L, 2 ));
	return 0;
}
Example #21
0
int LuaPrinter2::setCreator(lua_State *L)
{
	QPrinter* obj = ValueInstaller<LuaPrinter2>::check( L, 1 );
	obj->setCreator( luaL_checkstring( L, 2 ) );
	return 0;
}