[QGIS Commit] r9055 - in branches/advanced_printing_branch/src: app app/composer ui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Wed Aug 13 07:28:37 EDT 2008


Author: mhugent
Date: 2008-08-13 07:28:36 -0400 (Wed, 13 Aug 2008)
New Revision: 9055

Modified:
   branches/advanced_printing_branch/src/app/CMakeLists.txt
   branches/advanced_printing_branch/src/app/composer/qgscomposer.cpp
   branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp
   branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.cpp
   branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.h
   branches/advanced_printing_branch/src/app/composer/qgscomposerview.cpp
   branches/advanced_printing_branch/src/app/composer/qgscomposition.cpp
   branches/advanced_printing_branch/src/ui/qgscomposerpicturebase.ui
Log:
Composer picture

Modified: branches/advanced_printing_branch/src/app/CMakeLists.txt
===================================================================
--- branches/advanced_printing_branch/src/app/CMakeLists.txt	2008-08-12 23:24:50 UTC (rev 9054)
+++ branches/advanced_printing_branch/src/app/CMakeLists.txt	2008-08-13 11:28:36 UTC (rev 9055)
@@ -60,7 +60,7 @@
   composer/qgscomposeritemgroup.cpp
   composer/qgscomposerlabel.cpp
   composer/qgscomposerlabelwidget.cpp
-  #composer/qgscomposerpicture.cpp
+  composer/qgscomposerpicture.cpp
   composer/qgscomposermap.cpp
   composer/qgscomposermapwidget.cpp
   composer/qgscomposerscalebar.cpp

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposer.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposer.cpp	2008-08-12 23:24:50 UTC (rev 9054)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposer.cpp	2008-08-13 11:28:36 UTC (rev 9055)
@@ -980,12 +980,10 @@
 
 void QgsComposer::on_mActionAddImage_activated(void)
 {
-#if 0
-  mComposition->setTool ( QgsComposition::AddPicture );
-  setToolActionsOff();
-  mActionAddImage->setOn ( true );
-  mView->setCursor(QCursor(cross_hair_cursor));
-#endif //0
+  if(mView)
+    {
+      mView->setCurrentTool(QgsComposerView::AddPicture);
+    }
 }
 
 void QgsComposer::moveItemContent()

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp	2008-08-12 23:24:50 UTC (rev 9054)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp	2008-08-13 11:28:36 UTC (rev 9055)
@@ -61,7 +61,7 @@
 
     connect ( mMapCanvas, SIGNAL(layersChanged()), this, SLOT(mapCanvasChanged()) );
 
-    // Add to scene
+    setToolTip(tr("Map") + " " + QString::number(mId));
 
     QGraphicsRectItem::show();
 }
@@ -76,6 +76,7 @@
   mComposition = composition;
   mMapCanvas = mComposition->mapCanvas();
   mId = mCurrentComposerId++;
+  setToolTip(tr("Map") + " " + QString::number(mId));
   QGraphicsRectItem::show();
 }
 
