~ubuntu-branches/ubuntu/raring/openwalnut/raring

« back to all changes in this revision

Viewing changes to src/qt4gui/networkEditor/WQtNetworkItem.cpp

  • Committer: Package Import Robot
  • Author(s): Sebastian Eichelbaum
  • Date: 2012-12-12 11:26:32 UTC
  • mfrom: (3.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20121212112632-xhiuwkxuz5h0idkh
Tags: 1.3.1+hg5849-1
* Minor changes compared to 1.3.0 but included several bug fixes.
* See http://www.openwalnut.org/versions/4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//---------------------------------------------------------------------------
 
2
//
 
3
// Project: OpenWalnut ( http://www.openwalnut.org )
 
4
//
 
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
 
6
// For more information see http://www.openwalnut.org/copying
 
7
//
 
8
// This file is part of OpenWalnut.
 
9
//
 
10
// OpenWalnut is free software: you can redistribute it and/or modify
 
11
// it under the terms of the GNU Lesser General Public License as published by
 
12
// the Free Software Foundation, either version 3 of the License, or
 
13
// (at your option) any later version.
 
14
//
 
15
// OpenWalnut is distributed in the hope that it will be useful,
 
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
// GNU Lesser General Public License for more details.
 
19
//
 
20
// You should have received a copy of the GNU Lesser General Public License
 
21
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
 
22
//
 
23
//---------------------------------------------------------------------------
 
24
 
 
25
#include <algorithm>
 
26
#include <string>
 
27
#include <iostream>
 
28
 
 
29
#include <boost/shared_ptr.hpp>
 
30
 
 
31
#include <QtGui/QStyleOptionGraphicsItem>
 
32
#include <QtGui/QTextCharFormat>
 
33
#include <QtGui/QTextCursor>
 
34
 
 
35
#include "core/common/WStringUtils.h"
 
36
 
 
37
#include "../controlPanel/WQtTreeItem.h"
 
38
 
 
39
#include "WQtNetworkArrow.h"
 
40
#include "WQtNetworkItem.h"
 
41
#include "WQtNetworkItemActivator.h"
 
42
#include "WQtNetworkScene.h"
 
43
#include "WQtNetworkEditor.h"
 
44
#include "WQtNetworkColors.h"
 
45
#include "WQtNetworkEditorGlobals.h"
 
46
 
 
47
WQtNetworkItem::WQtNetworkItem( WQtNetworkEditor *editor, boost::shared_ptr< WModule > module )
 
48
    : QGraphicsRectItem(),
 
49
    m_isHovered( false ),
 
50
    m_isSelected( false ),
 
51
    m_busyIsDetermined( false ),
 
52
    m_busyPercent( 0.0 ),
 
53
    m_busyIndicatorShow( false ),
 
54
    m_forceUpdate( true )
 
55
{
 
56
    m_networkEditor = editor;
 
57
    m_module = module;
 
58
 
 
59
    setCacheMode( DeviceCoordinateCache );
 
60
 
 
61
    // caption
 
62
    m_textFull = module->getName();
 
63
    m_text = new QGraphicsTextItem( m_textFull.c_str() );
 
64
    m_text->setParentItem( this );
 
65
    m_text->setDefaultTextColor( Qt::white );
 
66
 
 
67
    // for captions of data modules
 
68
    boost::shared_ptr< WDataModule > dataModule;
 
69
    dataModule = boost::shared_dynamic_cast< WDataModule >( module );
 
70
    if( dataModule )
 
71
    {
 
72
        m_subtitleFull = dataModule->getFilename().filename().string();
 
73
    }
 
74
    else
 
75
    {
 
76
        m_subtitleFull = "Idle";
 
77
    }
 
78
 
 
79
    m_subtitle = new QGraphicsTextItem( m_subtitleFull.c_str() );
 
80
    m_subtitle->setParentItem( this );
 
81
    m_subtitle->setDefaultTextColor( Qt::white );
 
82
    QFont f = m_subtitle->font();
 
83
    f.setPointSizeF( f.pointSizeF() * 0.75 );
 
84
    f.setBold( true );
 
85
    m_subtitle->setFont( f );
 
86
 
 
87
    m_inPorts = QList< WQtNetworkInputPort* > ();
 
88
    m_outPorts = QList< WQtNetworkOutputPort* > ();
 
89
 
 
90
    //add input ports
 
91
    WModule::InputConnectorList cons = module->getInputConnectors();
 
92
    bool hasInput = cons.size();
 
93
    for( WModule::InputConnectorList::const_iterator iter = cons.begin(); iter != cons.end(); ++iter )
 
94
    {
 
95
        WQtNetworkInputPort *port = new WQtNetworkInputPort( *iter );
 
96
        port->setParentItem( this );
 
97
        this->addInputPort( port );
 
98
    }
 
99
 
 
100
    //add output ports
 
101
    WModule::OutputConnectorList outCons = module->getOutputConnectors();
 
102
    bool hasOutput = outCons.size();
 
103
    for( WModule::OutputConnectorList::const_iterator iter = outCons.begin(); iter != outCons.end(); ++iter )
 
104
    {
 
105
        WQtNetworkOutputPort *port = new WQtNetworkOutputPort( *iter );
 
106
        port->setParentItem( this );
 
107
        this->addOutputPort( port );
 
108
    }
 
109
 
 
110
    // Standard processing modules with in- and outputs are colored this way:
 
111
    m_itemColor = WQtNetworkColors::Module;
 
112
    if( !hasInput && !hasOutput )
 
113
    {
 
114
        // neither inputs nor outputs
 
115
        m_itemColor = WQtNetworkColors::StandaloneModule;
 
116
    }
 
117
    else if( !hasInput )
 
118
    {
 
119
        // no inputs -> source
 
120
        m_itemColor = WQtNetworkColors::SourceModule;
 
121
    }
 
122
    else if( !hasOutput )
 
123
    {
 
124
        // no outputs but inputs -> sink
 
125
        m_itemColor = WQtNetworkColors::SinkModule;
 
126
    }
 
127
 
 
128
    m_hidden = new WQtNetworkItemActivator( m_module );
 
129
    m_hidden->setParentItem( this );
 
130
 
 
131
    activate( false );
 
132
 
 
133
    fitLook();
 
134
    // this now calculated the optimal size. We keep them for later use
 
135
    m_itemBestWidth = boundingRect().width();
 
136
 
 
137
    m_layoutNode = NULL;
 
138
}
 
139
 
 
140
WQtNetworkItem::~WQtNetworkItem()
 
141
{
 
142
    foreach( WQtNetworkPort *port, m_inPorts )
 
143
    {
 
144
        delete port;
 
145
    }
 
146
 
 
147
    foreach( WQtNetworkPort *port, m_outPorts )
 
148
    {
 
149
        delete port;
 
150
    }
 
151
    delete m_text;
 
152
    delete m_subtitle;
 
153
}
 
154
 
 
155
int WQtNetworkItem::type() const
 
156
{
 
157
    return Type;
 
158
}
 
159
 
 
160
void WQtNetworkItem::updater()
 
161
{
 
162
    // it is very important to avoid unnecessary changes to pen/brush and similar stuff to avoid permanent updates of the graphics item.
 
163
    bool needUpdate = m_forceUpdate;
 
164
    m_forceUpdate = false;
 
165
 
 
166
    // progress indication is only needed for running modules
 
167
    if( m_currentState != Crashed )
 
168
    {
 
169
        // handle progress indication
 
170
        boost::shared_ptr< WProgressCombiner> p = m_module->getRootProgressCombiner();
 
171
 
 
172
        // update the progress combiners internal state
 
173
        p->update();
 
174
 
 
175
        if( p->isPending() )
 
176
        {
 
177
            m_busyIndicatorShow = true;
 
178
            m_busyIsDetermined = p->isDetermined();
 
179
 
 
180
            // update subtext
 
181
            m_subtitleFull = p->getCombinedNames( true );
 
182
            if( m_subtitleFull.empty() ) // if some lazy programmer did not provide names for the progress -> set one
 
183
            {
 
184
                m_subtitleFull = "Busy";
 
185
            }
 
186
 
 
187
            // we add the percent-counter to the front because the fitLook method shortens the subtext string if it is too long. This might clip out
 
188
            // the percentage if the p->getCombinedNames string is quite long.
 
189
            if(m_busyIsDetermined ) // <- of course only add if we have a known percentage
 
190
            {
 
191
                // NOTE: Percentage of a WProgressCombiner always multiplicatively combines all percentages of the children
 
192
                m_subtitleFull = string_utils::toString( static_cast< uint16_t >( p->getProgress() ) ) + "% - " + m_subtitleFull;
 
193
            }
 
194
 
 
195
            // this method ensures the text is shortened and correctly placed in the iem
 
196
            fitLook( m_itemBestWidth, m_itemBestWidth );
 
197
 
 
198
            // update indicator
 
199
            if( m_busyIsDetermined )
 
200
            {
 
201
                m_busyPercent = p->getProgress() / 100.0;
 
202
            }
 
203
            else
 
204
            {
 
205
                m_busyPercent += 0.025;
 
206
                if( m_busyPercent > 1.0 )
 
207
                {
 
208
                    m_busyPercent = 0.0;
 
209
                }
 
210
            }
 
211
            needUpdate = true;
 
212
        }
 
213
        else
 
214
        {
 
215
            // if busy indication was active -> update to remove it again
 
216
            needUpdate |= m_busyIndicatorShow;
 
217
            m_busyIndicatorShow = false;
 
218
            WDataModule::SPtr dataModule = boost::shared_dynamic_cast< WDataModule >( m_module );
 
219
            if( dataModule )
 
220
            {
 
221
                m_subtitleFull = dataModule->getFilename().filename().string();
 
222
            }
 
223
            else
 
224
            {
 
225
                m_subtitleFull = "Idle";
 
226
            }
 
227
            fitLook( m_itemBestWidth, m_itemBestWidth );
 
228
        }
 
229
    }
 
230
 
 
231
    // show crash state as text too
 
232
    if( ( m_currentState == Crashed ) && ( m_subtitleFull != "Error" ) )
 
233
    {
 
234
        m_subtitleFull = "Error";
 
235
        // this method ensures the text is shortened and correctly placed in the iem
 
236
        fitLook( m_itemBestWidth, m_itemBestWidth );
 
237
        needUpdate = true;
 
238
    }
 
239
 
 
240
    // update tooltip
 
241
    setToolTip( WQtTreeItem::createTooltip( m_module ).c_str() );
 
242
 
 
243
    // if something has changed -> update
 
244
    if( needUpdate )
 
245
    {
 
246
        update();
 
247
    }
 
248
}
 
249
 
 
250
void WQtNetworkItem::hoverEnterEvent( QGraphicsSceneHoverEvent *event )
 
251
{
 
252
    Q_UNUSED( event );
 
253
    m_isHovered = true;
 
254
    update();
 
255
}
 
256
 
 
257
void WQtNetworkItem::hoverLeaveEvent( QGraphicsSceneHoverEvent *event )
 
258
{
 
259
    Q_UNUSED( event );
 
260
    m_isHovered = false;
 
261
    update();
 
262
}
 
263
 
 
264
void WQtNetworkItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* w )
 
