[kde-doc-english] KDE/kdeedu/marble/src
Dennis Nienhüser
earthwings at gentoo.org
Sat Sep 11 13:57:23 CEST 2010
SVN commit 1174151 by nienhueser:
Extends the print dialog (X11 only, I'm afraid) with a new tab to configure Marble related print options: Toggle whether the map, the background (outer space), the legend, route summary and/or driving instructions are printed.
RB: 5254
FEATURE: 238137
FEATURE: 241551
FIXED-IN: 0.11.0 (KDE 4.6)
GUI:
M +204 -2 ControlView.cpp
M +6 -0 ControlView.h
M +3 -0 lib/CMakeLists.txt
M +4 -0 lib/MarbleLegendBrowser.cpp
M +27 -2 lib/MarbleModel.cpp
M +10 -0 lib/MarbleModel.h
M +0 -1 lib/MarbleWidget.cpp
A lib/PrintOptions.ui
A lib/PrintOptionsWidget.cpp [License: LGPL]
A lib/PrintOptionsWidget.h [License: LGPL]
M +5 -5 lib/routing/RoutingManager.cpp
--- trunk/KDE/kdeedu/marble/src/ControlView.cpp #1174150:1174151
@@ -19,13 +19,20 @@
#include <QtGui/QPrintPreviewDialog>
#include <QtGui/QPrinter>
#include <QtGui/QPainter>
+#include <QtGui/QTextDocument>
#include <QtCore/QPointer>
+#include <QtCore/QUrl>
#include "GeoSceneDocument.h"
#include "GeoSceneHead.h"
#include "MarbleWidget.h"
+#include "MarbleMap.h"
#include "MarbleModel.h"
#include "MapThemeManager.h"
+#include "PrintOptionsWidget.h"
+#include "routing/RoutingManager.h"
+#include "routing/RoutingModel.h"
+#include "routing/RouteRequest.h"
namespace Marble
{
@@ -159,10 +166,56 @@
void ControlView::printMapScreenShot( QPointer<QPrintDialog> printDialog)
{
#ifndef QT_NO_PRINTER
+ PrintOptionsWidget* printOptions = new PrintOptionsWidget( this );
+ bool const mapCoversViewport = m_marbleWidget->map()->mapCoversViewport();
+ printOptions->setBackgroundControlsEnabled( !mapCoversViewport );
+ bool hasLegend = m_marbleWidget->model()->legend() != 0;
+ printOptions->setLegendControlsEnabled( hasLegend );
+ bool hasRoute = marbleWidget()->model()->routingManager()->routingModel()->rowCount() > 0;
+ printOptions->setPrintRouteSummary( hasRoute );
+ printOptions->setPrintDrivingInstructions( hasRoute );
+ printOptions->setRouteControlsEnabled( hasRoute );
+ printDialog->setOptionTabs( QList<QWidget*>() << printOptions );
+
if (printDialog->exec() == QDialog::Accepted) {
- QPixmap mapPixmap = mapScreenShot();
- printPixmap( printDialog->printer(), mapPixmap );
+ QTextDocument document;
+ QString text = "<html><head><title>Marble Printout</title></head><body>";
+ QPalette const originalPalette = m_marbleWidget->palette();
+ bool const wasBackgroundVisible = m_marbleWidget->model()->backgroundVisible();
+ bool const hideBackground = !mapCoversViewport && !printOptions->printBackground();
+ if ( hideBackground ) {
+ // Temporarily remove the black background and layers painting on it
+ m_marbleWidget->model()->setBackgroundVisible( false );
+ m_marbleWidget->setPalette( QPalette ( Qt::white ) );
+ m_marbleWidget->repaint();
}
+
+ if ( printOptions->printMap() ) {
+ printMap( document, text, printDialog->printer() );
+ }
+
+ if ( printOptions->printLegend() ) {
+ printLegend( document, text );
+ }
+
+ if ( printOptions->printRouteSummary() ) {
+ printRouteSummary( document, text );
+ }
+
+ if ( printOptions->printDrivingInstructions() ) {
+ printDrivingInstructions( document, text );
+ }
+
+ text += "</body></html>";
+ document.setHtml( text );
+ document.print( printDialog->printer() );
+
+ if ( hideBackground ) {
+ m_marbleWidget->model()->setBackgroundVisible( wasBackgroundVisible );
+ m_marbleWidget->setPalette( originalPalette );
+ m_marbleWidget->repaint();
+ }
+ }
#endif
}
@@ -206,6 +259,155 @@
#endif
}
+void ControlView::printMap( QTextDocument &document, QString &text, QPrinter *printer )
+{
+#ifndef QT_NO_PRINTER
+ QPixmap image = mapScreenShot();
+
+ if ( m_marbleWidget->map()->mapCoversViewport() ) {
+ // Paint a black frame. Looks better.
+ QPainter painter(&image);
+ painter.setPen( Qt::black );
+ painter.drawRect( 0, 0, image.width() - 2, image.height() - 2 );
}
+ QString uri = "marble://screenshot.png";
+ document.addResource( QTextDocument::ImageResource, QUrl( uri ), QVariant( image) );
+ QString img = "<img src=\"%1\" width=\"%2\" align=\"center\">";
+ int width = qRound( printer->pageRect( QPrinter::Point ).width() );
+ text += img.arg( uri ).arg( width );
+#endif
+}
+
+void ControlView::printLegend( QTextDocument &document, QString &text )
+{
+#ifndef QT_NO_PRINTER
+ QTextDocument *legend = m_marbleWidget->model()->legend();
+ if ( legend ) {
+ legend->adjustSize();
+ QSize size = legend->size().toSize();
+ QSize imageSize = size + QSize( 4, 4 );
+ QImage image( imageSize, QImage::Format_ARGB32);
+ QPainter painter( &image );
+ painter.setRenderHint( QPainter::Antialiasing, true );
+ painter.drawRoundedRect( QRect( QPoint( 0, 0 ), size ), 5, 5 );
+ legend->drawContents( &painter );
+ document.addResource( QTextDocument::ImageResource, QUrl( "marble://legend.png" ), QVariant(image) );
+ QString img = "<p><img src=\"%1\" align=\"center\"></p>";
+ text += img.arg( "marble://legend.png" );
+ }
+#endif
+}
+
+void ControlView::printRouteSummary( QTextDocument &document, QString &text)
+{
+#ifndef QT_NO_PRINTER
+ RoutingModel* routingModel = m_marbleWidget->model()->routingManager()->routingModel();
+
+ if ( !routingModel ) {
+ return;
+ }
+
+ RouteRequest* routeRequest = m_marbleWidget->model()->routingManager()->routeRequest();
+ if ( routeRequest ) {
+ QString summary = "<h3>Route to %1: %2 %3</h3>";
+ QString destination;
+ if ( routeRequest->size() ) {
+ destination = routeRequest->name( routeRequest->size()-1 );
+ }
+
+ QString label = "<p>%1 %2</p>";
+ qreal distance = routingModel->totalDistance();
+ QString unit = distance > 1000 ? "km" : "m";
+ int precision = distance > 1000 ? 1 : 0;
+ if ( distance > 1000 ) {
+ distance /= 1000;
+ }
+ summary = summary.arg(destination).arg( distance, 0, 'f', precision ).arg( unit );
+ text += summary;
+
+ text += "<table cellpadding=\"2\">";
+ QString pixmapTemplate = "marble://viaPoint-%1.png";
+ for ( int i=0; i<routeRequest->size(); ++i ) {
+ text += "<tr><td>";
+ QPixmap pixmap = routeRequest->pixmap(i);
+ QString pixmapResource = pixmapTemplate.arg( i );
+ document.addResource(QTextDocument::ImageResource,
+ QUrl( pixmapResource ), QVariant( pixmap ) );
+ QString myimg = "<img src=\"%1\">";
+ text += myimg.arg( pixmapResource );
+ text += "</td><td>";
+ text += routeRequest->name( i );
+ text += "</td></tr>";
+ }
+ text += "</table>";
+ }
+#endif
+}
+
+void ControlView::printDrivingInstructions( QTextDocument &document, QString &text )
+{
+#ifndef QT_NO_PRINTER
+ RoutingModel* routingModel = m_marbleWidget->model()->routingManager()->routingModel();
+
+ if (!routingModel) {
+ return;
+ }
+
+ GeoDataLineString total;
+ for ( int i=0; i<routingModel->rowCount(); ++i ) {
+ QModelIndex index = routingModel->index(i, 0);
+ RoutingModel::RoutingItemType type = qVariantValue<RoutingModel::RoutingItemType>(index.data(RoutingModel::TypeRole));
+ if ( type == RoutingModel::WayPoint ) {
+ GeoDataCoordinates coordinates = qVariantValue<GeoDataCoordinates>(index.data(RoutingModel::CoordinateRole));
+ total.append(coordinates);
+ }
+ }
+
+ text += "<table cellpadding=\"4\">";
+ text += "<tr><th>No.</th><th>Distance</th><th>Instruction</th></tr>";
+ for ( int i=0, j=0; i<routingModel->rowCount(); ++i ) {
+ QModelIndex index = routingModel->index(i, 0);
+ RoutingModel::RoutingItemType type = qVariantValue<RoutingModel::RoutingItemType>( index.data( RoutingModel::TypeRole ) );
+ if ( type == RoutingModel::Instruction ) {
+ ++j;
+ GeoDataCoordinates coordinates = qVariantValue<GeoDataCoordinates>( index.data( RoutingModel::CoordinateRole ) );
+ GeoDataLineString accumulator;
+ for (int k=0; k<total.size(); ++k) {
+ accumulator << total.at(k);
+
+ if (total.at(k) == coordinates)
+ break;
+ }
+
+ if ( i%2 == 0 ) {
+ text += "<tr bgcolor=\"lightGray\"><td align=\"right\" valign=\"middle\">";
+ }
+ else {
+ text += "<tr><td align=\"right\" valign=\"middle\">";
+ }
+ text += QString::number( j );
+ text += "</td><td align=\"right\" valign=\"middle\">";
+
+ text += QString::number( accumulator.length( EARTH_RADIUS ) * METER2KM, 'f', 1 );
+ /** @todo: support localization */
+ text += " km</td><td valign=\"middle\">";
+
+ QPixmap instructionIcon = qVariantValue<QPixmap>( index.data( Qt::DecorationRole ) );
+ if ( !instructionIcon.isNull() ) {
+ QString uri = QString("marble://turnIcon%1.png").arg(i);
+ document.addResource( QTextDocument::ImageResource, QUrl( uri ), QVariant( instructionIcon ) );
+ text += QString("<img src=\"%1\">").arg(uri);
+ }
+
+ text += routingModel->data( index ).toString();
+ text += "</td></tr>";
+ }
+ }
+ text += "</table>";
+#endif
+}
+
+}
+
#include "ControlView.moc"
--- trunk/KDE/kdeedu/marble/src/ControlView.h #1174150:1174151
@@ -27,6 +27,7 @@
class QSplitter;
class QPrintDialog;
+class QTextDocument;
namespace Marble
{
@@ -79,6 +80,11 @@
void paintPrintPreview( QPrinter * printer );
private:
+ void printMap( QTextDocument &document, QString &text, QPrinter *printer );
+ void printLegend( QTextDocument &document, QString &text );
+ void printRouteSummary( QTextDocument &document, QString &text );
+ void printDrivingInstructions( QTextDocument &document, QString &text );
+
//MarbleModel *m_marbleModel;
MarbleWidget *m_marbleWidget;
MarbleControlBox *m_control;
--- trunk/KDE/kdeedu/marble/src/lib/CMakeLists.txt #1174150:1174151
@@ -201,6 +201,8 @@
BookmarkManager.cpp
BookmarkInfoDialog.cpp
NewFolderInfoDialog.cpp
+
+ PrintOptionsWidget.cpp
)
set (marblewidget_UI
@@ -227,6 +229,7 @@
DataMigrationWidget.ui
BookmarkInfoDialog.ui
NameDialog.ui
+ PrintOptions.ui
)
# FIXME: cleaner approach of src/lib/MarbleControlBox.* vs. marble.qrc
--- trunk/KDE/kdeedu/marble/src/lib/MarbleLegendBrowser.cpp #1174150:1174151
@@ -175,7 +175,11 @@
d->m_isLegendLoaded = true;
qDebug("loadLegend: Time elapsed: %d ms", t.elapsed());
+
+ if ( d->m_marbleWidget ) {
+ d->m_marbleWidget->model()->setLegend( document() );
}
+}
bool MarbleLegendBrowser::event( QEvent * event )
{
--- trunk/KDE/kdeedu/marble/src/lib/MarbleModel.cpp #1174150:1174151
@@ -108,7 +108,9 @@
m_positionTracking( 0 ),
m_planet( 0 ),
m_bookmarkManager( 0 ),
- m_routingManager( 0 )
+ m_routingManager( 0 ),
+ m_legend( 0 ),
+ m_backgroundVisible( true )
{
}
@@ -167,8 +169,9 @@
Planet *m_planet;
BookmarkManager *m_bookmarkManager;
-
RoutingManager *m_routingManager;
+ QTextDocument *m_legend;
+ bool m_backgroundVisible;
};
@@ -618,8 +621,10 @@
static_cast<GeoSceneLayer*>( d->m_mapTheme->map()->layer( themeID ) );
QStringList renderPositions;
+ if ( d->m_backgroundVisible ) {
renderPositions << "STARS" << "BEHIND_TARGET";
d->m_layerManager->renderLayers( painter, viewParams, renderPositions );
+ }
if ( redrawBackground ) {
if ( d->m_mapTheme->map()->hasTextureLayers() ) {
@@ -1165,6 +1170,26 @@
return d->m_clock->timezone();
}
+QTextDocument * MarbleModel::legend()
+{
+ return d->m_legend;
}
+void MarbleModel::setLegend( QTextDocument * legend )
+{
+ d->m_legend = legend;
+}
+
+bool MarbleModel::backgroundVisible() const
+{
+ return d->m_backgroundVisible;
+}
+
+void MarbleModel::setBackgroundVisible( bool visible )
+{
+ d->m_backgroundVisible = visible;
+}
+
+}
+
#include "MarbleModel.moc"
--- trunk/KDE/kdeedu/marble/src/lib/MarbleModel.h #1174150:1174151
@@ -41,6 +41,7 @@
class QAbstractItemModel;
class QPoint;
class QRect;
+class QTextDocument;
namespace Marble
{
@@ -311,6 +312,15 @@
* return instance of BookmarkManager
*/
BookmarkManager *bookmarkManager() const;
+
+ QTextDocument * legend();
+
+ void setLegend( QTextDocument * document );
+
+ bool backgroundVisible() const;
+
+ void setBackgroundVisible( bool visible );
+
public Q_SLOTS:
void clearVolatileTileCache();
--- trunk/KDE/kdeedu/marble/src/lib/MarbleWidget.cpp #1174150:1174151
@@ -812,7 +812,6 @@
// Create a painter that will do the painting.
GeoPainter painter( paintDevice, map()->viewport(),
map()->mapQuality(), doClip );
-
QRect dirtyRect = evt->rect();
// Draws the map like MarbleMap::paint does, but adds our customPaint in between
--- trunk/KDE/kdeedu/marble/src/lib/routing/RoutingManager.cpp #1174150:1174151
@@ -131,6 +131,11 @@
updateRoute();
}
+RouteRequest* RoutingManager::routeRequest()
+{
+ return d->m_routeRequest;
+}
+
void RoutingManager::updateRoute()
{
if ( !d->m_routeRequest ) {
@@ -190,11 +195,6 @@
return d->m_adjustNavigation;
}
-RouteRequest* RoutingManager::routeRequest()
-{
- return d->m_routeRequest;
-}
-
void RoutingManager::saveSettings() const
{
GeoWriter writer;
More information about the kde-doc-english
mailing list