@@ -269,11 +270,11 @@
 {
   double w = rectangle.width();
   double h = rectangle.height();
-  prepareGeometryChange();
+  //prepareGeometryChange();
 
   QgsComposerItem::setSceneRect(rectangle);
   
-  QGraphicsRectItem::update();
+  //QGraphicsRectItem::update();
   double newHeight = mExtent.width() * h / w ;
   mExtent = QgsRect(mExtent.xMin(), mExtent.yMin(), mExtent.xMax(), mExtent.yMin() + newHeight);
   mCacheUpdated = false;

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.cpp	2008-08-12 23:24:50 UTC (rev 9054)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.cpp	2008-08-13 11:28:36 UTC (rev 9055)
@@ -16,560 +16,127 @@
  ***************************************************************************/
 /* $Id$ */
 
-#if 0
-
 #include "qgscomposerpicture.h"
-#include "qgsproject.h"
-
-#include <QFileDialog>
-#include <QMessageBox>
+#include <QFileInfo>
+#include <QImageReader>
 #include <QPainter>
-#include <QImageWriter>
-#include <QSettings>
-#include <QPolygonF>
-#include <QGraphicsScene>
+#include <QSvgRenderer>
 
-#include <cmath>
-#include <iostream>
-
-#define PI 3.14159265358979323846
-
-QgsComposerPicture::QgsComposerPicture ( QgsComposition *composition, 
-					 int id, QString file )
-    : QWidget(composition),
-      QgsComposerItem(0),
-      mPicturePath ( file ),
-      mPictureValid(false),
-      mCX(-10), mCY(-10),
-      mWidth(0), mHeight(0), mAngle(0),
-      mFrame(false),
-      mAreaPoints(4)
+QgsComposerPicture::QgsComposerPicture(QgsComposition *composition): QgsComposerItem(composition), mMode(UNKNOWN), mSvgCacheUpToDate(false), mCachedDpi(0)
 {
-    setupUi(this);
-
-#ifdef QGISDEBUG
-    std::cout << "QgsComposerPicture::QgsComposerPicture()" << std::endl;
-#endif
-
-    setRect(QRectF(0,0,0,0));
-
-    mComposition = composition;
-    mId  = id;
-
-    init();
-    loadPicture();
-
-    // Add to scene
-    mComposition->canvas()->addItem(this);
-
-    QAbstractGraphicsShapeItem::show();
-    QAbstractGraphicsShapeItem::update();
-     
-    writeSettings();
 }
 
-QgsComposerPicture::QgsComposerPicture ( QgsComposition *composition, int id ) :
-    QWidget(),
-    QgsComposerItem(0),
-    mFrame(false),
-    mAreaPoints(4)
+QgsComposerPicture::QgsComposerPicture(): QgsComposerItem(0), mMode(UNKNOWN), mSvgCacheUpToDate(false)
 {
-#ifdef QGISDEBUG
-    std::cout << "QgsComposerPicture::QgsComposerPicture()" << std::endl;
-#endif
-    setRect(QRectF(0, 0, 0, 0));
 
-    setupUi(this);
-
-    mComposition = composition;
-    mId  = id;
-
-    init();
-
-    readSettings();
-
-    loadPicture();
-    adjustPictureSize();
-
-    // Add to scene
-    mComposition->canvas()->addItem(this);
-
-    recalculate();
-
-    QAbstractGraphicsShapeItem::show();
-    QAbstractGraphicsShapeItem::update();
 }
 
-void QgsComposerPicture::init ( void ) 
+QgsComposerPicture::~QgsComposerPicture()
 {
-  setSelected(false);
-  for ( int i = 0; i < 4; i++ ) 
-  {
-    mAreaPoints[i] = QPoint( 0, 0 );
-  }
 
-  QAbstractGraphicsShapeItem::setZValue(60);
-
 }
 
-void QgsComposerPicture::loadPicture ( void ) 
+void QgsComposerPicture::paint (QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget)
 {
-#ifdef QGISDEBUG
-    std::cerr << "QgsComposerPicture::loadPicture() mPicturePath = " << mPicturePath.toLocal8Bit().data() << std::endl;
-#endif
+  if(!painter)
+    {
+      return;
+    }
 
-  mPicture = QPicture(); 
-  mPictureValid = false;
-
-  if ( !mPicturePath.isNull() ) 
-  {
-	if ( mPicturePath.lower().right(3) == "svg" )
+  if(mMode == SVG)
+    {
+      int newDpi = (painter->device()->logicalDpiX() + painter->device()->logicalDpiY()) / 2;
+      if(newDpi != mCachedDpi)
 	{
-	  if ( !mPicture.load ( mPicturePath, "svg" ) )
-	  {
-		std::cerr << "Cannot load svg" << std::endl;
-	  }	
-	  else
-	  {
-		mPictureValid = true;
-	  }
+	  mSvgCacheUpToDate = false;
+	  mCachedDpi = newDpi;
+	  mImage = QImage(rect().width() * newDpi/25.4, rect().height() * newDpi/25.4, QImage::Format_ARGB32);
 	}
-	else
-	{
-      QImage image;
-	  if ( !image.load(mPicturePath) )
-	  {
-        std::cerr << "Cannot load raster" << std::endl;
-	  }
-	  else
-	  {	
-        QPainter  p;
-        p.begin( &mPicture );
-        p.drawImage ( 0, 0, image ); 
-        p.end();	
-        mPictureValid = true;
-	  }
-	}
-  }
 
-  if ( !mPictureValid ) 
-  {
-    // Dummy picture
-    QPainter  p;
-	p.begin( &mPicture );
-    QPen pen(QColor(0,0,0));
-    pen.setWidthF(3.0);
-    p.setPen( pen );
-    p.setBrush( QBrush( QColor( 150, 150, 150) ) );
-
-    double w, h; 
-    if ( mWidth > 0 && mHeight > 0 
-         && mWidth/mHeight > 0.001 && mWidth/mHeight < 1000 ) 
+      if(!mSvgCacheUpToDate)
 	{
-	  w = mWidth;
-	  h = mHeight;
-    }
-	else
- 	{
-	  w = 100;
-	  h = 100;
+	  updateImageFromSvg();
 	}
-	
-	p.drawRect (QRectF(0, 0, w, h)); 
-	p.drawLine (QLineF(0, 0, w-1, h-1));
-	p.drawLine (QLineF(w-1, 0, 0, h-1));
-
-	p.end();	
-
- 	mPicture.setBoundingRect ( QRect( 0, 0, (int)w, (int)h ) ); 
-  }//END if(!mPictureValid)
-}
-
-bool QgsComposerPicture::pictureValid ( void )
-{
-    return mPictureValid;
-}
-
-QgsComposerPicture::~QgsComposerPicture()
-{
-#ifdef QGISDEBUG
-    std::cerr << "QgsComposerPicture::~QgsComposerPicture()" << std::endl;
-#endif
-    QGraphicsItem::hide();
-}
-
-void QgsComposerPicture::paint ( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
-{
-#ifdef QGISDEBUG
-    std::cerr << "QgsComposerPicture::paint()" << std::endl;
-#endif
-
-    QRectF box = mPicture.boundingRect();
-    double scale = 1. * mWidth / box.width();
-
-    if(plotStyle() == QgsComposition::Postscript)
+    }
+  if(mMode != UNKNOWN)
     {
-      scale *= (96.0 / mComposition->resolution());
+      painter->drawImage(QRectF(0, 0, rect().width(), rect().height()), mImage, QRectF(0, 0, mImage.width(), mImage.height()));
     }
-    painter->save();
 
-    painter->translate(-mWidth/2, -mHeight/2);
-
-    painter->scale ( scale, scale );
-    painter->rotate ( -mAngle );
-    
-//    painter->drawPicture (QPointF(-box.width()/2, -box.height()/2), mPicture ); //this doesn't work right...
-
-    painter->drawPicture (0, 0, mPicture );
-
-    painter->restore();
-
-    if ( mFrame ) {
-	  // TODO: rect is not correct, +/- 1 pixel - Qt3?
-  	  painter->setPen( QPen(QColor(0,0,0), .3) );
-	  painter->setBrush( QBrush( Qt::NoBrush ) );
-
-	  painter->save();
-      painter->rotate ( -mAngle );
-      
-      painter->drawRect (QRectF(-mWidth/2, -mHeight/2, mWidth, mHeight));
-
-  	  painter->restore();
-    }
-
-    // Show selected / Highlight
-    if ( isSelected() && plotStyle() == QgsComposition::Preview ) {
-      painter->setPen( mComposition->selectionPen() );
-      painter->setBrush( mComposition->selectionBrush() );
-  
-      double s = mComposition->selectionBoxSize();
-
-	  for ( int i = 0; i < 4; i++ ) 
-	  {
-	    painter->save();
-	    painter->translate ( mAreaPoints[i].x(), mAreaPoints[i].y() );
-	    painter->rotate ( -mAngle + i * 90 );
-	    painter->drawRect(QRectF(0, 0, s, s));
-	    painter->restore();
-	  }
-    }//END of drawing selected highlight
-
-}
-
-void QgsComposerPicture::setSize(double width, double height)
-{
-  mWidth = width;
-  mHeight = height;
-  adjustPictureSize(); 
-  recalculate();
-}
-
-void QgsComposerPicture::resize(double dx, double dy )
-{
-    mWidth += dx;
-    mHeight += dy;
-    adjustPictureSize(); 
-
-    recalculate();
-}
-
-void QgsComposerPicture::recalculate()
-{
-#ifdef QGISDEBUG
-    std::cout << "QgsComposerPicture::recalculate" << std::endl;
-#endif
-    
-    QAbstractGraphicsShapeItem::prepareGeometryChange();
-
-    QRect box = mPicture.boundingRect(); //size of the image, in pixels
-
-    double angle = PI * mAngle / 180; //convert angle to radians
-    
-    // Angle between vertical in picture space and the vector 
-    // from center to upper left corner of the picture
-    double anglePicture = atan2 ( (double)box.width(), (double)box.height() );
-
-    // Angle (clockwise) between horizontal in paper space
-    // and the vector from center to upper left corner of the picture
-    double anglePaper = PI / 2 - anglePicture - angle;
-
-    // Distance from center to upper left corner in canvas units
-    double r = sqrt ((double)(mWidth*mWidth/4 + mHeight*mHeight/4) );
-
-    // Position of upper left corner in map
-    int dx = (int) ( r * cos ( anglePaper ) );
-    int dy = (int) ( r * sin ( anglePaper ) );
-
-
-    mAreaPoints[0] = QPointF( -dx, -dy ); //add the top-left point to the polygon
-    mAreaPoints[2] = QPointF( dx, dy ); //bottom-right
-
-    anglePaper = PI / 2 - anglePicture + angle;
-    dx = (int) ( r * cos ( anglePaper ) );
-    dy = (int) ( r * sin ( anglePaper ) );
-
-    mAreaPoints[1] =  QPointF( dx, -dy ); //top right
-    mAreaPoints[3] = QPointF( -dx, dy ); //bottom left
-
-    setRect(mAreaPoints.boundingRect());
-
-    QAbstractGraphicsShapeItem::update();
-    QAbstractGraphicsShapeItem::scene()->update();
-}
-
-QPolygonF QgsComposerPicture::areaPoints() const
-{
-#ifdef QGISDEBUG
-    std::cout << "QgsComposerPicture::areaPoints" << std::endl;
-#endif
-
-    return mAreaPoints;
-}
-
-
-void QgsComposerPicture::on_mFrameCheckBox_stateChanged ( int )
-{
-#ifdef QGISDEBUG
-    std::cout << "QgsComposerPicture::on_mFrameCheckBox_stateChanged" << std::endl;
-#endif
-
-    mFrame = mFrameCheckBox->isChecked();
-
-    QAbstractGraphicsShapeItem::update();
-    QAbstractGraphicsShapeItem::scene()->update();
-
-    writeSettings();
-}
-
-void QgsComposerPicture::on_mAngleLineEdit_editingFinished ( )
-{
-#ifdef QGISDEBUG
-    std::cout << "QgsComposerPicture::on_mAngleLineEdit_editingFinished()" << std::endl;
-#endif
-    mAngle = mAngleLineEdit->text().toDouble();
-
-    recalculate();
-
-    writeSettings();
-
-}
-
-void QgsComposerPicture::on_mWidthLineEdit_editingFinished ( )
-{
-#ifdef QGISDEBUG
-    std::cout << "QgsComposerPicture::on_mWidthLineEdit_editingFinished()" << std::endl;
-#endif
-
-    mWidth = mComposition->fromMM ( mWidthLineEdit->text().toDouble() );
-
-    QRect box = mPicture.boundingRect();
-    mHeight = mWidth*box.height()/box.width();
-    setOptions();
-
-    recalculate();
-
-    writeSettings();
-}
-
-void QgsComposerPicture::on_mPictureBrowseButton_clicked ( )
-{
-#ifdef QGISDEBUG
-    std::cout << "QgsComposerPicture::on_mPictureBrowseButton_clicked()" << std::endl;
-#endif
- 
-    QString file = QgsComposerPicture::pictureDialog();
-
-    if ( file.isNull() ) return;
-    
-    mPicturePath = file;
-    mPictureLineEdit->setText ( mPicturePath );
-
-    pictureChanged();
-}
-
-void QgsComposerPicture::pictureChanged ( )
-{
-#ifdef QGISDEBUG
-    std::cout << "QgsComposerPicture::pictureChanged()" << std::endl;
-#endif
-
-    mPicturePath = mPictureLineEdit->text();
-
-    loadPicture();
-
-    if ( !mPictureValid ) {
-        QMessageBox::warning( 0, tr("Warning"),
-                        tr("Cannot load picture.") );
-    }
-    else
+  //frame and selection boxes
+  drawFrame(painter);
+  if(isSelected())
     {
-        adjustPictureSize();
-        setOptions();
-        recalculate();
+      drawSelectionBoxes(painter);
     }
 }
 
-void QgsComposerPicture::on_mPictureLineEdit_editingFinished ( )
+void QgsComposerPicture::setPictureFile(const QString& path)
 {
-  pictureChanged();
-}
-
-void QgsComposerPicture::adjustPictureSize ( )
-{
-    // Addjust to original size
-    QRect box = mPicture.boundingRect();
-
-    if ( box.width() == 0 || box.height() == 0
-	 || mWidth == 0 || mHeight == 0 )
+  mSourceFile.setFileName(path);
+  if(!mSourceFile.exists())
     {
-	mWidth = 0;
-	mHeight = 0;
-
-	QRectF itemRect = QGraphicsRectItem::rect();
-	itemRect.setWidth(mWidth);
-	itemRect.setHeight(mHeight);
-	QGraphicsRectItem::setRect(itemRect);	
-        return;
+      mMode = UNKNOWN;
     }
-
-    if ( 1.*box.width()/box.height() > 1.*mWidth/mHeight )
+  
+  QFileInfo sourceFileInfo(mSourceFile);
+  QString sourceFileSuffix = sourceFileInfo.suffix();
+  if(sourceFileSuffix.compare("svg", Qt::CaseInsensitive) == 0)
     {
-	  mHeight = mWidth*box.height()/box.width();
+      //try to open svg
+      QSvgRenderer validTestRenderer(mSourceFile.fileName());
+      if(validTestRenderer.isValid())
+	{
+	  mMode = SVG;
+	}
+      else
+	{
+	  mMode = UNKNOWN;
+	}
     }
-    else
+  else
     {
-      mWidth = mHeight*box.width()/box.height();
+      //try to open raster with QImageReader
+      QImageReader imageReader(mSourceFile.fileName());
+      if(imageReader.read(&mImage))
+	{
+	  mMode = RASTER;
+	}
+      else
+	{
+	  mMode = UNKNOWN;
+	}
     }
-
-    //make sure the item rect corresponds to mWidth and mHeight...
-    QRectF itemRect = QGraphicsRectItem::rect();
-    itemRect.setWidth(mWidth);
-    itemRect.setHeight(mHeight);
-    QGraphicsRectItem::setRect(itemRect);
 }
 
-void QgsComposerPicture::setOptions ( void )
-{ 
-    mPictureLineEdit->setText ( mPicturePath );
-    mWidthLineEdit->setText ( QString("%1").arg( mComposition->toMM((int)mWidth), 0,'g') );
-    mHeightLineEdit->setText ( QString("%1").arg( mComposition->toMM((int)mHeight), 0,'g') );
-    mAngleLineEdit->setText ( QString::number ( mAngle ) );
-    mFrameCheckBox->setChecked ( mFrame );
-}
-
-void QgsComposerPicture::setSelected (  bool s ) 
+void QgsComposerPicture::updateImageFromSvg()
 {
-  QGraphicsRectItem::setSelected(s);
-  QAbstractGraphicsShapeItem::update(); // show highlight
-}    
-
-bool QgsComposerPicture::selected( void )
-{
-  return isSelected();
+  mImage.fill(0);
+  QPainter p(&mImage);
+  QSvgRenderer theRenderer(mSourceFile.fileName());
+  if(theRenderer.isValid())
+    {
+      theRenderer.render(&p);
+    }
+  mSvgCacheUpToDate = true;
 }
 
-QWidget *QgsComposerPicture::options ( void )
+void QgsComposerPicture::setSceneRect(const QRectF& rectangle)
 {
-    setOptions ();
-    return ( dynamic_cast <QWidget *> (this) ); 
-}
-
-QString QgsComposerPicture::pictureDialog ( void )
-{
-    QString filters = tr("Pictures ("); //+ " ( *.svg *.SVG ";
-    QList<QByteArray> formats = QImageWriter::supportedImageFormats();
-
-    for ( int i = 0; i < formats.count(); i++ )
+  mSvgCacheUpToDate = false;
+  if(mMode == SVG)
     {
-        QString frmt = formats.at( i );
-        QString fltr = " *." + frmt.lower() + " *." + frmt.upper();
-        filters += fltr;
+      mImage = QImage(rectangle.width() * mCachedDpi/25.4, rectangle.height() * mCachedDpi/25.4, QImage::Format_ARGB32);
     }
-    filters += ");;All other files (*.*)";
-
-    // Retrieve the last used directory
-    QSettings settings;
-    QString lastUsedDir = settings.readEntry("/UI/lastComposerPictureDir", ".");
-
-    QString file = QFileDialog::getOpenFileName(
-                    0,
-                    tr("Choose a file"),
-                    lastUsedDir,
-                    filters );
-    if (file.length() != 0)
-    {
-      QFileInfo myFile(file);
-      QString myPath = myFile.dirPath();
-      settings.writeEntry("/UI/lastComposerPictureDir", myPath);
-    }
-
-    return file; 
+  QgsComposerItem::setSceneRect(rectangle);
 }
 
-bool QgsComposerPicture::writeSettings ( void )  
+bool QgsComposerPicture::writeXML(QDomElement& elem, QDomDocument & doc)
 {
-#ifdef QGISDEBUG
-    std::cout << "QgsComposerPicture::writeSettings" << std::endl;
-#endif
-
-    QString path;
-    path.sprintf("/composition_%d/picture_%d/", mComposition->id(), mId ); 
-
-    QgsProject::instance()->writeEntry( "Compositions", path+"picture", mPicturePath );
-
-    QgsProject::instance()->writeEntry( "Compositions", path+"x", mComposition->toMM((int)QGraphicsItem::pos().x()) );
-    QgsProject::instance()->writeEntry( "Compositions", path+"y", mComposition->toMM((int)QGraphicsItem::pos().y()) );
-    QgsProject::instance()->writeEntry( "Compositions", path+"width", mComposition->toMM((int)mWidth) );
-    QgsProject::instance()->writeEntry( "Compositions", path+"height", mComposition->toMM((int)mHeight) );
-
-    QgsProject::instance()->writeEntry( "Compositions", path+"angle", mAngle );
-
-    QgsProject::instance()->writeEntry( "Compositions", path+"frame", mFrame );
-
-    return true; 
+  return false; //soon...
 }
 
-bool QgsComposerPicture::readSettings ( void )
+bool QgsComposerPicture::readXML(const QDomElement& itemElem, const QDomDocument& doc)
 {
-    bool ok;
-    QString path;
-    path.sprintf("/composition_%d/picture_%d/", mComposition->id(), mId );
-
-    mPicturePath = QgsProject::instance()->readEntry( "Compositions", path+"picture", "", &ok) ;
-
-    double x = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"x", 0, &ok));
-    double y = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"y", 0, &ok));
-    setPos(x, y);
-
-    mWidth = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"width", 0, &ok));
-    mHeight = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"height", 0, &ok));
-
-    mAngle = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"angle", 0, &ok));
-
-    mFrame = QgsProject::instance()->readBoolEntry("Compositions", path+"frame", true, &ok);
-
-    return true;
+  return false; //soon...
 }