265
{
 
266
    // This is the default appearance
 
267
    QPen newPen = QPen( m_itemColor, 1, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin );
 
268
    QColor fillColor = m_itemColor;
 
269
    // change appearance due to state changes
 
270
    switch( m_currentState )
 
271
    {
 
272
        case Disabled:
 
273
            fillColor = m_itemColor.darker( 300 );
 
274
            break;
 
275
        case Crashed:
 
276
            fillColor = WQtNetworkColors::ModuleCrashed;
 
277
            break;
 
278
        case Normal:
 
279
        default:
 
280
            // default behaviour
 
281
            break;
 
282
    }
 
283
 
 
284
    // if hovered:
 
285
    if( m_isHovered )
 
286
    {
 
287
        fillColor = fillColor.lighter();
 
288
    }
 
289
    // if selected:
 
290
    if( m_isSelected )
 
291
    {
 
292
        newPen = QPen( Qt::black, 2, Qt::DotLine, Qt::SquareCap, Qt::RoundJoin );
 
293
    }
 
294
 
 
295
    // only set brush and pen if they have changed
 
296
    QBrush newBrush = QBrush( fillColor );
 
297
    if( newBrush != brush() )
 
298
    {
 
299
        setBrush( newBrush );
 
300
    }
 
301
    if( newPen != pen() )
 
302
    {
 
303
        setPen( newPen );
 
304
    }
 
305
 
 
306
    QStyleOptionGraphicsItem *o = const_cast<QStyleOptionGraphicsItem*>( option );
 
307
    o->state &= ~QStyle::State_Selected;
 
308
    QGraphicsRectItem::paint( painter, o, w );
 
309
 
 
310
    // strike through crashed modules
 
311
    if( m_currentState == Crashed )
 
312
    {
 
313
        painter->setPen( QPen( Qt::black, 1, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin ) );
 
314
        painter->drawLine( QPoint( 0.0, 0.0 ), QPoint( m_width, m_height ) );
 
315
        painter->drawLine( QPoint( 0.0, m_height ), QPoint( m_width, 0.0 ) );
 
316
    }
 
317
 
 
318
    // draw busy indicator
 
319
    if( m_busyIndicatorShow )
 
320
    {
 
321
        float busyBarMarginX = 5.0;
 
322
        float busyIndicatorHeight = 2.0;
 
323
        painter->setPen( QPen( WQtNetworkColors::BusyIndicatorBackground, busyIndicatorHeight, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin ) );
 
324
        painter->drawLine( QPoint( busyBarMarginX, m_height / 2.0 ), QPoint( m_width - busyBarMarginX, m_height / 2.0 ) );
 
325
        painter->setPen( QPen( WQtNetworkColors::BusyIndicator, busyIndicatorHeight, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin ) );
 
326
        float pos = m_busyPercent * ( m_width - ( 2.0 * busyBarMarginX ) );
 
327
 
 
328
        // if the progress indicator is determined (known percentage) -> draw line from 0 to pos
 
329
        if( m_busyIsDetermined )
 
330
        {
 
331
            painter->drawLine( QPoint( busyBarMarginX, m_height / 2.0 ), QPoint( busyBarMarginX + pos, m_height / 2.0 ) );
 
332
        }
 
333
        else
 
334
        {
 
335
            painter->drawLine( QPoint( busyBarMarginX + pos, m_height / 2.0 ), QPoint( busyBarMarginX + pos + 5, m_height / 2.0 ) );
 
336
        }
 
337
    }
 
338
}
 
