[Uml-devel] branches/KDE/3.5/kdesdk/umbrello
Oliver Kellogg
okellogg at users.sourceforge.net
Fri Dec 8 18:11:43 UTC 2006
SVN commit 611554 by okellogg:
Apply OptimizePrinterMargin.diff by Achim Spangler at
http://www.geeksoc.org/~jr/umbrello/uml-devel/9895.html
> [...] the old code didn't differentiate between top and bottom margin [...]
> I get much better results for printing both in portrait (default) and
> landscape mode. Especially there is no more a too big margin at the wrong
> place.
M +2 -0 ChangeLog
M +22 -17 umbrello/umlview.cpp
--- branches/KDE/3.5/kdesdk/umbrello/ChangeLog #611553:611554
@@ -9,6 +9,8 @@
http://www.geeksoc.org/~jr/umbrello/uml-devel/9862.html
* Note widget is now always drawn on TOP of all widgets
http://www.geeksoc.org/~jr/umbrello/uml-devel/9863.html
+* Optimized printer margins
+ http://www.geeksoc.org/~jr/umbrello/uml-devel/9895.html
* Bugs/wishes from http://bugs.kde.org:
* Artifacts of a component diagram are wrongly placed in Deployment View folder (137564)
* Incorrect export to SQL (138139)
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/umlview.cpp #611553:611554
@@ -216,34 +216,39 @@
void UMLView::print(KPrinter *pPrinter, QPainter & pPainter) {
int height, width;
//get the size of the page
+ pPrinter->setFullPage( true );
QPaintDeviceMetrics metrics(pPrinter);
QFontMetrics fm = pPainter.fontMetrics(); // use the painter font metrics, not the screen fm!
int fontHeight = fm.lineSpacing();
- int marginX = pPrinter->margins().width();
- int marginY = pPrinter->margins().height();
+ uint left, right, top, bottom;
+ // fetch printer margins individual for all four page sides, as at least top and bottom are not the same
+ pPrinter->margins ( &top, &left, &bottom, &right );
+ // give a little extra space at each side
+ left += 2;
+ right += 2;
+ top += 2;
+ bottom += 2;
if(pPrinter->orientation() == KPrinter::Landscape) {
// we are printing in LANDSCAPE --> swap marginX and marginY
- // this is needed, as KPrinter reports width margin strictly as printer
- // default orientation margin - and not depend on LANDSCAPE/PORTRAIT
- int temp = marginX;
- marginX = marginY;
- marginY = temp;
+ uint right_old = right;
+ // the DiagramRight side is printed at PrintersTop
+ right = top;
+ // the DiagramTop side is printed at PrintersLeft
+ top = left;
+ // the DiagramLeft side is printed at PrintersBottom
+ left = bottom;
+ // the DiagramBottom side is printed at PrintersRight
+ bottom = right_old;
}
// The printer will probably use a different font with different font metrics,
// force the widgets to update accordingly on paint
forceUpdateWidgetFontMetrics(&pPainter);
- //double margin at bottom of page as it doesn't print down there
- //on my printer, so play safe as default.
- if(pPrinter->orientation() == KPrinter::Portrait) {
- width = metrics.width() - marginX * 2;
- height = metrics.height() - fontHeight - 4 - marginY * 3;
- } else {
- width = metrics.width() - marginX * 2;
- height = metrics.height() - fontHeight - 4 - marginY * 2;
- }
+ width = metrics.width() - left - right;
+ height = metrics.height() - top - bottom;
+
//get the smallest rect holding the diagram
QRect rect = getDiagramRect();
//now draw to printer
@@ -340,7 +345,7 @@
// set viewport - the physical mapping
// --> Qt's QPainter will map all drawed elements from diagram area ( window )
// to printer area ( viewport )
- pPainter.setViewport( marginX, marginY, width, height );
+ pPainter.setViewport( left, top, width, height );
// get Diagram
getDiagram(QRect(rect.x(), rect.y(), windowWidth, diagramHeight), pPainter);
More information about the umbrello-devel
mailing list