[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/base/marble
From:       Torsten Rahn <tackat () kde ! org>
Date:       2007-05-07 12:33:01
Message-ID: 1178541181.061575.4990.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 662073 by rahn:

07.05.07 - tackat
    Added Copy, Export Map and Printing to the Qt interface.




 M  +3 -0      ChangeLog  
 M  +1 -3      src/CMakeLists.txt  
 M  +101 -1    src/QtMainWindow.cpp  
 M  +12 -0     src/QtMainWindow.h  
 AM            src/icons/document-print.png  
 AM            src/icons/document-save-as.png  
 AM            src/icons/edit-copy.png  
 AM            src/icons/marble.png  
 M  +3 -0      src/katlascontrol.h  
 M  +3 -0      src/katlasview.h  
 M  +4 -0      src/marble.qrc  


--- trunk/playground/base/marble/ChangeLog #662072:662073
@@ -1,3 +1,6 @@
+07.05.07 - tackat
+    Added Copy, Export Map and Printing to the Qt interface.
+
 06.05.07 - ingwa
 	Cleaning: TextureMapper: use m_ for all members + getFoo() -> foo()
 	Cleaning: KAtlasView:    use m_ for all members + getFoo() -> foo()
--- trunk/playground/base/marble/src/CMakeLists.txt #662072:662073
@@ -22,13 +22,12 @@
            Quaternion.cpp
            GeoPoint.cpp
            GeoPolygon.cpp
-	   TextureTile.cpp
+            TextureTile.cpp
            TextureMapper.cpp
            GridMap.cpp
            katlascontrol.cpp
            katlasview.cpp
            katlasviewinputhandler.cpp
-           #KdeMainWindow.cpp
            texcolorizer.cpp
            TileLoader.cpp
            katlasglobe.cpp
@@ -72,7 +71,6 @@
            katlasview.h
            katlasviewinputhandler.h
            QtMainWindow.h
-           #KdeMainWindow.h
            texcolorizer.h
            TileLoader.h
            katlasglobe.h
--- trunk/playground/base/marble/src/QtMainWindow.cpp #662072:662073
@@ -6,6 +6,17 @@
 #include <QtGui/QMenuBar>
 #include <QtGui/QStatusBar>
 
+#include <QtGui/QFileDialog>
+#include <QtGui/QMessageBox>
+
+#include <QtGui/QPrintDialog>
+#include <QtGui/QPrinter>
+#include <QtGui/QPainter>
+
+#include <QtGui/QClipboard>
+
+#include "katlasaboutdialog.h"
+
 MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
 {
     m_katlascontrol = new KAtlasControl(0);
@@ -20,12 +31,30 @@
 
 void MainWindow::createActions()
  {
+     exportMapAct = new QAction( QIcon(":/icons/document-save-as.png"), tr("&Export \
Map..."), this); +     exportMapAct->setShortcut(tr("Ctrl+S"));
+     exportMapAct->setStatusTip(tr("Save a screenshot of the map"));
+     connect(exportMapAct, SIGNAL(triggered()), this, SLOT(exportMapScreenShot()));
+ 
+     printAct = new QAction( QIcon(":/icons/document-print.png"), tr("&Print..."), \
this); +     printAct->setShortcut(tr("Ctrl+P"));
+     printAct->setStatusTip(tr("Print a screenshot of the map"));
+     connect(printAct, SIGNAL(triggered()), this, SLOT(printMapScreenShot()));
+ 
      quitAct = new QAction( QIcon(":/icons/application-exit.png"), tr("&Quit"), \
this);  quitAct->setShortcut(tr("Ctrl+Q"));
      quitAct->setStatusTip(tr("Quit the Application"));
      connect(quitAct, SIGNAL(triggered()), qApp, SLOT(quit()));
 
- 
+     copyMapAct = new QAction( QIcon(":/icons/edit-copy.png"), tr("&Copy Map"), \
this); +     copyMapAct->setShortcut(tr("Ctrl+C"));
+     copyMapAct->setStatusTip(tr("Copy a screenshot of the map"));
+     connect(copyMapAct, SIGNAL(triggered()), this, SLOT(copyMap()));
+
+     aboutMarbleAct = new QAction( QIcon(":/icons/marble.png"), tr("&About Marble \
Desktop Globe"), this); +     aboutMarbleAct->setStatusTip(tr("Show the application's \
About Box")); +     connect(aboutMarbleAct, SIGNAL(triggered()), this, \
SLOT(aboutMarble())); +
      aboutQtAct = new QAction(tr("About &Qt"), this);
      aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
      connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
@@ -34,9 +63,16 @@
 void MainWindow::createMenus()
 {
     fileMenu = menuBar()->addMenu(tr("&File"));
+    fileMenu->addAction(exportMapAct);
+    fileMenu->addAction(printAct);
+    fileMenu->addSeparator();
     fileMenu->addAction(quitAct);
 
+    fileMenu = menuBar()->addMenu(tr("&Edit"));
+    fileMenu->addAction(copyMapAct);
+
     helpMenu = menuBar()->addMenu(tr("&Help"));
+    helpMenu->addAction(aboutMarbleAct);
     helpMenu->addAction(aboutQtAct);
 }
 
@@ -44,6 +80,70 @@
 {
     statusBar()->showMessage(tr("Ready"));
 }
+
+void MainWindow::exportMapScreenShot()
+{
+    QPixmap mapPixmap = m_katlascontrol->mapScreenShot();
+
+    QString fileName = QFileDialog::getSaveFileName(this, tr("Export Map"),
+                            QDir::homePath(),
+                            tr("Images (*.jpg *.png)"));
+
+    if ( !fileName.isEmpty() )
+    {
+        bool success = mapPixmap.save( fileName );
+        if ( success == false )
+        {
+            QMessageBox::warning(this, tr("Marble"),
+                   tr( "An error occured while trying to save the file.\n" ),
+                   QMessageBox::Ok);
+        }
+    }
+}
+
+void MainWindow::printMapScreenShot()
+{
+    QPixmap mapPixmap = m_katlascontrol->mapScreenShot();
+
+    QSize printSize = mapPixmap.size();
+
+    QPrinter* printer = new QPrinter();
+
+    QPrintDialog printDialog(printer, this);
+
+    if (printDialog.exec() == QDialog::Accepted) {
+
+        QRect mapPageRect = printer->pageRect();
+
+        printSize.scale( ( printer->pageRect() ).size(), Qt::KeepAspectRatio );
+
+        QPoint printTopLeft( mapPageRect.x() + mapPageRect.width() /2  - \
printSize.width() /2 , +                             mapPageRect.y() + \
mapPageRect.height()/2  - printSize.height()/2 ); +
+        QRect mapPrintRect( printTopLeft, printSize );
+
+        QPainter painter( printer );
+
+        painter.drawPixmap( mapPrintRect, mapPixmap, mapPixmap.rect() );
+
+    }
+}
+
+void MainWindow::copyMap()
+{
+    QPixmap mapPixmap = m_katlascontrol->mapScreenShot();
+
+    QClipboard *clipboard = QApplication::clipboard();
+
+    clipboard->setPixmap( mapPixmap );
+}
+
+void MainWindow::aboutMarble()
+{
+    KAtlasAboutDialog dlg(this);
+    dlg.exec();
+}
+
 #ifndef Q_OS_MACX
 #include "QtMainWindow.moc"
 #endif
--- trunk/playground/base/marble/src/QtMainWindow.h #662072:662073
@@ -20,12 +20,24 @@
         void createMenus();
         void createStatusBar();
 
+
         KAtlasControl *m_katlascontrol;
 
         QMenu *fileMenu;
         QMenu *helpMenu;
+
+        QAction *exportMapAct;
+        QAction *printAct;
         QAction *quitAct;
+        QAction *copyMapAct;
+        QAction *aboutMarbleAct;
         QAction *aboutQtAct;
+
+    private slots:
+        void exportMapScreenShot();
+        void printMapScreenShot();
+        void copyMap();
+        void aboutMarble();
 };
  
 #endif
** trunk/playground/base/marble/src/icons/document-print.png #property svn:mime-type
   + application/octet-stream
** trunk/playground/base/marble/src/icons/document-save-as.png #property \
svn:mime-type  + application/octet-stream
** trunk/playground/base/marble/src/icons/edit-copy.png #property svn:mime-type
   + application/octet-stream
** trunk/playground/base/marble/src/icons/marble.png #property svn:mime-type
   + application/octet-stream
--- trunk/playground/base/marble/src/katlascontrol.h #662072:662073
@@ -15,6 +15,7 @@
 
 #include "katlasview.h"
 
+#include <QtGui/QPixmap>
 
 /**
 @author Torsten Rahn
@@ -39,6 +40,8 @@
 
     void addPlaceMarkFile( QString filename ){ m_katlasview->addPlaceMarkFile( \
filename ); }  
+    QPixmap mapScreenShot(){ return m_katlasview->mapScreenShot(); }
+
  private:
     KAtlasView     *m_katlasview;
     KAtlasToolBox  *m_toolbox;
--- trunk/playground/base/marble/src/katlasview.h #662072:662073
@@ -4,6 +4,7 @@
 
 #include <QtGui/QWidget>
 #include <QtGui/QImage>
+#include <QtGui/QPixmap>
 
 #include "katlasglobe.h"
 #include "katlascrosshair.h"
@@ -44,6 +45,8 @@
 
     void addPlaceMarkFile( QString filename ){ m_pGlobe->addPlaceMarkFile( filename \
); }  
+    QPixmap mapScreenShot(){ return QPixmap::grabWidget( this ); }
+
  public slots:
     void  zoomView(int);
 
--- trunk/playground/base/marble/src/marble.qrc #662072:662073
@@ -18,5 +18,9 @@
         <file>icons/zoom-in.png</file>
         <file>icons/zoom-out.png</file>
         <file>icons/application-exit.png</file>
+        <file>icons/document-save-as.png</file>
+        <file>icons/document-print.png</file>
+        <file>icons/edit-copy.png</file>
+        <file>icons/marble.png</file>
     </qresource>
 </RCC>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic