[QGIS Commit] r8518 -
branches/advanced_printing_branch/src/app/composer
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Mon May 26 07:47:37 EDT 2008
Author: mhugent
Date: 2008-05-26 07:47:36 -0400 (Mon, 26 May 2008)
New Revision: 8518
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/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/qgscomposition.cpp
Log:
Handle selection on item class level
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposeritem.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposeritem.cpp 2008-05-26 00:02:29 UTC (rev 8517)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposeritem.cpp 2008-05-26 11:47:36 UTC (rev 8518)
@@ -18,6 +18,7 @@
#include <QDomNode>
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
+#include <QPainter>
#include "qgscomposition.h"
#include "qgscomposeritem.h"
@@ -26,16 +27,16 @@
QgsComposerItem::QgsComposerItem(QGraphicsItem* parent): QGraphicsRectItem(0), mBoundingResizeRectangle(0)
{
- mSelected = false;
mPlotStyle = QgsComposition::Preview;
setAcceptsHoverEvents(true);
+ setFlag(QGraphicsItem::ItemIsSelectable, true);
}
QgsComposerItem::QgsComposerItem(qreal x, qreal y, qreal width, qreal height, QGraphicsItem* parent): QGraphicsRectItem(x, y, width, height, parent), mBoundingResizeRectangle(0)
{
- mSelected = false;
mPlotStyle = QgsComposition::Preview;
setAcceptsHoverEvents(true);
+ setFlag(QGraphicsItem::ItemIsSelectable, true);
}
QgsComposerItem::~QgsComposerItem()
@@ -46,14 +47,14 @@
QgsComposition::PlotStyle QgsComposerItem::plotStyle ( void ) { return mPlotStyle; }
+
void QgsComposerItem::setSelected( bool s )
{
std::cout << "QgsComposerItem::setSelected" << std::endl;
- mSelected = s;
+ QGraphicsRectItem::setSelected(s);
+ update(); //to draw selection boxes
}
-bool QgsComposerItem::selected( void ) { return mSelected; }
-
int QgsComposerItem::id(void) { return mId; }
void QgsComposerItem::showOptions ( QWidget * parent ) { }
@@ -104,7 +105,7 @@
mBoundingResizeRectangle->moveBy(x(), y());
mBoundingResizeRectangle->setBrush( Qt::NoBrush );
mBoundingResizeRectangle->setPen( QPen(QColor(0,0,0), 0) );
- mBoundingResizeRectangle->setZValue(100);
+ mBoundingResizeRectangle->setZValue(90);
mBoundingResizeRectangle->show();
//QGraphicsRectItem::setVisible(false);
@@ -181,6 +182,10 @@
QgsComposerItem::mouseMoveAction QgsComposerItem::mouseMoveActionForPosition(const QPointF& itemCoordPos)
{
+
+ qWarning("mouseMoveAction: itemcoordpos: " );
+ qWarning(QString::number(itemCoordPos.x()).toLatin1());
+ qWarning(QString::number(itemCoordPos.y()).toLatin1());
bool nearLeftBorder = false;
bool nearRightBorder = false;
bool nearLowerBorder = false;
@@ -284,3 +289,27 @@
break;
}
}
+
+void QgsComposerItem::drawSelectionBoxes(QPainter* p)
+{
+ //p->setPen( mComposition->selectionPen() );
+ //p->setBrush( mComposition->selectionBrush() );
+ p->setPen(QPen(QColor(0, 0, 255)));
+
+ double s = 5;//mComposition->selectionBoxSize();
+
+ p->drawRect (QRectF(0, 0, s, s));
+ p->drawRect (QRectF(QGraphicsRectItem::rect().width() -s, 0, s, s));
+ p->drawRect (QRectF(QGraphicsRectItem::rect().width() -s, QGraphicsRectItem::rect().height() -s, s, s));
+ p->drawRect (QRectF(0, QGraphicsRectItem::rect().height() -s, s, s));
+}
+
+void QgsComposerItem::drawFrame(QPainter* p)
+{
+ QPen pen(QColor(0,0,0));
+ pen.setWidthF(1.0);
+ p->setPen( pen );
+ p->setBrush( Qt::NoBrush );
+ p->setRenderHint(QPainter::Antialiasing, true);
+ p->drawRect (QRectF( 0, 0, QGraphicsRectItem::rect().width(), QGraphicsRectItem::rect().height() ));
+}
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposeritem.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposeritem.h 2008-05-26 00:02:29 UTC (rev 8517)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposeritem.h 2008-05-26 11:47:36 UTC (rev 8518)
@@ -59,7 +59,7 @@
virtual void setSelected( bool s );
/** \brief Is selected */
- virtual bool selected( void );
+ virtual bool selected( void ){return QGraphicsRectItem::isSelected();}
/** item id */
int id ( void );
@@ -97,7 +97,6 @@
protected:
QgsComposition::PlotStyle mPlotStyle;
- bool mSelected;
int mId;
QgsComposerItem::mouseMoveAction mCurrentMouseMoveAction;
/**Start point of the last mouse move action (in scene coordinates)*/
@@ -107,6 +106,8 @@
/**Rectangle used during move and resize actions*/
QGraphicsRectItem* mBoundingResizeRectangle;
+
+ bool mSelected;
//event handlers
virtual void mouseMoveEvent ( QGraphicsSceneMouseEvent * event );
@@ -130,6 +131,18 @@
@param rx out: width of rectangle should be resized by rx
@param ry out: height of rectangle should be resized by ry*/
void rectangleChange(double dx, double dy, double& mx, double& my, double& rx, double& ry) const;
+
+#if 0 //todo: implement on item level if not provided by graphics view
+ void drawBackground();
+ void drawOutline();
+ void drawSelectionBoxes();
+#endif //0
+
+ /**Draw selection boxes around item*/
+ void drawSelectionBoxes(QPainter* p);
+
+ /**Draw black frame around item*/
+ void drawFrame(QPainter* p);
};
#endif
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp 2008-05-26 00:02:29 UTC (rev 8517)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp 2008-05-26 11:47:36 UTC (rev 8518)
@@ -48,8 +48,6 @@
#endif
setupUi(this);
- setAcceptsHoverEvents(true);
-
mComposition = composition;
mId = id;
mMapCanvas = mComposition->mapCanvas();
@@ -72,8 +70,6 @@
{
setupUi(this);
- setAcceptsHoverEvents(true);
-
mComposition = composition;
mId = id;
mMapCanvas = mComposition->mapCanvas();
@@ -232,7 +228,11 @@
void QgsComposerMap::paint ( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget)
{
- if ( mDrawing ) return;
+
+ if ( mDrawing )
+ {
+ return;
+ }
mDrawing = true;
#ifdef QGISDEBUG
@@ -240,73 +240,53 @@
<< " mPreviewMode = " << mPreviewMode << std::endl;
#endif
- if ( plotStyle() == QgsComposition::Preview && mPreviewMode == Cache ) { // Draw from cache
- if ( !mCacheUpdated || mMapCanvas->layerCount() != mNumCachedLayers )
- {
- cache();
- }
-
- // Scale so that the cache fills the map rectangle
- double scale = 1.0 * QGraphicsRectItem::rect().width() / mCachePixmap.width();
- #ifdef QGISDEBUG
- std::cout << "scale = " << scale << std::endl;
- #endif
-
- painter->save();
-
- painter->translate(0, 0); //do we need this?
- painter->scale(scale,scale);
-
- // Note: drawing only a visible part of the pixmap doesn't make it much faster
- painter->drawPixmap(0,0, mCachePixmap);
-
- painter->restore();
- }
+ if ( plotStyle() == QgsComposition::Preview && mPreviewMode == Cache )
+ { // Draw from cache
+ if ( !mCacheUpdated || mMapCanvas->layerCount() != mNumCachedLayers )
+ {
+ cache();
+ }
+
+ // Scale so that the cache fills the map rectangle
+ double scale = 1.0 * QGraphicsRectItem::rect().width() / mCachePixmap.width();
+#ifdef QGISDEBUG
+ std::cout << "scale = " << scale << std::endl;
+#endif
+
+ painter->save();
+
+ painter->translate(0, 0); //do we need this?
+ painter->scale(scale,scale);
+
+ painter->drawPixmap(0,0, mCachePixmap);
+
+ painter->restore();
+ }
else if ( (plotStyle() == QgsComposition::Preview && mPreviewMode == Render) ||
plotStyle() == QgsComposition::Print ||
plotStyle() == QgsComposition::Postscript )
- {
- QgsDebugMsg("render")
+ {
+ QgsDebugMsg("render")
- QPaintDevice* thePaintDevice = painter->device();
- if(!thePaintDevice)
- {
- return;
- }
+ QPaintDevice* thePaintDevice = painter->device();
+ if(!thePaintDevice)
+ {
+ return;
+ }
- QRectF bRect = boundingRect();
- QSize theSize(bRect.width(), bRect.height());
- painter->setClipRect (QRectF( 0, 0, QGraphicsRectItem::rect().width(), QGraphicsRectItem::rect().height() ));
- draw( painter, mExtent, theSize, 25.4); //scene coordinates seem to be in mm
- }
+ QRectF bRect = boundingRect();
+ QSize theSize(bRect.width(), bRect.height());
+ painter->setClipRect (QRectF( 0, 0, QGraphicsRectItem::rect().width(), QGraphicsRectItem::rect().height() ));
+ draw( painter, mExtent, theSize, 25.4); //scene coordinates seem to be in mm
+ }
- // Draw frame around
- if ( mFrame ) {
- QPen pen(QColor(0,0,0));
- pen.setWidthF(0.6*mComposition->scale());
- painter->setPen( pen );
- painter->setBrush( Qt::NoBrush );
- painter->setRenderHint(QPainter::Antialiasing, true); //turn on antialiasing for drawing the box
- painter->save();
- painter->translate(0, 0);//do we need this?
- painter->drawRect (QRectF( 0, 0, QGraphicsRectItem::rect().width(), QGraphicsRectItem::rect().height() ));
- painter->restore();
- }
-
- // Show selected / Highlight
- if ( mSelected && plotStyle() == QgsComposition::Preview ) {
- painter->setPen( mComposition->selectionPen() );
- painter->setBrush( mComposition->selectionBrush() );
-
- double s = mComposition->selectionBoxSize();
-
- painter->drawRect (QRectF(0, 0, s, s));
- painter->drawRect (QRectF(QGraphicsRectItem::rect().width() -s, 0, s, s));
- painter->drawRect (QRectF(QGraphicsRectItem::rect().width() -s, QGraphicsRectItem::rect().height() -s, s, s));
- painter->drawRect (QRectF(0, QGraphicsRectItem::rect().height() -s, s, s));
- }
-
+ drawFrame(painter);
+ if(isSelected())
+ {
+ drawSelectionBoxes(painter);
+ }
+
mDrawing = false;
}
@@ -553,13 +533,6 @@
mComposition->emitMapChanged ( mId );
}
-void QgsComposerMap::setSelected ( bool s )
-{
- mSelected = s;
- QGraphicsRectItem::setSelected(s);
- QGraphicsRectItem::update(); //re-paint, so we show the highlight boxes
-}
-
bool QgsComposerMap::selected( void )
{
return mSelected;
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposermap.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposermap.h 2008-05-26 00:02:29 UTC (rev 8517)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposermap.h 2008-05-26 11:47:36 UTC (rev 8518)
@@ -62,7 +62,7 @@
void init ( void );
// Reimplement QgsComposerItem:
- void setSelected( bool s );
+ //void setSelected( bool s );
bool selected( void );
QWidget *options ( void );
bool writeSettings ( void );
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.cpp 2008-05-26 00:02:29 UTC (rev 8517)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposerpicture.cpp 2008-05-26 11:47:36 UTC (rev 8518)
@@ -421,7 +421,12 @@
|| mWidth == 0 || mHeight == 0 )
{
mWidth = 0;
- mHeight = 0;
+ mHeight = 0;
+
+ QRectF itemRect = QGraphicsRectItem::rect();
+ itemRect.setWidth(mWidth);
+ itemRect.setHeight(mHeight);
+ QGraphicsRectItem::setRect(itemRect);
return;
}
Modified: branches/advanced_printing_branch/src/app/composer/qgscomposition.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposition.cpp 2008-05-26 00:02:29 UTC (rev 8517)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposition.cpp 2008-05-26 11:47:36 UTC (rev 8518)
@@ -240,7 +240,8 @@
// mGrabPoint = mCanvas.mapToItem(p);
- switch ( mTool ) {
+ switch ( mTool )
+ {
case Select:
{
@@ -251,6 +252,19 @@
newItem = 0;
}
+ QgsComposerItem* selectedItem = dynamic_cast<QgsComposerItem*>(newItem);
+ if(selectedItem)
+ {
+ selectedItem->setSelected(true);
+ if(selectedItem != mSelectedItem)
+ {
+ mSelectedItem->setSelected(false);
+ mComposer->showItemOptions(selectedItem->options());
+ mSelectedItem = selectedItem;
+ }
+ }
+ break;
+
//what is this doing? Grabbing the first item in the list?
/*
QList<QGraphicsItem*> l = mCanvas->items(p);
@@ -259,6 +273,7 @@
newItem = *it;
}
*/
+#if 0
if ( newItem ) { // found
mGrabPoint = newItem->mapFromScene(p);
@@ -287,6 +302,23 @@
}
break;
+
+ if(newItem)
+ {
+ QgsComposerItem* debugItem = dynamic_cast<QgsComposerItem*>(newItem);
+ if(debugItem)
+ {
+ debugItem->setSelected(true);
+ debugItem->update();
+ }
+ //newItem->setSelected(true);
+ //newItem->update();
+ //mComposer->showItemOptions((QWidget*)(newItem));
+ }
+ break;
+#endif //0
+ }
+
case AddMap:
#ifdef QGISDEBUG
@@ -474,10 +506,12 @@
delete mRectangleItem;
mRectangleItem = 0;
+ QgsComposerMap* m = 0;
+
if ( w > 0 && h > 0 ) {
mComposer->selectItem(); // usually just one map
- QgsComposerMap *m = new QgsComposerMap ( this, mNextItemId++, x, y, w, h );
+ m = new QgsComposerMap ( this, mNextItemId++, x, y, w, h );
m->setPos(x, y);
@@ -503,7 +537,11 @@
mRectangleItem = 0;
QgsComposerPicture *pi = dynamic_cast <QgsComposerPicture*> (mNewCanvasItem);
+ pi->setSize(w, h);
+ delete mRectangleItem;
+ mRectangleItem = 0;
+
if ( w > 0 && h > 0 )
{
mNewCanvasItem = 0; // !!! Must be before mComposer->selectItem()
More information about the QGIS-commit
mailing list