[Marble-commits] KDE/kdeedu/marble/src

Dennis Nienhüser earthwings at gentoo.org
Sat Sep 4 23:44:58 CEST 2010


SVN commit 1171700 by nienhueser:

Move duplicated print methods in qt/kde classes to common ControlView.

 M  +55 -0     ControlView.cpp  
 M  +6 -0      ControlView.h  
 M  +11 -60    QtMainWindow.cpp  
 M  +0 -3      QtMainWindow.h  
 M  +11 -61    marble_part.cpp  
 M  +0 -3      marble_part.h  


--- trunk/KDE/kdeedu/marble/src/ControlView.cpp #1171699:1171700
@@ -15,6 +15,11 @@
 #include <QtGui/QLayout>
 #include <QtGui/QSplitter>
 #include <QtGui/QStringListModel>
+#include <QtGui/QPrintDialog>
+#include <QtGui/QPrintPreviewDialog>
+#include <QtGui/QPrinter>
+#include <QtGui/QPainter>
+#include <QtCore/QPointer>
 
 #include "GeoSceneDocument.h"
 #include "GeoSceneHead.h"
@@ -151,6 +156,56 @@
     return QString();
 }
 
+void ControlView::printMapScreenShot( QPointer<QPrintDialog> printDialog)
+{
+#ifndef QT_NO_PRINTER
+    if (printDialog->exec() == QDialog::Accepted) {
+        QPixmap mapPixmap = mapScreenShot();
+        printPixmap( printDialog->printer(), mapPixmap );
 }
+#endif
+}
 
+void ControlView::printPixmap( QPrinter * printer, const QPixmap& pixmap  )
+{
+#ifndef QT_NO_PRINTER
+    QSize printSize = pixmap.size();
+    QRect mapPageRect = printer->pageRect();
+    printSize.scale( printer->pageRect().size(), Qt::KeepAspectRatio );
+    QPoint printTopLeft( ( mapPageRect.width() - printSize.width() ) / 2 ,
+                         ( mapPageRect.height() - printSize.height() ) / 2 );
+    QRect mapPrintRect( printTopLeft, printSize );
+
+    QPainter painter;
+    if (!painter.begin(printer))
+        return;
+    painter.drawPixmap( mapPrintRect, pixmap, pixmap.rect() );
+    painter.end();
+#endif
+}
+
+// QPointer is used because of issues described in http://www.kdedevelopers.org/node/3919
+void ControlView::printPreview()
+{
+#ifndef QT_NO_PRINTER
+    QPrinter printer( QPrinter::HighResolution );
+
+    QPointer<QPrintPreviewDialog> preview = new QPrintPreviewDialog( &printer, this );
+    preview->setWindowFlags ( Qt::Window );
+    connect( preview, SIGNAL( paintRequested( QPrinter * ) ), SLOT( paintPrintPreview( QPrinter * ) ) );
+    preview->exec();
+    delete preview;
+#endif
+}
+
+void ControlView::paintPrintPreview( QPrinter * printer )
+{
+#ifndef QT_NO_PRINTER
+    QPixmap mapPixmap = mapScreenShot();
+    printPixmap( printer, mapPixmap );
+#endif
+}
+
+}
+
 #include "ControlView.moc"
--- trunk/KDE/kdeedu/marble/src/ControlView.h #1171699:1171700
@@ -20,11 +20,13 @@
 
 #include <QtGui/QWidget>
 #include <QtGui/QPixmap>
+#include <QtCore/QPointer>
 
 #include "MarbleWidget.h"
 #include "MarbleControlBox.h"
 
 class QSplitter;