-
-bool QgsComposerPicture::removeSettings( void )
-{
-#ifdef QGISDEBUG
-    std::cerr << "QgsComposerPicture::deleteSettings" << std::endl;
-#endif
-
-    QString path;
-    path.sprintf("/composition_%d/picture_%d", mComposition->id(), mId ); 
-    return QgsProject::instance()->removeEntry ( "Compositions", path );
-}
-
-bool QgsComposerPicture::writeXML( QDomNode & node, QDomDocument & document, bool temp )
-{
-    return true;
-}
-
-bool QgsComposerPicture::readXML( QDomNode & node )
-{
-    return true;
-}
-
-#endif //0

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.h	2008-08-12 23:24:50 UTC (rev 9054)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.h	2008-08-13 11:28:36 UTC (rev 9055)
@@ -17,139 +17,59 @@
 #ifndef QGSCOMPOSERPICTURE_H
 #define QGSCOMPOSERPICTURE_H
 
+#include "qgscomposeritem.h"
+#include <QFile>
+#include <QImage>
 
-#if 0
+/**A composer class that displays svg files or raster format (jpg, png, ...)*/
+class QgsComposerPicture: public QgsComposerItem
+{
+ public:
+  QgsComposerPicture(QgsComposition *composition);
+  ~QgsComposerPicture();
 
-#include "ui_qgscomposerpicturebase.h"
-#include "qgscomposeritem.h"
-#include <QAbstractGraphicsShapeItem>
-#include <QPen>
-#include <QPicture>
-#include <QPolygonF>
-#include <QRect>
+  /**Reimplementation of QCanvasItem::paint*/
+  void paint (QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget);
 
-class QgsComposition;
-class QDomNode;
-class QDomDocument;
-class QPainter;
+  /**Sets the source file of the image (may be svg or a raster format)*/
+  void setPictureFile(const QString& path);
 
-/** \class QgsComposerPicture 
- *  \brief Object representing map window. 
- */
-// NOTE: QgsComposerPictureBase must be first, otherwise does not compile
-//                                public QCanvasRectangle, 
-class QgsComposerPicture : public QWidget, private Ui::QgsComposerPictureBase, public QgsComposerItem
-{
-    Q_OBJECT
+  /**Sets this items bound in scene coordinates such that 1 item size units
+     corresponds to 1 scene size unit*/
+  void setSceneRect(const QRectF& rectangle);
 
-public:
-    /** \brief Constructor  
-     *  \param id object id
+  /** stores state in DOM node
+     * @param node is DOM node corresponding to 'Composer' tag
+     * @param temp write template file
      */
-    QgsComposerPicture( QgsComposition *composition, int id, QString file );
+    bool writeXML(QDomElement& elem, QDomDocument & doc);
 
-    /** \brief Constructor. Settings are read from project. 
-     *  \param id object id
+   /** sets state from DOM document
+     * @param itemElem is DOM node corresponding to item tag
      */
-    QgsComposerPicture( QgsComposition *composition, int id );
-    ~QgsComposerPicture();
+    bool readXML(const QDomElement& itemElem, const QDomDocument& doc); 
 
-    /** \brief Initialise GUI etc., shared by constructors. */
-    void init(void);
+ private:
 
-    // Reimplement QgsComposerItem:
-    void setSelected( bool s );
-    bool selected( void );
-    QWidget *options ( void );
-    bool writeSettings ( void );
-    bool readSettings ( void );
-    bool removeSettings ( void );
-    bool writeXML( QDomNode & node, QDomDocument & document, bool temp = false );
-    bool readXML( QDomNode & node );
+  enum Mode //SVG or raster graphic format
+    {
+      SVG,
+      RASTER,
+      UNKNOWN
+    };
 
-    QPolygonF areaPoints() const;
+  //default constructor is forbidden
+  QgsComposerPicture();
+  /**Updates content of current image using svg generator*/
+  void updateImageFromSvg();
 
-    /** \brief Reimplementation of QCanvasItem::paint - draw on canvas */
-    void paint ( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
-    
-    /** \brief Set values in GUI to current values */
-    void setOptions ( void );
-
-    /** \brief returns TRUE if picture is valid / loaded */
-    bool pictureValid();
-
-    void setSize(double width, double height);
-
-    // Set box, picture will be inside box, used when placed by mouse.
-    // Coordinates do not need to be oriented
-    void resize(double dx, double dy);
-
-    // Picture dialog, returns file name or empty string
-    static QString pictureDialog ( void );    
-
-public slots:
-    // Called when picture file is changed in edit line
-    void on_mPictureLineEdit_editingFinished ( void );
-
-    // Select new picture in dialog box
-    void on_mPictureBrowseButton_clicked ( void );
-
-    // Frame settings changed
-    void on_mFrameCheckBox_stateChanged ( int );
-
-    // Angle changed
-    void on_mAngleLineEdit_editingFinished ( void );
-
-    // Width changed
-    void on_mWidthLineEdit_editingFinished ( void );
-
-private:
-    // Pointer to composition
-    QgsComposition *mComposition;
-
-    // Picture name
-    QString mPicturePath;
-
-    // Picture
-    QPicture mPicture;
-
-    bool mPictureValid;
-
-    // Coordinates of picture center
-    int mCX, mCY;
-
-    // Coordinates of upper left picture corner
-    int mX, mY;
-
-    // Picture width and height in scene units
-    double mWidth, mHeight;
-
-    // Scale, number of canvas units / image unit
-
-    // Rotation in degrees counter clockwise
-    double mAngle;
-
-    /** \brief Draw frame  */
-    bool mFrame;
-
-    // Frame pen
-    QPen  mPen;
-
-    // Load mPicturePath picture
-    void loadPicture();
-    
-    /** \brief Calculate size according to current settings */
-    void recalculate ( void );
-
-    QPolygonF mAreaPoints;
-
-    // Called when picture file is changed
-    void pictureChanged ( void );
-
-    // Adjust size so that picture fits to current box
-    void adjustPictureSize();
+  QImage mImage;
+  double mRotation;
+  QFile mSourceFile;
+  Mode mMode;
+  /**False if image needs to be rendered from svg*/
+  bool mSvgCacheUpToDate;
+  int mCachedDpi; //store dpis for which the svg cache is valid
 };
 
-#endif //0
-
 #endif

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerview.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerview.cpp	2008-08-12 23:24:50 UTC (rev 9054)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerview.cpp	2008-08-13 11:28:36 UTC (rev 9055)
@@ -23,6 +23,7 @@
 #include "qgscomposerlegend.h"
 #include "qgscomposermap.h"
 #include "qgscomposeritemgroup.h"
+#include "qgscomposerpicture.h"
 #include "qgscomposerscalebar.h"
 
 QgsComposerView::QgsComposerView( QWidget* parent, const char* name, Qt::WFlags f) :
@@ -140,6 +141,16 @@
       emit selectedItemChanged(newLegend);
       break;
     }
+  case AddPicture:
+    {
+      QgsComposerPicture* newPicture = new QgsComposerPicture(composition());
+      scene()->addItem(newPicture);
+      scene()->clearSelection();
+      newPicture->setZValue(60);
+      newPicture->setSceneRect(QRectF(scenePoint.x(), scenePoint.y(), 30, 30));
+      newPicture->setSelected(true);
+      emit selectedItemChanged(newPicture);
+    }
 
   default:
     break;

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposition.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposition.cpp	2008-08-12 23:24:50 UTC (rev 9054)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposition.cpp	2008-08-13 11:28:36 UTC (rev 9055)
@@ -20,7 +20,6 @@
 #include <QDomDocument>
 #include <QDomElement>
 #include <QGraphicsRectItem>
-#include <QPrinter> //to find out screen resolution
 
 QgsComposition::QgsComposition(QgsMapCanvas* mapCanvas): QGraphicsScene(0), mMapCanvas(mapCanvas), mPlotStyle(QgsComposition::Preview), mPaperItem(0)
 {
@@ -31,9 +30,7 @@
   mPaperItem->setBrush(Qt::white);
   addItem(mPaperItem);
   mPaperItem->setZValue(0);
-
-  QPrinter resolutionTest(QPrinter::ScreenResolution);
-  mPrintoutResolution = resolutionTest.resolution();
+  mPrintoutResolution = 300; //hardcoded default
 }
 
 QgsComposition::QgsComposition(): QGraphicsScene(0), mMapCanvas(0), mPlotStyle(QgsComposition::Preview), mPaperItem(0)

Modified: branches/advanced_printing_branch/src/ui/qgscomposerpicturebase.ui
===================================================================
--- branches/advanced_printing_branch/src/ui/qgscomposerpicturebase.ui	2008-08-12 23:24:50 UTC (rev 9054)
+++ branches/advanced_printing_branch/src/ui/qgscomposerpicturebase.ui	2008-08-13 11:28:36 UTC (rev 9055)
@@ -1,6 +1,6 @@
 <ui version="4.0" >
- <class>QgsComposerPictureBase</class>
- <widget class="QWidget" name="QgsComposerPictureBase" >
+ <class>QgsComposerPictureWidgetBase</class>
+ <widget class="QWidget" name="QgsComposerPictureWidgetBase" >
   <property name="geometry" >
    <rect>
     <x>0</x>
@@ -10,9 +10,7 @@
    </rect>
   </property>
   <property name="sizePolicy" >
-   <sizepolicy>
-    <hsizetype>7</hsizetype>
-    <vsizetype>7</vsizetype>
+   <sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
     <horstretch>0</horstretch>
     <verstretch>0</verstretch>
    </sizepolicy>
@@ -20,30 +18,31 @@
   <property name="windowTitle" >
    <string>Picture Options</string>
   </property>
-  <layout class="QVBoxLayout" >
-   <property name="margin" >
-    <number>9</number>
-   </property>
-   <property name="spacing" >
-    <number>6</number>
-   </property>
-   <item>
+  <layout class="QGridLayout" >
+   <item row="0" column="0" >
     <layout class="QHBoxLayout" >
-     <property name="margin" >
-      <number>0</number>
-     </property>
      <property name="spacing" >
       <number>6</number>
      </property>
+     <property name="leftMargin" >
+      <number>0</number>
+     </property>
+     <property name="topMargin" >
+      <number>0</number>
+     </property>
+     <property name="rightMargin" >
+      <number>0</number>
+     </property>
+     <property name="bottomMargin" >
+      <number>0</number>
+     </property>
      <item>
       <widget class="QLineEdit" name="mPictureLineEdit" />
      </item>
      <item>
       <widget class="QPushButton" name="mPictureBrowseButton" >
        <property name="sizePolicy" >
-        <sizepolicy>
-         <hsizetype>5</hsizetype>
-         <vsizetype>5</vsizetype>
+        <sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
          <horstretch>0</horstretch>
          <verstretch>0</verstretch>
         </sizepolicy>
@@ -55,62 +54,18 @@
         </size>
        </property>
        <property name="text" >
-        <string>Browse</string>
+        <string>Browse...</string>
        </property>
       </widget>
      </item>
     </layout>
    </item>
-   <item>
+   <item row="1" column="0" >
     <layout class="QGridLayout" >
-     <property name="margin" >
-      <number>0</number>
-     </property>
-     <property name="spacing" >
-      <number>6</number>
-     </property>
-     <item row="0" column="1" >
-      <widget class="QLineEdit" name="mWidthLineEdit" >
-       <property name="sizePolicy" >
-        <sizepolicy>
-         <hsizetype>7</hsizetype>
-         <vsizetype>5</vsizetype>
-         <horstretch>0</horstretch>
-         <verstretch>0</verstretch>
-        </sizepolicy>
-       </property>
-       <property name="maximumSize" >
-        <size>
-         <width>32767</width>
-         <height>32767</height>
-        </size>
-       </property>
-      </widget>
-     </item>
-     <item row="2" column="1" >
-      <widget class="QLineEdit" name="mAngleLineEdit" >
-       <property name="sizePolicy" >
-        <sizepolicy>
-         <hsizetype>7</hsizetype>
-         <vsizetype>5</vsizetype>
-         <horstretch>0</horstretch>
-         <verstretch>0</verstretch>
-        </sizepolicy>
-       </property>
-       <property name="maximumSize" >
-        <size>
-         <width>32767</width>
-         <height>32767</height>
-        </size>
-       </property>
-      </widget>
-     </item>
      <item row="0" column="0" >
       <widget class="QLabel" name="textLabel3" >
        <property name="sizePolicy" >
-        <sizepolicy>
-         <hsizetype>1</hsizetype>
-         <vsizetype>5</vsizetype>
+        <sizepolicy vsizetype="Preferred" hsizetype="Minimum" >
          <horstretch>0</horstretch>
          <verstretch>0</verstretch>
         </sizepolicy>
@@ -121,17 +76,15 @@
        <property name="wordWrap" >
         <bool>true</bool>
        </property>
-       <property name="buddy" >
-        <cstring>mWidthLineEdit</cstring>
-       </property>
       </widget>
      </item>
+     <item row="0" column="1" >
+      <widget class="QDoubleSpinBox" name="mWidthSpinBox" />
+     </item>
      <item row="1" column="0" >
       <widget class="QLabel" name="textLabel4" >
        <property name="sizePolicy" >
-        <sizepolicy>
-         <hsizetype>1</hsizetype>
-         <vsizetype>5</vsizetype>
+        <sizepolicy vsizetype="Preferred" hsizetype="Minimum" >
          <horstretch>0</horstretch>
          <verstretch>0</verstretch>
         </sizepolicy>
@@ -142,63 +95,40 @@
        <property name="wordWrap" >
         <bool>true</bool>
        </property>
-       <property name="buddy" >
-        <cstring>mHeightLineEdit</cstring>
-       </property>
       </widget>
      </item>
+     <item row="1" column="1" >
+      <widget class="QDoubleSpinBox" name="mHeightSpinBox" />
+     </item>
      <item row="2" column="0" >
-      <widget class="QLabel" name="textLabel1" >
+      <widget class="QLabel" name="mRotationLabel" >
        <property name="sizePolicy" >
-        <sizepolicy>
-         <hsizetype>1</hsizetype>
-         <vsizetype>5</vsizetype>
+        <sizepolicy vsizetype="Preferred" hsizetype="Minimum" >
          <horstretch>0</horstretch>
          <verstretch>0</verstretch>
         </sizepolicy>
        </property>
        <property name="text" >
-        <string>Angle</string>
+        <string>Rotation</string>
        </property>
        <property name="wordWrap" >
         <bool>true</bool>
        </property>
-       <property name="buddy" >
-        <cstring>mAngleLineEdit</cstring>
-       </property>
       </widget>
      </item>
-     <item row="1" column="1" >
-      <widget class="QLineEdit" name="mHeightLineEdit" >
-       <property name="enabled" >
-        <bool>false</bool>
-       </property>
-       <property name="sizePolicy" >
-        <sizepolicy>
-         <hsizetype>7</hsizetype>
-         <vsizetype>0</vsizetype>
-         <horstretch>0</horstretch>
-         <verstretch>0</verstretch>
-        </sizepolicy>
-       </property>
-       <property name="maximumSize" >
-        <size>
-         <width>32767</width>
-         <height>32767</height>
-        </size>
-       </property>
-      </widget>
+     <item row="2" column="1" >
+      <widget class="QDoubleSpinBox" name="mRotationSpinBox" />
      </item>
     </layout>
    </item>
-   <item>
+   <item row="2" column="0" >
     <widget class="QCheckBox" name="mFrameCheckBox" >
      <property name="text" >
       <string>Frame</string>
      </property>
     </widget>
    </item>
-   <item>
+   <item row="3" column="0" >
     <spacer>
      <property name="orientation" >
       <enum>Qt::Vertical</enum>
@@ -220,9 +150,6 @@
  <tabstops>
   <tabstop>mPictureBrowseButton</tabstop>
   <tabstop>mPictureLineEdit</tabstop>
-  <tabstop>mWidthLineEdit</tabstop>
-  <tabstop>mHeightLineEdit</tabstop>
-  <tabstop>mAngleLineEdit</tabstop>
   <tabstop>mFrameCheckBox</tabstop>
  </tabstops>
  <resources/>



More information about the QGIS-commit mailing list