28 #include <QGraphicsScene>
29 #include <QGraphicsSceneMouseEvent>
31 #include <QStyleOption>
42 setFlag(ItemIsMovable);
43 setFlag(ItemSendsGeometryChanges);
44 setCacheMode(DeviceCoordinateCache);
53 posColor0 =
"#1c870b";
54 posColor1 =
"#116703";
55 negColor0 =
"#aa0000";
56 negColor1 =
"#aa0000";
59 void MixerNode::addEdge(
Edge *edge)
70 QRectF MixerNode::boundingRect()
const
72 return cmdNode ? QRectF(-4, -4, 15, 10) : QRectF(-13, -13, 26, 26);
75 QPainterPath MixerNode::shape()
const
78 path.addEllipse(boundingRect());
82 void MixerNode::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *)
84 QString text = cmdNode ? cmdText : QString().sprintf(
"%.2f", value());
85 painter->setFont(graph->font());
87 QRadialGradient gradient(-3, -3, 10);
88 if (option->state & QStyle::State_Sunken) {
89 gradient.setCenter(3, 3);
90 gradient.setFocalPoint(3, 3);
92 gradient.setColorAt(1, Qt::darkBlue);
93 gradient.setColorAt(0, Qt::darkBlue);
96 gradient.setColorAt(0, cmdActive ? posColor0 : negColor0);
97 gradient.setColorAt(1, cmdActive ? posColor1 : negColor1);
100 gradient.setColorAt(0, negColor0);
101 gradient.setColorAt(1, negColor1);
103 gradient.setColorAt(0, posColor0);
104 gradient.setColorAt(1, posColor1);
108 painter->setBrush(gradient);
109 painter->setPen(QPen(Qt::black, 0));
110 painter->drawEllipse(boundingRect());
113 painter->drawImage(boundingRect().adjusted(1, 1, -1, -1), image);
117 painter->setPen(QPen(drawNode ? Qt::white : Qt::black, 0));
119 painter->drawText(0, 4, text);
121 painter->drawText((value() < 0) ? -13 : -11, 4, text);
126 void MixerNode::verticalMove(
bool flag)
131 void MixerNode::commandNode(
bool enable)
135 void MixerNode::commandText(QString text)
140 double MixerNode::value()
142 double h = graph->sceneRect().height();
143 double ratio = (h - pos().y()) / h;
149 QPointF newPos = val.toPointF();
150 double h = graph->sceneRect().height();
153 case ItemPositionChange: {
159 newPos.setX(pos().
x());
170 case ItemPositionHasChanged: {
171 foreach (
Edge *edge, edgeList)
183 return QGraphicsItem::itemChange(change, val);
193 QGraphicsItem::mousePressEvent(event);
199 QGraphicsItem::mouseReleaseEvent(event);