339
 
 
340
void WQtNetworkItem::mouseMoveEvent( QGraphicsSceneMouseEvent *mouseEvent )
 
341
{
 
342
    QGraphicsItem::mouseMoveEvent( mouseEvent );
 
343
 
 
344
    foreach( WQtNetworkPort *port, m_inPorts )
 
345
    {
 
346
        port->updateArrows();
 
347
    }
 
348
    foreach( WQtNetworkPort *port, m_outPorts )
 
349
    {
 
350
        port->updateArrows();
 
351
    }
 
352
}
 
353
 
 
354
void WQtNetworkItem::mousePressEvent( QGraphicsSceneMouseEvent *event )
 
355
{
 
356
    m_networkEditor->getScene()->clearSelection();
 
357
    setSelected( true );
 
358
    QGraphicsItem::mousePressEvent( event );
 
359
}
 
360
 
 
361
QVariant WQtNetworkItem::itemChange( GraphicsItemChange change, const QVariant &value )
 
362
{
 
363
    switch( change )
 
364
    {
 
365
        case ItemSelectedHasChanged:
 
366
            m_isSelected = isSelected();
 
367
            break;
 
368
        case ItemPositionHasChanged:
 
369
            foreach( WQtNetworkPort *port, m_inPorts )
 
370
            {
 
371
                port->updateArrows();
 
372
            }
 
373
            foreach( WQtNetworkPort *port, m_outPorts )
 
374
            {
 
375
                port->updateArrows();
 
376
            }
 
377
        default:
 
378
            break;
 
379
    }
 
380
 
 
381
    return QGraphicsItem::itemChange( change, value );
 
382
}
 
