OpenWalnut  1.5.0dev
WQtNetworkItemActivator.h
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 #ifndef WQTNETWORKITEMACTIVATOR_H
26 #define WQTNETWORKITEMACTIVATOR_H
27 
28 #include <memory>
29 
30 #include <QGraphicsLineItem>
31 #include <QGraphicsPolygonItem>
32 #include <boost/signals2.hpp>
33 
34 #include "WQtNetworkArrow.h"
35 #include "WQtNetworkItemActivator.h"
36 
37 /**
38  * Small graphics item that respresents whether a module in the network editor
39  * is active or not. Clicking on it can toggle the state.
40  */
42 {
43 public:
44  /**
45  * Constructor for indicator showing if module is active.
46  *
47  * \param module The module whose state is represented by this indicator.
48  */
49  explicit WQtNetworkItemActivator( std::shared_ptr< WModule > module );
50 
51  /**
52  * Destructor
53  */
55 
56  /**
57  * This customize the return value of type()
58  */
59  enum
60  {
61  Type = UserType + 13
62  };
63 
64  /**
65  * Reimplementation from QGraphicsItem
66  * \return the type of the item as int
67  */
68  virtual int type() const;
69 
70  /**
71  * Actually paints the port.
72  *
73  * \param painter the painter
74  * \param option style options
75  * \param widget parent widget.
76  */
77  virtual void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget );
78 protected:
79  /**
80  * Start drawing an arrow temporary.
81  *
82  * \param mouseEvent the mouse event
83  */
84  void mousePressEvent( QGraphicsSceneMouseEvent *mouseEvent );
85 
86  std::shared_ptr< WModule > m_module; //!< the module
87 
88  QColor m_activeColor; //!< color used for active indicator
89  QColor m_inactiveColor; //!< color used for inactive indicator
90 
91  /**
92  * The connection used for notification.
93  */
94  boost::signals2::connection m_notifierConnection;
95 
96  /**
97  * Callback getting called by the module's active property to know about state changes
98  */
99  void activeChangeNotifier();
100 
101  /**
102  * If true, the module state changed. Update the item.
103  */
105 
106  /**
107  * Setups tooltip and brush acccording to state.
108  */
109  void handleActiveState();
110 };
111 #endif // WQTNETWORKITEMACTIVATOR_H
Small graphics item that respresents whether a module in the network editor is active or not.
void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
Start drawing an arrow temporary.
WQtNetworkItemActivator(std::shared_ptr< WModule > module)
Constructor for indicator showing if module is active.
std::shared_ptr< WModule > m_module
the module
bool m_needStateUpdate
If true, the module state changed.
void activeChangeNotifier()
Callback getting called by the module's active property to know about state changes.
boost::signals2::connection m_notifierConnection
The connection used for notification.
void handleActiveState()
Setups tooltip and brush acccording to state.
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Actually paints the port.
QColor m_inactiveColor
color used for inactive indicator
virtual int type() const
Reimplementation from QGraphicsItem.
QColor m_activeColor
color used for active indicator