[Marble-commits] KDE/kdeedu/marble/src/lib

Bernhard Beschow bbeschow at cs.tu-berlin.de
Mon Jan 3 15:56:56 CET 2011


SVN commit 1211290 by beschow:

visualize and auto-suggest preview image

 M  +39 -78    MapWizard.cpp  
 M  +0 -1      MapWizard.h  
 M  +39 -30    MapWizard.ui  


--- trunk/KDE/kdeedu/marble/src/lib/MapWizard.cpp #1211289:1211290
@@ -72,6 +72,7 @@
 
     mapType mapProviderType;
     QByteArray levelZero;
+    QImage previewImage;
 
     QString wmsProtocol;
     QString wmsHost;
@@ -97,9 +98,18 @@
     if ( id == 1 ) {
         m_serverCapabilitiesValid = false;
     } else if ( id == 2 ) {
-        levelZero = QImage();
+        levelZero.clear();
+    } else if ( id == 5 ) {
+        if ( mapProviderType == MapWizardPrivate::StaticImageMap ) {
+            previewImage = QImage( uiWidget.lineEditSource->text() ).scaled( 136, 136, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
+        } else {
+            previewImage = QImage::fromData( levelZero ).scaled( 136, 136, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
     }
+        uiWidget.labelPreview->setPixmap( QPixmap::fromImage( previewImage ) );
+    } else if ( id == 6 ) {
+        uiWidget.labelThumbnail->setPixmap( QPixmap::fromImage( previewImage ) );
 }
+}
 
 MapWizard::MapWizard( QWidget* parent ) : QWizard( parent ), d( new MapWizardPrivate )
 {
@@ -121,7 +131,6 @@
     connect( d->uiWidget.pushButtonLegend, SIGNAL( clicked( bool ) ), this, SLOT( queryLegendImage() ) );
     connect( d->uiWidget.pushButtonStaticUrlLegend, SIGNAL( clicked( bool ) ), this, SLOT( queryStaticUrlLegendImage() ) );
     connect( d->uiWidget.pushButtonStaticUrlTest, SIGNAL( clicked( bool ) ), this, SLOT( downloadLevelZero() ) );
-    connect( d->uiWidget.pushButtonSuggest, SIGNAL( clicked( bool ) ), this, SLOT( downloadLevelZero() ) );
 
     connect( d->uiWidget.comboBoxWmsServer, SIGNAL( currentIndexChanged( QString ) ), d->uiWidget.lineEditWmsUrl, SLOT( setText( QString ) ) );
     connect( d->uiWidget.comboBoxWmsMap, SIGNAL( currentIndexChanged( QString ) ), this, SLOT( autoFillDetails() ) );
@@ -149,6 +158,8 @@
 
 void MapWizard::parseServerCapabilities( QNetworkReply* reply )
 {
+    button( MapWizard::NextButton )->setEnabled( true );
+
     QString result( reply->readAll() );
     QDomDocument xml;
     if( !xml.setContent( result ) )
@@ -413,11 +424,10 @@
         }
 
         // Preview image
-        QString pixmapPath = d->uiWidget.lineEditPreview->text();
-        QImage previewImage = QImage( pixmapPath ).scaled( 136, 136, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
-        previewImage.save( QString( "%1/%2/%3" ).arg( maps.absolutePath() )
+        QString pixmapPath = QString( "%1/%2/%3" ).arg( maps.absolutePath() )
                                                 .arg( head->theme() )
-                                                .arg( head->icon()->pixmap() ) );
+                                                  .arg( head->icon()->pixmap() );
+        d->previewImage.save( pixmapPath );
 
         // DGML
         QFile file( QString( "%1/%2/%2.dgml" ).arg( maps.absolutePath() )
@@ -510,37 +520,39 @@
         QNetworkRequest request( downloadUrl );
         d->levelZeroAccessManager.get( request );
     }
-    
-    else if( d->mapProviderType == MapWizardPrivate::StaticImageMap ){
-        suggestPreviewImage();
     }
-}
 
 void MapWizard::createLevelZero( QNetworkReply* reply )
 {
+    button( MapWizard::NextButton )->setEnabled( true );
+
     d->levelZero = reply->readAll();
+    QImage testImage = QImage::fromData( d->levelZero );
 
     if ( d->mapProviderType == MapWizardPrivate::WmsMap )
     {
         if ( d->levelZero.isNull() ) {
             QMessageBox::information( this,
                                       tr( "Base Tile" ),
-                                      tr( "The base tile could not be downloaded. The server replied:\n\n%1" ).arg( QString( result ) ) );
-        } else if ( currentId() == 2 ) {
+                                      tr( "The base tile could not be downloaded." ) );
+        }
+        else if ( testImage.isNull() ) {
+            QMessageBox::information( this,
+                                      tr( "Base Tile" ),
+                                      tr( "The base tile could not be downloaded successfully. The server replied:\n\n%1" ).arg( QString( d->levelZero ) ) );
+        }
+        else {
             next();
         }
     }
 
     if( d->mapProviderType == MapWizardPrivate::StaticUrlMap )
     {
-        QImage testImage = QImage::fromData( d->levelZero );
         if ( !testImage.isNull() ) {
             QImage levelZero = testImage.scaled( d->uiWidget.labelStaticUrlTest->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation );
             d->uiWidget.labelStaticUrlTest->setPixmap( QPixmap::fromImage( levelZero ) );
         }
     }
-
-    suggestPreviewImage();
 }
 
 void MapWizard::createLegend()
@@ -573,10 +585,10 @@
 void MapWizard::queryPreviewImage()
 {
     QString fileName = QFileDialog::getOpenFileName();
-    d->uiWidget.lineEditPreview->setText( fileName );
+    d->previewImage = QImage( fileName );
 
-    QPixmap preview( fileName );
-    d->uiWidget.labelThumbnail->setPixmap( QPixmap( fileName ) );
+    QPixmap preview = QPixmap::fromImage( d->previewImage );
+    d->uiWidget.labelThumbnail->setPixmap( preview );
     d->uiWidget.labelThumbnail->resize( preview.width(), preview.height() );
 }
 
@@ -665,14 +677,21 @@
 {
     if ( currentId() == 1 && !d->m_serverCapabilitiesValid ) {
         queryServerCapabilities();
+        button( MapWizard::NextButton )->setEnabled( false );
         return false;
     }
 
     if ( currentId() == 2 && d->levelZero.isNull() ) {
         downloadLevelZero();
+        button( MapWizard::NextButton )->setEnabled( false );
         return false;
     }
 
+    if ( currentId() == 5 && d->previewImage.isNull() ) {
+        QMessageBox::information( this, tr( "Preview Image" ), tr( "Please specify a preview image." ) );
+        return false;
+    }
+
     return QWizard::validateCurrentPage();
 }
 
@@ -713,57 +732,6 @@
     return currentId() + 1;
 }
 
