コード例 #1
0
ファイル: ippreportdlg.cpp プロジェクト: Fat-Zer/tdelibs
void IppReportDlg::slotUser1()
{
	KPrinter	printer;
	printer.setFullPage(true);
	printer.setDocName(caption());
	if (printer.setup(this))
	{
		TQPainter	painter(&printer);
		TQPaintDeviceMetrics	metrics(&printer);

		// report is printed using TQSimpleRichText
		TQSimpleRichText	rich(m_edit->text(), font());
		rich.setWidth(&painter, metrics.width());
		int	margin = (int)(1.5 / 2.54 * metrics.logicalDpiY());	// 1.5 cm
		TQRect	r(margin, margin, metrics.width()-2*margin, metrics.height()-2*margin);
		int	hh = rich.height(), page(1);
		while (1)
		{
			rich.draw(&painter, margin, margin, r, colorGroup());
			TQString	s = caption() + ": " + TQString::number(page);
			TQRect	br = painter.fontMetrics().boundingRect(s);
			painter.drawText(r.right()-br.width()-5, r.top()-br.height()-4, br.width()+5, br.height()+4, Qt::AlignRight|Qt::AlignTop, s);
			r.moveBy(0, r.height()-10);
			painter.translate(0, -(r.height()-10));
			if (r.top() < hh)
			{
				printer.newPage();
				page++;
			}
			else
				break;
		}
	}
}
コード例 #2
0
void KGVDocument::print()
{
    if( !dsc() ) return;

    KPrinter printer;
    
    if( dsc()->isStructured() ) 
    {
	printer.setPageSelection( KPrinter::ApplicationSide );

	printer.setCurrentPage( _part->miniWidget()->displayOptions().page() + 1 );
	printer.setMinMax( 1, dsc()->page_count() );
	printer.setOption( "kde-range", 
	                    pageListToRange( _part->markList()->markList() ) );

	if( printer.setup( _part->widget(), i18n("Print %1").arg(_part->url().fileName()) ) ) 
	{
	    KTempFile tf( QString::null, ".ps" );
	    if( tf.status() == 0 ) 
	    {
		if ( printer.pageList().empty() ) { 
		    KMessageBox::sorry( 0,
			    i18n( "Printing failed because the list of "
				"pages to be printed was empty." ),
			    i18n( "Error Printing" ) );
		} else if ( savePages( tf.name(), printer.pageList() ) ) {
		    printer.printFiles( QStringList( tf.name() ), true );
		} else {
		    KMessageBox::error( 0, i18n( "<qt><strong>Printing failure:</strong><br>Could not convert to PostScript</qt>" ) );
		}
	    }
	    else 
	    {
	        // TODO: Proper error handling
	        ;
	    }
	}
    }
    else 
    {
	printer.setPageSelection( KPrinter::SystemSide );
	
	if( printer.setup( _part->widget(), i18n("Print %1").arg(_part->url().fileName()) ) )
	    printer.printFiles( _fileName );
    }
}
コード例 #3
0
void KSnapshot::slotPrint()
{
    KPrinter printer;
    if (snapshot.width() > snapshot.height())
        printer.setOrientation(KPrinter::Landscape);
    else
        printer.setOrientation(KPrinter::Portrait);

    qApp->processEvents();

    if (printer.setup(this, i18n("Print Screenshot")))
    {
        qApp->processEvents();

        QPainter painter(&printer);
        QPaintDeviceMetrics metrics(painter.device());

        float w = snapshot.width();
        float dw = w - metrics.width();
        float h = snapshot.height();
        float dh = h - metrics.height();
        bool scale = false;

        if ( (dw > 0.0) || (dh > 0.0) )
            scale = true;

        if ( scale ) {

            QImage img = snapshot.convertToImage();
            qApp->processEvents();

            float newh, neww;
            if ( dw > dh ) {
                neww = w-dw;
                newh = neww/w*h;
            }
            else {
                newh = h-dh;
                neww = newh/h*w;
            }

            img = img.smoothScale( int(neww), int(newh), QImage::ScaleMin );
            qApp->processEvents();

            int x = (metrics.width()-img.width())/2;
            int y = (metrics.height()-img.height())/2;

            painter.drawImage( x, y, img);
        }
        else {
            int x = (metrics.width()-snapshot.width())/2;
            int y = (metrics.height()-snapshot.height())/2;
            painter.drawPixmap( x, y, snapshot );
        }
    }

    qApp->processEvents();
}
コード例 #4
0
ファイル: kgpgeditor.cpp プロジェクト: Fat-Zer/tdeutils
void KgpgApp::slotFilePrint()
{
        KPrinter prt;
        //kdDebug(2100)<<"Printing..."<<endl;
        if (prt.setup(this)) {
                TQPainter painter(&prt);
                TQPaintDeviceMetrics metrics(painter.device());
                painter.drawText( 0, 0, metrics.width(), metrics.height(), AlignLeft|AlignTop|DontClip,view->editor->text() );
        }
}
コード例 #5
0
void Kolf::print()
{
	KPrinter pr;
	pr.addDialogPage(new PrintDialogPage());

    if (pr.setup(this, i18n("Print %1 - Hole %2").arg(game->courseName()).arg(game->currentHole())))
	{
		pr.newPage();
		if (game)
			game->print(pr);
	}
}
コード例 #6
0
void KstApp::slotFilePrint() {
  slotUpdateStatusMsg(i18n("Printing..."));

  KPrinter printer;
  printer.setPageSize(KPrinter::Letter);
  printer.setOrientation(KPrinter::Landscape);

  // FIXME: Make a better title for the printingdialog
  if (printer.setup(this, i18n("Print Data")))
  {
    view->print(&printer);
  }

  slotUpdateStatusMsg(i18n("Ready"));
}
コード例 #7
0
ファイル: kjotsedit.cpp プロジェクト: Fat-Zer/tdeutils
void KJotsEdit::print(TQString title)
{
    KPrinter printer;
    printer.setDocName(title);
    printer.setFullPage(false);
    printer.setCreator("KJots");

    if (printer.setup(this))
    {
        TQFont printFont = font();
        TQPainter painter( &printer );
        TQPaintDeviceMetrics metrics( &printer );
        int y = 0;
        int maxWidth = metrics.width();
        int maxHeight = metrics.height();
        TQString currentParagraph;

        for (int paragraphCount = 0; paragraphCount < paragraphs(); ++paragraphCount )
        {
            currentParagraph = text(paragraphCount);
            TQRect r = painter.boundingRect(0, y, maxWidth, maxHeight,
                    TQPainter::ExpandTabs | TQPainter::WordBreak,
                    currentParagraph);

            if ((y + r.height()) > maxHeight)
            {
                printer.newPage();
                y = 0;
            }

            painter.drawText(0, y, maxWidth, maxHeight - y,
                    TQPainter::ExpandTabs | TQPainter::WordBreak,
                    currentParagraph);
            y += r.height();
        }
        painter.end();
    }
}
コード例 #8
0
bool KexiSimplePrintingCommand::print(const QString& aTitleText)
{
	KexiDB::Connection *conn = m_mainWin->project()->dbConnection();
	KexiDB::TableOrQuerySchema tableOrQuery(conn, m_objectId);
	if (!tableOrQuery.table() && !tableOrQuery.query()) {
//! @todo item not found
		return false;
	}
	QString titleText(aTitleText.stripWhiteSpace());
	if (titleText.isEmpty())
		titleText = tableOrQuery.captionOrName();

	KexiSimplePrintingEngine engine(m_settings, this);
	QString errorMessage;
	if (!engine.init(*conn, tableOrQuery, titleText, errorMessage)) {
		if (!errorMessage.isEmpty())
			KMessageBox::sorry(m_mainWin, errorMessage, i18n("Printing"));
		return false;
	}

	//setup printing
#ifdef Q_WS_WIN
	QPrinter printer(QPrinter::HighResolution);
	printer.setOrientation( m_settings.pageLayout.orientation == PG_PORTRAIT 
		? QPrinter::Portrait : QPrinter::Landscape );
	printer.setPageSize( 
		(QPrinter::PageSize)KoPageFormat::printerPageSize( m_settings.pageLayout.format ) );

	// "chicken-egg" problem: 
	// we cannot use real from/to values in setMinMax() and setFromTo() 
	// because page count is known after obtaining print settings
	printer.setFromTo(1,1);
#else
	KPrinter printer;
	printer.setOrientation( m_settings.pageLayout.orientation == PG_PORTRAIT 
		? KPrinter::Portrait : KPrinter::Landscape );
	printer.setPageSize( 
		(KPrinter::PageSize)KoPageFormat::printerPageSize( m_settings.pageLayout.format ) );
#endif

	printer.setFullPage(true);
	QString docName( titleText );
	printer.setDocName( docName );
	printer.setCreator(KEXI_APP_NAME);
	if ( !printer.setup( m_mainWin ) ) {
		return true;
	}

	// now we have final settings

//! @todo get printer.pageOrder() (for reversed order requires improved engine)
	QPainter painter;

	if (!painter.begin(&printer)) {
//! @todo msg
		return false;
	}
	engine.calculatePagesCount(painter);

	uint loops, loopsPerPage;
	QValueList<int> pagesToPrint;
	int fromPage = 0;
#ifdef Q_WS_WIN
	int toPage = 0;
	if (QPrinter::PageRange == printer.printRange()) {
		fromPage = printer.fromPage();
		toPage = printer.toPage();
	}
	if (fromPage==0 || toPage==0) {
		fromPage = 0;
		toPage = (int)engine.pagesCount()-1;
	}
	else {
		fromPage--;
		if (toPage > (int)engine.pagesCount())
			toPage = (int)engine.pagesCount();
		toPage--;
	}
	// win32 only supports one range, build the list
	for (int i = fromPage; i<=toPage; i++) {
		pagesToPrint.append(i);
	}
	// on win32 the OS does perform buffering (only when collation is off, each copy needs to be repeated)
	loops = 1;
	loopsPerPage = printer.collateCopies() ? 1 : printer.numCopies();
#else
	// on !win32 print QPrinter::numCopies() times (the OS does not perform buffering)
	pagesToPrint = printer.pageList();
	kdDebug() << pagesToPrint << endl;
	if (pagesToPrint.isEmpty()) {
		fromPage = 0;
		for (int i = 0; i<(int)engine.pagesCount(); i++) {
			pagesToPrint.append(i);
		}
	}
	else
		fromPage = pagesToPrint.first();
	if (printer.collate()==KPrinter::Collate) {
		//collation: p1, p2,..pn; p1, p2,..pn; ......; p1, p2,..pn
		loops = printer.numCopies();
		loopsPerPage = 1;
	}
	else {
		//no collation: p1, p1, ..., p1; p2, p2, ..., p2; ......; pn, pn,..pn
		loops = 1; 
		loopsPerPage = printer.numCopies();
	}
//! @todo also look at printer.pageSet() option : all/odd/even pages
#endif
	// now, total number of printed pages is printer.numCopies()*printer.pageList().count()

	kdDebug() << "printing..." << endl;
	bool firstPage = true;
	for (uint copy = 0;copy < loops; copy++) {
		kdDebug() << "copy " << (copy+1) << " of " << loops << endl;
		uint pageNumber = fromPage;
		QValueList<int>::ConstIterator pagesIt = pagesToPrint.constBegin();
		for(;(int)pageNumber == fromPage || !engine.eof(); ++pageNumber) {
			kdDebug() << "printing..." << endl;
			if (pagesIt == pagesToPrint.constEnd()) //no more pages to print
				break;
			if ((int)pageNumber < *pagesIt) { //skip pages without printing (needed for computation)
				engine.paintPage(pageNumber, painter, false);
				continue;
			}
			if (*pagesIt < (int)pageNumber) { //sanity
				++pagesIt;
				continue;
			}
			for (uint onePageCounter = 0; onePageCounter < loopsPerPage; onePageCounter++) {
				if (!firstPage)
					printer.newPage();
				else
					firstPage = false;
				kdDebug() << "page #" << pageNumber << endl;
				engine.paintPage(pageNumber, painter);
			}
			++pagesIt;
		}
	}
	kdDebug() << "end of printing." << endl;

	// stop painting, this will automatically send the print data to the printer
	if (!painter.end())
		return false;

	if (!engine.done())
		return false;

	return true;
}