Esempio n. 1
0
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;
		}
	}
}
Esempio n. 2
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);
	}
}
Esempio n. 3
0
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();
    }
}
Esempio n. 4
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;
}
Esempio n. 5
0
void TopLevel::printIt( KPrinter &printer, QPainter &painter )
{
  QPaintDeviceMetrics dm(painter.device());

  QApplication::setOverrideCursor( waitCursor );
  kapp->processEvents();

  const bool fullpage = printer.option(APP_KFAX_SCALE_FULLPAGE) == "true";
  const bool center_h = printer.option(APP_KFAX_CENTER_HORZ) == "true";
  const bool center_v = printer.option(APP_KFAX_CENTER_VERT) == "true";

  int currentpage = 0;
  bool first_page_printed = false;
  struct pagenode *pn;
  for(pn = firstpage; pn; pn = pn->next) {

    ++currentpage;
    // should this page be printed ?
    if (printer.pageList().findIndex(currentpage) < 0)
	continue;

    XImage *Image = Pimage(pn);
    if (!Image)
	continue;

    // byte-swapping the image
    QByteArray bytes( Image->height*Image->bytes_per_line );
    for (int y=Image->height-1; y>=0; --y) {
      Q_UINT32 offset  = y*Image->bytes_per_line;
      Q_UINT32 *source = (Q_UINT32 *) (Image->data + offset);
      Q_UINT32 *dest   = (Q_UINT32 *) (bytes.data() + offset);
      for (int x=(Image->bytes_per_line/4)-1; x>=0; --x) {
 	Q_UINT32 dv = 0, sv = *source;
	for (int bit=32; bit>0; --bit) {
		dv <<= 1;
		dv |= sv&1;
		sv >>= 1;
	}
        *dest = dv;
	++dest;
	++source;
      }
    }

    QImage image( (uchar *)bytes.data(), Image->bytes_per_line*8, Image->height, 1, NULL, 2, QImage::LittleEndian);

    if (first_page_printed)
	printer.newPage();
    first_page_printed = true;

    const QSize printersize( dm.width(), dm.height() );
    kdDebug() << "Printersize = " << printersize << endl;
    // print Image in original size if possible, else scale it.

    const QSize size(  // logical size of the image
			Image->width  * dm.logicalDpiX() / pn->dpiX,
			Image->height * dm.logicalDpiY() / pn->dpiY
		);

    kdDebug()	<< "Org image size = " << Image->width << "x" << Image->height 
		<< " logical picture res = " << pn->dpiX << "x" << pn->dpiY << endl;
    kdDebug()	<< "New image size = " << size 
		<< " logical printer res = " << dm.logicalDpiX() << "x" << dm.logicalDpiY() << endl;

    uint top, left, bottom, right;
    if (fullpage)
       top = left = bottom = right = 0;
    else
       printer.margins( &top, &left, &bottom, &right );
    kdDebug() << "Margins = " << top << " " << left << " " << bottom << " " << right << endl;

    const QSize maxSize( printersize.width()-left-right, printersize.height()-top-bottom );
    QSize scaledImageSize = size;
    if (size.width() > maxSize.width() || size.height() > maxSize.height() ) {
	// Image does not fit - scale it and print centered
	scaledImageSize.scale( maxSize, QSize::ScaleMin );
	kdDebug() << "Image does not fit - scaling to " << maxSize << endl;
    } else {
	// Image does fit - print it in original size, but centered
	scaledImageSize.scale( size, QSize::ScaleMin );
	kdDebug() << "Image does fit - scaling to " << size << endl;
    }
    kdDebug() << "Final image size " << scaledImageSize << endl;
    int x,y;
    if (center_h)
	x = (maxSize.width()-scaledImageSize.width())/2 + left;
    else
	x = left;
    if (center_v)
	y = (maxSize.height()-scaledImageSize.height())/2 + top;
    else
	y = top;
    painter.drawImage( QRect(x,y,scaledImageSize.width(), scaledImageSize.height()), image );

  }

  QApplication::restoreOverrideCursor();
}