+class QPrintDialog;
 
 namespace Marble
 {
@@ -71,6 +73,10 @@
     void setMapViewTabShown( bool );
     void setCurrentLocationTabShown( bool );
     void setFileViewTabShown( bool );
+    void printMapScreenShot( QPointer<QPrintDialog> dialog );
+    void printPixmap( QPrinter * printer, const QPixmap& pixmap );
+    void printPreview();
+    void paintPrintPreview( QPrinter * printer );
 
  private:
     //MarbleModel       *m_marbleModel;
--- trunk/KDE/kdeedu/marble/src/QtMainWindow.cpp #1171699:1171700
@@ -31,11 +31,8 @@
 #include <QtGui/QDesktopServices>
 #include <QtGui/QFileDialog>
 #include <QtGui/QMessageBox>
-
 #include <QtGui/QPrintDialog>
-#include <QtGui/QPrintPreviewDialog>
 #include <QtGui/QPrinter>
-#include <QtGui/QPainter>
 
 #include <QtGui/QClipboard>
 
@@ -151,7 +148,7 @@
 
      m_printPreviewAct = new QAction( QIcon(":/icons/document-printpreview.png"), tr("Print Previe&w ..."), this);
      m_printPreviewAct->setStatusTip(tr("Print a screenshot of the map"));
-     connect(m_printPreviewAct, SIGNAL(triggered()), this, SLOT(printPreview()));
+     connect(m_printPreviewAct, SIGNAL(triggered()), m_controlView, SLOT(printPreview()));
 
      m_quitAct = new QAction( QIcon(":/icons/application-exit.png"), tr("&Quit"), this);
      m_quitAct->setShortcut(tr("Ctrl+Q"));
@@ -552,63 +549,7 @@
     }
 }
 
-void MainWindow::printMapScreenShot()
-{
-#ifndef QT_NO_PRINTER
-    QPrinter printer( QPrinter::HighResolution );
-    QPointer<QPrintDialog> printDialog = new QPrintDialog( &printer, this );
 
-    if (printDialog->exec() == QDialog::Accepted) {
-        QPixmap mapPixmap = m_controlView->mapScreenShot();
-        printPixmap( &printer, mapPixmap );
-    }
-    delete printDialog;
-#endif
-}
-
-void MainWindow::printPixmap( QPrinter * printer, const QPixmap& pixmap  )
-{
-#ifndef QT_NO_PRINTER
-    QSize printSize = pixmap.size();
-
-    QRect mapPageRect = printer->pageRect();
-
-    printSize.scale( printer->pageRect().size(), Qt::KeepAspectRatio );
-
-    QPoint printTopLeft( ( mapPageRect.width() - printSize.width() ) / 2 ,
-                         ( mapPageRect.height() - printSize.height() ) / 2 );
-
-    QRect mapPrintRect( printTopLeft, printSize );
-
-    QPainter painter;
-    if (!painter.begin(printer))
-        return;
-    painter.drawPixmap( mapPrintRect, pixmap, pixmap.rect() );
-    painter.end();
-#endif
-}
-
-void MainWindow::printPreview()
-{
-#ifndef QT_NO_PRINTER
-    QPrinter printer( QPrinter::HighResolution );
-
-    QPointer<QPrintPreviewDialog> preview = new QPrintPreviewDialog( &printer, this );
-    preview->setWindowFlags ( Qt::Window );
-    connect( preview, SIGNAL( paintRequested( QPrinter * ) ), SLOT( paintPrintPreview( QPrinter * ) ) );
-    preview->exec();
-    delete preview;
-#endif
-}
-
-void MainWindow::paintPrintPreview( QPrinter * printer )
-{
-#ifndef QT_NO_PRINTER
-    QPixmap mapPixmap = m_controlView->mapScreenShot();
-    printPixmap( printer, mapPixmap );
-#endif
-}
-
 void MainWindow::showFullScreen( bool isChecked )
 {
     if ( isChecked ) {
@@ -1095,4 +1036,14 @@
     m_controlView->marbleWidget()->map()->model()->downloadRegion( sourceDir, pyramid );
 }
 
+void MainWindow::printMapScreenShot()
+{
+#ifndef QT_NO_PRINTER
+    QPrinter printer( QPrinter::HighResolution );
+    QPointer<QPrintDialog> printDialog = new QPrintDialog( &printer, this );
+    m_controlView->printMapScreenShot( printDialog );
+    delete printDialog;
+#endif
+}
+
 #include "QtMainWindow.moc"
--- trunk/KDE/kdeedu/marble/src/QtMainWindow.h #1171699:1171700
@@ -71,9 +71,6 @@
     void  exportMapScreenShot();
     void  showDownloadRegionDialog();
     void  printMapScreenShot();
-    void  printPixmap( QPrinter * printer, const QPixmap& pixmap );
-    void  printPreview();
-    void  paintPrintPreview( QPrinter * printer );
     void  workOffline( bool );
     
     // Edit Menu
--- trunk/KDE/kdeedu/marble/src/marble_part.cpp #1171699:1171700
@@ -24,9 +24,7 @@
 #include <QtGui/QFontMetrics>
 #include <QtGui/QPrinter>
 #include <QtGui/QPrintDialog>
-#include <QtGui/QPrintPreviewDialog>
 #include <QtGui/QProgressBar>
-#include <QtGui/QPainter>
 #include <QtGui/QStandardItemModel>
 #include <QtNetwork/QNetworkProxy>
 
@@ -237,65 +235,7 @@
 }
 
 
