40 : QGraphicsView(parent)
43 , curveUpdating(false)
57 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
58 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
59 setRenderHint(QPainter::Antialiasing);
61 setFrameStyle(QFrame::NoFrame);
62 setStyleSheet(
"background:transparent");
64 QGraphicsScene *scene =
new QGraphicsScene(
this);
65 QSvgRenderer *renderer =
new QSvgRenderer();
66 plot =
new QGraphicsSvgItem();
67 renderer->load(QString(
":/configgadget/images/curve-bg.svg"));
68 plot->setSharedRenderer(renderer);
73 scene->setSceneRect(plot->boundingRect());
76 posColor0 =
"#1c870b";
77 posColor1 =
"#116703";
78 negColor0 =
"#ff0000";
79 negColor1 =
"#ff0000";
84 node->setName(
"Reset");
85 node->setToolTip(
"Reset Curve to Defaults");
86 node->setToggle(
false);
87 node->setPositiveColor(
"#ffffff",
"#ffffff");
88 node->setNegativeColor(
"#ffffff",
"#ffffff");
92 node = getCommandNode(1);
93 node->setName(
"Linear");
94 node->setToolTip(
"Generate a Linear Curve");
95 QImage img = QImage(
":/core/images/curve_linear.png");
99 node->commandText(
"/");
101 scene->addItem(node);
104 node = getCommandNode(2);
105 node->setName(
"Log");
106 node->setToolTip(
"Generate a Logarithmic Curve");
107 img = QImage(
":/core/images/curve_log.png");
111 node->commandText(
"(");
112 scene->addItem(node);
115 node = getCommandNode(3);
116 node->setName(
"Exp");
117 node->setToolTip(
"Generate an Exponential Curve");
118 img = QImage(
":/core/images/curve_exp.png");
122 node->commandText(
")");
123 scene->addItem(node);
126 node = getCommandNode(4);
127 node->setName(
"Flat");
128 node->setToolTip(
"Generate a Flat Curve");
129 img = QImage(
":/core/images/curve_flat.png");
133 node->commandText(
"--");
134 scene->addItem(node);
137 node = getCommandNode(5);
138 node->setName(
"Step");
139 node->setToolTip(
"Generate a Stepped Curve");
140 img = QImage(
":/core/images/curve_step.png");
144 node->commandText(
"z");
145 scene->addItem(node);
148 node = getCommandNode(6);
149 node->setName(
"MinPlus");
150 node->setToolTip(
"Increase Curve Minimum");
151 img = QImage(
":/core/images/curve_plus.png");
155 node->commandText(
"+");
156 node->setToggle(
false);
157 node->setPositiveColor(
"#00aa00",
"#00aa00");
158 node->setNegativeColor(
"#00aa00",
"#00aa00");
159 scene->addItem(node);
161 node = getCommandNode(7);
162 node->setName(
"MinMinus");
163 node->setToolTip(
"Decrease Curve Minimum");
164 img = QImage(
":/core/images/curve_minus.png");
168 node->commandText(
"-");
170 node->setToggle(
false);
171 node->setPositiveColor(
"#aa0000",
"#aa0000");
172 node->setNegativeColor(
"#aa0000",
"#aa0000");
173 scene->addItem(node);
175 node = getCommandNode(8);
176 node->setName(
"MaxPlus");
177 node->setToolTip(
"Increase Curve Maximum");
178 img = QImage(
":/core/images/curve_plus.png");
182 node->commandText(
"+");
184 node->setToggle(
false);
185 node->setPositiveColor(
"#00aa00",
"#00aa00");
186 node->setNegativeColor(
"#00aa00",
"#00aa00");
187 scene->addItem(node);
189 node = getCommandNode(9);
190 node->setName(
"MaxMinus");
191 node->setToolTip(
"Decrease Curve Maximum");
192 img = QImage(
":/core/images/curve_plus.png");
196 node->commandText(
"-");
198 node->setToggle(
false);
199 node->setPositiveColor(
"#aa0000",
"#aa0000");
200 node->setNegativeColor(
"#aa0000",
"#aa0000");
201 scene->addItem(node);
203 node = getCommandNode(10);
204 node->setName(
"StepPlus");
205 node->setToolTip(
"Increase Step/Power Value");
206 img = QImage(
":/core/images/curve_plus.png");
210 node->commandText(
"+");
211 node->setToggle(
false);
212 node->setPositiveColor(
"#00aa00",
"#00aa00");
213 node->setNegativeColor(
"#00aa00",
"#00aa00");
214 scene->addItem(node);
216 node = getCommandNode(11);
217 node->setName(
"StepMinus");
218 node->setToolTip(
"Decrease Step/Power Value");
219 img = QImage(
":/core/images/curve_minus.png");
223 node->commandText(
"-");
225 node->setToggle(
false);
226 node->setPositiveColor(
"#aa0000",
"#aa0000");
227 node->setNegativeColor(
"#aa0000",
"#aa0000");
228 scene->addItem(node);
230 node = getCommandNode(12);
231 node->setName(
"StepValue");
232 node->setDrawNode(
false);
233 node->setToolTip(
"Current Step/Power Value");
234 node->setToggle(
false);
235 node->setPositiveColor(
"#0000aa",
"#0000aa");
236 node->setNegativeColor(
"#0000aa",
"#0000aa");
237 scene->addItem(node);
240 node = getCommandNode(13);
241 node->setName(
"Commands");
242 node->setToolTip(
"Toggle Command Buttons On/Off");
243 node->setToggle(
true);
244 node->setPositiveColor(
"#00aa00",
"#00aa00");
245 node->setNegativeColor(
"#000000",
"#000000");
246 scene->addItem(node);
249 node = getCommandNode(14);
250 node->setName(
"Popup");
251 node->setToolTip(
"Advanced Mode...");
252 node->commandText(
"");
253 node->setToggle(
false);
254 node->setPositiveColor(
"#ff0000",
"#ff0000");
255 node->setNegativeColor(
"#ff0000",
"#ff0000");
256 scene->addItem(node);
265 while (!nodePool.isEmpty())
266 delete nodePool.takeFirst();
268 while (!edgePool.isEmpty())
269 delete edgePool.takeFirst();
271 while (!cmdNodePool.isEmpty())
272 delete cmdNodePool.takeFirst();
275 MixerNode *MixerCurveWidget::getCommandNode(
int index)
279 if (index >= 0 && index < cmdNodePool.count()) {
280 node = cmdNodePool.at(index);
283 node->commandNode(
true);
284 node->commandText(
"");
285 node->setCommandIndex(index);
286 node->setActive(
false);
287 node->setPositiveColor(
"#aaaa00",
"#aaaa00");
288 node->setNegativeColor(
"#1c870b",
"#116703");
289 cmdNodePool.append(node);
294 MixerNode *MixerCurveWidget::getNode(
int index)
298 if (index >= 0 && index < nodePool.count()) {
299 node = nodePool.at(index);
302 nodePool.append(node);
310 if (index >= 0 && index < edgePool.count()) {
311 edge = edgePool.at(index);
315 edge =
new Edge(sourceNode, destNode);
316 edgePool.append(edge);
321 void MixerCurveWidget::setPositiveColor(QString color0, QString color1)
325 for (
int i = 0;
i < nodePool.count();
i++) {
327 node->setPositiveColor(color0, color1);
330 void MixerCurveWidget::setNegativeColor(QString color0, QString color1)
334 for (
int i = 0;
i < nodePool.count();
i++) {
336 node->setNegativeColor(color0, color1);
348 if (points->length() < 2)
355 void MixerCurveWidget::initNodes(
int numPoints)
358 if (nodeList.count()) {
360 foreach (
Edge *edge, node->edges()) {
362 scene()->removeItem(edge);
365 scene()->removeItem(node);
373 for (
int i = 0;
i < numPoints;
i++) {
377 nodeList.append(node);
378 scene()->addItem(node);
383 scene()->addItem(getEdge(
i, prevNode, node));
399 list.append(node->value());
409 double range = maxValue - minValue;
412 for (
double i = 0;
i < (double)numPoints;
i++) {
413 double val = (range * (
i / (double)(numPoints - 1))) + minValue;
423 curveUpdating =
true;
425 int ptCnt = points->count();
426 if (nodeList.count() != ptCnt)
429 double range = curveMax - curveMin;
431 qreal w = plot->boundingRect().width() / (ptCnt - 1);
432 qreal
h = plot->boundingRect().height();
433 for (
int i = 0;
i < ptCnt;
i++) {
435 double val = (points->at(
i) < curveMin)
437 : (points->at(
i) > curveMax) ? curveMax : points->at(
i);
440 val -= (curveMin + range);
444 node->setPos(w *
i, h - (val * h));
445 node->verticalMove(
true);
449 curveUpdating =
false;
463 QRectF rect = plot->boundingRect();
465 fitInView(rect.adjusted(-15, -15, 15, 15), Qt::KeepAspectRatio);
472 QRectF rect = plot->boundingRect();
474 fitInView(rect.adjusted(-15, -15, 15, 15), Qt::KeepAspectRatio);
477 void MixerCurveWidget::resizeCommands()
479 QRectF rect = plot->boundingRect();
483 node = getCommandNode(14);
484 node->setPos((rect.left() + rect.width() / 2) - 20, rect.height() + 10);
487 node = getCommandNode(0);
488 node->setPos((rect.left() + rect.width() / 2) + 20, rect.height() + 10);
491 node = getCommandNode(13);
492 node->setPos(rect.right() - 15, rect.bottomRight().x() - 14);
494 for (
int i = 1;
i < 6;
i++) {
495 node = getCommandNode(
i);
498 node->setPos(rect.right() - 130 + (
i * 18), rect.bottomRight().x() - 14);
502 node = getCommandNode(6);
503 node->setPos(rect.bottomLeft().x() + 15, rect.bottomLeft().y() - 10);
506 node = getCommandNode(7);
507 node->setPos(rect.bottomLeft().x() + 15, rect.bottomLeft().y() + 5);
510 node = getCommandNode(8);
511 node->setPos(rect.topRight().x() - 20, rect.topRight().y() - 7);
514 node = getCommandNode(9);
515 node->setPos(rect.topRight().x() - 20, rect.topRight().y() + 8);
518 node = getCommandNode(10);
519 node->setPos(rect.bottomRight().x() - 40, rect.bottomRight().y() + 5);
522 node = getCommandNode(11);
523 node->setPos(rect.bottomRight().x() - 40, rect.bottomRight().y() + 15);
526 node = getCommandNode(12);
527 node->setPos(rect.bottomRight().x() - 22, rect.bottomRight().y() + 9);
534 if (!curveUpdating) {
541 if (curveMin != value)
549 if (curveMax != value)
567 return curveMax - curveMin;
573 for (
int i = 0;
i < cmdNodePool.count();
i++) {
575 if (n->getName() == name)
583 for (
int i = 0;
i < cmdNodePool.count();
i++) {
585 if (n->getName() == name) {
586 n->commandText(text);
593 for (
int i = 1;
i < cmdNodePool.count() - 2;
i++) {
595 node->setCommandActive(node->getName() == name);
612 for (
int i = 1;
i < cmdNodePool.count() - 2;
i++) {
627 active = node->getCommandActive();
634 if (node->getToggle()) {
635 if (node->getName() ==
"Commands") {
636 node->setCommandActive(!node->getCommandActive());
639 for (
int i = 1;
i < cmdNodePool.count() - 2;
i++) {
641 n->setCommandActive(
false);
645 node->setCommandActive(
true);