[QGIS Commit] r8492 -
branches/advanced_printing_branch/src/app/composer
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Thu May 22 04:33:54 EDT 2008
Author: mhugent
Date: 2008-05-22 04:33:53 -0400 (Thu, 22 May 2008)
New Revision: 8492
Modified:
branches/advanced_printing_branch/src/app/composer/qgscomposeritem.cpp
branches/advanced_printing_branch/src/app/composer/qgscomposeritem.h
branches/advanced_printing_branch/src/app/composer/qgscomposerlabel.cpp
branches/advanced_printing_branch/src/app/composer/qgscomposerlabel.h
branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp
branches/advanced_printing_branch/src/app/composer/qgscomposermap.h
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/qgscomposerscalebar.cpp
branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.h
branches/advanced_printing_branch/src/app/composer/qgscomposervectorlegend.cpp
branches/advanced_printing_branch/src/app/composer/qgscomposervectorlegend.h
branches/advanced_printing_branch/src/app/composer/qgscomposerview.cpp
branches/advanced_printing_branch/src/app/composer/qgscomposition.cpp
branches/advanced_printing_branch/src/app/composer/qgscomposition.h
Log:
Derive QgsComposerItem from QGraphicsRectItem to later handle mouse events directly in item classes. Draw hand cursor if an item is to be moved
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposeritem.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposeritem.cpp 2008-05-21 21:09:37 UTC (rev 8491)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposeritem.cpp 2008-05-22 08:33:53 UTC (rev 8492)
@@ -16,18 +16,25 @@
***************************************************************************/
#include <QWidget>
#include <QDomNode>
+#include <QGraphicsSceneMouseEvent>
#include "qgscomposition.h"
#include "qgscomposeritem.h"
#include <iostream>
-QgsComposerItem::QgsComposerItem(void)
+QgsComposerItem::QgsComposerItem(QGraphicsItem* parent): QGraphicsRectItem(0)
{
mSelected = false;
mPlotStyle = QgsComposition::Preview;
}
+QgsComposerItem::QgsComposerItem(qreal x, qreal y, qreal width, qreal height, QGraphicsItem* parent): QGraphicsRectItem(x, y, width, height, parent)
+{
+ mSelected = false;
+ mPlotStyle = QgsComposition::Preview;
+}
+
QgsComposerItem::~QgsComposerItem()
{
}
@@ -59,3 +66,25 @@
bool QgsComposerItem::writeXML( QDomNode & node, QDomDocument & doc, bool templ ) { return true; }
bool QgsComposerItem::readXML( QDomNode & node ) { return true; }
+
+void QgsComposerItem::mouseMoveEvent ( QGraphicsSceneMouseEvent * event )
+{
+ qWarning("QgsComposerItem::mouseMoveEvent");
+}
+
+void QgsComposerItem::mousePressEvent ( QGraphicsSceneMouseEvent * event )
+{
+ qWarning("QgsComposerItem::mousePressEvent");
+ setCursor(QCursor(evaluateCursor(event->pos())));
+}
+
+void QgsComposerItem::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
+{
+ qWarning("QgsComposerItem::mouseReleseEvent");
+ setCursor(Qt::ArrowCursor);
+}
+
+Qt::CursorShape QgsComposerItem::evaluateCursor(const QPointF& itemCoordPos)
+{
+ return Qt::ClosedHandCursor;
+}
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposeritem.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposeritem.h 2008-05-21 21:09:37 UTC (rev 8491)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposeritem.h 2008-05-22 08:33:53 UTC (rev 8492)
@@ -18,6 +18,7 @@
#define QGSCOMPOSERITEM_H
#include "qgscomposition.h"
+#include <QGraphicsRectItem>
class QWidget;
class QDomNode;
@@ -25,11 +26,12 @@
class QqsComposition;
-class QgsComposerItem
+class QgsComposerItem: public QGraphicsRectItem
{
public:
- QgsComposerItem();
+ QgsComposerItem(QGraphicsItem* parent = 0);
+ QgsComposerItem(qreal x, qreal y, qreal width, qreal height,QGraphicsItem* parent = 0);
virtual ~QgsComposerItem();
public:
/** \brief Set plot style */
@@ -62,7 +64,7 @@
virtual bool readSettings ( void );
/** delete settings from project file */
- virtual bool removeSettings( void );
+ virtual bool removeSettings( void );
/** stores state in DOM node
* @param node is DOM node corresponding to '???' tag
@@ -80,6 +82,14 @@
bool mSelected;
int mId;
+ //event handlers
+ virtual void mouseMoveEvent ( QGraphicsSceneMouseEvent * event );
+ virtual void mousePressEvent ( QGraphicsSceneMouseEvent * event );
+ virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event );
+
+ /**Finds out the appropriate cursor for the current mouse position in the widget (e.g. move in the middle, resize at border)*/
+ Qt::CursorShape evaluateCursor(const QPointF& itemCoordPos);
+
private:
};
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerlabel.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerlabel.cpp 2008-05-21 21:09:37 UTC (rev 8491)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerlabel.cpp 2008-05-22 08:33:53 UTC (rev 8492)
@@ -18,7 +18,6 @@
#include "qgsproject.h"
#include <QGraphicsScene>
-#include <QAbstractGraphicsShapeItem>
#include <QPolygonF>
#include <QFontDialog>
#include <QPainter>
@@ -27,7 +26,7 @@
QgsComposerLabel::QgsComposerLabel ( QgsComposition *composition, int id,
int x, int y, QString text, int fontSize )
- : QWidget(composition), QAbstractGraphicsShapeItem(0), mBox(false)
+ : QWidget(composition), QgsComposerItem(0), mBox(false)
{
setupUi(this);
@@ -47,7 +46,7 @@
// Could make this user variable in the future
mPen.setWidthF (0.5);
- QAbstractGraphicsShapeItem::setPos(x, y);
+ QGraphicsRectItem::setPos(x, y);
mSelected = false;
@@ -56,15 +55,15 @@
// Add to canvas
mComposition->canvas()->addItem(this);
- QAbstractGraphicsShapeItem::setZValue(100);
- QAbstractGraphicsShapeItem::show();
- QAbstractGraphicsShapeItem::update();
+ QGraphicsRectItem::setZValue(100);
+ QGraphicsRectItem::show();
+ QGraphicsRectItem::update();
writeSettings();
}
QgsComposerLabel::QgsComposerLabel ( QgsComposition *composition, int id )
- : QAbstractGraphicsShapeItem(0)
+ : QgsComposerItem(0)
{
#ifdef QGISDEBUG
std::cout << "QgsComposerLabel::QgsComposerLabel()" << std::endl;
@@ -82,9 +81,9 @@
// Add to canvas
mComposition->canvas()->addItem(this);
- QAbstractGraphicsShapeItem::setZValue(100);
- QAbstractGraphicsShapeItem::show();
- QAbstractGraphicsShapeItem::update();
+ QGraphicsRectItem::setZValue(100);
+ QGraphicsRectItem::show();
+ QGraphicsRectItem::update();
}
@@ -181,29 +180,64 @@
{
bool result;
- QRectF r = boundingRect();
-
mFont = QFontDialog::getFont(&result, mFont, this );
if ( result ) {
- QAbstractGraphicsShapeItem::prepareGeometryChange();
- QAbstractGraphicsShapeItem::update();
+ QGraphicsRectItem::prepareGeometryChange();
+ QGraphicsRectItem::update();
}
+
+ setRect(calculateBoundingRect());
writeSettings();
}
void QgsComposerLabel::on_mBoxCheckBox_clicked()
+{
+ mBox = mBoxCheckBox->isChecked();
+
+ QGraphicsRectItem::prepareGeometryChange();
+ QGraphicsRectItem::update();
+ writeSettings();
+}
+
+QPolygonF QgsComposerLabel::areaPoints() const
{
+#ifdef QGISDEBUG
+ std::cout << "QgsComposerLabel::areaPoints" << std::endl;
+#endif
QRectF r = boundingRect();
+
+ QPolygonF pa;
+ pa << QPointF( r.x(), r.y() );
+ pa << QPointF( r.x()+r.width(), r.y() );
+ pa << QPointF( r.x()+r.width(), r.y()+r.height() );
+ pa << QPointF( r.x(), r.y()+r.height() );
+
+ return pa ;
+}
+
+void QgsComposerLabel::setOptions ( void )
+{
+ mTextEdit->setText ( mText );
+ mBoxCheckBox->setChecked ( mBox );
- mBox = mBoxCheckBox->isChecked();
+}
- QAbstractGraphicsShapeItem::prepareGeometryChange();
- QAbstractGraphicsShapeItem::update();
+void QgsComposerLabel::on_mTextEdit_textChanged()
+{
+#if QT_VERSION < 0x040300
+ mText = mTextEdit->text();
+#else
+ mText = mTextEdit->toPlainText();
+#endif
+
+ setRect(calculateBoundingRect());
+ QGraphicsRectItem::prepareGeometryChange();
+ QGraphicsRectItem::update();
writeSettings();
}
-QRectF QgsComposerLabel::boundingRect ( void ) const
+QRectF QgsComposerLabel::calculateBoundingRect ( void ) const
{
// Recalculate sizes according to current font size
@@ -241,42 +275,6 @@
}
-QPolygonF QgsComposerLabel::areaPoints() const
-{
-#ifdef QGISDEBUG
- std::cout << "QgsComposerLabel::areaPoints" << std::endl;
-#endif
- QRectF r = boundingRect();
-
- QPolygonF pa;
- pa << QPointF( r.x(), r.y() );
- pa << QPointF( r.x()+r.width(), r.y() );
- pa << QPointF( r.x()+r.width(), r.y()+r.height() );
- pa << QPointF( r.x(), r.y()+r.height() );
-
- return pa ;
-}
-
-void QgsComposerLabel::setOptions ( void )
-{
- mTextEdit->setText ( mText );
- mBoxCheckBox->setChecked ( mBox );
-
-}
-
-void QgsComposerLabel::on_mTextEdit_textChanged()
-{
- QRectF r = boundingRect();
-#if QT_VERSION < 0x040300
- mText = mTextEdit->text();
-#else
- mText = mTextEdit->toPlainText();
-#endif
- QAbstractGraphicsShapeItem::prepareGeometryChange();
- QAbstractGraphicsShapeItem::update();
- writeSettings();
-}
-
void QgsComposerLabel::setSelected ( bool s )
{
#ifdef QGISDEBUG
@@ -284,7 +282,7 @@
#endif
mSelected = s;
- QAbstractGraphicsShapeItem::update(); // show highlight
+ QGraphicsRectItem::update(); // show highlight
}
bool QgsComposerLabel::selected( void )
@@ -305,8 +303,8 @@
QgsProject::instance()->writeEntry( "Compositions", path+"text", mText );
- QgsProject::instance()->writeEntry( "Compositions", path+"x", mComposition->toMM((int)QAbstractGraphicsShapeItem::x()) );
- QgsProject::instance()->writeEntry( "Compositions", path+"y", mComposition->toMM((int)QAbstractGraphicsShapeItem::y()) );
+ QgsProject::instance()->writeEntry( "Compositions", path+"x", mComposition->toMM((int)QGraphicsRectItem::x()) );
+ QgsProject::instance()->writeEntry( "Compositions", path+"y", mComposition->toMM((int)QGraphicsRectItem::y()) );
QgsProject::instance()->writeEntry( "Compositions", path+"font/size", mFont.pointSize() );
QgsProject::instance()->writeEntry( "Compositions", path+"font/family", mFont.family() );
@@ -331,7 +329,7 @@
int x = mComposition->fromMM( QgsProject::instance()->readDoubleEntry( "Compositions", path+"x", 0, &ok) );
int y = mComposition->fromMM(QgsProject::instance()->readDoubleEntry( "Compositions", path+"y", 0, &ok) );
- QAbstractGraphicsShapeItem::setPos(x,y);
+ QGraphicsRectItem::setPos(x,y);
mFont.setFamily ( QgsProject::instance()->readEntry("Compositions", path+"font/family", "", &ok) );
mFont.setPointSize ( QgsProject::instance()->readNumEntry("Compositions", path+"font/size", 10, &ok) );
@@ -341,7 +339,7 @@
mBox = QgsProject::instance()->readBoolEntry("Compositions", path+"box", false, &ok);
- QAbstractGraphicsShapeItem::update();
+ QGraphicsRectItem::update();
return true;
}
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerlabel.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerlabel.h 2008-05-21 21:09:37 UTC (rev 8491)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerlabel.h 2008-05-22 08:33:53 UTC (rev 8492)
@@ -35,7 +35,7 @@
*/
// NOTE: QgsComposerLabelBase must be first, otherwise does not compile
//class QgsComposerLabel : public QgsComposerLabelBase, public QCanvasRectangle, public QgsComposerItem
-class QgsComposerLabel : public QWidget, private Ui::QgsComposerLabelBase, public QAbstractGraphicsShapeItem, public QgsComposerItem
+class QgsComposerLabel : public QWidget, private Ui::QgsComposerLabelBase, public QgsComposerItem
{
Q_OBJECT
@@ -62,13 +62,13 @@
bool removeSettings ( void );
bool writeXML( QDomNode & node, QDomDocument & document, bool temp = false );
bool readXML( QDomNode & node );
-
- QRectF boundingRect ( void ) const; //errors about overriding things?
/** \brief Reimplementation of QGraphicsItem::paint() - draw on canvas */
void paint ( QPainter*, const QStyleOptionGraphicsItem*, QWidget* );
QPolygonF areaPoints() const;
+
+ QRectF calculateBoundingRect ( void ) const;
/** \brief Set values in GUI to current values */
void setOptions ( void );
@@ -100,10 +100,6 @@
// Margin in box
int mMargin;
- // Current bounding box
- // Not used - would it be more effecient if paint() updated the bounding box, and boundingRect returned this?
- //QRect mBoundingRect;
-
// Draw box around the label
bool mBox;
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp 2008-05-21 21:09:37 UTC (rev 8491)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp 2008-05-22 08:33:53 UTC (rev 8492)
@@ -31,7 +31,6 @@
#include "qgslabelattributes.h"
#include <QGraphicsScene>
-#include <QGraphicsRectItem>
#include <QPainter>
#include <iostream>
#include <cmath>
@@ -42,13 +41,15 @@
#endif
QgsComposerMap::QgsComposerMap ( QgsComposition *composition, int id, int x, int y, int width, int height )
- : QWidget(), QGraphicsRectItem(0,0,width,height,0)
+ : QWidget(), QgsComposerItem(0,0,width,height,0)
{
#ifdef QGISDEBUG
std::cout << "QgsComposerMap::QgsComposerMap()" << std::endl;
#endif
setupUi(this);
+ setAcceptsHoverEvents(true);
+
mComposition = composition;
mId = id;
mMapCanvas = mComposition->mapCanvas();
@@ -67,10 +68,12 @@
}
QgsComposerMap::QgsComposerMap ( QgsComposition *composition, int id )
- : QGraphicsRectItem(0,0,10,10,0)
+ : QgsComposerItem(0,0,10,10,0)
{
setupUi(this);
+ setAcceptsHoverEvents(true);
+
mComposition = composition;
mId = id;
mMapCanvas = mComposition->mapCanvas();
@@ -553,6 +556,7 @@
void QgsComposerMap::setSelected ( bool s )
{
mSelected = s;
+ QGraphicsRectItem::setSelected(s);
QGraphicsRectItem::update(); //re-paint, so we show the highlight boxes
}
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposermap.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposermap.h 2008-05-21 21:09:37 UTC (rev 8491)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposermap.h 2008-05-22 08:33:53 UTC (rev 8492)
@@ -34,7 +34,7 @@
* \brief Object representing map window.
*/
// NOTE: QgsComposerMapBase must be first, otherwise does not compile
-class QgsComposerMap : public QWidget, private Ui::QgsComposerMapBase, public QGraphicsRectItem, public QgsComposerItem
+class QgsComposerMap : public QWidget, private Ui::QgsComposerMapBase, public QgsComposerItem
{
Q_OBJECT
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.cpp 2008-05-21 21:09:37 UTC (rev 8491)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.cpp 2008-05-22 08:33:53 UTC (rev 8492)
@@ -25,7 +25,6 @@
#include <QImageWriter>
#include <QSettings>
#include <QPolygonF>
-#include <QAbstractGraphicsShapeItem>
#include <QGraphicsScene>
#include <cmath>
@@ -34,16 +33,15 @@
#define PI 3.14159265358979323846
QgsComposerPicture::QgsComposerPicture ( QgsComposition *composition,
- int id, QString file )
+ int id, QString file )
: QWidget(composition),
- QAbstractGraphicsShapeItem(0),
+ QgsComposerItem(0),
mPicturePath ( file ),
mPictureValid(false),
mCX(-10), mCY(-10),
mWidth(0), mHeight(0), mAngle(0),
mFrame(false),
- mAreaPoints(4),
- mBoundingRect(0,0,0,0)
+ mAreaPoints(4)
{
setupUi(this);
@@ -51,6 +49,8 @@
std::cout << "QgsComposerPicture::QgsComposerPicture()" << std::endl;
#endif
+ setRect(QRectF(0,0,0,0));
+
mComposition = composition;
mId = id;
@@ -68,14 +68,14 @@
QgsComposerPicture::QgsComposerPicture ( QgsComposition *composition, int id ) :
QWidget(),
- QAbstractGraphicsShapeItem(0),
+ QgsComposerItem(0),
mFrame(false),
- mAreaPoints(4),
- mBoundingRect(0,0,0,0)
+ mAreaPoints(4)
{
#ifdef QGISDEBUG
std::cout << "QgsComposerPicture::QgsComposerPicture()" << std::endl;
#endif
+ setRect(QRectF(0, 0, 0, 0));
setupUi(this);
@@ -301,20 +301,12 @@
mAreaPoints[1] = QPointF( dx, -dy ); //top right
mAreaPoints[3] = QPointF( -dx, dy ); //bottom left
- mBoundingRect = mAreaPoints.boundingRect();
+ setRect(mAreaPoints.boundingRect());
QAbstractGraphicsShapeItem::update();
QAbstractGraphicsShapeItem::scene()->update();
}
-QRectF QgsComposerPicture::boundingRect ( void ) const
-{
-#ifdef QGISDEBUG
- std::cout << "QgsComposerPicture::boundingRect" << std::endl;
-#endif
- return mBoundingRect;
-}
-
QPolygonF QgsComposerPicture::areaPoints() const
{
#ifdef QGISDEBUG
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.h 2008-05-21 21:09:37 UTC (rev 8491)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.h 2008-05-22 08:33:53 UTC (rev 8492)
@@ -35,8 +35,7 @@
*/
// NOTE: QgsComposerPictureBase must be first, otherwise does not compile
// public QCanvasRectangle,
-class QgsComposerPicture : public QWidget, private Ui::QgsComposerPictureBase,
- public QAbstractGraphicsShapeItem, public QgsComposerItem
+class QgsComposerPicture : public QWidget, private Ui::QgsComposerPictureBase, public QgsComposerItem
{
Q_OBJECT
@@ -65,10 +64,6 @@
bool writeXML( QDomNode & node, QDomDocument & document, bool temp = false );
bool readXML( QDomNode & node );
-
- // Reimplement QCanvasItem::boundingRect
- QRectF boundingRect ( void ) const;
-
QPolygonF areaPoints() const;
/** \brief Reimplementation of QCanvasItem::paint - draw on canvas */
@@ -146,9 +141,6 @@
// Called when picture file is changed
void pictureChanged ( void );
- // Current bounding box
- QRectF mBoundingRect;
-
// Adjust size so that picture fits to current box
void adjustPictureSize();
};
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.cpp 2008-05-21 21:09:37 UTC (rev 8491)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.cpp 2008-05-22 08:33:53 UTC (rev 8492)
@@ -29,7 +29,7 @@
QgsComposerScalebar::QgsComposerScalebar ( QgsComposition *composition, int id,
int x, int y )
: QWidget(composition),
- QAbstractGraphicsShapeItem(0),
+ QgsComposerItem(0),
mComposition(composition),
mMap(0),
mBrush(QColor(150,150,150))
@@ -45,7 +45,7 @@
mMapCanvas = mComposition->mapCanvas();
- QAbstractGraphicsShapeItem::setPos(x, y);
+ QGraphicsRectItem::setPos(x, y);
init();
@@ -111,14 +111,14 @@
// Add to scene
mComposition->canvas()->addItem(this);
- QAbstractGraphicsShapeItem::show();
- QAbstractGraphicsShapeItem::update();
+ QGraphicsRectItem::show();
+ QGraphicsRectItem::update();
writeSettings();
}
QgsComposerScalebar::QgsComposerScalebar ( QgsComposition *composition, int id )
- : QAbstractGraphicsShapeItem(0),
+ : QgsComposerItem(0),
mComposition(composition),
mMap(0),
mBrush(QColor(150,150,150))
@@ -144,8 +144,8 @@
// Add to scene
mComposition->canvas()->addItem(this);
- QAbstractGraphicsShapeItem::show();
- QAbstractGraphicsShapeItem::update();
+ QGraphicsRectItem::show();
+ QGraphicsRectItem::update();
}
void QgsComposerScalebar::init(void)
@@ -153,7 +153,7 @@
mUnitLabel = "m";
// Rectangle
- QAbstractGraphicsShapeItem::setZValue(50);
+ QGraphicsRectItem::setZValue(50);
// setActive(true);
// Default value (map units?) for the scalebar border
@@ -168,7 +168,7 @@
QgsComposerScalebar::~QgsComposerScalebar()
{
std::cerr << "QgsComposerScalebar::~QgsComposerScalebar()" << std::endl;
- QGraphicsItem::hide();
+ QGraphicsRectItem::hide();
}
#define FONT_WORKAROUND_SCALE 10
@@ -306,7 +306,7 @@
#ifdef QGISDEBUG
std::cout << "draw mPlotStyle = " << plotStyle() << std::endl;
#endif
- mBoundingRect = render(painter);
+ setRect(render(painter));
// Show selected / Highlight
if (mSelected && plotStyle() == QgsComposition::Preview)
@@ -339,8 +339,8 @@
if (result)
{
recalculate();
- QAbstractGraphicsShapeItem::update();
- QAbstractGraphicsShapeItem::scene()->update();
+ QGraphicsRectItem::update();
+ QGraphicsRectItem::scene()->update();
writeSettings();
}
}
@@ -349,8 +349,8 @@
{
mUnitLabel = mUnitLabelLineEdit->text();
recalculate();
- QAbstractGraphicsShapeItem::update();
- QAbstractGraphicsShapeItem::scene()->update();
+ QGraphicsRectItem::update();
+ QGraphicsRectItem::scene()->update();
writeSettings();
}
@@ -358,8 +358,8 @@
{
mMap = mMaps[i];
recalculate();
- QAbstractGraphicsShapeItem::update();
- QAbstractGraphicsShapeItem::scene()->update();
+ QGraphicsRectItem::update();
+ QGraphicsRectItem::scene()->update();
writeSettings();
}
@@ -368,8 +368,8 @@
if (id != mMap)
return;
recalculate();
- QAbstractGraphicsShapeItem::update();
- QAbstractGraphicsShapeItem::scene()->update();
+ QGraphicsRectItem::update();
+ QGraphicsRectItem::scene()->update();
}
void QgsComposerScalebar::sizeChanged()
@@ -379,8 +379,8 @@
mPen.setWidthF(mLineWidthSpinBox->value());
mMapUnitsPerUnit = mMapUnitsPerUnitLineEdit->text().toInt();
recalculate();
- QAbstractGraphicsShapeItem::update();
- QAbstractGraphicsShapeItem::scene()->update();
+ QGraphicsRectItem::update();
+ QGraphicsRectItem::scene()->update();
writeSettings();
}
@@ -421,28 +421,20 @@
// !!! prepareGeometryChange() MUST BE called before the value returned by areaPoints() changes
//Is this still true after the port to GraphicsView?
- QAbstractGraphicsShapeItem::prepareGeometryChange();
+ QGraphicsRectItem::prepareGeometryChange();
- mBoundingRect = render(0);
+ setRect(render(0));
QGraphicsItem::update();
}
-QRectF QgsComposerScalebar::boundingRect(void) const
-{
-#ifdef QGISDEBUG
- std::cout << "QgsComposerScalebar::boundingRect" << std::endl;
-#endif
- return mBoundingRect;
-}
-
QPolygonF QgsComposerScalebar::areaPoints(void) const
{
#ifdef QGISDEBUG
std::cout << "QgsComposerScalebar::areaPoints" << std::endl;
#endif
- QRectF r = boundingRect();
+ QRectF r = QGraphicsRectItem::rect();
QPolygonF pa;
pa << QPointF(r.x(), r.y());
pa << QPointF(r.x() + r.width(), r.y());
@@ -491,7 +483,7 @@
void QgsComposerScalebar::setSelected(bool s)
{
mSelected = s;
- QAbstractGraphicsShapeItem::update(); // show highlight
+ QGraphicsRectItem::update(); // show highlight
}
bool QgsComposerScalebar::selected(void)
@@ -514,8 +506,8 @@
QString path;
path.sprintf("/composition_%d/scalebar_%d/", mComposition->id(), mId);
- QgsProject::instance()->writeEntry("Compositions", path + "x", mComposition->toMM((int) QAbstractGraphicsShapeItem::x()));
- QgsProject::instance()->writeEntry("Compositions", path + "y", mComposition->toMM((int) QAbstractGraphicsShapeItem::y()));
+ QgsProject::instance()->writeEntry("Compositions", path + "x", mComposition->toMM((int) QGraphicsRectItem::x()));
+ QgsProject::instance()->writeEntry("Compositions", path + "y", mComposition->toMM((int) QGraphicsRectItem::y()));
QgsProject::instance()->writeEntry("Compositions", path + "map", mMap);
@@ -544,7 +536,7 @@
double x = mComposition->fromMM(QgsProject::instance()->readDoubleEntry("Compositions", path + "x", 0, &ok));
double y = mComposition->fromMM(QgsProject::instance()->readDoubleEntry("Compositions", path + "y", 0, &ok));
- QAbstractGraphicsShapeItem::setPos(x, y);
+ QGraphicsRectItem::setPos(x, y);
mMap = QgsProject::instance()->readNumEntry("Compositions", path + "map", 0, &ok);
mUnitLabel = QgsProject::instance()->readEntry("Compositions", path + "unit/label", "???", &ok);
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.h 2008-05-21 21:09:37 UTC (rev 8491)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerscalebar.h 2008-05-22 08:33:53 UTC (rev 8492)
@@ -35,7 +35,7 @@
* \brief Object representing map window.
*/
// NOTE: QgsComposerScalebarBase must be first, otherwise does not compile
-class QgsComposerScalebar : public QWidget, private Ui::QgsComposerScalebarBase, public QAbstractGraphicsShapeItem, public QgsComposerItem
+class QgsComposerScalebar : public QWidget, private Ui::QgsComposerScalebarBase, public QgsComposerItem
{
Q_OBJECT
@@ -64,8 +64,6 @@
bool removeSettings ( void );
bool writeXML( QDomNode & node, QDomDocument & document, bool temp = false );
bool readXML( QDomNode & node );
-
- QRectF boundingRect ( void ) const;
/** \brief Draw to paint device, internal use
* \param painter painter or 0
@@ -120,9 +118,6 @@
// Vector of map id for maps in combobox
std::vector<int> mMaps;
- // Current bounding box
- QRectF mBoundingRect;
-
// Number of map units in scalebar unit
double mMapUnitsPerUnit;
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposervectorlegend.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposervectorlegend.cpp 2008-05-21 21:09:37 UTC (rev 8491)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposervectorlegend.cpp 2008-05-22 08:33:53 UTC (rev 8492)
@@ -38,7 +38,7 @@
QgsComposerVectorLegend::QgsComposerVectorLegend ( QgsComposition *composition, int id,
int x, int y, int fontSize )
- : QWidget(composition), QGraphicsRectItem(x,y,10,10,0)
+ : QWidget(composition), QgsComposerItem(x,y,10,10,0)
{
setupUi(this);
@@ -77,7 +77,7 @@
}
QgsComposerVectorLegend::QgsComposerVectorLegend ( QgsComposition *composition, int id )
- : QGraphicsRectItem(0,0,10,10,0)
+ : QgsComposerItem(0,0,10,10,0)
{
#ifdef QGISDEBUG
std::cout << "QgsComposerVectorLegend::QgsComposerVectorLegend()" << std::endl;
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposervectorlegend.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposervectorlegend.h 2008-05-21 21:09:37 UTC (rev 8491)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposervectorlegend.h 2008-05-22 08:33:53 UTC (rev 8492)
@@ -58,8 +58,7 @@
*/
// NOTE: QgsComposerVectorLegendBase must be first, otherwise does not compile
class QgsComposerVectorLegend : public QWidget,
- private Ui::QgsComposerVectorLegendBase,
- public QGraphicsRectItem,
+ private Ui::QgsComposerVectorLegendBase,
public QgsComposerItem
{
Q_OBJECT
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerview.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerview.cpp 2008-05-21 21:09:37 UTC (rev 8491)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerview.cpp 2008-05-22 08:33:53 UTC (rev 8492)
@@ -40,6 +40,8 @@
setFocusProxy ( 0 );
setResizeAnchor ( QGraphicsView::AnchorViewCenter );
+ setMouseTracking(true);
+ setInteractive(true);
}
@@ -48,16 +50,28 @@
// TODO: find how to get focus without setFocus
setFocus ();
mComposer->composition()->mousePressEvent(e);
+ if(mComposer->composition()->tool() == QgsComposition::Select)
+ {
+ QGraphicsView::mousePressEvent(e);
+ }
}
void QgsComposerView::mouseReleaseEvent(QMouseEvent* e)
{
mComposer->composition()->mouseReleaseEvent(e);
+ if(mComposer->composition()->tool() == QgsComposition::Select)
+ {
+ QGraphicsView::mouseReleaseEvent(e);
+ }
}
void QgsComposerView::mouseMoveEvent(QMouseEvent* e)
{
mComposer->composition()->mouseMoveEvent(e);
+ if(mComposer->composition()->tool() == QgsComposition::Select)
+ {
+ QGraphicsView::mouseMoveEvent(e);
+ }
}
void QgsComposerView::keyPressEvent ( QKeyEvent * e )
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposition.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposition.cpp 2008-05-21 21:09:37 UTC (rev 8491)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposition.cpp 2008-05-22 08:33:53 UTC (rev 8492)
@@ -386,6 +386,7 @@
void QgsComposition::mouseMoveEvent(QMouseEvent* e)
{
+
#ifdef QGISDEBUG
std::cerr << "QgsComposition::mouseMoveEvent() mTool = " << mTool << " mToolStep = "
<< mToolStep << std::endl;
@@ -481,14 +482,8 @@
m->setUserExtent( mMapCanvas->extent());
mItems.push_back(m);
- m->setSelected ( true );//do we need this twice?
-
- if ( mSelectedItem ) {
- QgsComposerItem *coi = dynamic_cast <QgsComposerItem *> (mSelectedItem);
- coi->setSelected ( false );
- }
-
m->setSelected ( true );
+
mComposer->showItemOptions ( m->options() );
mSelectedItem = dynamic_cast <QGraphicsItem *> (m);
} else {
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposition.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposition.h 2008-05-21 21:09:37 UTC (rev 8491)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposition.h 2008-05-22 08:33:53 UTC (rev 8492)
@@ -126,6 +126,9 @@
/** \brief Get resolutin */
int resolution ( void );
+ /**Get active tool*/
+ QgsComposition::Tool tool() const {return mTool;}
+
/** \brief Create default composition */
void createDefault ( void );
@@ -156,10 +159,10 @@
/** \brief recieves mouseReleaseEvent from view */
void mouseReleaseEvent(QMouseEvent*);
-
+
/** \brief recieves mouseMoveEvent from view */
void mouseMoveEvent(QMouseEvent*);
-
+
/** \brief recieves keyPressEvent from view */
void keyPressEvent ( QKeyEvent * e );
More information about the QGIS-commit
mailing list