-void MapWizard::suggestPreviewImage()
-{
-    if( currentId() == 4 )
-    {
-        QPointer<QDialog> dialog = new QDialog;
-        QPixmap pixmap;
-        if( d->mapProviderType == MapWizardPrivate::StaticImageMap ) {
-            pixmap = QPixmap( d->uiWidget.lineEditSource->text() );
-        } else if ( d->mapProviderType == MapWizardPrivate::WmsMap || d->mapProviderType == MapWizardPrivate::StaticUrlMap ){
-            pixmap.loadFromData( d->levelZero );
-        }
-
-        QLabel *previewImage = new QLabel();
-        previewImage->setPixmap( pixmap.scaled( 136, 136, Qt::KeepAspectRatio, Qt::SmoothTransformation ) );
-
-        QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
-        connect( buttonBox, SIGNAL( accepted() ), dialog, SLOT( accept() ) );
-        connect( buttonBox, SIGNAL( rejected() ), dialog, SLOT( reject() ) );
-
-        QGridLayout *grid = new QGridLayout();
-        grid->addWidget( previewImage );
-        grid->addWidget( buttonBox );
-
-        dialog->setLayout( grid );
-        if( dialog->exec() )
-        {
-
-            QTemporaryFile tempFile;
-            tempFile.open();
-
-            if( d->mapProviderType == MapWizardPrivate::StaticImageMap )
-            {
-                QImage tempPreview = pixmap.toImage();
-                tempPreview.save( tempFile.fileName() + ".png" );
-                d->uiWidget.lineEditPreview->setText( tempFile.fileName() + ".png" );
-            }
-
-            else if( d->mapProviderType == MapWizardPrivate::StaticUrlMap ||
-                     d->mapProviderType == MapWizardPrivate::WmsMap )
-            {
-                QImage tempPreview = QImage::fromData( d->levelZero );
-                tempPreview.save( tempFile.fileName() + ".png" );
-                d->uiWidget.lineEditPreview->setText( tempFile.fileName() + ".png" );
-            }
-
-            d->uiWidget.labelThumbnail->setPixmap( pixmap.scaled( 136, 136, Qt::KeepAspectRatio, Qt::SmoothTransformation ) );
-        }
-        delete dialog;
-    }
-}
-
 GeoSceneDocument* MapWizard::createDocument()
 {
     GeoSceneDocument *document = new GeoSceneDocument;
@@ -880,8 +848,7 @@
     }
 
     if( !document->head()->name().isEmpty() && 
-        !document->head()->description().isEmpty() && 
-        !d->uiWidget.lineEditPreview->text().isEmpty() )
+        !document->head()->description().isEmpty() )
     {
         if( d->mapProviderType == MapWizardPrivate::StaticImageMap && !QFile( d->sourceImage ).exists() )
         {
@@ -889,12 +856,6 @@
             return;
         }
 
-        if( !QFile( d->uiWidget.lineEditPreview->text() ).exists() )
-        {
-            QMessageBox::critical( this, tr( "File not found" ), tr( "Preview image is not found." ) );
-            return;
-        }
-        
         createDgml( document.data() );
 
         if( createFiles( document->head() ) )
@@ -911,7 +872,7 @@
             d->uiWidget.lineEditTitle->clear();
             d->uiWidget.lineEditTheme->clear();
             d->uiWidget.textEditDesc->clear();
-            d->uiWidget.lineEditPreview->clear();
+            d->uiWidget.labelPreview->clear();
             d->uiWidget.lineEditSource->clear();
             d->dgmlOutput = QString();
             QTimer::singleShot( 0, this, SLOT( restart() ) );
--- trunk/KDE/kdeedu/marble/src/lib/MapWizard.h #1211289:1211290
@@ -65,7 +65,6 @@
     void autoFillDetails();
     void downloadLevelZero();
     void createLevelZero( QNetworkReply* reply = 0 );
-    void suggestPreviewImage();
 
 private:
     Q_PRIVATE_SLOT( d, void pageEntered( int ) )
--- trunk/KDE/kdeedu/marble/src/lib/MapWizard.ui #1211289:1211290
@@ -562,8 +562,8 @@
    </layout>
   </widget>
   <widget class="QWizardPage" name="wizardPageInfo">
-   <layout class="QVBoxLayout" name="verticalLayout_4">
-    <item>
+   <layout class="QGridLayout" name="gridLayout_2">
+    <item row="0" column="0" colspan="2">
      <widget class="QLabel" name="label_6">
       <property name="text">
        <string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
@@ -578,9 +578,7 @@
       </property>
      </widget>
     </item>
-    <item>
-     <layout class="QFormLayout" name="formLayout_2">
-      <item row="0" column="0">
+    <item row="1" column="0">
        <widget class="QLabel" name="labelMapTitle">
         <property name="text">
          <string>Map Title:</string>
@@ -593,14 +591,14 @@
         </property>
        </widget>
       </item>
-      <item row="0" column="1">
+    <item row="1" column="1">
        <widget class="QLineEdit" name="lineEditTitle">
         <property name="toolTip">
          <string>A short concise name for your map theme.</string>
         </property>
        </widget>
       </item>
-      <item row="1" column="0">
+    <item row="2" column="0">
        <widget class="QLabel" name="labelMapTheme">
         <property name="text">
          <string>Map Theme:</string>
@@ -610,7 +608,7 @@
         </property>
        </widget>
       </item>
-      <item row="1" column="1">
+    <item row="2" column="1">
        <widget class="QLineEdit" name="lineEditTheme">
         <property name="toolTip">
          <string>The lowercase map theme id.</string>
@@ -620,7 +618,7 @@
         </property>
        </widget>
       </item>
-      <item row="2" column="0">
+    <item row="3" column="0">
        <widget class="QLabel" name="labelMapDesc">
         <property name="text">
          <string>Description:</string>
@@ -633,7 +631,7 @@
         </property>
        </widget>
       </item>
-      <item row="2" column="1">
+    <item row="3" column="1">
        <widget class="QTextEdit" name="textEditDesc">
         <property name="toolTip">
          <string>A short description of your map theme. Here you can provide information about the purpose, origin, copyright and license of the data used in your map theme.</string>
@@ -643,53 +641,64 @@
         </property>
        </widget>
       </item>
-      <item row="3" column="0">
+    <item row="4" column="0">
        <widget class="QLabel" name="labelMapIcon">
         <property name="text">
          <string>Preview Image:</string>
         </property>
         <property name="alignment">
-         <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+       <set>Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing</set>
         </property>
-        <property name="buddy">
-         <cstring>lineEditPreview</cstring>
-        </property>
        </widget>
       </item>
-      <item row="3" column="1">
+    <item row="4" column="1">
        <layout class="QHBoxLayout" name="horizontalLayout_5">
         <item>
-         <widget class="QLineEdit" name="lineEditPreview">
-          <property name="toolTip">
-           <string>An icon that can be used for your map theme.</string>
+       <layout class="QVBoxLayout" name="verticalLayout_4">
+        <item>
+         <widget class="QLabel" name="labelPreview">
+          <property name="sizePolicy">
+           <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+            <horstretch>0</horstretch>
+            <verstretch>0</verstretch>
+           </sizepolicy>
           </property>
-          <property name="whatsThis">
-           <string>It will show up in the map view of the navigation panel.</string>
+          <property name="minimumSize">
+           <size>
+            <width>128</width>
+            <height>128</height>
+           </size>
           </property>
+          <property name="text">
+           <string>preview image</string>
+          </property>
          </widget>
         </item>
         <item>
          <widget class="QPushButton" name="pushButtonPreview">
           <property name="text">
-           <string>...</string>
+           <string>Change...</string>
           </property>
          </widget>
         </item>
+       </layout>
+      </item>
         <item>
-         <widget class="QPushButton" name="pushButtonSuggest">
-          <property name="toolTip">
-           <string>Press &quot;Suggest&quot; to suggest an icon for your map theme automatically.</string>
+       <spacer name="horizontalSpacer_3">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
           </property>
-          <property name="text">
-           <string>Suggest</string>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>354</width>
+          <height>20</height>
+         </size>
           </property>
-         </widget>
+       </spacer>
         </item>
        </layout>
       </item>
      </layout>
-    </item>
-   </layout>
   </widget>
   <widget class="QWizardPage" name="wizardPageSummary">
    <layout class="QVBoxLayout" name="verticalLayout_5">


More information about the Marble-commits mailing list