383
 
 
384
void WQtNetworkItem::addInputPort( WQtNetworkInputPort *port )
 
385
{
 
386
    m_inPorts.append( port );
 
387
}
 
388
 
 
389
void WQtNetworkItem::addOutputPort( WQtNetworkOutputPort *port )
 
390
{
 
391
    m_outPorts.append( port );
 
392
}
 
393
 
 
394
QList< WQtNetworkInputPort *> WQtNetworkItem::getInPorts()
 
395
{
 
396
    return m_inPorts;
 
397
}
 
398
 
 
399
QList< WQtNetworkOutputPort *> WQtNetworkItem::getOutPorts()
 
400
{
 
401
    return m_outPorts;
 
402
}
 
403
 
 
404
WNetworkLayoutNode * WQtNetworkItem::getLayoutNode()
 
405
{
 
406
    return m_layoutNode;
 
407
}
 
408
 
 
409
/**
 
410
 * This function cuts away some text and attaches "..." to ensure a maximum width.
 
411
 *
 
412
 * \param item the item to clip
 
413
 * \param maxWidth the maximum width. After this function finished, the item is <=maxWidth.
 
414
 * \param fullText the original full text
 
415
 */
 
416
void clipText( QGraphicsTextItem* item, float maxWidth, std::string fullText )
 
