File indexing completed on 2024-10-13 09:28:35
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2013 Dennis Nienhüser <nienhueser@kde.org> 0004 // 0005 0006 #include <MarbleWidget.h> 0007 #include <MarbleModel.h> 0008 #include <GeoDataTreeModel.h> 0009 #include <RenderPlugin.h> 0010 0011 #include <QDebug> 0012 #include <QApplication> 0013 #include <QPixmap> 0014 #include <QPainter> 0015 #include <QProcess> 0016 #include <QDir> 0017 #include <QThread> 0018 0019 using namespace Marble; 0020 0021 class Cheeeeze : private QThread { public: using QThread::msleep; }; 0022 0023 QPixmap resize(const QPixmap &pixmap) 0024 { 0025 if ( QProcess::execute("convert", QStringList() << "-version") == 0 ) { 0026 QString const inputFile = QDir::tempPath() + QLatin1String("/marble-preview.png"); 0027 QString const outputFile = QDir::tempPath() + QLatin1String("/marble-preview-scaled.png"); 0028 if ( pixmap.save( inputFile ) 0029 && QProcess::execute( "convert", QStringList() << inputFile << "-resize" << "130x130" 0030 << "-sharpen" << "1x1" << outputFile ) == 0 0031 ) { 0032 QPixmap result( outputFile ); 0033 if ( !result.isNull() ) { 0034 return result; 0035 } 0036 } 0037 } 0038 0039 qDebug() << "Warning: Unable to resize pixmap properly. Check imagemagick installation."; 0040 return pixmap.scaled( 130, 130, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ); 0041 } 0042 0043 int main(int argc, char** argv) 0044 { 0045 QApplication app(argc,argv); 0046 0047 if ( argc < 2 ) { 0048 qDebug() << "Usage: " << argv[0] << " <maptheme> [output.png]"; 0049 qDebug() << "Where <maptheme> is a map theme id a la 'body/maptheme/maptheme.dgml'."; 0050 return 1; 0051 } 0052 0053 MarbleWidget *mapWidget = new MarbleWidget; 0054 mapWidget->setMapThemeId( argv[1] ); 0055 QStringList const features = QStringList() << "atmosphere"; 0056 for( RenderPlugin* plugin: mapWidget->renderPlugins() ) { 0057 if ( !features.contains( plugin->nameId() ) ) { 0058 plugin->setEnabled( false ); 0059 } 0060 } 0061 double const scale = 4.0; 0062 mapWidget->resize( 130 * scale, 130 * scale ); 0063 mapWidget->centerOn( 49.59526, 18.48104 ); 0064 mapWidget->setRadius( 120 * scale / 2.0 ); 0065 0066 QPixmap canvas( ":/canvas.png" ); 0067 Q_ASSERT(!canvas.isNull()); 0068 QPainter globePainter( &canvas ); 0069 0070 // Hack: Wait up to ten seconds for six documents to be parsed. 0071 // We need proper load progress signalization in Marble 0072 for ( int i=0; i<400 && mapWidget->model()->treeModel()->rowCount() < 6; ++i ) { 0073 Cheeeeze::msleep( 25 ); 0074 app.processEvents(); 0075 } 0076 QPixmap const globe = QPixmap::grabWidget( mapWidget ); 0077 globePainter.drawPixmap( QPoint( 2, 2 ), resize( globe ) ); 0078 globePainter.end(); 0079 canvas.save( argc > 2 ? argv[2] : "preview.png" ); 0080 0081 return 0; 0082 }