OpenWalnut
1.5.0dev
|
Implement a virtual grid for placing QGraphicsItems. More...
#include <WQtNetworkItemGrid.h>
Public Types | |
typedef std::shared_ptr< WQtNetworkItemGrid > | SPtr |
Convenience typedef for a std::shared_ptr< WQtNetworkItemGrid >. More... | |
typedef std::shared_ptr< const WQtNetworkItemGrid > | ConstSPtr |
Convenience typedef for a std::shared_ptr< const WQtNetworkItemGrid >. More... | |
Public Slots | |
void | blendIn () |
Allows blending in the underlaying layout structure. More... | |
void | blendOut () |
Allows blending out the underlaying layout structure. More... | |
Signals | |
void | updatedBounds () |
emitted when the grid shrinks or grows to update scene bounds More... | |
Public Member Functions | |
WQtNetworkItemGrid () | |
Default constructor. More... | |
virtual | ~WQtNetworkItemGrid () |
Destructor. More... | |
virtual QRectF | boundingRect () const |
The bounding area of the item. More... | |
virtual QRect | getGridBoundingRect () const |
Returns the boundaries in grid coordinates. More... | |
void | updateDimensions () |
Update the m_dimensions. More... | |
virtual void | paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
Paint the item. More... | |
int | getFirstFreeColumn () const |
Return the index of the first empty column. More... | |
bool | setItem (QGraphicsItem *item, int col, int row) |
Set the specified item to the specified position. More... | |
bool | setItem (QGraphicsItem *item, QPoint cell) |
Set the specified item to the specified position. More... | |
void | removeItem (int col, int row) |
Remove the item at the given position. More... | |
bool | removeItem (QGraphicsItem *item) |
Remove the item from the list. More... | |
bool | moveItem (QGraphicsItem *item, int col, int row) |
Move item from its current position to the specified one. More... | |
bool | moveItem (QGraphicsItem *item, QPoint cell) |
Move item from its current position to the specified one. More... | |
bool | isOccupied (int col, int row) |
Is there an element at the given position? More... | |
bool | isOccupied (QPoint cell) |
Is there an element at the given position? More... | |
virtual QPointF | mapToWorld (int col, int row) |
Map the grid coordinate to world coordinates. More... | |
virtual QPointF | mapToWorld (QPoint gridCoord) |
Map the grid coordinate to world coordinates. More... | |
virtual QRectF | mapCellAreaToWorld (QPoint cell) |
Build a rect which covers the cell area in world space. More... | |
virtual QRectF | mapCellAreaToWorld (int row, int col) |
Build a rect which covers the cell area in world space. More... | |
virtual QPoint | whereIs (QGraphicsItem *item) |
Find the position of the specified item. More... | |
virtual bool | isInGrid (QGraphicsItem *item) |
Check whether the item is managed in the grid. More... | |
virtual QPoint | findNearestCell (QPointF worldSpace) |
Find the nearest cell matching the specified world coordinates. More... | |
virtual void | physicalMoveTo (QGraphicsItem *item, int col, int row, bool animate=true) |
Move the item to the position physically. More... | |
virtual void | physicalMoveTo (QGraphicsItem *item, QPoint cell, bool animate) |
Move the item to the position physically. More... | |
void | highlightCell (QPoint cell, QColor color) |
Highlights the specified cell. More... | |
void | highlightCell () |
Turns off highlight. More... | |
void | disableBoundsUpdate (bool disable=true) |
Allows for temporarily disabling bounds update signal. More... | |
Protected Member Functions | |
virtual QGraphicsItem * | at (int col, int row) |
Return the element at the given position. More... | |
virtual QGraphicsItem * | setItemImpl (QGraphicsItem *item, int col, int row, bool suppressUpdate=false) |
Really sets the item to the grid position. More... | |
virtual bool | removeItemImpl (QGraphicsItem *item, bool suppressUpdate=false) |
Remove the item from the grid if existing. More... | |
Private Types | |
typedef std::map< QPoint, QGraphicsItem * > | Grid |
List of lists of QGraphicsItem. More... | |
typedef std::map< QGraphicsItem *, QPoint > | ItemCoordinateMap |
Maps between item and its grid coordinates. More... | |
Private Slots | |
void | animationBlendInTick (qreal value) |
Called when the animation timers tick and progress in timeline. More... | |
void | animationBlendOutTick (qreal value) |
Called when the animation timers tick and progress in timeline. More... | |
Private Member Functions | |
void | updateBoundingRect () |
Use to update bounding box when you modify the m_grid dimensions. More... | |
Private Attributes | |
Grid | m_grid |
The virtual grid. More... | |
ItemCoordinateMap | m_gridReverse |
Keeps track of the item coordinates. More... | |
QRect | m_dimensions |
The largest number of entries in a column/row. More... | |
QRectF | m_bb |
Bounding Rect of the Grid in world coordinates. More... | |
QPoint | m_highlightCell |
Current cell to highlight. More... | |
QColor | m_highlightColor |
Color of the highlight. More... | |
bool | m_highlightCellEnabled |
En/Dis-able highlughting. More... | |
QTimeLine * | m_blendInTimer |
Timer used for blend in effects of the grid. More... | |
QTimeLine * | m_blendOutTimer |
Timer used for blend in effects of the grid. More... | |
bool | m_disableUpdateBounds |
Disable updateBounds signal. More... | |
Implement a virtual grid for placing QGraphicsItems.
It itself is a QGraphicsItem to allow drawing the grid or parts of the grid.
Definition at line 54 of file WQtNetworkItemGrid.h.
typedef std::shared_ptr< const WQtNetworkItemGrid > WQtNetworkItemGrid::ConstSPtr |
Convenience typedef for a std::shared_ptr< const WQtNetworkItemGrid >.
Definition at line 66 of file WQtNetworkItemGrid.h.
|
private |
List of lists of QGraphicsItem.
Definition at line 357 of file WQtNetworkItemGrid.h.
|
private |
Maps between item and its grid coordinates.
Definition at line 367 of file WQtNetworkItemGrid.h.
typedef std::shared_ptr< WQtNetworkItemGrid > WQtNetworkItemGrid::SPtr |
Convenience typedef for a std::shared_ptr< WQtNetworkItemGrid >.
Definition at line 61 of file WQtNetworkItemGrid.h.
WQtNetworkItemGrid::WQtNetworkItemGrid | ( | ) |
Default constructor.
Definition at line 38 of file WQtNetworkItemGrid.cpp.
References animationBlendInTick(), animationBlendOutTick(), m_blendInTimer, and m_blendOutTimer.
|
virtual |
Destructor.
Definition at line 55 of file WQtNetworkItemGrid.cpp.
References m_blendInTimer, and m_blendOutTimer.
|
privateslot |
Called when the animation timers tick and progress in timeline.
Used to blend the item in.
value | the value between 0 and 1 |
Definition at line 462 of file WQtNetworkItemGrid.cpp.
Referenced by WQtNetworkItemGrid().
|
privateslot |
Called when the animation timers tick and progress in timeline.
Used to blend the item out.
value | the value between 0 and 1 |
Definition at line 467 of file WQtNetworkItemGrid.cpp.
Referenced by WQtNetworkItemGrid().
|
protectedvirtual |
Return the element at the given position.
If the position is invalid, NULL is returned.
col | the column ( x coordinate ) |
row | the row ( y coordinate ) |
Definition at line 240 of file WQtNetworkItemGrid.cpp.
References m_grid.
Referenced by isOccupied().
|
slot |
Allows blending in the underlaying layout structure.
Definition at line 426 of file WQtNetworkItemGrid.cpp.
References m_blendInTimer, and m_blendOutTimer.
Referenced by WQtNetworkSceneLayout::blendIn().
|
slot |
Allows blending out the underlaying layout structure.
Definition at line 444 of file WQtNetworkItemGrid.cpp.
References m_blendInTimer, and m_blendOutTimer.
Referenced by WQtNetworkSceneLayout::blendOut().
|
virtual |
The bounding area of the item.
Definition at line 62 of file WQtNetworkItemGrid.cpp.
References m_bb.
Referenced by WQtNetworkSceneLayout::getBoundingBox(), and paint().
void WQtNetworkItemGrid::disableBoundsUpdate | ( | bool | disable = true | ) |
Allows for temporarily disabling bounds update signal.
This is needed sometimes, where bounds are updated during another Qt event, causing the update event again, causing the Qt event again, causing the update event again, segfault.
disable | true to disable. |
Definition at line 472 of file WQtNetworkItemGrid.cpp.
References m_disableUpdateBounds.
Referenced by WQtNetworkItem::mouseMoveEvent().
|
virtual |
Find the nearest cell matching the specified world coordinates.
worldSpace | the coordinates to find the next cell for. |
Definition at line 394 of file WQtNetworkItemGrid.cpp.
Referenced by WQtNetworkSceneLayout::snapAccept(), and WQtNetworkSceneLayout::snapTemporarily().
int WQtNetworkItemGrid::getFirstFreeColumn | ( | ) | const |
Return the index of the first empty column.
Definition at line 295 of file WQtNetworkItemGrid.cpp.
References m_dimensions.
Referenced by WQtNetworkSceneLayout::addItem(), and WQtNetworkEditorProjectFileIO::done().
|
virtual |
Returns the boundaries in grid coordinates.
If you need world coords, use boundingRect instead.
Definition at line 477 of file WQtNetworkItemGrid.cpp.
References m_dimensions.
Referenced by WQtNetworkEditorProjectFileIO::save().
void WQtNetworkItemGrid::highlightCell | ( | ) |
Turns off highlight.
Definition at line 417 of file WQtNetworkItemGrid.cpp.
References m_highlightCellEnabled, and updateBoundingRect().
void WQtNetworkItemGrid::highlightCell | ( | QPoint | cell, |
QColor | color | ||
) |
Highlights the specified cell.
Note that only one cell can be highlighted. If you call this method with another cell, the old highlight fades out.
cell | the cell to highlight |
color | the color of the highlight |
Definition at line 404 of file WQtNetworkItemGrid.cpp.
References m_highlightCell, m_highlightCellEnabled, m_highlightColor, and updateBoundingRect().
Referenced by WQtNetworkSceneLayout::snapAccept(), and WQtNetworkSceneLayout::snapTemporarily().
|
virtual |
Check whether the item is managed in the grid.
item | the item |
Definition at line 333 of file WQtNetworkItemGrid.cpp.
References m_gridReverse.
Referenced by WQtNetworkEditorProjectFileIO::save().
bool WQtNetworkItemGrid::isOccupied | ( | int | col, |
int | row | ||
) |
Is there an element at the given position?
col | the column ( x coordinate ) |
row | the row ( y coordinate ) |
Definition at line 230 of file WQtNetworkItemGrid.cpp.
References at().
Referenced by WQtNetworkSceneLayout::connection(), isOccupied(), moveItem(), setItem(), and WQtNetworkSceneLayout::snapTemporarily().
bool WQtNetworkItemGrid::isOccupied | ( | QPoint | cell | ) |
Is there an element at the given position?
cell | the cell |
Definition at line 235 of file WQtNetworkItemGrid.cpp.
References isOccupied().
|
virtual |
Build a rect which covers the cell area in world space.
row | the row |
col | the col |
Definition at line 312 of file WQtNetworkItemGrid.cpp.
References mapToWorld().
|
virtual |
Build a rect which covers the cell area in world space.
cell | the cell to create the rect for |
Definition at line 318 of file WQtNetworkItemGrid.cpp.
Referenced by paint().
|
virtual |
Map the grid coordinate to world coordinates.
col | the column ( x coordinate ) |
row | the row ( y coordinate ) |
Definition at line 301 of file WQtNetworkItemGrid.cpp.
Referenced by mapCellAreaToWorld(), mapToWorld(), and physicalMoveTo().
|
virtual |
Map the grid coordinate to world coordinates.
gridCoord | the grid coordinates |
Definition at line 307 of file WQtNetworkItemGrid.cpp.
References mapToWorld().
bool WQtNetworkItemGrid::moveItem | ( | QGraphicsItem * | item, |
int | col, | ||
int | row | ||
) |
Move item from its current position to the specified one.
If the item does not exist right now, it will get moved from its current position. If the target position is occupied right now, nothing happens and false will be returned.
item | the item |
col | target columns |
row | target row |
Definition at line 202 of file WQtNetworkItemGrid.cpp.
References isOccupied(), physicalMoveTo(), removeItemImpl(), setItemImpl(), and updateDimensions().
Referenced by WQtNetworkSceneLayout::connection(), moveItem(), and WQtNetworkSceneLayout::snapAccept().
bool WQtNetworkItemGrid::moveItem | ( | QGraphicsItem * | item, |
QPoint | cell | ||
) |
Move item from its current position to the specified one.
If the item does not exist right now, it will get moved from its current position. If the target position is occupied right now, nothing happens and false will be returned.
item | the item |
cell | target cell |
Definition at line 225 of file WQtNetworkItemGrid.cpp.
References moveItem().
|
virtual |
Paint the item.
painter | implements drawing commands |
option | provides style options for the item, such as its state, exposed area and its level-of-detail hints |
widget | the widget on which is painted. Can be NULL. |
Definition at line 96 of file WQtNetworkItemGrid.cpp.
References boundingRect(), m_highlightCell, m_highlightCellEnabled, m_highlightColor, and mapCellAreaToWorld().
|
virtual |
Move the item to the position physically.
This does not modify the grid. It only moves the QGraphicsItem in the scene.
row | target row |
col | target col |
animate | if true, the item uses its build in animations |
item | item to move |
Definition at line 143 of file WQtNetworkItemGrid.cpp.
References WQtNetworkItem::animatedMoveTo(), mapToWorld(), and WQtNetworkItem::moveTo().
Referenced by moveItem(), physicalMoveTo(), setItem(), WQtNetworkSceneLayout::snapAccept(), and WQtNetworkSceneLayout::snapTemporarily().
|
virtual |
Move the item to the position physically.
This does not modify the grid. It only moves the QGraphicsItem in the scene.
cell | target cell |
animate | if true, the item uses its build in animations |
item | item to move |
Definition at line 165 of file WQtNetworkItemGrid.cpp.
References physicalMoveTo().
void WQtNetworkItemGrid::removeItem | ( | int | col, |
int | row | ||
) |
Remove the item at the given position.
col | the column ( x coordinate ) |
row | the row ( y coordinate ) |
Definition at line 192 of file WQtNetworkItemGrid.cpp.
References m_grid, and removeItemImpl().
Referenced by WQtNetworkSceneLayout::removeItem().
bool WQtNetworkItemGrid::removeItem | ( | QGraphicsItem * | item | ) |
Remove the item from the list.
item | the item |
Definition at line 197 of file WQtNetworkItemGrid.cpp.
References removeItemImpl().
|
protectedvirtual |
Remove the item from the grid if existing.
item | item to remove |
suppressUpdate | if true, the call will not call updateDimensionsRemove. Useful when using this method in another, more complex operation. |
Definition at line 269 of file WQtNetworkItemGrid.cpp.
References m_grid, m_gridReverse, and updateDimensions().
Referenced by moveItem(), and removeItem().
bool WQtNetworkItemGrid::setItem | ( | QGraphicsItem * | item, |
int | col, | ||
int | row | ||
) |
Set the specified item to the specified position.
item | the item to set |
col | the column ( x coordinate ) |
row | the row ( y coordinate ) |
Definition at line 170 of file WQtNetworkItemGrid.cpp.
References isOccupied(), physicalMoveTo(), and setItemImpl().
Referenced by WQtNetworkSceneLayout::addItem(), and setItem().
bool WQtNetworkItemGrid::setItem | ( | QGraphicsItem * | item, |
QPoint | cell | ||
) |
Set the specified item to the specified position.
item | the item to set |
cell | the column ( x coordinate ) |
Definition at line 187 of file WQtNetworkItemGrid.cpp.
References setItem().
|
protectedvirtual |
Really sets the item to the grid position.
Ignores previous items. You should manage any previous existing item at that grid position for yourself.
item | the item |
col | the column ( x coordinate ) |
row | the row ( y coordinate ) |
suppressUpdate | if true, the call will not call updateDimensionsAdd. Useful when using this method in another, more complex operation. |
Definition at line 250 of file WQtNetworkItemGrid.cpp.
References m_grid, m_gridReverse, and updateDimensions().
Referenced by moveItem(), and setItem().
|
private |
Use to update bounding box when you modify the m_grid dimensions.
Definition at line 67 of file WQtNetworkItemGrid.cpp.
References m_bb, m_dimensions, m_disableUpdateBounds, m_highlightCell, m_highlightCellEnabled, and updatedBounds().
Referenced by highlightCell(), and updateDimensions().
|
signal |
emitted when the grid shrinks or grows to update scene bounds
Referenced by updateBoundingRect().
void WQtNetworkItemGrid::updateDimensions | ( | ) |
Update the m_dimensions.
This method rebuilds the bounding area of the grid by re-reading all items in the grid. This is useful, whenever you do a lot of complex operations while suppressing all updates. Then use this method to force a complete update of the dimensions.
Definition at line 339 of file WQtNetworkItemGrid.cpp.
References m_dimensions, m_grid, and updateBoundingRect().
Referenced by moveItem(), removeItemImpl(), and setItemImpl().
|
virtual |
Find the position of the specified item.
item | item to search |
Definition at line 323 of file WQtNetworkItemGrid.cpp.
References m_gridReverse.
Referenced by WQtNetworkSceneLayout::connection(), WQtNetworkEditorProjectFileIO::save(), WQtNetworkSceneLayout::snapAccept(), and WQtNetworkSceneLayout::snapTemporarily().
|
private |
Bounding Rect of the Grid in world coordinates.
Definition at line 382 of file WQtNetworkItemGrid.h.
Referenced by boundingRect(), and updateBoundingRect().
|
private |
Timer used for blend in effects of the grid.
Definition at line 407 of file WQtNetworkItemGrid.h.
Referenced by blendIn(), blendOut(), WQtNetworkItemGrid(), and ~WQtNetworkItemGrid().
|
private |
Timer used for blend in effects of the grid.
Definition at line 412 of file WQtNetworkItemGrid.h.
Referenced by blendIn(), blendOut(), WQtNetworkItemGrid(), and ~WQtNetworkItemGrid().
|
private |
The largest number of entries in a column/row.
Definition at line 377 of file WQtNetworkItemGrid.h.
Referenced by getFirstFreeColumn(), getGridBoundingRect(), updateBoundingRect(), and updateDimensions().
|
private |
Disable updateBounds signal.
Definition at line 417 of file WQtNetworkItemGrid.h.
Referenced by disableBoundsUpdate(), and updateBoundingRect().
|
private |
The virtual grid.
Column-first. Means outer list is the list of x coordinates, containing a list of all items in this column.
Definition at line 362 of file WQtNetworkItemGrid.h.
Referenced by at(), removeItem(), removeItemImpl(), setItemImpl(), and updateDimensions().
|
private |
Keeps track of the item coordinates.
Definition at line 372 of file WQtNetworkItemGrid.h.
Referenced by isInGrid(), removeItemImpl(), setItemImpl(), and whereIs().
|
private |
Current cell to highlight.
Definition at line 392 of file WQtNetworkItemGrid.h.
Referenced by highlightCell(), paint(), and updateBoundingRect().
|
private |
En/Dis-able highlughting.
Definition at line 402 of file WQtNetworkItemGrid.h.
Referenced by highlightCell(), paint(), and updateBoundingRect().
|
private |
Color of the highlight.
Definition at line 397 of file WQtNetworkItemGrid.h.
Referenced by highlightCell(), and paint().