417
{
 
418
    item->setPlainText( fullText.c_str() );
 
419
    //item->adjustSize();
 
420
 
 
421
    // get size
 
422
    float w = item->boundingRect().width();
 
423
    std::string newText = fullText;
 
424
 
 
425
    // as long as the width is too large, cut away some letters
 
426
    while( w > maxWidth )
 
427
    {
 
428
        // shorten the text
 
429
        newText = newText.substr( 0, newText.length() - 1 );
 
430
        item->setPlainText( ( newText + "..." ).c_str() );
 
431
        // and measure new size
 
432
        w = item->boundingRect().width();
 
433
    }
 
434
}
 
435
 
 
436
void WQtNetworkItem::fitLook( float maximumWidth, float minimumWidth )
 
437
{
 
438
    // The purpose of this method is to ensure proper dimensions of the item and the contained text. This method ensures:
 
439
    //  * an item maximum size is WNETWORKITEM_MINIMUM_WIDTH or the width of the connectors!
 
440
    //  * text exceeding size limits is cut
 
441
 
 
442
    m_width = minimumWidth;
 
443
    m_height = WNETWORKITEM_MINIMUM_HEIGHT;
 
444
 
 
445
    // we need to respect the size minimally needed by ports
 
446
    float portWidth = WQtNetworkPort::getMultiplePortWidth( std::max( m_outPorts.size(), m_inPorts.size() ) );
 
447
 
 
448
    // the item needs a maximum size constraint to avoid enormously large items
 
449
    // NOTE: the specified size max can only be overwritten by the
 
450
    float maxWidth = std::max( static_cast< float >( maximumWidth ), portWidth );
 
451
 
 
452
    // the width of the text elements
 
453
    float textWidth = 0.0;
 
454
    float textHeight = 0.0;
 
455
 
 
456
    // the width and height of the subtext elements
 
457
    float subtextWidth = 0.0;
 
458
    float subtextHeight = 0.0;
 
459
    float subtextMargin = 0.0;  // the margin between text and subtext
 
460
 
 
461
    // 1: query sizes of sub elements
 
462
    if( m_text != 0 )
 
463
    {
 
464
        textWidth = static_cast< float >( m_text->boundingRect().width() );
 
465
        textHeight = static_cast< float >( m_text->boundingRect().height() );
 
466
    }
 
467
    if( m_subtitle != 0 )
 
468
    {
 
469
        subtextWidth = static_cast< float >( m_subtitle->boundingRect().width() );
 
470
        subtextHeight = static_cast< float >( m_subtitle->boundingRect().height() );
 
471
        subtextMargin = 1.0f * WNETWORKITEM_MARGINY;
 
472
    }
 
473
 
 
474
    // and another height: the height of text and subtext
 
475
    float wholeTextHeight = textHeight + subtextHeight + subtextMargin;
 
476
 
 
477
    // get the required width and height
 
478
    float maxTextWidth = maxWidth - ( 2.0f * WNETWORKITEM_MARGINX );
 
479
 
 
480
    // 2: limit sizes of sub elements if needed (especially the subtext)
 
481
    if( ( m_text != 0 ) )
 
482
    {
 
483
        clipText( m_text, maxTextWidth, m_textFull );
 
484
    }
 
485
    if( ( m_subtitle != 0 ) )
 
486
    {
 
487
        clipText( m_subtitle, maxTextWidth, m_subtitleFull );
 
488
    }
 
489
 
 
490
    // the new text boxes now define the final sizes:
 
491
    if( m_text != 0 )
 
492
    {
 
493
        textWidth = static_cast< float >( m_text->boundingRect().width() );
 
494
        textHeight = static_cast< float >( m_text->boundingRect().height() );
 
495
    }
 
496
    if( m_subtitle != 0 )
 
497
    {
 
498
        subtextWidth = static_cast< float >( m_subtitle->boundingRect().width() );
 
499
        subtextHeight = static_cast< float >( m_subtitle->boundingRect().height() );
 
500
    }
 
501
    float requiredWidth = std::max( portWidth, std::max( subtextWidth, textWidth ) + ( 2.0f * WNETWORKITEM_MARGINX ) );
 
502
    float requiredHeight = wholeTextHeight + ( 2.0f * WNETWORKITEM_MARGINY );
 
503
 
 
504
    // 3: set the final sizes
 
505
    m_height = std::max( requiredHeight, static_cast< float >( WNETWORKITEM_MINIMUM_HEIGHT ) );
 
506
    m_width = std::min( std::max( requiredWidth, static_cast< float >( minimumWidth ) ), maxWidth );
 
507
 
 
508
    QRectF rect( 0, 0, m_width, m_height );
 
509
    m_rect = rect;
 
510
    setRect( m_rect );
 
511
 
 
512
    // 4: use the sizes and set the positions and sizes of the text elements properly
 
513
    if( m_text != 0)
 
514
    {
 
515
        qreal x = ( m_width / 2.0 ) - ( m_text->boundingRect().width() / 2.0 );
 
516
        qreal y = ( m_height / 2.0 ) - ( wholeTextHeight / 2.0 );
 
517
        m_text->setPos( x, y );
 
518
    }
 
519
 
 
520
    if( m_subtitle != 0)
 
521
    {
 
522
        qreal x = ( m_width / 2.0 ) - ( m_subtitle->boundingRect().width() / 2.0 );
 
523
        qreal y = ( m_height / 2.0 ) - ( subtextMargin );
 
524
        m_subtitle->setPos( x, y );
 
525
    }
 
526
 
 
527
    // 5: handle the ports
 
528
    int portNumber = 1;
 
529
    foreach( WQtNetworkPort *port, m_inPorts )
 
530
    {
 
531
        port->alignPosition( m_inPorts.size(), portNumber, m_rect, false );
 
532
        portNumber++;
 
533
    }
 
534
 
 
535
    portNumber = 1;
 
536
    foreach( WQtNetworkPort *port, m_outPorts )
 
537
    {
 
538
        port->alignPosition( m_outPorts.size(), portNumber, m_rect, true );
 
539
        portNumber++;
 
540
    }
 
541
}
 
