GraphicsView_Object::GraphicsView_Object( QGraphicsItem* theParent )
: QGraphicsItem( theParent ),
myPriority( 0 ),
- myIsOnTop( false ),
- myIsHighlighted( false ),
- myIsSelected( false ),
- myIsMoving( false ),
- myIsMovable( true )
+ myIsOnTop( false )
+// myIsHighlighted( false ),
+ //myIsSelected( false ),
+// myIsMoving( false ),
+// myIsMovable( true )
{
}
//================================================================
QRectF GraphicsView_Object::getRect() const
{
- return sceneBoundingRect();
+// return sceneBoundingRect();
+ return boundingRect();
}
//================================================================
//================================================================
bool GraphicsView_Object::highlight( double theX, double theY )
{
+/*
QCursor aCursor;
if( (myIsHighlighted = isVisible()) )
myIsHighlighted = checkHighlight( theX, theY, aCursor );
return myIsHighlighted;
+*/
+ return false;
}
//================================================================
//================================================================
void GraphicsView_Object::unhighlight()
{
- myIsHighlighted = false;
+// myIsHighlighted = false;
}
//================================================================
//================================================================
bool GraphicsView_Object::select( double theX, double theY, const QRectF& theRect )
{
+/*
QCursor aCursor;
if( (myIsSelected = isVisible()) )
{
myIsSelected = checkHighlight( theX, theY, aCursor );
}
return myIsSelected;
+*/
+ return false;
}
//================================================================
//================================================================
void GraphicsView_Object::unselect()
{
- myIsSelected = false;
+// myIsSelected = false;
}
//================================================================
//================================================================
void GraphicsView_Object::move( double theDX, double theDY, bool theIsAtOnce )
{
+/*
if( !myIsMovable )
return;
myIsMoving = true;
moveBy( theDX, theDY );
+*/
}
//================================================================
//================================================================
bool GraphicsView_Object::finishMove( bool theStatus )
{
+/*
myIsMoving = false;
if( theStatus )
if( GraphicsView_Scene* aScene = dynamic_cast<GraphicsView_Scene*>( scene() ) )
aScene->processRectChanged();
return true;
+*/
+ return false;
}
//================================================================
{
myViewTransform = theTransform;
}
+
+
+bool GraphicsView_Object::isMovable() const
+{
+ return (flags() & QGraphicsItem::ItemIsMovable);
+}
+
+void GraphicsView_Object::setMovable(bool theMovable)
+{
+ setFlag(QGraphicsItem::ItemIsMovable, theMovable);
+}
virtual bool isSelectable() const { return true; }
- virtual bool isMovable() const { return myIsMovable; }
- virtual void setMovable( bool theMovable ) { myIsMovable = theMovable; }
+// virtual bool isMovable() const { return myIsMovable; }
+// virtual void setMovable( bool theMovable ) { myIsMovable = theMovable; }
+
+ virtual bool isMovable() const;
+ virtual void setMovable( bool theMovable );
virtual QRectF getRect() const;
virtual bool highlight( double theX, double theY );
virtual void unhighlight();
- virtual bool isHighlighted() const { return myIsHighlighted; }
+// virtual bool isHighlighted() const { return myIsHighlighted; }
virtual bool select( double theX, double theY, const QRectF& theRect );
virtual void unselect();
- virtual bool isSelected() const { return myIsSelected; }
- virtual void setSelected( bool theState ) { myIsSelected = theState; }
+
+// virtual bool isSelected() const { return myIsSelected; }
+// virtual void setSelected( bool theState ) { myIsSelected = theState; }
+
+ virtual void setSelected( bool theState ) { }
virtual void move( double theDX, double theDY, bool theIsAtOnce = false );
virtual bool finishMove( bool theStatus );
- virtual bool isMoving() const { return myIsMoving; }
+
+// virtual bool isMoving() const { return myIsMoving; }
+ virtual bool isMoving() const { return false; }
virtual bool isMovingByXAllowed( double /*theDX*/ ) { return true; }
virtual bool isMovingByYAllowed( double /*theDY*/ ) { return true; }
int myPriority;
bool myIsOnTop;
- bool myIsHighlighted;
- bool myIsSelected;
+// bool myIsHighlighted;
+// bool myIsSelected;
- bool myIsMoving;
- bool myIsMovable;
+// bool myIsMoving;
+// bool myIsMovable;
QTransform myViewTransform;
};
#include <QGraphicsLineItem>
#include <QGraphicsRectItem>
#include <QGraphicsSceneWheelEvent>
-
+#include <iostream>
+#include "GraphicsView_Object.h"
//#define VIEWER_DEBUG
//=======================================================================
//================================================================
void GraphicsView_Scene::mousePressEvent( QGraphicsSceneMouseEvent* e )
{
- emit gsMouseEvent( e );
+/*
+ std::cout << "============================================================" << std::endl;
+ std::cout << "QGraphicsScene::mousePressEvent --> nb selected : " << selectedItems().count() << std::endl;
+
+ if (!selectedItems().isEmpty())
+ {
+ GraphicsView_Object* obj = (GraphicsView_Object*) selectedItems().front();
+ std::cout << " Item : " << obj->getName().toStdString() << std::endl;
+ }
+
+// emit gsMouseEvent( e );
+*/
+/*
+ QList<QGraphicsItem *> items1 = items(e->scenePos());
+ QList<QGraphicsItem*>::const_iterator it;
+
+ for (it = items1.constBegin(); it != items1.constEnd(); ++it)
+ {
+ GraphicsView_Object* anItem = (GraphicsView_Object*)(*it);
+ std::cout << "Item at pos : " << anItem->getName().toStdString() << std::endl;
+ }
+*/
+ //QGraphicsItem* gitem = mouseGrabberItem();
+ GraphicsView_Object* gitem = (GraphicsView_Object*)mouseGrabberItem();
+ std::cout << "Grabber : " << mouseGrabberItem() << std::endl;
+ if (gitem)
+ std::cout << "Grabber item : " << gitem->getName().toStdString() << std::endl;
QGraphicsScene::mousePressEvent( e );
}
//================================================================
void GraphicsView_Scene::mouseReleaseEvent( QGraphicsSceneMouseEvent* e )
{
- emit gsMouseEvent( e );
+// emit gsMouseEvent( e );
+
+ std::cout << "QGraphicsScene::mouseReleaseEvent --> nb selected : " << selectedItems().count() << std::endl;
+
+ if (!selectedItems().isEmpty())
+ {
+ GraphicsView_Object* obj = (GraphicsView_Object*) selectedItems().front();
+ std::cout << " Item : " << obj->getName().toStdString() << std::endl;
+ }
+
QGraphicsScene::mouseReleaseEvent( e );
}
//================================================================
void GraphicsView_Scene::mouseDoubleClickEvent( QGraphicsSceneMouseEvent* e )
{
- emit gsMouseEvent( e );
+ // emit gsMouseEvent( e );
QGraphicsScene::mouseDoubleClickEvent( e );
}
//================================================================
void GraphicsView_Scene::contextMenuEvent( QGraphicsSceneContextMenuEvent* e )
{
- emit gsContextMenuEvent( e );
+// emit gsContextMenuEvent( e );
QGraphicsScene::contextMenuEvent( e );
}
#include <QMouseEvent>
#include <QString>
#include <QWheelEvent>
+#include <iostream>
//=======================================================================
// Name : GraphicsView_ViewFrame
switch ( e->type() )
{
case QEvent::GraphicsSceneMousePress:
+ std::cout << "GraphicsView_ViewFrame::mousePressEvent" << std::endl;
emit mousePressed( e );
break;
case QEvent::GraphicsSceneMouseMove:
#include <QPainter>
#include <math.h>
-
+#include <iostream>
#define FOREGROUND_Z_VALUE -2
#define GRID_Z_VALUE -1
#define SKETCH_Z_VALUE 3000
connect( myScene, SIGNAL( gsKeyEvent( QKeyEvent* ) ),
this, SLOT( onKeyEvent( QKeyEvent* ) ) );
- connect( myScene, SIGNAL( gsMouseEvent( QGraphicsSceneMouseEvent* ) ),
- this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
+// connect( myScene, SIGNAL( gsMouseEvent( QGraphicsSceneMouseEvent* ) ),
+// this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
connect( myScene, SIGNAL( gsWheelEvent( QGraphicsSceneWheelEvent* ) ),
this, SLOT( onWheelEvent( QGraphicsSceneWheelEvent* ) ) );
connect( myScene, SIGNAL( gsContextMenuEvent( QGraphicsSceneContextMenuEvent* ) ),
}
}
return aStatus;
+
+// return false;
}
//================================================================
{
case QEvent::GraphicsSceneMousePress:
{
+ std::cout << "GraphicsView_ViewPort::onMousePressEvent" << std::endl;
if( hasInteractionFlag( EditFlags ) && nbSelected() )
for( initSelected(); moreSelected() && !anIsHandled; nextSelected() )
if( GraphicsView_Object* anObject = selectedObject() )
if( myViewLabel )
myViewLabel->setAcceptMoveEvents( true );
}
+
+void GraphicsView_ViewPort::mousePressEvent(QMouseEvent *event)
+{
+// std::cout << "QGraphicsView::mousePressEvent" << std::endl;
+ QGraphicsView::mousePressEvent(event);
+}
+
+void GraphicsView_ViewPort::mouseReleaseEvent(QMouseEvent *event)
+{
+ std::cout << "QGraphicsView::mouseReleaseEvent --> nb selected : " << scene()->selectedItems().count() << std::endl;
+
+ if (!scene()->selectedItems().isEmpty())
+ {
+ GraphicsView_Object* obj = (GraphicsView_Object*) scene()->selectedItems().front();
+ std::cout << " Item : " << obj->getName().toStdString() << std::endl;
+ }
+ QGraphicsView::mouseReleaseEvent(event);
+}
+
protected:
virtual void scrollContentsBy( int theDX, int theDY );
+ virtual void mousePressEvent(QMouseEvent *event);
+ virtual void mouseReleaseEvent(QMouseEvent *event);
signals:
void vpKeyEvent( QKeyEvent* );
#include <QMenu>
#include <math.h>
-
+#include <iostream>
// testing ImageViewer
/*
#include "GraphicsView_PrsImage.h"
//================================================================
void GraphicsView_Viewer::onMouseEvent( QGraphicsSceneMouseEvent* e )
{
+
switch( e->type() )
{
case QEvent::GraphicsSceneMousePress:
+ std::cout << "GraphicsView_Viewer::onMousePressEvent" << std::endl;
handleMousePress( e );
break;
case QEvent::GraphicsSceneMouseMove:
//================================================================
void GraphicsView_Viewer::handleMousePress( QGraphicsSceneMouseEvent* e )
{
+ std::cout << "GraphicsView_Viewer::handleMousePress" << std::endl;
// test accel for transforms
if ( e->modifiers() & GraphicsView_ViewTransformer::accelKey() )
{
//================================================================
void GraphicsView_Viewer::handleMouseRelease( QGraphicsSceneMouseEvent* e )
{
+ std::cout << "GraphicsView_Viewer::handleMouseRelease" << std::endl;
// selection
if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
{