-void MarblePart::printMapScreenShot()
-{
-#ifndef QT_NO_PRINTER
-    QPrinter printer( QPrinter::HighResolution );
-    QPrintDialog *printDialog = KdePrint::createPrintDialog(&printer, widget());
 
-    if (printDialog->exec()) {
-        QPixmap mapPixmap = m_controlView->mapScreenShot();
-        printPixmap( &printer, mapPixmap );
-    }
-    
-    delete printDialog;
-#endif
-}
-
-void MarblePart::printPixmap( QPrinter * printer, const QPixmap& pixmap  )
-{
-#ifndef QT_NO_PRINTER
-    QSize printSize = pixmap.size();
-
-    QRect mapPageRect = printer->pageRect();
-
-    printSize.scale( printer->pageRect().size(), Qt::KeepAspectRatio );
-
-    QPoint printTopLeft( ( mapPageRect.width() - printSize.width() ) / 2 ,
-                         ( mapPageRect.height() - printSize.height() ) / 2 );
-
-    QRect mapPrintRect( printTopLeft, printSize );
-
-    QPainter painter;
-    if (!painter.begin(printer))
-        return;
-    painter.drawPixmap( mapPrintRect, pixmap, pixmap.rect() );
-    painter.end();
-#endif
-}
-
-// QPointer is used because of issues described in http://www.kdedevelopers.org/node/3919
-void MarblePart::printPreview()
-{
-#ifndef QT_NO_PRINTER
-    QPrinter printer( QPrinter::HighResolution );
-
-    QPointer<QPrintPreviewDialog> preview = new QPrintPreviewDialog( &printer, widget() );
-    preview->setWindowFlags( Qt::Window );
-    connect( preview, SIGNAL( paintRequested( QPrinter * ) ), SLOT( paintPrintPreview( QPrinter * ) ) );
-    preview->exec();
-    delete preview;
-#endif
-}
-
-void MarblePart::paintPrintPreview( QPrinter * printer )
-{
-#ifndef QT_NO_PRINTER
-    QPixmap mapPixmap = m_controlView->mapScreenShot();
-    printPixmap( printer, mapPixmap );
-#endif
-}
-
 void MarblePart::setShowClouds( bool isChecked )
 {
     m_controlView->marbleWidget()->setShowClouds( isChecked );
@@ -678,7 +618,7 @@
     m_printMapAction = KStandardAction::print( this, SLOT( printMapScreenShot() ),
                                                actionCollection() );
 
-    m_printPreviewAction = KStandardAction::printPreview( this, SLOT( printPreview() ),
+    m_printPreviewAction = KStandardAction::printPreview( m_controlView, SLOT( printPreview() ),
                                                actionCollection() );
                                                
     // Action: Export Map
@@ -1608,6 +1548,16 @@
     }
 }
 
+void MarblePart::printMapScreenShot()
+{
+#ifndef QT_NO_PRINTER
+    QPrinter printer( QPrinter::HighResolution );
+    QPointer<QPrintDialog> printDialog = KdePrint::createPrintDialog(&printer, widget());
+    m_controlView->printMapScreenShot( printDialog );
+    delete printDialog;
+#endif
 }
 
+}
+
 #include "marble_part.moc"
--- trunk/KDE/kdeedu/marble/src/marble_part.h #1171699:1171700
@@ -76,9 +76,6 @@
 
     void  exportMapScreenShot();
     void  printMapScreenShot();
-    void  printPixmap( QPrinter * printer, const QPixmap& pixmap );
-    void  printPreview();
-    void  paintPrintPreview( QPrinter * printer );
     void  copyMap();
     void  copyCoordinates();
     void  setShowClouds( bool );


More information about the Marble-commits mailing list