Пример #1
0
void KPMarginPage::initPageSize(const QString& ps, bool landscape)
{
	// first retrieve the Qt values for page size and margins
	QPrinter	prt(QPrinter::PrinterResolution);
	prt.setFullPage(true);
	prt.setPageSize((QPrinter::PageSize)(ps.isEmpty() ? KGlobal::locale()->pageSize() : ps.toInt()));
	QPaintDeviceMetrics	metrics(&prt);
	float	w = metrics.width();
	float	h = metrics.height();
	unsigned int	it, il, ib, ir;
	prt.margins( &it, &il, &ib, &ir );
	float	mt = it;
	float	ml = il;
	float	mb = ib;
	float	mr = ir;

	if (driver() && m_usedriver )
	{
		QString	pageSize(ps);

		if (pageSize.isEmpty())
		{
			DrListOption	*o = (DrListOption*)driver()->findOption("PageSize");
			if (o)
				pageSize = o->get("default");
		}
		if (!pageSize.isEmpty())
		{
			DrPageSize	*dps = driver()->findPageSize(pageSize);
			if (dps)
			{
				w = dps->pageWidth();
				h = dps->pageHeight();
				mt = QMAX( mt, dps->topMargin() );
				ml = QMAX( ml, dps->leftMargin() );
				mb = QMAX( mb, dps->bottomMargin() );
				mr = QMAX( mr, dps->rightMargin() );
			}
		}
	}
	m_margin->setPageSize(w, h);
	m_margin->setOrientation(landscape ? KPrinter::Landscape : KPrinter::Portrait);
	m_margin->setDefaultMargins( mt, mb, ml, mr );
	m_margin->setCustomEnabled(false);
}
Пример #2
0
void KPrinter::translateQtOptions()
{
	d->m_wrapper->setCreator(creator());
	d->m_wrapper->setDocName(docName());
	d->m_wrapper->setFullPage(fullPage());
	d->m_wrapper->setColorMode((QPrinter::ColorMode)colorMode());
	d->m_wrapper->setOrientation((QPrinter::Orientation)orientation());
	if ( !option( "kde-printsize" ).isEmpty() )
		d->m_wrapper->setPageSize( ( QPrinter::PageSize )option( "kde-printsize" ).toInt() );
	else
		d->m_wrapper->setPageSize((QPrinter::PageSize)pageSize());
	d->m_wrapper->setOutputToFile(true);
	d->m_wrapper->setOutputFileName(d->m_tmpbuffer);
	d->m_wrapper->setNumCopies(option("kde-qtcopies").isEmpty() ? 1 : option("kde-qtcopies").toInt());
	if (!option("kde-margin-top").isEmpty())
	{
		/**
		 * Scale margings as the margin widget always stores values
		 * in dot units ( 1/72th in ), to be resolution independent
		 * when specified by the user ( who usually specifies margins
		 * in metric units ).
		 */
		int res = resolution();
		d->m_wrapper->setMargins(
				( int )( ( option("kde-margin-top").toFloat() * res + 71 ) / 72 ),
				( int )( ( option("kde-margin-left").toFloat() * res + 71 ) / 72 ),
				( int )( ( option("kde-margin-bottom").toFloat() * res + 71 ) / 72 ),
				( int )( ( option("kde-margin-right").toFloat() * res + 71 ) / 72 ) );
	}
	else if ( d->m_pagesize != NULL )
	{
		int res = resolution();
		DrPageSize *ps = d->m_pagesize;
		int top = ( int )( ps->topMargin() * res + 71 ) / 72;
		int left = ( int )( ps->leftMargin() * res + 71 ) / 72;
		int bottom = ( int )( ps->bottomMargin() * res + 71 ) / 72;
		int right = ( int )( ps->rightMargin() * res + 71 ) / 72;
		if ( !fullPage() )
		{
			// Printers can often print very close to the edges (PPD files say ImageArea==PaperDimension).
			// But that doesn't mean it looks good. Apps which use setFullPage(false) assume that
			// KPrinter will give them reasonable margins, so let's QMAX with defaults from Qt in that case.
			// Keep this in sync with KPMarginPage::initPageSize
			unsigned int it, il, ib, ir;
			d->m_wrapper->margins( &it, &il, &ib, &ir );
			top = QMAX( top, (int)it );
			left = QMAX( left, (int)il );
			bottom = QMAX( bottom, (int)ib );
			right = QMAX( right, (int)ir );
		}
		d->m_wrapper->setMargins( top, left, bottom, right );
	}
	/*else
	{
		int res = d->m_wrapper->resolution();
		d->m_wrapper->setMargins( res/3, res/2, res/3, res/2 );
	}*/
	// for special printers, copies are handled by Qt
	if (option("kde-isspecial") == "1")
		d->m_wrapper->setNumCopies(numCopies());
}