[Marble-commits] KDE/kdeedu/marble/src
Torsten Rahn
tackat at kde.org
Sat Jan 9 21:39:22 CET 2010
SVN commit 1072279 by rahn:
- Print Preview for KDE and Qt Marble Version
- Printing fix.
- Removal of second toolbar menu entry.
- Move of "reload" menu entry a bit higher within the view menu (to
match the
place in other applications)
M +49 -17 QtMainWindow.cpp
M +39 -29 QtMainWindow.h
M +1 -2 lib/MarbleMap.cpp
M +50 -16 marble_part.cpp
M +5 -0 marble_part.h
M +6 -5 marble_part.rc
M +2 -1 marbleui.rc
--- trunk/KDE/kdeedu/marble/src/QtMainWindow.cpp #1072278:1072279
@@ -5,7 +5,7 @@
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
-// Copyright 2006-2007 Torsten Rahn <tackat at kde.org>
+// Copyright 2006-2010 Torsten Rahn <tackat at kde.org>
// Copyright 2007 Inge Wallin <ingwa at kde.org>
//
@@ -31,6 +31,7 @@
#include <QtGui/QMessageBox>
#include <QtGui/QPrintDialog>
+#include <QtGui/QPrintPreviewDialog>
#include <QtGui/QPrinter>
#include <QtGui/QPainter>
@@ -115,12 +116,16 @@
m_exportMapAct->setShortcut(tr("Ctrl+S"));
m_exportMapAct->setStatusTip(tr("Save a screenshot of the map"));
connect(m_exportMapAct, SIGNAL(triggered()), this, SLOT(exportMapScreenShot()));
-
+
m_printAct = new QAction( QIcon(":/icons/document-print.png"), tr("&Print..."), this);
m_printAct->setShortcut(tr("Ctrl+P"));
m_printAct->setStatusTip(tr("Print a screenshot of the map"));
connect(m_printAct, SIGNAL(triggered()), this, SLOT(printMapScreenShot()));
+ 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()));
+
m_quitAct = new QAction( QIcon(":/icons/application-exit.png"), tr("&Quit"), this);
m_quitAct->setShortcut(tr("Ctrl+Q"));
m_quitAct->setStatusTip(tr("Quit the Application"));
@@ -207,7 +212,9 @@
m_fileMenu->addAction(m_openAct);
m_fileMenu->addAction(m_downloadAct);
m_fileMenu->addAction(m_exportMapAct);
+ m_fileMenu->addSeparator();
m_fileMenu->addAction(m_printAct);
+ m_fileMenu->addAction(m_printPreviewAct);
m_fileMenu->addSeparator();
m_fileMenu->addAction(m_workOfflineAct);
m_fileMenu->addAction(m_quitAct);
@@ -385,33 +392,58 @@
void MainWindow::printMapScreenShot()
{
#ifndef QT_NO_PRINTER
- QPixmap mapPixmap = m_controlView->mapScreenShot();
-
- QSize printSize = mapPixmap.size();
-
- QPrinter printer;
-
+ QPrinter printer( QPrinter::HighResolution );
QPrintDialog printDialog( &printer, this );
if (printDialog.exec() == QDialog::Accepted) {
+ QPixmap mapPixmap = m_controlView->mapScreenShot();
+ printPixmap( &printer, mapPixmap );
+ }
+#endif
+}
- QRect mapPageRect = printer.pageRect();
+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 );
+ 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 );
+ QPoint printTopLeft( ( mapPageRect.width() - printSize.width() ) / 2 ,
+ ( mapPageRect.height() - printSize.height() ) / 2 );
- QRect mapPrintRect( printTopLeft, printSize );
+ QRect mapPrintRect( printTopLeft, printSize );
- QPainter painter( &printer );
+ QPainter painter;
+ if (!painter.begin(printer))
+ return;
+ painter.drawPixmap( mapPrintRect, pixmap, pixmap.rect() );
+ painter.end();
+#endif
+}
- painter.drawPixmap( mapPrintRect, mapPixmap, mapPixmap.rect() );
+void MainWindow::printPreview()
+{
+#ifndef QT_NO_PRINTER
+ QPrinter printer( QPrinter::HighResolution );
- }
-#endif
+ QPrintPreviewDialog preview( &printer, this );
+ preview.setWindowFlags ( Qt::Window );
+ connect( &preview, SIGNAL( paintRequested( QPrinter * ) ), SLOT( paintPrintPreview( QPrinter * ) ) );
+ preview.exec();
+#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 ) {
--- trunk/KDE/kdeedu/marble/src/QtMainWindow.h #1072278:1072279
@@ -5,7 +5,7 @@
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
-// Copyright 2006-2007 Torsten Rahn <tackat at kde.org>
+// Copyright 2006-2010 Torsten Rahn <tackat at kde.org>
// Copyright 2007 Inge Wallin <ingwa at kde.org>
//
@@ -22,6 +22,7 @@
class QAction;
class QLabel;
class QMenu;
+class QPrinter;
namespace Marble
{
@@ -53,56 +54,69 @@
void readSettings();
void writeSettings();
- public Q_SLOTS:
+ private Q_SLOTS:
void showPosition( const QString& position);
void showDistance( const QString& position);
- private Q_SLOTS:
void initObject();
void editSettings();
void updateSettings();
+
+ // File Menu
+ void openFile();
+ void openMapSite();
void exportMapScreenShot();
void printMapScreenShot();
+ void printPixmap( QPrinter * printer, const QPixmap& pixmap );
+ void printPreview();
+ void paintPrintPreview( QPrinter * printer );
+ void workOffline( bool );
+
+ // Edit Menu
void copyMap();
void copyCoordinates();
- void showFullScreen( bool );
- void showSideBar( bool );
- void showStatusBar( bool );
+
+ // View Menu
+ void lockPosition( bool );
+ void createInfoBoxesMenu();
+ void createOnlineServicesMenu();
+ void createPluginMenus();
void showClouds( bool );
- void workOffline( bool );
void showAtmosphere( bool );
void controlSun();
void showSun( bool );
+
+ // Settings Menu
+ void showFullScreen( bool );
+ void showSideBar( bool );
+ void showStatusBar( bool );
+ void setupStatusBar();
+
+ // Help Menu
void enterWhatsThis();
void aboutMarble();
void handbook();
- void openMapSite();
- void openFile();
- void setupStatusBar();
- void lockPosition( bool );
- void createInfoBoxesMenu();
- void createOnlineServicesMenu();
- void createPluginMenus();
private:
ControlView *m_controlView;
SunControlWidget* m_sunControlDialog;
+ QtMarbleConfigDialog *m_configDialog;
+ /// Store plugin toolbar pointers so that they can be removed/updated later
+ QList<QToolBar*> m_pluginToolbars;
+ /// Store plugin menus so that they can be removed/updated later
+ QList<QMenu*> m_pluginMenus;
+
QMenu *m_fileMenu;
QMenu *m_helpMenu;
QMenu *m_settingsMenu;
QMenu *m_infoBoxesMenu;
QMenu *m_onlineServicesMenu;
- /// Store plugin toolbar pointers so that they can be removed/updated later
- QList<QToolBar*> m_pluginToolbars;
-
- /// Store plugin menus so that they can be removed/updated later
- QList<QMenu*> m_pluginMenus;
-
// File Menu
QAction *m_exportMapAct;
QAction *m_downloadAct;
+ QAction *m_printPreviewAct;
QAction *m_printAct;
QAction *m_workOfflineAct;
QAction *m_quitAct;
@@ -130,15 +144,11 @@
QAction *m_lockFloatItemsAct;
QAction *m_handbookAct;
- QString m_position;
- QString m_distance;
-
- // Zoom label for the statusbar.
- QLabel *m_positionLabel;
- QLabel *m_distanceLabel;
-
- QtMarbleConfigDialog *m_configDialog;
-
+ // Status Bar
+ QString m_position;
+ QString m_distance;
+ QLabel *m_positionLabel;
+ QLabel *m_distanceLabel;
void updateStatusBar();
};
--- trunk/KDE/kdeedu/marble/src/lib/MarbleMap.cpp #1072278:1072279
@@ -1222,13 +1222,12 @@
const Marble::DistanceUnit distanceUnit = MarbleGlobal::getInstance()->locale()->distanceUnit();
- // FIXME: why is "km" translated and "mi" not?
if ( distanceUnit == Marble::Meter ) {
distanceUnitString = tr("km");
}
else {
distance *= KM2MI;
- distanceUnitString = "mi";
+ distanceUnitString = tr("mi");
}
return QString( "%L1 %2" ).arg( distance, 8, 'f', 1, QChar(' ') ).arg( distanceUnitString );
--- trunk/KDE/kdeedu/marble/src/marble_part.cpp #1072278:1072279
@@ -23,6 +23,7 @@
#include <QtGui/QFontMetrics>
#include <QtGui/QPrinter>
#include <QtGui/QPrintDialog>
+#include <QtGui/QPrintPreviewDialog>
#include <QtGui/QProgressBar>
#include <QtGui/QPainter>
#include <QtGui/QStandardItemModel>
@@ -216,31 +217,61 @@
void MarblePart::printMapScreenShot()
{
- QPixmap mapPixmap = m_controlView->mapScreenShot();
- QSize printSize = mapPixmap.size();
- QPrinter printer;
-
+#ifndef QT_NO_PRINTER
+ QPrinter printer( QPrinter::HighResolution );
QPrintDialog *printDialog = KdePrint::createPrintDialog(&printer, widget());
- if ( printDialog->exec() ) {
+ if (printDialog->exec()) {
+ QPixmap mapPixmap = m_controlView->mapScreenShot();
+ printPixmap( &printer, mapPixmap );
+ }
+
+ delete printDialog;
+#endif
+}
- QRect mapPageRect = printer.pageRect();
+void MarblePart::printPixmap( QPrinter * printer, const QPixmap& pixmap )
+{
+#ifndef QT_NO_PRINTER
+ QSize printSize = pixmap.size();
- printSize.scale( ( printer.pageRect() ).size(), Qt::KeepAspectRatio );
+ QRect mapPageRect = printer->pageRect();
- QPoint printTopLeft( mapPageRect.x() + mapPageRect.width() / 2
- - printSize.width() / 2,
- mapPageRect.y() + mapPageRect.height() / 2
- - printSize.height() / 2 );
+ printSize.scale( printer->pageRect().size(), Qt::KeepAspectRatio );
- QRect mapPrintRect( printTopLeft, printSize );
- QPainter painter( &printer );
+ QPoint printTopLeft( ( mapPageRect.width() - printSize.width() ) / 2 ,
+ ( mapPageRect.height() - printSize.height() ) / 2 );
- painter.drawPixmap( mapPrintRect, mapPixmap, mapPixmap.rect() );
- }
- delete printDialog;
+ QRect mapPrintRect( printTopLeft, printSize );
+
+ QPainter painter;
+ if (!painter.begin(printer))
+ return;
+ painter.drawPixmap( mapPrintRect, pixmap, pixmap.rect() );
+ painter.end();
+#endif
}
+void MarblePart::printPreview()
+{
+#ifndef QT_NO_PRINTER
+ QPrinter printer( QPrinter::HighResolution );
+
+ QPrintPreviewDialog preview( &printer, widget() );
+ preview.setWindowFlags ( Qt::Window );
+ connect( &preview, SIGNAL( paintRequested( QPrinter * ) ), SLOT( paintPrintPreview( QPrinter * ) ) );
+ preview.exec();
+#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 );
@@ -562,6 +593,9 @@
m_printMapAction = KStandardAction::print( this, SLOT( printMapScreenShot() ),
actionCollection() );
+ m_printPreviewAction = KStandardAction::printPreview( this, SLOT( printPreview() ),
+ actionCollection() );
+
// Action: Export Map
m_exportMapAction = new KAction( this );
actionCollection()->addAction( "exportMap", m_exportMapAction );
--- trunk/KDE/kdeedu/marble/src/marble_part.h #1072278:1072279
@@ -22,6 +22,7 @@
class KConfigDialog;
class QLabel;
+class QPrinter;
class QProgressBar;
class QStandardItemModel;
@@ -64,6 +65,9 @@
void exportMapScreenShot();
void printMapScreenShot();
+ void printPixmap( QPrinter * printer, const QPixmap& pixmap );
+ void printPreview();
+ void paintPrintPreview( QPrinter * printer );
void copyMap();
void copyCoordinates();
void setShowClouds( bool );
@@ -165,6 +169,7 @@
// Actions for the GUI.
KAction *m_exportMapAction;
KAction *m_printMapAction;
+ KAction *m_printPreviewAction;
KAction *m_workOfflineAction;
KAction *m_copyMapAction;
KAction *m_copyCoordinatesAction;
--- trunk/KDE/kdeedu/marble/src/marble_part.rc #1072278:1072279
@@ -1,5 +1,5 @@
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
-<kpartgui name="marble_part" version="9">
+<kpartgui name="marble_part" version="12">
<MenuBar>
<Menu name="file" noMerge="1">
@@ -7,7 +7,9 @@
<Action name="file_open"/>
<Action name="new_stuff"/>
<Action name="exportMap"/>
+ <Separator/>
<Action name="file_print"/>
+ <Action name="file_print_preview"/>
<Separator/>
<Action name="workOffline"/>
<Action name="file_quit"/>
@@ -19,10 +21,10 @@
</Menu>
<Menu name="view" noMerge="1">
<text>&View</text>
- <Merge name="StandardToolBarMenuHandler" />
<Action name="show_currentlocation" group="show_merge"/>
<Separator/>
<Action name="show_crosshairs" group="show_merge"/>
+ <Action name="view_redisplay"/>
<Separator/>
<Menu name="infoboxes" noMerge="1">
<text>&Info Boxes</text>
@@ -39,7 +41,6 @@
<Action name="show_atmosphere"/>
<Separator/>
<Action name="control_sun"/>
- <Action name="view_redisplay"/>
</Menu>
<Menu name="settings" noMerge="1">
<text>&Settings</text>
@@ -60,10 +61,10 @@
<Separator/>
<Action name="edit_copy"/>
</ToolBar>
-
+<!--
<ToolBar position="Top" hidden="true" name="pluginToolBar">
<text>Edit Toolbar</text>
<ActionList name="plugins_actionlist" />
</ToolBar>
-
+-->
</kpartgui>
--- trunk/KDE/kdeedu/marble/src/marbleui.rc #1072278:1072279
@@ -1,11 +1,12 @@
<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
-<gui name="marble" version="5">
+<gui name="marble" version="6">
<MenuBar>
<Menu name="file" noMerge="1"><text>&File</text>
<Action name="file_open"/>
<Action name="exportMap"/>
<Action name="file_print"/>
+ <Action name="file_printPreview"/>
<Separator/>
<Action name="file_workOffline"/>
<Action name="file_quit"/>
More information about the Marble-commits
mailing list