2 ******************************************************************************
4 * @file mixercurvepoint.h
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @addtogroup GCSPlugins GCS Plugins
8 * @addtogroup UAVObjectWidgetUtils Plugin
10 * @brief Utility plugin for UAVObject to Widget relation management
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <QGraphicsScene>
29 #include <QGraphicsSceneMouseEvent>
31 #include <QStyleOption>
35 #include "mixercurveline.h"
36 #include "mixercurvepoint.h"
37 #include "mixercurvewidget.h"
39 MixerNode::MixerNode(MixerCurveWidget
*graphWidget
, QGraphicsItem
*graphItem
)
40 : m_graph(graphWidget
), m_graphItem(graphItem
)
42 setFlag(ItemIsMovable
);
43 setFlag(ItemSendsGeometryChanges
);
44 setCacheMode(DeviceCoordinateCache
);
51 m_positiveColor
= "#609FF2"; // blueish?
52 m_neutralColor
= "#14CE24"; // greenish?
53 m_negativeColor
= "#EF5F5F"; // redish?
54 m_disabledColor
= "#dddddd";
55 m_disabledTextColor
= "#aaaaaa";
58 void MixerNode::addEdge(Edge
*edge
)
64 QList
<Edge
*> MixerNode::edges() const
70 QRectF
MixerNode::boundingRect() const
72 return QRectF(-13, -13, 26, 26);
75 QPainterPath
MixerNode::shape() const
79 path
.addEllipse(boundingRect());
83 void MixerNode::paint(QPainter
*painter
, const QStyleOptionGraphicsItem
*option
, QWidget
*)
85 QString text
= QString().sprintf("%.2f", value());
87 painter
->setFont(m_graph
->font());
89 QRadialGradient
gradient(-3, -3, 10);
93 color
= m_negativeColor
;
94 } else if (value() == 0) {
95 color
= m_neutralColor
;
97 color
= m_positiveColor
;
99 color
.setAlphaF(m_alpha
);
101 if (option
->state
& QStyle::State_Sunken
) {
102 gradient
.setCenter(3, 3);
103 gradient
.setFocalPoint(3, 3);
105 QColor selColor
= color
.darker();
106 gradient
.setColorAt(1, selColor
.darker());
107 gradient
.setColorAt(0, selColor
);
109 gradient
.setColorAt(0, m_graph
->isEnabled() ? color
: m_disabledColor
);
110 gradient
.setColorAt(1, m_graph
->isEnabled() ? color
.darker() : m_disabledColor
);
112 painter
->setBrush(gradient
);
113 painter
->setPen(m_graph
->isEnabled() ? QPen(Qt::black
, 0) : QPen(m_disabledTextColor
));
114 painter
->drawEllipse(boundingRect());
116 if (!m_image
.isNull()) {
117 painter
->drawImage(boundingRect().adjusted(1, 1, -1, -1), m_image
);
122 if (m_graph
->isEnabled()) {
123 painter
->setPen(QPen(m_drawNode
? Qt::white
: Qt::black
, 0));
125 painter
->setPen(QPen(m_disabledTextColor
));
128 painter
->drawText((value() < 0) ? -10 : -8, 3, text
);
132 void MixerNode::verticalMove(bool flag
)
137 double MixerNode::value()
139 double h
= m_graphItem
->boundingRect().height();
140 double ratio
= (h
- pos().y()) / h
;
142 return ((m_graph
->getMax() - m_graph
->getMin()) * ratio
) + m_graph
->getMin();
146 QVariant
MixerNode::itemChange(GraphicsItemChange change
, const QVariant
&val
)
148 QPointF newPos
= val
.toPointF();
149 double h
= m_graphItem
->boundingRect().height();
152 case ItemPositionChange
:
158 // Force node to move vertically
159 newPos
.setX(pos().x());
162 if (newPos
.y() < 0) {
165 // qDebug() << h << " - " << newPos.y();
166 if (newPos
.y() > h
) {
172 case ItemPositionHasChanged
:
174 foreach(Edge
* edge
, m_edgeList
)
179 m_graph
->itemMoved(value());
187 return QGraphicsItem::itemChange(change
, val
);
190 void MixerNode::mousePressEvent(QGraphicsSceneMouseEvent
*event
)
193 QGraphicsItem::mousePressEvent(event
);
196 void MixerNode::mouseReleaseEvent(QGraphicsSceneMouseEvent
*event
)
199 QGraphicsItem::mouseReleaseEvent(event
);