31 #include "core/common/WLogger.h"
33 #include "WQtNetworkEditorGlobals.h"
34 #include "WQtNetworkItem.h"
36 #include "WQtNetworkItemGrid.h"
40 m_highlightCellEnabled( false ),
41 m_disableUpdateBounds( false )
48 m_blendInTimer =
new QTimeLine( WNETWORKITEM_GRIDBLENDIN_DURATION );
69 float boxWidth = WNETWORKITEM_XSPACE + WNETWORKITEM_MAXIMUM_WIDTH;
70 float boxHeight = WNETWORKITEM_YSPACE + WNETWORKITEM_MAXIMUM_HEIGHT;
78 dimensions = dimensions.united( h );
82 float minX = ( dimensions.x() - 1 ) * boxWidth;
83 float minY = ( dimensions.y() - 1 ) * boxHeight;
84 float maxX = ( dimensions.width() + 2 ) * boxWidth;
85 float maxY = ( dimensions.height() + 2 ) * boxHeight;
88 m_bb = QRectF( minX, minY, maxX, maxY );
101 float sx = WNETWORKITEM_XSPACE + WNETWORKITEM_MAXIMUM_WIDTH;
102 float sy = WNETWORKITEM_YSPACE + WNETWORKITEM_MAXIMUM_HEIGHT;
104 float lineWidth = 1.0;
107 for(
float y = sy; y < bb.height(); y = y + sy )
109 QRectF r( bb.x(), bb.y() + y, bb.width(), lineWidth );
110 QLinearGradient gradient( bb.topLeft(), bb.topRight() );
111 gradient.setColorAt( 0.0, QColor( 0, 0, 0, 0 ) );
112 gradient.setColorAt( 0.4, QColor( 0, 0, 0, 128 ) );
113 gradient.setColorAt( 0.6, QColor( 0, 0, 0, 128 ) );
114 gradient.setColorAt( 1.0, QColor( 0, 0, 0, 0 ) );
115 painter->fillRect( r, gradient );
118 for(
float x = sx; x < bb.width(); x = x + sx )
120 QRectF r( bb.x() + x, bb.y(), lineWidth, bb.height() );
121 QLinearGradient gradient( bb.topLeft(), bb.bottomLeft() );
122 gradient.setColorAt( 0.0, QColor( 0, 0, 0, 0 ) );
123 gradient.setColorAt( 0.4, QColor( 0, 0, 0, 128 ) );
124 gradient.setColorAt( 0.6, QColor( 0, 0, 0, 128 ) );
125 gradient.setColorAt( 1.0, QColor( 0, 0, 0, 0 ) );
126 painter->fillRect( r, gradient );
147 p.rx() += WNETWORKITEM_XSPACE * 0.5;
148 p.ry() += WNETWORKITEM_YSPACE * 0.5;
189 return setItem( item, cell.x(), cell.y() );
227 return moveItem( item, cell.x(), cell.y() );
232 return at( col, row );
242 Grid::iterator it =
m_grid.find( QPoint( col, row ) );
247 return ( *it ).second;
256 m_grid[ QPoint( col, row ) ] = item;
261 if( !suppressUpdate )
279 QPoint where = ( *it ).second;
287 if( !suppressUpdate )
303 return QPointF( col * ( WNETWORKITEM_XSPACE + WNETWORKITEM_MAXIMUM_WIDTH ),
304 row * ( WNETWORKITEM_YSPACE + WNETWORKITEM_MAXIMUM_HEIGHT ) );
309 return mapToWorld( gridCoord.x(), gridCoord.y() );
315 return QRectF( c.x(), c.y(), WNETWORKITEM_XSPACE + WNETWORKITEM_MAXIMUM_WIDTH, WNETWORKITEM_YSPACE + WNETWORKITEM_MAXIMUM_HEIGHT );
330 return ( *it ).second;
342 prepareGeometryChange();
349 for( Grid::const_iterator it =
m_grid.begin(); it !=
m_grid.end(); ++it )
352 if( !( *it ).second )
357 QPoint p = ( *it ).first;
368 min.rx() = std::min( p.x(), min.x() );
369 min.ry() = std::min( p.y(), min.y() );
370 max.rx() = std::max( p.x(), max.x() );
371 max.ry() = std::max( p.y(), max.y() );
396 float boxWidth = WNETWORKITEM_XSPACE + WNETWORKITEM_MAXIMUM_WIDTH;
397 float boxHeight = WNETWORKITEM_YSPACE + WNETWORKITEM_MAXIMUM_HEIGHT;
400 return QPoint( std::floor( worldSpace.x() / boxWidth ),
401 std::floor( worldSpace.y() / boxHeight ) );
407 prepareGeometryChange();
420 prepareGeometryChange();
433 float remaining = doneRatio *
static_cast< float >(
m_blendInTimer->duration() );
434 m_blendInTimer->setCurrentTime(
static_cast< int >( remaining ) );
451 float remaining = doneRatio *
static_cast< float >(
m_blendOutTimer->duration() );
464 setOpacity( value * value );
469 setOpacity( 1.0 - ( value * value ) );
QRectF m_bb
Bounding Rect of the Grid in world coordinates.
ItemCoordinateMap m_gridReverse
Keeps track of the item coordinates.
virtual QGraphicsItem * at(int col, int row)
Return the element at the given position.
bool setItem(QGraphicsItem *item, int col, int row)
Set the specified item to the specified position.
virtual QRectF boundingRect() const
The bounding area of the item.
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Paint the item.
virtual QPoint whereIs(QGraphicsItem *item)
Find the position of the specified item.
QTimeLine * m_blendInTimer
Timer used for blend in effects of the grid.
bool m_disableUpdateBounds
Disable updateBounds signal.
bool moveItem(QGraphicsItem *item, int col, int row)
Move item from its current position to the specified one.
virtual QPoint findNearestCell(QPointF worldSpace)
Find the nearest cell matching the specified world coordinates.
virtual void physicalMoveTo(QGraphicsItem *item, int col, int row, bool animate=true)
Move the item to the position physically.
virtual ~WQtNetworkItemGrid()
Destructor.
void updateBoundingRect()
Use to update bounding box when you modify the m_grid dimensions.
virtual bool isInGrid(QGraphicsItem *item)
Check whether the item is managed in the grid.
virtual QRectF mapCellAreaToWorld(QPoint cell)
Build a rect which covers the cell area in world space.
void animationBlendInTick(qreal value)
Called when the animation timers tick and progress in timeline.
WQtNetworkItemGrid()
Default constructor.
virtual QGraphicsItem * setItemImpl(QGraphicsItem *item, int col, int row, bool suppressUpdate=false)
Really sets the item to the grid position.
Grid m_grid
The virtual grid.
virtual QRect getGridBoundingRect() const
Returns the boundaries in grid coordinates.
QTimeLine * m_blendOutTimer
Timer used for blend in effects of the grid.
QRect m_dimensions
The largest number of entries in a column/row.
void blendOut()
Allows blending out the underlaying layout structure.
void updateDimensions()
Update the m_dimensions.
void highlightCell()
Turns off highlight.
virtual QPointF mapToWorld(int col, int row)
Map the grid coordinate to world coordinates.
void disableBoundsUpdate(bool disable=true)
Allows for temporarily disabling bounds update signal.
void blendIn()
Allows blending in the underlaying layout structure.
QColor m_highlightColor
Color of the highlight.
void removeItem(int col, int row)
Remove the item at the given position.
int getFirstFreeColumn() const
Return the index of the first empty column.
bool m_highlightCellEnabled
En/Dis-able highlughting.
bool isOccupied(int col, int row)
Is there an element at the given position?
void animationBlendOutTick(qreal value)
Called when the animation timers tick and progress in timeline.
void updatedBounds()
emitted when the grid shrinks or grows to update scene bounds
virtual bool removeItemImpl(QGraphicsItem *item, bool suppressUpdate=false)
Remove the item from the grid if existing.
QPoint m_highlightCell
Current cell to highlight.
This class represents a WModule as QGraphicsItem and contains a reference to its in- and outports.
void animatedMoveTo(QPointF pos)
Move item to specified position smoothly, via animation.
void moveTo(QPointF pos)
Move item to specified position smoothly, no animation.