25 #ifndef WQTNETWORKITEMGRID_H
26 #define WQTNETWORKITEMGRID_H
31 #include <QGraphicsItem>
33 #include <QtCore/QObject>
34 #include <QtCore/QPoint>
44 inline bool operator< (
const QPoint& lhs,
const QPoint& rhs )
46 return ( lhs.x() < rhs.x() ) || ( !( rhs.x() < lhs.x() ) && ( lhs.y() < rhs.y() ) );
61 typedef std::shared_ptr< WQtNetworkItemGrid >
SPtr;
66 typedef std::shared_ptr< const WQtNetworkItemGrid >
ConstSPtr;
105 virtual void paint( QPainter* painter,
const QStyleOptionGraphicsItem* option,
203 virtual QPointF
mapToWorld(
int col,
int row );
212 virtual QPointF
mapToWorld( QPoint gridCoord );
357 typedef std::map< QPoint, QGraphicsItem* >
Grid;
Implement a virtual grid for placing QGraphicsItems.
std::map< QPoint, QGraphicsItem * > Grid
List of lists of QGraphicsItem.
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.
std::shared_ptr< const WQtNetworkItemGrid > ConstSPtr
Convenience typedef for a std::shared_ptr< const WQtNetworkItemGrid >.
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.
std::shared_ptr< WQtNetworkItemGrid > SPtr
Convenience typedef for a std::shared_ptr< WQtNetworkItemGrid >.
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.
std::map< QGraphicsItem *, QPoint > ItemCoordinateMap
Maps between item and its grid coordinates.