542
 
 
543
void WQtNetworkItem::setTextItem( QGraphicsTextItem *text )
 
544
{
 
545
    m_text = text;
 
546
}
 
547
 
 
548
QString WQtNetworkItem::getText()
 
549
{
 
550
    return QString::fromStdString( m_textFull );
 
551
}
 
552
 
 
553
void WQtNetworkItem::setCrashed()
 
554
{
 
555
    changeState( Crashed );
 
556
}
 
557
 
 
558
void WQtNetworkItem::changeState( State state )
 
559
{
 
560
    m_forceUpdate = ( m_currentState != state );
 
561
    m_currentState = state;
 
562
    update();
 
563
}
 
564
 
 
565
boost::shared_ptr< WModule > WQtNetworkItem::getModule()
 
566
{
 
567
    return m_module;
 
568
}
 
569
 
 
570
void WQtNetworkItem::activate( bool active )
 
571
{
 
572
    setEnabled( active );
 
573
 
 
574
    if( active == true )
 
575
    {
 
576
        setAcceptsHoverEvents( true );
 
577
        setFlag( QGraphicsItem::ItemIsSelectable );
 
578
        setFlag( QGraphicsItem::ItemIsMovable );
 
579
        changeState( m_module->isCrashed() ? Crashed : Normal );
 
580
    }
 
581
    if( active == false )
 
582
    {
 
583
        setAcceptsHoverEvents( false );
 
584
        setFlag( QGraphicsItem::ItemIsSelectable, false );
 
585
        setFlag( QGraphicsItem::ItemIsMovable, false );
 
586
        changeState( Disabled );
 
587
    }
 
588
}
 
589
 
 
590
bool WQtNetworkItem::advance()
 
591
{
 
592
    if( m_newPos == pos() )
 
593
        return false;
 
594
 
 
595
    setPos( m_newPos );
 
596
 
 
597
    foreach( WQtNetworkPort *port, m_inPorts )
 
598
    {
 
599
        port->updateArrows();
 
600
    }
 
601
    foreach( WQtNetworkPort *port, m_outPorts )
 
602
    {
 
603
        port->updateArrows();
 
604
    }
 
605
 
 
606
    return true;
 
607
}
 
608