2011-03-29 20:32:09 +00:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file mixercurvewidget.cpp
|
2012-02-05 20:07:19 +00:00
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
2011-03-29 20:32:09 +00:00
|
|
|
* @addtogroup GCSPlugins GCS Plugins
|
|
|
|
* @{
|
2012-02-05 20:07:19 +00:00
|
|
|
* @addtogroup UAVObjectWidgetUtils Plugin
|
2011-03-29 20:32:09 +00:00
|
|
|
* @{
|
2012-02-05 20:07:19 +00:00
|
|
|
* @brief Utility plugin for UAVObject to Widget relation management
|
2011-03-29 20:32:09 +00:00
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mixercurvewidget.h"
|
|
|
|
#include "mixercurveline.h"
|
|
|
|
#include "mixercurvepoint.h"
|
|
|
|
|
2012-07-11 21:49:05 -07:00
|
|
|
#include <QObject>
|
2011-03-29 20:32:09 +00:00
|
|
|
#include <QtGui>
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the widget
|
|
|
|
*/
|
|
|
|
MixerCurveWidget::MixerCurveWidget(QWidget *parent) : QGraphicsView(parent)
|
|
|
|
{
|
|
|
|
|
|
|
|
// Create a layout, add a QGraphicsView and put the SVG inside.
|
|
|
|
// The Mixer Curve widget looks like this:
|
|
|
|
// |--------------------|
|
|
|
|
// | |
|
|
|
|
// | |
|
|
|
|
// | Graph |
|
|
|
|
// | |
|
|
|
|
// | |
|
|
|
|
// | |
|
|
|
|
// |--------------------|
|
|
|
|
|
|
|
|
|
|
|
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
setRenderHint(QPainter::Antialiasing);
|
|
|
|
|
|
|
|
curveMin=0.0;
|
|
|
|
curveMax=1.0;
|
|
|
|
|
2011-05-02 22:56:01 +02:00
|
|
|
setFrameStyle(QFrame::NoFrame);
|
|
|
|
setStyleSheet("background:transparent");
|
2011-03-29 20:32:09 +00:00
|
|
|
|
|
|
|
QGraphicsScene *scene = new QGraphicsScene(this);
|
|
|
|
QSvgRenderer *renderer = new QSvgRenderer();
|
|
|
|
plot = new QGraphicsSvgItem();
|
2013-04-15 21:43:04 +02:00
|
|
|
renderer->load(QString(":/uavobjectwidgetutils/images/curve-bg.svg"));
|
2011-03-29 20:32:09 +00:00
|
|
|
plot->setSharedRenderer(renderer);
|
|
|
|
//plot->setElementId("map");
|
|
|
|
scene->addItem(plot);
|
|
|
|
plot->setZValue(-1);
|
2012-06-22 17:01:33 -07:00
|
|
|
|
2011-03-29 20:32:09 +00:00
|
|
|
scene->setSceneRect(plot->boundingRect());
|
|
|
|
setScene(scene);
|
|
|
|
|
2012-07-11 21:49:05 -07:00
|
|
|
posColor0 = "#1c870b"; //greenish?
|
|
|
|
posColor1 = "#116703"; //greenish?
|
|
|
|
negColor0 = "#ff0000"; //red
|
|
|
|
negColor1 = "#ff0000"; //red
|
|
|
|
|
|
|
|
// commmand nodes
|
|
|
|
// reset
|
2012-09-12 11:09:30 +01:00
|
|
|
MixerNode* node = getCommandNode(0);
|
2012-07-11 21:49:05 -07:00
|
|
|
node->setName("Reset");
|
2012-07-12 10:49:22 -07:00
|
|
|
node->setToolTip("Reset Curve to Defaults");
|
2012-07-11 21:49:05 -07:00
|
|
|
node->setToggle(false);
|
|
|
|
node->setPositiveColor("#ffffff", "#ffffff"); //white
|
|
|
|
node->setNegativeColor("#ffffff", "#ffffff");
|
|
|
|
scene->addItem(node);
|
|
|
|
|
|
|
|
// linear
|
|
|
|
node = getCommandNode(1);
|
|
|
|
node->setName("Linear");
|
2012-07-12 10:49:22 -07:00
|
|
|
node->setToolTip("Generate a Linear Curve");
|
2012-07-13 16:34:29 -07:00
|
|
|
QImage img = QImage(":/core/images/curve_linear.png");
|
|
|
|
if (!img.isNull())
|
|
|
|
node->setImage(img);
|
|
|
|
else
|
|
|
|
node->commandText("/");
|
|
|
|
|
2012-07-11 21:49:05 -07:00
|
|
|
scene->addItem(node);
|
|
|
|
|
|
|
|
// log
|
|
|
|
node = getCommandNode(2);
|
|
|
|
node->setName("Log");
|
2012-07-12 10:49:22 -07:00
|
|
|
node->setToolTip("Generate a Logarithmic Curve");
|
2012-07-13 16:34:29 -07:00
|
|
|
img = QImage(":/core/images/curve_log.png");
|
|
|
|
if (!img.isNull())
|
|
|
|
node->setImage(img);
|
|
|
|
else
|
|
|
|
node->commandText("(");
|
2012-07-11 21:49:05 -07:00
|
|
|
scene->addItem(node);
|
|
|
|
|
|
|
|
// exp
|
|
|
|
node = getCommandNode(3);
|
|
|
|
node->setName("Exp");
|
2012-07-12 10:49:22 -07:00
|
|
|
node->setToolTip("Generate an Exponential Curve");
|
2012-07-13 16:34:29 -07:00
|
|
|
img = QImage(":/core/images/curve_exp.png");
|
|
|
|
if (!img.isNull())
|
|
|
|
node->setImage(img);
|
|
|
|
else
|
|
|
|
node->commandText(")");
|
2012-07-11 21:49:05 -07:00
|
|
|
scene->addItem(node);
|
|
|
|
|
|
|
|
// flat
|
|
|
|
node = getCommandNode(4);
|
|
|
|
node->setName("Flat");
|
2012-07-12 10:49:22 -07:00
|
|
|
node->setToolTip("Generate a Flat Curve");
|
2012-07-13 16:34:29 -07:00
|
|
|
img = QImage(":/core/images/curve_flat.png");
|
|
|
|
if (!img.isNull())
|
|
|
|
node->setImage(img);
|
|
|
|
else
|
|
|
|
node->commandText("--");
|
2012-07-11 21:49:05 -07:00
|
|
|
scene->addItem(node);
|
|
|
|
|
|
|
|
// step
|
|
|
|
node = getCommandNode(5);
|
|
|
|
node->setName("Step");
|
2012-07-12 10:49:22 -07:00
|
|
|
node->setToolTip("Generate a Stepped Curve");
|
2012-07-13 16:34:29 -07:00
|
|
|
img = QImage(":/core/images/curve_step.png");
|
|
|
|
if (!img.isNull())
|
|
|
|
node->setImage(img);
|
|
|
|
else
|
|
|
|
node->commandText("z");
|
2012-07-11 21:49:05 -07:00
|
|
|
scene->addItem(node);
|
|
|
|
|
|
|
|
|
|
|
|
// curve min/max nodes
|
|
|
|
node = getCommandNode(6);
|
|
|
|
node->setName("MinPlus");
|
2012-07-12 10:49:22 -07:00
|
|
|
node->setToolTip("Increase Curve Minimum");
|
2012-07-13 16:34:29 -07:00
|
|
|
img = QImage(":/core/images/curve_plus.png");
|
|
|
|
if (!img.isNull())
|
|
|
|
node->setImage(img);
|
|
|
|
else
|
|
|
|
node->commandText("+");
|
2012-07-11 21:49:05 -07:00
|
|
|
node->setToggle(false);
|
2012-07-12 10:49:22 -07:00
|
|
|
node->setPositiveColor("#00aa00", "#00aa00"); //green
|
|
|
|
node->setNegativeColor("#00aa00", "#00aa00");
|
2012-07-11 21:49:05 -07:00
|
|
|
scene->addItem(node);
|
|
|
|
|
|
|
|
node = getCommandNode(7);
|
|
|
|
node->setName("MinMinus");
|
2012-07-12 10:49:22 -07:00
|
|
|
node->setToolTip("Decrease Curve Minimum");
|
2012-07-13 16:34:29 -07:00
|
|
|
img = QImage(":/core/images/curve_minus.png");
|
|
|
|
if (!img.isNull())
|
|
|
|
node->setImage(img);
|
|
|
|
else
|
|
|
|
node->commandText("-");
|
|
|
|
|
2012-07-11 21:49:05 -07:00
|
|
|
node->setToggle(false);
|
2012-07-12 10:49:22 -07:00
|
|
|
node->setPositiveColor("#aa0000", "#aa0000"); //red
|
|
|
|
node->setNegativeColor("#aa0000", "#aa0000");
|
2012-07-11 21:49:05 -07:00
|
|
|
scene->addItem(node);
|
|
|
|
|
|
|
|
node = getCommandNode(8);
|
|
|
|
node->setName("MaxPlus");
|
2012-07-12 10:49:22 -07:00
|
|
|
node->setToolTip("Increase Curve Maximum");
|
2012-07-13 16:34:29 -07:00
|
|
|
img = QImage(":/core/images/curve_plus.png");
|
|
|
|
if (!img.isNull())
|
|
|
|
node->setImage(img);
|
|
|
|
else
|
|
|
|
node->commandText("+");
|
|
|
|
|
2012-07-11 21:49:05 -07:00
|
|
|
node->setToggle(false);
|
2012-07-12 10:49:22 -07:00
|
|
|
node->setPositiveColor("#00aa00", "#00aa00"); //green
|
|
|
|
node->setNegativeColor("#00aa00", "#00aa00");
|
2012-07-11 21:49:05 -07:00
|
|
|
scene->addItem(node);
|
|
|
|
|
|
|
|
node = getCommandNode(9);
|
|
|
|
node->setName("MaxMinus");
|
2012-07-12 10:49:22 -07:00
|
|
|
node->setToolTip("Decrease Curve Maximum");
|
2012-07-13 16:34:29 -07:00
|
|
|
img = QImage(":/core/images/curve_plus.png");
|
|
|
|
if (!img.isNull())
|
|
|
|
node->setImage(img);
|
|
|
|
else
|
|
|
|
node->commandText("-");
|
|
|
|
|
2012-07-11 21:49:05 -07:00
|
|
|
node->setToggle(false);
|
2012-07-12 10:49:22 -07:00
|
|
|
node->setPositiveColor("#aa0000", "#aa0000"); //red
|
|
|
|
node->setNegativeColor("#aa0000", "#aa0000");
|
2012-07-11 21:49:05 -07:00
|
|
|
scene->addItem(node);
|
|
|
|
|
|
|
|
node = getCommandNode(10);
|
|
|
|
node->setName("StepPlus");
|
2012-07-12 10:49:22 -07:00
|
|
|
node->setToolTip("Increase Step/Power Value");
|
2012-07-13 16:34:29 -07:00
|
|
|
img = QImage(":/core/images/curve_plus.png");
|
|
|
|
if (!img.isNull())
|
|
|
|
node->setImage(img);
|
|
|
|
else
|
|
|
|
node->commandText("+");
|
2012-07-11 21:49:05 -07:00
|
|
|
node->setToggle(false);
|
2012-07-12 10:49:22 -07:00
|
|
|
node->setPositiveColor("#00aa00", "#00aa00"); //green
|
|
|
|
node->setNegativeColor("#00aa00", "#00aa00");
|
2012-07-11 21:49:05 -07:00
|
|
|
scene->addItem(node);
|
|
|
|
|
|
|
|
node = getCommandNode(11);
|
|
|
|
node->setName("StepMinus");
|
2012-07-12 10:49:22 -07:00
|
|
|
node->setToolTip("Decrease Step/Power Value");
|
2012-07-13 16:34:29 -07:00
|
|
|
img = QImage(":/core/images/curve_minus.png");
|
|
|
|
if (!img.isNull())
|
|
|
|
node->setImage(img);
|
|
|
|
else
|
|
|
|
node->commandText("-");
|
|
|
|
|
2012-07-11 21:49:05 -07:00
|
|
|
node->setToggle(false);
|
2012-07-12 10:49:22 -07:00
|
|
|
node->setPositiveColor("#aa0000", "#aa0000"); //red
|
|
|
|
node->setNegativeColor("#aa0000", "#aa0000");
|
2012-07-11 21:49:05 -07:00
|
|
|
scene->addItem(node);
|
|
|
|
|
|
|
|
node = getCommandNode(12);
|
|
|
|
node->setName("StepValue");
|
2012-07-13 22:41:58 -07:00
|
|
|
node->setDrawNode(false);
|
2012-07-12 10:49:22 -07:00
|
|
|
node->setToolTip("Current Step/Power Value");
|
2012-07-11 21:49:05 -07:00
|
|
|
node->setToggle(false);
|
2012-07-12 10:49:22 -07:00
|
|
|
node->setPositiveColor("#0000aa", "#0000aa"); //blue
|
|
|
|
node->setNegativeColor("#0000aa", "#0000aa");
|
2012-07-11 21:49:05 -07:00
|
|
|
scene->addItem(node);
|
|
|
|
|
2012-07-12 12:40:51 -07:00
|
|
|
// commands toggle
|
|
|
|
node = getCommandNode(13);
|
|
|
|
node->setName("Commands");
|
|
|
|
node->setToolTip("Toggle Command Buttons On/Off");
|
|
|
|
node->setToggle(true);
|
|
|
|
node->setPositiveColor("#00aa00", "#00aa00"); //greenish
|
|
|
|
node->setNegativeColor("#000000", "#000000");
|
|
|
|
scene->addItem(node);
|
|
|
|
|
2012-07-13 13:44:56 -07:00
|
|
|
// popup
|
|
|
|
node = getCommandNode(14);
|
|
|
|
node->setName("Popup");
|
|
|
|
node->setToolTip("Advanced Mode...");
|
2012-07-13 22:41:58 -07:00
|
|
|
node->commandText("");
|
2012-07-13 13:44:56 -07:00
|
|
|
node->setToggle(false);
|
|
|
|
node->setPositiveColor("#ff0000", "#ff0000"); //red
|
|
|
|
node->setNegativeColor("#ff0000", "#ff0000");
|
|
|
|
scene->addItem(node);
|
|
|
|
|
2012-07-11 21:49:05 -07:00
|
|
|
resizeCommands();
|
|
|
|
|
2012-06-19 10:28:42 -07:00
|
|
|
initNodes(MixerCurveWidget::NODE_NUMELEM);
|
2012-07-11 21:49:05 -07:00
|
|
|
|
2011-03-29 20:32:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MixerCurveWidget::~MixerCurveWidget()
|
|
|
|
{
|
2012-06-20 12:46:07 -07:00
|
|
|
while (!nodePool.isEmpty())
|
|
|
|
delete nodePool.takeFirst();
|
2012-06-19 10:28:42 -07:00
|
|
|
|
2012-06-20 12:46:07 -07:00
|
|
|
while (!edgePool.isEmpty())
|
|
|
|
delete edgePool.takeFirst();
|
2012-07-11 21:49:05 -07:00
|
|
|
|
|
|
|
while (!cmdNodePool.isEmpty())
|
|
|
|
delete cmdNodePool.takeFirst();
|
|
|
|
}
|
|
|
|
|
2012-09-12 11:09:30 +01:00
|
|
|
MixerNode* MixerCurveWidget::getCommandNode(int index)
|
2012-07-11 21:49:05 -07:00
|
|
|
{
|
2012-09-12 11:09:30 +01:00
|
|
|
MixerNode* node;
|
2012-07-11 21:49:05 -07:00
|
|
|
|
|
|
|
if (index >= 0 && index < cmdNodePool.count())
|
|
|
|
{
|
|
|
|
node = cmdNodePool.at(index);
|
|
|
|
}
|
|
|
|
else {
|
2012-09-12 11:09:30 +01:00
|
|
|
node = new MixerNode(this);
|
2012-07-11 21:49:05 -07:00
|
|
|
node->commandNode(true);
|
|
|
|
node->commandText("");
|
|
|
|
node->setCommandIndex(index);
|
|
|
|
node->setActive(false);
|
2012-07-12 10:49:22 -07:00
|
|
|
node->setPositiveColor("#aaaa00", "#aaaa00");
|
2012-07-13 13:44:56 -07:00
|
|
|
node->setNegativeColor("#1c870b", "#116703");
|
2012-07-11 21:49:05 -07:00
|
|
|
cmdNodePool.append(node);
|
|
|
|
}
|
|
|
|
return node;
|
2012-07-13 13:44:56 -07:00
|
|
|
|
2012-06-19 10:28:42 -07:00
|
|
|
}
|
|
|
|
|
2012-09-12 11:09:30 +01:00
|
|
|
MixerNode* MixerCurveWidget::getNode(int index)
|
2012-06-19 10:28:42 -07:00
|
|
|
{
|
2012-09-12 11:09:30 +01:00
|
|
|
MixerNode* node;
|
2012-06-19 10:28:42 -07:00
|
|
|
|
|
|
|
if (index >= 0 && index < nodePool.count())
|
|
|
|
{
|
|
|
|
node = nodePool.at(index);
|
|
|
|
}
|
|
|
|
else {
|
2012-09-12 11:09:30 +01:00
|
|
|
node = new MixerNode(this);
|
2012-06-19 10:28:42 -07:00
|
|
|
nodePool.append(node);
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
2012-09-12 11:09:30 +01:00
|
|
|
Edge* MixerCurveWidget::getEdge(int index, MixerNode* sourceNode, MixerNode* destNode)
|
2012-06-19 10:28:42 -07:00
|
|
|
{
|
|
|
|
Edge* edge;
|
2011-03-29 20:32:09 +00:00
|
|
|
|
2012-06-19 10:28:42 -07:00
|
|
|
if (index >= 0 && index < edgePool.count())
|
|
|
|
{
|
|
|
|
edge = edgePool.at(index);
|
|
|
|
edge->setSourceNode(sourceNode);
|
|
|
|
edge->setDestNode(destNode);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
edge = new Edge(sourceNode,destNode);
|
|
|
|
edgePool.append(edge);
|
|
|
|
}
|
|
|
|
return edge;
|
2011-03-29 20:32:09 +00:00
|
|
|
}
|
|
|
|
|
2012-07-11 21:49:05 -07:00
|
|
|
void MixerCurveWidget::setPositiveColor(QString color0, QString color1)
|
|
|
|
{
|
|
|
|
posColor0 = color0;
|
|
|
|
posColor1 = color1;
|
|
|
|
for (int i=0; i<nodePool.count(); i++) {
|
2012-09-12 11:09:30 +01:00
|
|
|
MixerNode* node = nodePool.at(i);
|
2012-07-11 21:49:05 -07:00
|
|
|
node->setPositiveColor(color0, color1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void MixerCurveWidget::setNegativeColor(QString color0, QString color1)
|
|
|
|
{
|
|
|
|
negColor0 = color0;
|
|
|
|
negColor1 = color1;
|
|
|
|
for (int i=0; i<nodePool.count(); i++) {
|
2012-09-12 11:09:30 +01:00
|
|
|
MixerNode* node = nodePool.at(i);
|
2012-07-11 21:49:05 -07:00
|
|
|
node->setNegativeColor(color0, color1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-29 20:32:09 +00:00
|
|
|
/**
|
|
|
|
Init curve: create a (flat) curve with a specified number of points.
|
|
|
|
|
|
|
|
If a curve exists already, resets it.
|
|
|
|
Points should be between 0 and 1.
|
|
|
|
*/
|
2012-06-28 15:56:40 -07:00
|
|
|
void MixerCurveWidget::initCurve(const QList<double>* points)
|
2011-03-29 20:32:09 +00:00
|
|
|
{
|
2012-06-28 15:56:40 -07:00
|
|
|
if (points->length() < 2)
|
2011-03-29 20:32:09 +00:00
|
|
|
return; // We need at least 2 points on a curve!
|
|
|
|
|
2012-06-19 10:28:42 -07:00
|
|
|
// finally, set node positions
|
|
|
|
setCurve(points);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MixerCurveWidget::initNodes(int numPoints)
|
|
|
|
{
|
2012-06-19 15:22:11 -07:00
|
|
|
// First of all, clear any existing list
|
2012-06-19 10:28:42 -07:00
|
|
|
if (nodeList.count()) {
|
2012-09-12 11:09:30 +01:00
|
|
|
foreach (MixerNode *node, nodeList ) {
|
2012-06-22 17:01:33 -07:00
|
|
|
foreach(Edge *edge, node->edges()) {
|
|
|
|
if (edge->sourceNode() == node) {
|
2012-06-19 15:22:11 -07:00
|
|
|
scene()->removeItem(edge);
|
|
|
|
}
|
2011-03-29 20:32:09 +00:00
|
|
|
}
|
2012-06-19 10:28:42 -07:00
|
|
|
scene()->removeItem(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
nodeList.clear();
|
2011-03-29 20:32:09 +00:00
|
|
|
}
|
|
|
|
|
2012-06-19 15:22:11 -07:00
|
|
|
// Create the nodes and edges
|
2012-09-12 11:09:30 +01:00
|
|
|
MixerNode* prevNode = 0;
|
2012-06-19 10:28:42 -07:00
|
|
|
for (int i=0; i<numPoints; i++) {
|
|
|
|
|
2012-09-12 11:09:30 +01:00
|
|
|
MixerNode *node = getNode(i);
|
2012-06-19 10:28:42 -07:00
|
|
|
|
2011-03-29 20:32:09 +00:00
|
|
|
nodeList.append(node);
|
2012-06-19 10:28:42 -07:00
|
|
|
scene()->addItem(node);
|
2011-03-29 20:32:09 +00:00
|
|
|
|
2012-06-21 11:53:51 -07:00
|
|
|
node->setPos(0,0);
|
|
|
|
|
2012-06-19 15:22:11 -07:00
|
|
|
if (prevNode) {
|
|
|
|
scene()->addItem(getEdge(i, prevNode, node));
|
|
|
|
}
|
|
|
|
|
|
|
|
prevNode = node;
|
2011-03-29 20:32:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the current curve settings
|
|
|
|
*/
|
|
|
|
QList<double> MixerCurveWidget::getCurve() {
|
2012-06-19 16:51:22 -07:00
|
|
|
|
2011-03-29 20:32:09 +00:00
|
|
|
QList<double> list;
|
|
|
|
|
2012-09-12 11:09:30 +01:00
|
|
|
foreach(MixerNode *node, nodeList) {
|
2012-06-21 11:53:51 -07:00
|
|
|
list.append(node->value());
|
2011-03-29 20:32:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
2011-06-12 00:49:05 +01:00
|
|
|
/**
|
|
|
|
Sets a linear graph
|
|
|
|
*/
|
2012-06-22 17:01:33 -07:00
|
|
|
void MixerCurveWidget::initLinearCurve(int numPoints, double maxValue, double minValue)
|
2011-06-12 00:49:05 +01:00
|
|
|
{
|
2012-07-06 13:38:46 -07:00
|
|
|
double range = maxValue - minValue; // setRange(minValue, maxValue);
|
2012-06-19 15:22:11 -07:00
|
|
|
|
2011-06-12 00:49:05 +01:00
|
|
|
QList<double> points;
|
2012-06-22 17:01:33 -07:00
|
|
|
for (double i=0; i < (double)numPoints; i++) {
|
2012-06-24 11:11:53 -07:00
|
|
|
double val = (range * ( i / (double)(numPoints-1) ) ) + minValue;
|
2012-06-19 15:22:11 -07:00
|
|
|
points.append(val);
|
2011-06-12 00:49:05 +01:00
|
|
|
}
|
2012-06-28 15:56:40 -07:00
|
|
|
initCurve(&points);
|
2011-06-12 00:49:05 +01:00
|
|
|
}
|
2011-03-29 20:32:09 +00:00
|
|
|
/**
|
|
|
|
Setd the current curve settings
|
|
|
|
*/
|
2012-06-28 15:56:40 -07:00
|
|
|
void MixerCurveWidget::setCurve(const QList<double>* points)
|
2011-03-29 20:32:09 +00:00
|
|
|
{
|
2012-06-19 10:28:42 -07:00
|
|
|
curveUpdating = true;
|
|
|
|
|
2012-06-28 15:56:40 -07:00
|
|
|
int ptCnt = points->count();
|
2012-06-22 17:31:14 -07:00
|
|
|
if (nodeList.count() != ptCnt)
|
|
|
|
initNodes(ptCnt);
|
2012-06-19 10:28:42 -07:00
|
|
|
|
2012-06-22 17:31:14 -07:00
|
|
|
double range = curveMax - curveMin;
|
2012-06-21 11:53:51 -07:00
|
|
|
|
2012-06-22 17:31:14 -07:00
|
|
|
qreal w = plot->boundingRect().width()/(ptCnt-1);
|
|
|
|
qreal h = plot->boundingRect().height();
|
|
|
|
for (int i=0; i<ptCnt; i++) {
|
2012-06-19 10:28:42 -07:00
|
|
|
|
2012-06-28 15:56:40 -07:00
|
|
|
double val = (points->at(i) < curveMin) ? curveMin : (points->at(i) > curveMax) ? curveMax : points->at(i);
|
2012-06-19 10:28:42 -07:00
|
|
|
|
2012-06-22 17:31:14 -07:00
|
|
|
val += range;
|
|
|
|
val -= (curveMin + range);
|
|
|
|
val /= range;
|
2012-06-19 10:28:42 -07:00
|
|
|
|
2012-09-12 11:09:30 +01:00
|
|
|
MixerNode* node = nodeList.at(i);
|
2012-06-21 11:53:51 -07:00
|
|
|
node->setPos(w*i, h - (val*h));
|
|
|
|
node->verticalMove(true);
|
2012-07-11 21:49:05 -07:00
|
|
|
|
2012-06-30 14:35:38 -07:00
|
|
|
node->update();
|
2012-06-21 11:53:51 -07:00
|
|
|
}
|
2012-06-19 10:28:42 -07:00
|
|
|
curveUpdating = false;
|
|
|
|
|
2012-06-21 11:53:51 -07:00
|
|
|
update();
|
|
|
|
|
2012-06-30 14:35:38 -07:00
|
|
|
emit curveUpdated();
|
2011-03-29 20:32:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MixerCurveWidget::showEvent(QShowEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event)
|
|
|
|
// Thit fitInView method should only be called now, once the
|
|
|
|
// widget is shown, otherwise it cannot compute its values and
|
|
|
|
// the result is usually a ahrsbargraph that is way too small.
|
|
|
|
|
2012-07-06 11:44:16 -07:00
|
|
|
QRectF rect = plot->boundingRect();
|
2012-07-11 21:49:05 -07:00
|
|
|
resizeCommands();
|
2012-07-07 21:56:07 -07:00
|
|
|
fitInView(rect.adjusted(-15,-15,15,15), Qt::KeepAspectRatio);
|
2011-03-29 20:32:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MixerCurveWidget::resizeEvent(QResizeEvent* event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event);
|
2012-07-06 11:28:46 -07:00
|
|
|
|
2012-07-06 11:44:16 -07:00
|
|
|
QRectF rect = plot->boundingRect();
|
2012-07-11 21:49:05 -07:00
|
|
|
resizeCommands();
|
2012-07-08 10:38:15 -07:00
|
|
|
fitInView(rect.adjusted(-15,-15,15,15), Qt::KeepAspectRatio);
|
2011-03-29 20:32:09 +00:00
|
|
|
}
|
|
|
|
|
2012-07-11 21:49:05 -07:00
|
|
|
void MixerCurveWidget::resizeCommands()
|
|
|
|
{
|
|
|
|
QRectF rect = plot->boundingRect();
|
|
|
|
|
2012-09-12 11:09:30 +01:00
|
|
|
MixerNode* node;
|
2012-07-13 13:44:56 -07:00
|
|
|
//popup
|
|
|
|
node = getCommandNode(14);
|
|
|
|
node->setPos((rect.left() + rect.width() / 2) - 20, rect.height() + 10);
|
|
|
|
|
2012-07-12 12:40:51 -07:00
|
|
|
//reset
|
2012-07-12 10:49:22 -07:00
|
|
|
node = getCommandNode(0);
|
2012-07-13 13:44:56 -07:00
|
|
|
node->setPos((rect.left() + rect.width() / 2) + 20, rect.height() + 10);
|
2012-07-12 10:49:22 -07:00
|
|
|
|
2012-07-12 12:40:51 -07:00
|
|
|
//commands on/off
|
|
|
|
node = getCommandNode(13);
|
2012-07-13 22:41:58 -07:00
|
|
|
node->setPos(rect.right() - 15, rect.bottomRight().x() - 14);
|
2012-07-12 10:49:22 -07:00
|
|
|
|
|
|
|
for (int i = 1; i<6; i++) {
|
2012-07-11 21:49:05 -07:00
|
|
|
node = getCommandNode(i);
|
|
|
|
|
2012-07-12 10:49:22 -07:00
|
|
|
//bottom right of widget
|
2012-07-13 22:41:58 -07:00
|
|
|
node->setPos(rect.right() - 130 + (i * 18), rect.bottomRight().x() - 14);
|
2012-07-11 21:49:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//curveminplus
|
|
|
|
node = getCommandNode(6);
|
|
|
|
node->setPos(rect.bottomLeft().x() + 15, rect.bottomLeft().y() - 10);
|
|
|
|
|
|
|
|
//curveminminus
|
|
|
|
node = getCommandNode(7);
|
|
|
|
node->setPos(rect.bottomLeft().x() + 15, rect.bottomLeft().y() + 5);
|
|
|
|
|
|
|
|
//curvemaxplus
|
|
|
|
node = getCommandNode(8);
|
|
|
|
node->setPos(rect.topRight().x() - 20, rect.topRight().y() - 7);
|
|
|
|
|
|
|
|
//curvemaxminus
|
|
|
|
node = getCommandNode(9);
|
|
|
|
node->setPos(rect.topRight().x() - 20, rect.topRight().y() + 8);
|
|
|
|
|
|
|
|
//stepplus
|
|
|
|
node = getCommandNode(10);
|
2012-07-13 22:41:58 -07:00
|
|
|
node->setPos(rect.bottomRight().x() - 40, rect.bottomRight().y() + 5);
|
2012-07-11 21:49:05 -07:00
|
|
|
|
|
|
|
//stepminus
|
|
|
|
node = getCommandNode(11);
|
2012-07-13 22:41:58 -07:00
|
|
|
node->setPos(rect.bottomRight().x() - 40, rect.bottomRight().y() + 15);
|
2012-07-11 21:49:05 -07:00
|
|
|
|
|
|
|
//step
|
|
|
|
node = getCommandNode(12);
|
2012-07-13 22:41:58 -07:00
|
|
|
node->setPos(rect.bottomRight().x() - 22, rect.bottomRight().y() + 9);
|
2012-07-11 21:49:05 -07:00
|
|
|
}
|
|
|
|
|
2011-03-29 20:32:09 +00:00
|
|
|
void MixerCurveWidget::itemMoved(double itemValue)
|
|
|
|
{
|
2012-07-11 21:49:05 -07:00
|
|
|
Q_UNUSED(itemValue);
|
|
|
|
|
2012-06-19 10:28:42 -07:00
|
|
|
if (!curveUpdating) {
|
2012-06-30 14:35:38 -07:00
|
|
|
emit curveUpdated();
|
2012-06-19 10:28:42 -07:00
|
|
|
}
|
2011-03-29 20:32:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MixerCurveWidget::setMin(double value)
|
|
|
|
{
|
2012-06-30 14:35:38 -07:00
|
|
|
if (curveMin != value)
|
|
|
|
emit curveMinChanged(value);
|
|
|
|
|
2011-03-29 20:32:09 +00:00
|
|
|
curveMin = value;
|
|
|
|
}
|
2012-06-30 14:35:38 -07:00
|
|
|
|
2011-03-29 20:32:09 +00:00
|
|
|
void MixerCurveWidget::setMax(double value)
|
|
|
|
{
|
2012-06-30 14:35:38 -07:00
|
|
|
if (curveMax != value)
|
|
|
|
emit curveMaxChanged(value);
|
|
|
|
|
2011-03-29 20:32:09 +00:00
|
|
|
curveMax = value;
|
|
|
|
}
|
2012-06-30 14:35:38 -07:00
|
|
|
|
2012-06-19 16:51:22 -07:00
|
|
|
double MixerCurveWidget::getMin()
|
|
|
|
{
|
|
|
|
return curveMin;
|
|
|
|
}
|
|
|
|
double MixerCurveWidget::getMax()
|
|
|
|
{
|
|
|
|
return curveMax;
|
|
|
|
}
|
2012-06-24 11:11:53 -07:00
|
|
|
double MixerCurveWidget::setRange(double min, double max)
|
2011-03-29 20:32:09 +00:00
|
|
|
{
|
|
|
|
curveMin = min;
|
|
|
|
curveMax = max;
|
2012-06-24 11:11:53 -07:00
|
|
|
return curveMax - curveMin;
|
2011-03-29 20:32:09 +00:00
|
|
|
}
|
2012-07-11 21:49:05 -07:00
|
|
|
|
2012-09-12 11:09:30 +01:00
|
|
|
MixerNode* MixerCurveWidget::getCmdNode(const QString& name)
|
2012-07-11 21:49:05 -07:00
|
|
|
{
|
2012-09-12 11:09:30 +01:00
|
|
|
MixerNode* node = 0;
|
2012-07-11 21:49:05 -07:00
|
|
|
for (int i=0; i<cmdNodePool.count(); i++) {
|
2012-09-12 11:09:30 +01:00
|
|
|
MixerNode* n = cmdNodePool.at(i);
|
2012-07-11 21:49:05 -07:00
|
|
|
if (n->getName() == name)
|
|
|
|
node = n;
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MixerCurveWidget::setCommandText(const QString& name, const QString& text)
|
|
|
|
{
|
|
|
|
for (int i=0; i<cmdNodePool.count(); i++) {
|
2012-09-12 11:09:30 +01:00
|
|
|
MixerNode* n = cmdNodePool.at(i);
|
2012-07-11 21:49:05 -07:00
|
|
|
if (n->getName() == name) {
|
|
|
|
n->commandText(text);
|
|
|
|
n->update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void MixerCurveWidget::activateCommand(const QString& name)
|
|
|
|
{
|
2012-07-13 13:44:56 -07:00
|
|
|
for (int i=1; i<cmdNodePool.count()-2; i++) {
|
2012-09-12 11:09:30 +01:00
|
|
|
MixerNode* node = cmdNodePool.at(i);
|
2012-07-12 12:40:51 -07:00
|
|
|
node->setCommandActive(node->getName() == name);
|
2012-07-11 21:49:05 -07:00
|
|
|
node->update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-13 22:41:58 -07:00
|
|
|
void MixerCurveWidget::showCommand(const QString& name, bool show)
|
|
|
|
{
|
2012-09-12 11:09:30 +01:00
|
|
|
MixerNode* node = getCmdNode(name);
|
2012-07-13 22:41:58 -07:00
|
|
|
if (node) {
|
|
|
|
if (show)
|
|
|
|
node->show();
|
|
|
|
else
|
|
|
|
node->hide();
|
|
|
|
}
|
|
|
|
}
|
2012-07-12 12:40:51 -07:00
|
|
|
void MixerCurveWidget::showCommands(bool show)
|
|
|
|
{
|
2012-07-13 13:44:56 -07:00
|
|
|
for (int i=1; i<cmdNodePool.count()-2; i++) {
|
2012-09-12 11:09:30 +01:00
|
|
|
MixerNode* node = cmdNodePool.at(i);
|
2012-07-12 12:40:51 -07:00
|
|
|
if (show)
|
|
|
|
node->show();
|
|
|
|
else
|
|
|
|
node->hide();
|
|
|
|
|
|
|
|
node->update();
|
|
|
|
}
|
|
|
|
}
|
2012-07-13 22:41:58 -07:00
|
|
|
bool MixerCurveWidget::isCommandActive(const QString& name)
|
|
|
|
{
|
|
|
|
bool active = false;
|
2012-09-12 11:09:30 +01:00
|
|
|
MixerNode* node = getCmdNode(name);
|
2012-07-13 22:41:58 -07:00
|
|
|
if (node) {
|
|
|
|
active = node->getCommandActive();
|
|
|
|
}
|
|
|
|
return active;
|
|
|
|
}
|
|
|
|
|
2012-09-12 11:09:30 +01:00
|
|
|
void MixerCurveWidget::cmdActivated(MixerNode* node)
|
2012-07-11 21:49:05 -07:00
|
|
|
{
|
|
|
|
if (node->getToggle()) {
|
2012-07-12 12:40:51 -07:00
|
|
|
if (node->getName() == "Commands") {
|
|
|
|
node->setCommandActive(!node->getCommandActive());
|
|
|
|
showCommands(node->getCommandActive());
|
|
|
|
}
|
|
|
|
else {
|
2012-07-13 13:44:56 -07:00
|
|
|
for (int i=1; i<cmdNodePool.count()-2; i++) {
|
2012-09-12 11:09:30 +01:00
|
|
|
MixerNode* n = cmdNodePool.at(i);
|
2012-07-12 12:40:51 -07:00
|
|
|
n->setCommandActive(false);
|
|
|
|
n->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
node->setCommandActive(true);
|
2012-07-11 21:49:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
node->update();
|
|
|
|
emit commandActivated(node);
|
|
|
|
}
|
|
|
|
|