30 #include <QStyleOptionGraphicsItem>
31 #include <QTextCharFormat>
32 #include <QTextCursor>
34 #include "../controlPanel/WQtPropertyGroupWidget.h"
35 #include "../controlPanel/WQtTreeItem.h"
36 #include "../guiElements/WQtDataModuleInput.h"
37 #include "WQtNetworkArrow.h"
38 #include "WQtNetworkColors.h"
39 #include "WQtNetworkEditor.h"
40 #include "WQtNetworkItem.h"
41 #include "WQtNetworkItemActivator.h"
42 #include "WQtNetworkItemGrid.h"
43 #include "WQtNetworkScene.h"
44 #include "WQtNetworkSceneLayout.h"
45 #include "core/common/WLogger.h"
46 #include "core/common/WStringUtils.h"
52 m_isSelected( false ),
53 m_busyIsDetermined( false ),
55 m_busyIndicatorShow( false ),
56 m_forceUpdate( true ),
57 m_propertyToolWindow( NULL ),
59 m_wasLayedOut( false ),
60 m_wasManuallyPlaced( false ),
67 setFlag( ItemSendsGeometryChanges );
68 setFlag( QGraphicsItem::ItemIsSelectable );
69 setFlag( QGraphicsItem::ItemIsMovable,
false );
71 setCacheMode( DeviceCoordinateCache );
81 m_text->setParentItem(
this );
82 m_text->setDefaultTextColor( Qt::white );
85 std::shared_ptr< WDataModule > dataModule;
86 dataModule = std::dynamic_pointer_cast< WDataModule >( module );
89 if( dataModule->getInput() )
116 for(
int i = 0; i < steps; ++i )
118 float stepNorm =
static_cast< float >( i ) /
static_cast< float >( steps - 1 );
119 float s = stepNorm * stepNorm;
135 for(
int i = 0; i < steps; ++i )
137 float stepNorm =
static_cast< float >( i ) /
static_cast< float >( steps - 1 );
138 float s = 1.0 - ( stepNorm * stepNorm );
147 f.setPointSizeF( f.pointSizeF() * 0.75 );
156 bool hasInput = cons.size();
157 for( WModule::InputConnectorList::const_iterator iter = cons.begin(); iter != cons.end(); ++iter )
160 port->setParentItem(
this );
166 bool hasOutput = outCons.size();
167 for( WModule::OutputConnectorList::const_iterator iter = outCons.begin(); iter != outCons.end(); ++iter )
170 port->setParentItem(
this );
176 if( !hasInput && !hasOutput )
186 else if( !hasOutput )
203 connect(
this, SIGNAL( xChanged() ),
this, SLOT(
positionChanged() ) );
204 connect(
this, SIGNAL( yChanged() ),
this, SLOT(
positionChanged() ) );
279 std::shared_ptr< WProgressCombiner> p =
m_module->getRootProgressCombiner();
331 if( dataModule->getInput() )
386 QPen newPen = QPen(
m_itemColor, 1, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin );
395 fillColor = WQtNetworkColors::ModuleCrashed;
406 fillColor = fillColor.lighter();
411 newPen = QPen( Qt::black, 2, Qt::DotLine, Qt::SquareCap, Qt::RoundJoin );
415 QBrush newBrush = QBrush( fillColor );
416 painter->setBrush( newBrush );
417 painter->setPen( newPen );
419 QStyleOptionGraphicsItem* o =
const_cast<QStyleOptionGraphicsItem*
>( option );
420 o->state &= ~QStyle::State_Selected;
422 painter->drawRect(
m_rect );
427 painter->setPen( QPen( Qt::black, 1, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin ) );
435 float busyBarMarginX = 5.0;
436 float busyIndicatorHeight = 2.0;
437 painter->setPen( QPen( WQtNetworkColors::BusyIndicatorBackground, busyIndicatorHeight, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin ) );
438 painter->drawLine( QPoint( busyBarMarginX,
m_height / 2.0 ), QPoint(
m_width - busyBarMarginX,
m_height / 2.0 ) );
439 painter->setPen( QPen( WQtNetworkColors::BusyIndicator, busyIndicatorHeight, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin ) );
445 painter->drawLine( QPoint( busyBarMarginX,
m_height / 2.0 ), QPoint( busyBarMarginX + pos,
m_height / 2.0 ) );
449 painter->drawLine( QPoint( busyBarMarginX + pos,
m_height / 2.0 ), QPoint( busyBarMarginX + pos + 5,
m_height / 2.0 ) );
479 QGraphicsItem::mouseMoveEvent( event );
490 if( event->button() == Qt::LeftButton )
497 if( event->button() == Qt::RightButton )
539 v->ensureVisible(
this );
544 QGraphicsItem::mouseReleaseEvent( event );
559 std::string name =
m_module->getName();
560 WPropString runtimeName =
m_module->getRuntimeName();
561 name = ( name == runtimeName->get() ) ? name : name +
" - " + runtimeName->get();
567 QWidget* contents =
new QWidget();
568 QVBoxLayout* contentLayout =
new QVBoxLayout();
569 contents->setLayout( contentLayout );
570 contentLayout->setContentsMargins( QMargins( 0, 0, 0, 0 ) );
571 contentLayout->setSpacing( 0 );
572 contentLayout->setAlignment( Qt::AlignTop );
581 contentLayout->addWidget( props );
584 sa->setWidget( contents );
585 sa->setWidgetResizable(
true );
586 sa->setWindowFlags( Qt::Window );
587 sa->setWindowRole(
"Properties" );
588 sa->setWindowTitle( QString::fromStdString(
"Properties: " + name ) );
602 case ItemSelectedHasChanged:
605 case ItemPositionHasChanged:
611 return QGraphicsItem::itemChange( change, value );
641 void clipText( QGraphicsTextItem* item,
float maxWidth, std::string fullText )
643 item->setPlainText( fullText.c_str() );
647 float w = item->boundingRect().width();
648 std::string newText = fullText;
651 while( w > maxWidth )
654 newText = newText.substr( 0, newText.length() - 1 );
655 item->setPlainText( ( newText +
"..." ).c_str() );
657 w = item->boundingRect().width();
664 prepareGeometryChange();
671 m_height = WNETWORKITEM_MINIMUM_HEIGHT;
678 float maxWidth = std::max(
static_cast< float >( maximumWidth ), portWidth );
681 float textWidth = 0.0;
682 float textHeight = 0.0;
685 float subtextWidth = 0.0;
686 float subtextHeight = 0.0;
687 float subtextMargin = 0.0;
692 textWidth =
static_cast< float >(
m_text->boundingRect().width() );
693 textHeight =
static_cast< float >(
m_text->boundingRect().height() );
697 subtextWidth =
static_cast< float >(
m_subtitle->boundingRect().width() );
698 subtextHeight =
static_cast< float >(
m_subtitle->boundingRect().height() );
699 subtextMargin = 1.0f * WNETWORKITEM_MARGINY;
703 float wholeTextHeight = textHeight + subtextHeight + subtextMargin;
706 float maxTextWidth = maxWidth - ( 2.0f * WNETWORKITEM_MARGINX );
721 textWidth =
static_cast< float >(
m_text->boundingRect().width() );
722 textHeight =
static_cast< float >(
m_text->boundingRect().height() );
726 subtextWidth =
static_cast< float >(
m_subtitle->boundingRect().width() );
727 subtextHeight =
static_cast< float >(
m_subtitle->boundingRect().height() );
729 float requiredWidth = std::max( portWidth, std::max( subtextWidth, textWidth ) + ( 2.0f * WNETWORKITEM_MARGINX ) );
730 float requiredHeight = wholeTextHeight + ( 2.0f * WNETWORKITEM_MARGINY );
733 m_height = std::max( requiredHeight,
static_cast< float >( WNETWORKITEM_MINIMUM_HEIGHT ) );
734 m_width = std::min( std::max( requiredWidth,
static_cast< float >( minimumWidth ) ), maxWidth );
742 qreal x = (
m_width / 2.0 ) - (
m_text->boundingRect().width() / 2.0 );
743 qreal y = (
m_height / 2.0 ) - ( wholeTextHeight / 2.0 );
750 qreal y = (
m_height / 2.0 ) - ( subtextMargin );
810 setEnabled( active );
814 setAcceptHoverEvents(
true );
815 setFlag( QGraphicsItem::ItemIsSelectable,
true );
818 if( active ==
false )
820 setAcceptHoverEvents(
false );
821 setFlag( QGraphicsItem::ItemIsSelectable,
false );
843 if( scene() != NULL )
845 scene()->removeItem(
this );
858 setOpacity( 1.0 - ( value * value ) );
863 setOpacity( value * value );
869 QGraphicsItemAnimation* animation =
new QGraphicsItemAnimation;
870 QTimeLine* animationTimer =
new QTimeLine( WNETWORKITEM_MOVE_DURATION );
873 animationTimer->setFrameRange( 0, 100 );
874 animation->setItem(
this );
875 animation->setTimeLine( animationTimer );
878 connect( animationTimer, SIGNAL( finished() ),
this, SLOT(
moveFinished() ) );
879 connect( animationTimer, SIGNAL( finished() ), animation, SLOT( deleteLater() ) );
880 connect( animationTimer, SIGNAL( finished() ), animationTimer, SLOT( deleteLater() ) );
884 QPointF oldPos = pos();
885 for(
int i = 0; i < steps; ++i )
887 float stepNorm =
static_cast< float >( i ) /
static_cast< float >( steps - 1 );
888 QPointF p = ( ( 1.0 - stepNorm ) * oldPos ) + ( stepNorm * newPos );
889 animation->setPosAt( stepNorm, p );
891 animation->setPosAt( 1.0, newPos );
899 animationTimer->start();
909 moveTo( pos.x(), pos.y() );
std::shared_ptr< WDataModule > SPtr
Convenience typedef for a std::shared_ptr< WDataModule >.
std::shared_ptr< WModule > SPtr
Shared pointer to a WModule.
std::vector< std::shared_ptr< WModuleOutputConnector > > OutputConnectorList
The type for the list of output connectors.
std::vector< std::shared_ptr< WModuleInputConnector > > InputConnectorList
The type for the list of input connectors.
static void execInGUIThreadAsync(boost::function< void(void) > functor, WCondition::SPtr notify=WCondition::SPtr())
Call a given function from within the GUI thread.
This class extends the basic functionality of QGraphicsView to allow comfortable panning and zooming.
void ensureVisibleSmooth(QGraphicsItem *item, int xmargin=50, int ymargin=50)
Improved version of QGraphicsView::ensureVisible for smooth scrolling.
void focusOn(QGraphicsItem *item)
The Item to focus on.
Container widget to hold the WQtNetworkScene.
WQtNetworkEditorView * getView()
Get the view handling the scene.
WQtNetworkScene * getScene()
Returns the current scene.
WQtNetworkSceneLayout * getLayout()
Get the layouter of the scene.
Small graphics item that respresents whether a module in the network editor is active or not.
void disableBoundsUpdate(bool disable=true)
Allows for temporarily disabling bounds update signal.
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
If the item is changed we want to get notified.
void changeState(State state)
Update the visual state of the item.
QString getText()
Get the caption as QString.
void setLayedOut(bool layedOut=true)
Marks the item as already layed out.
State
Denotes the current state this item is in.
std::string m_subtitleFull
always contains the unclipped text of m_subtitle
void dead(WQtNetworkItem *item)
The item is now dead.
WQtNetworkItemActivator * m_hidden
indicator showing if module's graphics are activated (allows to activate it)
void addOutputPort(WQtNetworkOutputPort *outPort)
Add a port to the item.
void addInputPort(WQtNetworkInputPort *inPort)
Add a port to the item.
void setManuallyPlaced(bool manual=true)
Mark item as manually placed.
bool m_noDrag
If true, the mouse events do not cause a drag and move operation.
virtual ~WQtNetworkItem()
Destructor.
bool m_busyIsDetermined
If true, a percentage is shown.
void activate(bool active)
Here the module can be enabled when the WModule is ready.
void animatedMoveTo(QPointF pos)
Move item to specified position smoothly, via animation.
float m_width
the width of the rect
bool m_isSelected
If true, the item is selected.
bool m_isHovered
If true, the item is hovered.
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
If the cursor leaves the item, the item gets his default color.
bool m_busyIndicatorShow
If true, the busy indication is active.
virtual void updater()
Can be used for polling the module states.
boost::signals2::connection m_runtimeNameConnection
Keep track of runtime name changes of this module.
void moveFinished()
Called whenever a animated move was finished.
QColor m_itemColor
the color of the item. Depends on type (source, sink, ...).
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
If the WQtNetworkItem is moved, then the contained ports have to update the connected WQtNetworkArrow...
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
Reimplemented from QGraphicsRectItem.
std::shared_ptr< WModule > getModule()
Get the WModule represented by this object.
void fitLook(float maximumWidth=WNETWORKITEM_MAXIMUM_WIDTH, float minimumWidth=WNETWORKITEM_MINIMUM_WIDTH)
This method aligns the in- and outports as well as the modulename in a regular way.
bool wasLayedOut() const
Checks whether the item was layed out earlier.
QGraphicsItemAnimation * m_animation
Animation for appearance and deletion.
void setTextItem(QGraphicsTextItem *text)
Set the QGraphicsTextItem ( the caption ) of the item.
QList< WQtNetworkInputPort * > getInPorts()
Returns the item inports.
WQtNetworkEditor * m_networkEditor
the related WQtNetworkEditor
void setCrashed()
Mark this module as crashed.
QTimeLine * m_removalAnimationTimer
Timer for the animation.
QList< WQtNetworkOutputPort * > m_outPorts
the output ports of the item
void removalAnimationDone()
Called when the m_removalAnimationTimer finishes.
std::string m_textFull
always contains the unclipped text of m_text
bool m_wasManuallyPlaced
Item has been placed manually.
bool m_wasLayedOut
Mark item as already positioned.
QGraphicsItemAnimation * m_removalAnimation
Animation for appearance and deletion.
void moveTo(QPointF pos)
Move item to specified position smoothly, no animation.
QGraphicsTextItem * m_subtitle
the caption
float m_itemBestWidth
Optimal width for this module.
int type() const
Reimplementation from QGraphicsItem.
void animationBlendOutTick(qreal value)
Called when the animation timers tick and progress in timeline.
bool m_forceUpdate
If true, the next call to update() will force a redraw.
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
Called upon double click.
QGraphicsTextItem * m_text
the caption
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
Mouse was released.
void setText(std::string text)
Set the new title text.
State m_currentState
denotes the state the item currently is in
QWidget * m_propertyToolWindow
The property toolbox window if any.
void positionChanged()
Called whenever the item moves around.
WQtNetworkItem(WQtNetworkEditor *editor, std::shared_ptr< WModule > module)
Constructs new item in the network scene.
float m_height
the height of the rect
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
If the cursor enters the item, the item gets a green color.
std::shared_ptr< WModule > m_module
the module
QTimeLine * die()
Animate removal and finally, instruct the owning network editor to remove the item.
QList< WQtNetworkInputPort * > m_inPorts
the input ports of the item
QRectF m_rect
the size of the items rect
void animationBlendInTick(qreal value)
Called when the animation timers tick and progress in timeline.
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *w)
Draw some customized stuff in the scene.
QTimeLine * m_animationTimer
Timer for the animation.
bool wasManuallyPlaced() const
Item was placed by hand.
QList< WQtNetworkOutputPort * > getOutPorts()
Returns the item outports.
QPointF m_draggingStart
Start position of dragging.
virtual QRectF boundingRect() const
The bounding area of the item.
void runtimeNameChanged()
Update name as it has been changed.
float m_busyPercent
Counter used for busy indication.
This class represents the ports a module have.
Abstract class to distinguish between input- and output ports from a module.
void alignPosition(int size, int portNumber, QRectF rect, bool outPort)
Calculates the position inside a item for each port to get a correct alignment.
static float getMultiplePortWidth(size_t nbPorts)
Calculates the spaced needed for the given amount of ports.
virtual void updateArrows()
The position of every arrow connected with this port is updating its position in the scene.
void snapAccept(WQtNetworkItem *item, QPointF worldCoords)
Accept the current item position and update layout accordingly.
void blendOut()
Allows blending out the underlaying layout structure.
virtual void removeItem(WQtNetworkItem *item)
Remove the item from the layout.
void blendIn()
Allows blending in the underlaying layout structure.
WQtNetworkItemGrid * getGrid() const
Get the grid used for the layout.
void snapTemporarily(WQtNetworkItem *item, QPointF worldCoords, bool noPhysicalMove=false)
Snap the item to the nearest layout element.
static std::string createTooltip(WModule::SPtr module)
Create tooltip for a given module.
std::string toString(const T &value)
Convert a given value to a string.