[prev in list] [next in list] [prev in thread] [next in thread]
List: koffice-devel
Subject: kspread: patch for "nothing to print" warning
From: Ariya Hidayat <ariya () kde ! org>
Date: 2003-11-13 20:57:47
[Download RAW message or body]
If there's no cell to print, KSpread will display "Nothing to print"
dialog box. This is annoying for print preview. The attached patch fixes
the problem, that dialog box would only be displayed for real printing
and would not appear at all with print preview (and instead, a blank
page will be shown for the preview).
That dummy "one point painting" hack is needed, otherwise KPrinter will
complain (something about application/x-zerosize mimetype). If there's
any better hack (or solution), please educate me...
The patch also fixes painting problem (again and again) when the dialog
is still not closed by user.
(And hopefully this is the last patch which can close bug #60147)
Best regards,
Ariya Hidayat
http://ariya.pandu.org/
["noprint.patch" (text/plain)]
Index: kspread_sheetprint.cc
===================================================================
RCS file: /home/kde/koffice/kspread/kspread_sheetprint.cc,v
retrieving revision 1.8
diff -u -p -r1.8 kspread_sheetprint.cc
--- kspread_sheetprint.cc 27 Apr 2003 16:24:17 -0000 1.8
+++ kspread_sheetprint.cc 13 Nov 2003 20:11:27 -0000
@@ -178,7 +178,7 @@ bool KSpreadSheetPrint::pageNeedsPrintin
return filled;
}
-void KSpreadSheetPrint::print( QPainter &painter, KPrinter *_printer )
+bool KSpreadSheetPrint::print( QPainter &painter, KPrinter *_printer )
{
kdDebug(36001)<<"PRINTING ...."<<endl;
@@ -248,46 +248,40 @@ void KSpreadSheetPrint::print( QPainter
if ( page_list.count() == 0 )
{
- KMessageBox::information( 0, i18n("Nothing to print.") );
- if ( !m_bPrintGrid )
- {
- // Restore the grid pen
- m_pDoc->setDefaultGridPen( gridPen );
- }
- m_pSheet->setShowGrid( oldShowGrid );
-
- //abort printing
- _printer->abort();
-
- return;
+ // nothing to print
+ painter.setPen( QPen( Qt::black, 1 ) );
+ painter.drawPoint( 1, 1 );
}
+ else
+ {
- int pageNo = 1;
+ int pageNo = 1;
- //
- // Print all pages in the list
- //
- QValueList<QRect>::Iterator it = page_list.begin();
- QValueList<KoRect>::Iterator fit = page_frame_list.begin();
- QValueList<KoPoint>::Iterator fito = page_frame_list_offset.begin();
+ //
+ // Print all pages in the list
+ //
+ QValueList<QRect>::Iterator it = page_list.begin();
+ QValueList<KoRect>::Iterator fit = page_frame_list.begin();
+ QValueList<KoPoint>::Iterator fito = page_frame_list_offset.begin();
- for( ; it != page_list.end(); ++it, ++fit, ++fito, ++pageNo )
- {
- painter.setClipRect( 0, 0, m_pDoc->zoomItX( paperWidthPts() ),
- m_pDoc->zoomItY( paperHeightPts() ) );
- printHeaderFooter( painter, pageNo );
+ for( ; it != page_list.end(); ++it, ++fit, ++fito, ++pageNo )
+ {
+ painter.setClipRect( 0, 0, m_pDoc->zoomItX( paperWidthPts() ),
+ m_pDoc->zoomItY( paperHeightPts() ) );
+ printHeaderFooter( painter, pageNo );
- painter.translate( m_pDoc->zoomItX( leftBorderPts() ),
- m_pDoc->zoomItY( topBorderPts() ) );
+ painter.translate( m_pDoc->zoomItX( leftBorderPts() ),
+ m_pDoc->zoomItY( topBorderPts() ) );
- // Print the page
- printPage( painter, *it, *fit, *fito );
+ // Print the page
+ printPage( painter, *it, *fit, *fito );
- painter.translate( - m_pDoc->zoomItX( leftBorderPts() ),
- - m_pDoc->zoomItY( topBorderPts() ) );
+ painter.translate( - m_pDoc->zoomItX( leftBorderPts() ),
+ - m_pDoc->zoomItY( topBorderPts() ) );
- if ( pageNo < (int)page_list.count() )
- _printer->newPage();
+ if ( pageNo < (int)page_list.count() )
+ _printer->newPage();
+ }
}
if ( !m_bPrintGrid )
@@ -296,6 +290,8 @@ void KSpreadSheetPrint::print( QPainter
m_pDoc->setDefaultGridPen( gridPen );
}
m_pSheet->setShowGrid( oldShowGrid );
+
+ return ( page_list.count() > 0 );
}
void KSpreadSheetPrint::printPage( QPainter &_painter, const QRect& page_range,
@@ -378,7 +374,7 @@ void KSpreadSheetPrint::printRect( QPain
bottomRight.setX( bottomRight.x()
+ m_pSheet->columnFormat( x )->dblWidth() );
for ( int y = regionTop; y <= regionBottom; ++y )
- bottomRight.setY( bottomRight.y()
+ bottomRight.setY( bottomRight.y()
+ m_pSheet->rowFormat( y )->dblHeight() );
KoRect rect( topLeft, bottomRight );
Index: kspread_sheetprint.h
===================================================================
RCS file: /home/kde/koffice/kspread/kspread_sheetprint.h,v
retrieving revision 1.4
diff -u -p -r1.4 kspread_sheetprint.h
--- kspread_sheetprint.h 27 Apr 2003 16:24:17 -0000 1.4
+++ kspread_sheetprint.h 13 Nov 2003 20:11:28 -0000
@@ -37,7 +37,10 @@ public:
KSpreadSheetPrint( KSpreadSheet *sheet );
~KSpreadSheetPrint();
- void print( QPainter &painter, KPrinter *_printer );
+ /**
+ * @return false if nothing to print.
+ */
+ bool print( QPainter &painter, KPrinter *_printer );
/**
* @return the printable width of the paper in millimeters.
Index: kspread_view.cc
===================================================================
RCS file: /home/kde/koffice/kspread/kspread_view.cc,v
retrieving revision 1.698
diff -u -p -r1.698 kspread_view.cc
--- kspread_view.cc 5 Nov 2003 21:16:38 -0000 1.698
+++ kspread_view.cc 13 Nov 2003 20:11:28 -0000
@@ -3988,7 +3988,7 @@ void KSpreadView::print( KPrinter &prt )
print->setPaperOrientation( PG_PORTRAIT );
}
- print->print( painter, &prt );
+ bool result = print->print( painter, &prt );
//Restore original orientation
print->setPaperOrientation( _orient );
@@ -4001,6 +4001,16 @@ void KSpreadView::print( KPrinter &prt )
setZoom( oldZoom, false );
m_pDoc->emitEndOperation();
+ // Nothing to print
+ if( !result )
+ {
+ if( !prt.previewOnly() )
+ {
+ KMessageBox::information( 0, i18n("Nothing to print.") );
+ prt.abort();
+ }
+ }
+
painter.end();
}
_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic