• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • tools
  • maptheme-previewimage
tools/maptheme-previewimage/main.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2013 Dennis Nienhüser <earthwings@gentoo.org>
9 //
10 
11 #include <MarbleWidget.h>
12 #include <MarbleModel.h>
13 #include <GeoDataTreeModel.h>
14 #include <RenderPlugin.h>
15 
16 #include <QDebug>
17 #include <QApplication>
18 #include <QPixmap>
19 #include <QPainter>
20 #include <QProcess>
21 #include <QDir>
22 #include <QThread>
23 
24 using namespace Marble;
25 
26 class Cheeeeze : private QThread { public: using QThread::msleep; };
27 
28 QPixmap resize(const QPixmap &pixmap)
29 {
30  if ( QProcess::execute("convert -version") == 0 ) {
31  QString const inputFile = QDir::tempPath() + "/marble-preview.png";
32  QString const outputFile = QDir::tempPath() + "/marble-preview-scaled.png";
33  if ( pixmap.save( inputFile )
34  && QProcess::execute( "convert", QStringList() << inputFile << "-resize" << "130x130"
35  << "-sharpen" << "1x1" << outputFile ) == 0
36  ) {
37  QPixmap result( outputFile );
38  if ( !result.isNull() ) {
39  return result;
40  }
41  }
42  }
43 
44  qDebug() << "Warning: Unable to resize pixmap properly. Check imagemagick installation.";
45  return pixmap.scaled( 130, 130, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
46 }
47 
48 int main(int argc, char** argv)
49 {
50  QApplication app(argc,argv);
51 
52  if ( argc < 2 ) {
53  qDebug() << "Usage: " << argv[0] << " <maptheme> [output.png]";
54  qDebug() << "Where <maptheme> is a map theme id a la 'body/maptheme/maptheme.dgml'.";
55  return 1;
56  }
57 
58  MarbleWidget *mapWidget = new MarbleWidget;
59  mapWidget->setMapThemeId( argv[1] );
60  QStringList const features = QStringList() << "atmosphere";
61  foreach( RenderPlugin* plugin, mapWidget->renderPlugins() ) {
62  if ( !features.contains( plugin->nameId() ) ) {
63  plugin->setEnabled( false );
64  }
65  }
66  double const scale = 4.0;
67  mapWidget->resize( 130 * scale, 130 * scale );
68  mapWidget->centerOn( 49.59526, 18.48104 );
69  mapWidget->setRadius( 120 * scale / 2.0 );
70 
71  QPixmap canvas( ":/canvas.png" );
72  Q_ASSERT(!canvas.isNull());
73  QPainter globePainter( &canvas );
74 
75  // Hack: Wait up to ten seconds for six documents to be parsed.
76  // We need proper load progress signalization in Marble
77  for ( int i=0; i<400 && mapWidget->model()->treeModel()->rowCount() < 6; ++i ) {
78  Cheeeeze::msleep( 25 );
79  app.processEvents();
80  }
81  QPixmap const globe = QPixmap::grabWidget( mapWidget );
82  globePainter.drawPixmap( QPoint( 2, 2 ), resize( globe ) );
83  globePainter.end();
84  canvas.save( argc > 2 ? argv[2] : "preview.png" );
85 
86  return 0;
87 }
QProcess::execute
int execute(const QString &program, const QStringList &arguments)
resize
QPixmap resize(const QPixmap &pixmap)
Definition: tools/maptheme-previewimage/main.cpp:28
Marble::MarbleModel::treeModel
GeoDataTreeModel * treeModel()
Return the list of Placemarks as a QAbstractItemModel *.
Definition: MarbleModel.cpp:477
MarbleModel.h
This file contains the headers for MarbleModel.
QApplication
QStringList::contains
bool contains(const QString &str, Qt::CaseSensitivity cs) const
QPoint
Marble::MarbleWidget
A widget class that displays a view of the earth.
Definition: MarbleWidget.h:104
Marble::MarbleWidget::setMapThemeId
void setMapThemeId(const QString &maptheme)
Set a new map theme.
Definition: MarbleWidget.cpp:759
QWidget::resize
void resize(int w, int h)
QCoreApplication::processEvents
void processEvents(QFlags< QEventLoop::ProcessEventsFlag > flags)
QPixmap::save
bool save(const QString &fileName, const char *format, int quality) const
QDir::tempPath
QString tempPath()
Marble::MarbleWidget::model
MarbleModel * model()
Return the model that this view shows.
Definition: MarbleWidget.cpp:289
QPainter
QPixmap::scaled
QPixmap scaled(int width, int height, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformMode) const
QString
GeoDataTreeModel.h
QStringList
QPixmap
Marble::RenderPlugin::nameId
QString nameId
Definition: RenderPlugin.h:48
QPixmap::isNull
bool isNull() const
Marble::MarbleWidget::centerOn
void centerOn(const qreal lon, const qreal lat, bool animated=false)
Center the view on a geographical point.
Definition: MarbleWidget.cpp:549
Marble::MarbleWidget::setRadius
void setRadius(int radius)
Set the radius of the globe in pixels.
Definition: MarbleWidget.cpp:330
Marble::RenderPlugin::setEnabled
void setEnabled(bool enabled)
settting enabled
Definition: RenderPlugin.cpp:139
RenderPlugin.h
QPixmap::grabWidget
QPixmap grabWidget(QWidget *widget, const QRect &rectangle)
MarbleWidget.h
This file contains the headers for MarbleWidget.
Marble::GeoDataTreeModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const
Return the number of Items in the Model.
Definition: GeoDataTreeModel.cpp:142
QThread
main
int main(int argc, char **argv)
Definition: tools/maptheme-previewimage/main.cpp:48
Marble::RenderPlugin
The abstract class that creates a renderable item.
Definition: RenderPlugin.h:43
Marble::MarbleWidget::renderPlugins
QList< RenderPlugin * > renderPlugins() const
Returns a list of all RenderPlugins on the widget, this includes float items.
Definition: MarbleWidget.cpp:1107
QThread::msleep
void msleep(unsigned long msecs)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal