1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-17 02:52:12 +01:00

MixerCurve: simplified.

This commit is contained in:
Mike LaBranche 2012-07-11 21:49:05 -07:00
parent 0c6bd52a57
commit e1b469b130
7 changed files with 705 additions and 367 deletions

View File

@ -47,18 +47,26 @@ MixerCurve::MixerCurve(QWidget *parent) :
// set the default mixer type
setMixerType(MixerCurve::MIXERCURVE_THROTTLE);
// setup and turn off advanced mode
CommandActivated();
// paint the ui
UpdateCurveUI();
// wire up our signals
connect(m_mixerUI->CurveType, SIGNAL(currentIndexChanged(int)), this, SLOT(CurveTypeChanged()));
connect(m_mixerUI->ResetCurve, SIGNAL(clicked()), this, SLOT(ResetCurve()));
connect(m_mixerUI->GenerateCurve, SIGNAL(clicked()), this, SLOT(GenerateCurve()));
connect(m_curve, SIGNAL(curveUpdated()), this, SLOT(UpdateSettingsTable()));
connect(m_curve, SIGNAL(commandActivated(Node*)),this, SLOT(CommandActivated(Node*)));
connect(m_settings, SIGNAL(cellChanged(int,int)), this, SLOT(SettingsTableChanged()));
connect(m_mixerUI->CurveMin, SIGNAL(valueChanged(double)), this, SLOT(CurveMinChanged(double)));
connect(m_mixerUI->CurveMax, SIGNAL(valueChanged(double)), this, SLOT(CurveMaxChanged(double)));
connect(m_mixerUI->CurveStep, SIGNAL(valueChanged(double)), this, SLOT(GenerateCurve()));
}
MixerCurve::~MixerCurve()
@ -86,7 +94,8 @@ void MixerCurve::setMixerType(MixerCurveType curveType)
case MixerCurve::MIXERCURVE_PITCH:
{
m_mixerUI->SettingsGroup->setTitle("Pitch Curve");
m_curve->setRange(-1.0, 1.0);
m_curve->setRange(-1.0, 1.0);
m_curve->setPositiveColor("#0000ff", "#0000ff");
m_mixerUI->CurveMin->setMinimum(-1.0);
m_mixerUI->CurveMax->setMinimum(-1.0);
break;
@ -109,6 +118,8 @@ void MixerCurve::ResetCurve()
initLinearCurve(MixerCurveWidget::NODE_NUMELEM, getCurveMax(), getCurveMin());
m_curve->activateCommand("Linear");
UpdateSettingsTable();
}
@ -117,14 +128,11 @@ void MixerCurve::UpdateCurveUI()
//get the user settings
QString curveType = m_mixerUI->CurveType->currentText();
m_mixerUI->CurveMin->setValue(m_mixerUI->CurveMin->minimum());
m_mixerUI->CurveMax->setValue(m_mixerUI->CurveMax->maximum());
m_mixerUI->CurveStep->setMinimum(0.0);
m_mixerUI->CurveStep->setMaximum(100.0);
m_mixerUI->CurveStep->setSingleStep(1.00);
//set default visible
m_mixerUI->minLabel->setText("Min");
m_mixerUI->minLabel->setVisible(true);
m_mixerUI->CurveMin->setVisible(true);
m_mixerUI->maxLabel->setVisible(false);
@ -134,7 +142,10 @@ void MixerCurve::UpdateCurveUI()
if ( curveType.compare("Flat")==0)
{
m_mixerUI->minLabel->setText("Value");
m_mixerUI->CurveStep->setMinimum(m_mixerUI->CurveMin->minimum());
m_mixerUI->CurveStep->setMaximum(m_mixerUI->CurveMax->maximum());
m_mixerUI->CurveStep->setSingleStep(0.01);
m_mixerUI->CurveStep->setValue(m_mixerUI->CurveMax->value() / 2);
}
if ( curveType.compare("Linear")==0)
{
@ -155,7 +166,7 @@ void MixerCurve::UpdateCurveUI()
{
m_mixerUI->maxLabel->setVisible(true);
m_mixerUI->CurveMax->setVisible(true);
m_mixerUI->stepLabel->setText("Strength");
m_mixerUI->stepLabel->setText("Power");
m_mixerUI->stepLabel->setVisible(true);
m_mixerUI->CurveStep->setVisible(true);
@ -165,7 +176,7 @@ void MixerCurve::UpdateCurveUI()
{
m_mixerUI->maxLabel->setVisible(true);
m_mixerUI->CurveMax->setVisible(true);
m_mixerUI->stepLabel->setText("Strength");
m_mixerUI->stepLabel->setText("Power");
m_mixerUI->stepLabel->setVisible(true);
m_mixerUI->CurveStep->setVisible(true);
m_mixerUI->CurveStep->setMinimum(1.0);
@ -184,6 +195,8 @@ void MixerCurve::GenerateCurve()
double value2 = getCurveMax();
double value3 = getCurveStep();
m_curve->setCommandText("StepValue", QString("%0").arg(value3));
QString CurveType = m_mixerUI->CurveType->currentText();
QList<double> points;
@ -194,7 +207,7 @@ void MixerCurve::GenerateCurve()
if ( CurveType.compare("Flat")==0)
{
points.append(value1);
points.append(value3);
}
if ( CurveType.compare("Linear")==0)
{
@ -323,6 +336,57 @@ void MixerCurve::SettingsTableChanged()
m_curve->setCurve(&points);
}
void MixerCurve::CommandActivated(Node* node)
{
//m_mixerUI->GenerateCurve->hide();
m_mixerUI->SettingsGroup->hide();
m_mixerUI->ValuesGroup->hide();
QString name = (node) ? node->getName() : "Reset";
if (name == "Reset") {
ResetCurve();
}
else if (name == "Linear") {
m_mixerUI->CurveType->setCurrentIndex(m_mixerUI->CurveType->findText("Linear"));
}
else if (name == "Log") {
m_mixerUI->CurveType->setCurrentIndex(m_mixerUI->CurveType->findText("Log"));
}
else if (name == "Exp") {
m_mixerUI->CurveType->setCurrentIndex(m_mixerUI->CurveType->findText("Exp"));
}
else if (name == "Flat") {
m_mixerUI->CurveType->setCurrentIndex(m_mixerUI->CurveType->findText("Flat"));
}
else if (name == "Step") {
m_mixerUI->CurveType->setCurrentIndex(m_mixerUI->CurveType->findText("Step"));
}
else if (name == "MinPlus") {
m_mixerUI->CurveMin->stepUp();
}
else if (name == "MinMinus") {
m_mixerUI->CurveMin->stepDown();
}
else if (name == "MaxPlus") {
m_mixerUI->CurveMax->stepUp();
}
else if (name == "MaxMinus"){
m_mixerUI->CurveMax->stepDown();
}
else if (name == "StepPlus") {
m_mixerUI->CurveStep->stepUp();
m_curve->setCommandText("StepValue", QString("%0").arg(getCurveStep()));
}
else if (name == "StepMinus") {
m_mixerUI->CurveStep->stepDown();
m_curve->setCommandText("StepValue", QString("%0").arg(getCurveStep()));
}
GenerateCurve();
}
void MixerCurve::CurveTypeChanged()
{
// setup the ui for this curvetype

View File

@ -82,6 +82,7 @@ public slots:
void UpdateSettingsTable();
private slots:
void CommandActivated(Node* node = 0);
void SettingsTableChanged();
void CurveTypeChanged();
void CurveMinChanged(double value);

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>441</width>
<height>321</height>
<height>334</height>
</rect>
</property>
<property name="sizePolicy">
@ -43,340 +43,309 @@
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QHBoxLayout" name="MainLayout">
<item>
<layout class="QVBoxLayout" name="SettingsLayout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<widget class="QGroupBox" name="SettingsGroup">
<property name="maximumSize">
<size>
<width>150</width>
<height>16777215</height>
</size>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" rowspan="2">
<widget class="QGroupBox" name="SettingsGroup">
<property name="maximumSize">
<size>
<width>150</width>
<height>16777215</height>
</size>
</property>
<property name="title">
<string>Throttle Curve</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTableWidget" name="CurveSettings">
<property name="maximumSize">
<size>
<width>100</width>
<height>200</height>
</size>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="autoScroll">
<bool>false</bool>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="rowCount">
<number>5</number>
</property>
<property name="columnCount">
<number>1</number>
</property>
<row>
<property name="text">
<string>Max</string>
</property>
<property name="title">
<string>Throttle Curve</string>
</row>
<row>
<property name="text">
<string>4</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTableWidget" name="CurveSettings">
<property name="maximumSize">
<size>
<width>100</width>
<height>200</height>
</size>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="autoScroll">
<bool>false</bool>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="rowCount">
<number>5</number>
</property>
<property name="columnCount">
<number>1</number>
</property>
<row>
<property name="text">
<string>5</string>
</property>
</row>
<row>
<property name="text">
<string>4</string>
</property>
</row>
<row>
<property name="text">
<string>3</string>
</property>
</row>
<row>
<property name="text">
<string>2</string>
</property>
</row>
<row>
<property name="text">
<string>1</string>
</property>
</row>
<column>
<property name="text">
<string>Value</string>
</property>
<property name="textAlignment">
<set>AlignJustify|AlignVCenter</set>
</property>
</column>
<item row="0" column="0">
<property name="text">
<string>1.0</string>
</property>
</item>
<item row="1" column="0">
<property name="text">
<string>.75</string>
</property>
</item>
<item row="2" column="0">
<property name="text">
<string>.50</string>
</property>
</item>
<item row="3" column="0">
<property name="text">
<string>.25</string>
</property>
</item>
<item row="4" column="0">
<property name="text">
<string>.00</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QComboBox" name="CurveType">
<item>
<property name="text">
<string>Linear</string>
</property>
</item>
<item>
<property name="text">
<string>Log</string>
</property>
</item>
<item>
<property name="text">
<string>Exp</string>
</property>
</item>
<item>
<property name="text">
<string>Flat</string>
</property>
</item>
<item>
<property name="text">
<string>Step</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QPushButton" name="GenerateCurve">
<property name="text">
<string>Generate</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="ResetCurve">
<property name="text">
<string>Reset</string>
</property>
</widget>
</item>
</layout>
<zorder>GenerateCurve</zorder>
<zorder>CurveSettings</zorder>
<zorder>ResetCurve</zorder>
<zorder>CurveType</zorder>
<zorder>verticalSpacer</zorder>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<widget class="QGroupBox" name="CurveGroup">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>1</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</row>
<row>
<property name="text">
<string>3</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMinAndMaxSize</enum>
</property>
<item row="1" column="0">
<widget class="MixerCurveWidget" name="CurveWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>5</horstretch>
<verstretch>5</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>1000</width>
<height>1000</height>
</size>
</property>
<property name="sizeIncrement">
<size>
<width>10</width>
<height>10</height>
</size>
</property>
<property name="baseSize">
<size>
<width>200</width>
<height>200</height>
</size>
</property>
<property name="font">
<font>
<pointsize>7</pointsize>
</font>
</property>
</widget>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="CurveLayout">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="minLabel">
<property name="text">
<string>Min</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="CurveMin">
<property name="correctionMode">
<enum>QAbstractSpinBox::CorrectToNearestValue</enum>
</property>
<property name="minimum">
<double>-1.000000000000000</double>
</property>
<property name="maximum">
<double>1.000000000000000</double>
</property>
<property name="singleStep">
<double>0.010000000000000</double>
</property>
<property name="value">
<double>0.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="maxLabel">
<property name="text">
<string>Max</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="CurveMax">
<property name="correctionMode">
<enum>QAbstractSpinBox::CorrectToNearestValue</enum>
</property>
<property name="minimum">
<double>0.000000000000000</double>
</property>
<property name="maximum">
<double>1.000000000000000</double>
</property>
<property name="singleStep">
<double>0.010000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="stepLabel">
<property name="text">
<string>Step</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="CurveStep">
<property name="correctionMode">
<enum>QAbstractSpinBox::CorrectToNearestValue</enum>
</property>
<property name="value">
<double>50.000000000000000</double>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</item>
</layout>
</row>
<row>
<property name="text">
<string>2</string>
</property>
</row>
<row>
<property name="text">
<string>Min</string>
</property>
</row>
<column>
<property name="text">
<string>Value</string>
</property>
<property name="textAlignment">
<set>AlignJustify|AlignVCenter</set>
</property>
</column>
<item row="0" column="0">
<property name="text">
<string>1.0</string>
</property>
</item>
<item row="1" column="0">
<property name="text">
<string>.75</string>
</property>
</item>
<item row="2" column="0">
<property name="text">
<string>.50</string>
</property>
</item>
<item row="3" column="0">
<property name="text">
<string>.25</string>
</property>
</item>
<item row="4" column="0">
<property name="text">
<string>.00</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QComboBox" name="CurveType">
<item>
<property name="text">
<string>Linear</string>
</property>
</item>
<item>
<property name="text">
<string>Log</string>
</property>
</item>
<item>
<property name="text">
<string>Exp</string>
</property>
</item>
<item>
<property name="text">
<string>Flat</string>
</property>
</item>
<item>
<property name="text">
<string>Step</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QPushButton" name="GenerateCurve">
<property name="text">
<string>Generate</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="ResetCurve">
<property name="text">
<string>Reset</string>
</property>
</widget>
</item>
</layout>
<zorder>GenerateCurve</zorder>
<zorder>CurveSettings</zorder>
<zorder>ResetCurve</zorder>
<zorder>CurveType</zorder>
<zorder>verticalSpacer</zorder>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="MixerCurveWidget" name="CurveWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>5</horstretch>
<verstretch>5</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>1000</width>
<height>1000</height>
</size>
</property>
<property name="sizeIncrement">
<size>
<width>10</width>
<height>10</height>
</size>
</property>
<property name="baseSize">
<size>
<width>200</width>
<height>200</height>
</size>
</property>
<property name="font">
<font>
<pointsize>7</pointsize>
</font>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QGroupBox" name="ValuesGroup">
<property name="title">
<string/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="minLabel">
<property name="text">
<string>Min</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="CurveMin">
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="correctionMode">
<enum>QAbstractSpinBox::CorrectToNearestValue</enum>
</property>
<property name="minimum">
<double>-1.000000000000000</double>
</property>
<property name="maximum">
<double>1.000000000000000</double>
</property>
<property name="singleStep">
<double>0.010000000000000</double>
</property>
<property name="value">
<double>0.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="maxLabel">
<property name="text">
<string>Max</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="CurveMax">
<property name="correctionMode">
<enum>QAbstractSpinBox::CorrectToNearestValue</enum>
</property>
<property name="minimum">
<double>0.000000000000000</double>
</property>
<property name="maximum">
<double>1.000000000000000</double>
</property>
<property name="singleStep">
<double>0.010000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="stepLabel">
<property name="text">
<string>Step</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="CurveStep">
<property name="correctionMode">
<enum>QAbstractSpinBox::CorrectToNearestValue</enum>
</property>
<property name="value">
<double>50.000000000000000</double>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>

View File

@ -29,6 +29,7 @@
#include <QGraphicsSceneMouseEvent>
#include <QPainter>
#include <QStyleOption>
#include <QColor>
#include <QDebug>
#include "mixercurveline.h"
@ -42,7 +43,16 @@ Node::Node(MixerCurveWidget *graphWidget)
setFlag(ItemSendsGeometryChanges);
setCacheMode(DeviceCoordinateCache);
setZValue(-1);
cmdActive = false;
vertical = false;
cmdNode = false;
cmdToggle = true;
posColor0 = "#1c870b"; //greenish?
posColor1 = "#116703"; //greenish?
negColor0 = "#ff0000"; //red
negColor1 = "#ff0000"; //red
}
void Node::addEdge(Edge *edge)
@ -59,53 +69,53 @@ QList<Edge *> Node::edges() const
QRectF Node::boundingRect() const
{
return QRectF(-13, -13, 26, 26);
return cmdNode ? QRectF(-4, -4, 15, 10) : QRectF(-13, -13, 26, 26);
}
QPainterPath Node::shape() const
{
QPainterPath path;
path.addEllipse(-13, -13, 26, 26);
path.addEllipse(boundingRect());
return path;
}
void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
{
/*
painter->setPen(Qt::NoPen);
painter->setBrush(Qt::darkGray);
painter->drawEllipse(-7, -7, 20, 20);
*/
QString text = cmdNode ? cmdText : QString().sprintf("% .2f", value());
QRadialGradient gradient(-3, -3, 10);
if (option->state & QStyle::State_Sunken) {
gradient.setCenter(3, 3);
gradient.setFocalPoint(3, 3);
//gradient.setColorAt(1, QColor("#1c870b").light(120));
//gradient.setColorAt(0, QColor("#116703").light(120));
gradient.setColorAt(1, Qt::darkBlue);
gradient.setColorAt(0, Qt::darkBlue);
} else {
if (value() < 0) {
gradient.setColorAt(0, Qt::red);
gradient.setColorAt(1, Qt::red);
if (cmdNode) {
gradient.setColorAt(0, cmdActive ? posColor0 : negColor0);
gradient.setColorAt(1, cmdActive ? posColor1 : negColor1);
}
else {
gradient.setColorAt(0, "#1c870b");
gradient.setColorAt(1, "#116703");
if (value() < 0) {
gradient.setColorAt(0, negColor0);
gradient.setColorAt(1, negColor1);
}
else {
gradient.setColorAt(0, posColor0);
gradient.setColorAt(1, posColor1);
}
}
}
painter->setBrush(gradient);
painter->setPen(QPen(Qt::black, 0));
painter->drawEllipse(-13, -13, 26, 26);
painter->drawEllipse(boundingRect());
painter->setPen(QPen(Qt::white, 0));
if (value() < 0) {
painter->drawText(-13, 4, QString().sprintf("% .2f", value()));
if (cmdNode) {
painter->drawText(0,4,text);
}
else {
painter->drawText(-11, 4, QString().sprintf("%.2f", value()));
painter->drawText(-13, 4, text);
}
}
@ -113,6 +123,13 @@ void Node::verticalMove(bool flag){
vertical = flag;
}
void Node::commandNode(bool enable){
cmdNode = enable;
}
void Node::commandText(QString text){
cmdText = text;
}
double Node::value() {
double h = graph->sceneRect().height();
double ratio = (h - pos().y()) / h;
@ -161,6 +178,10 @@ QVariant Node::itemChange(GraphicsItemChange change, const QVariant &val)
void Node::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (cmdNode) {
graph->cmdActivated(this);
//return;
}
update();
QGraphicsItem::mousePressEvent(event);
}

View File

@ -29,6 +29,7 @@
#define MIXERCURVEPOINT_H
#include <QGraphicsItem>
#include <QColor>
#include <QList>
class Edge;
@ -48,8 +49,20 @@ public:
enum { Type = UserType + 1 };
int type() const { return Type; }
void setName(QString name) { cmdName = name; }
const QString& getName() { return cmdName; }
void verticalMove(bool flag);
void commandNode(bool enable);
void commandText(QString text);
int getCommandIndex() { return index; }
void setCommandIndex(int idx) { index = idx; }
void setActive(bool enable) { cmdActive = enable; }
void setToggle(bool enable) { cmdToggle = enable; }
bool getToggle() { return cmdToggle; }
void setPositiveColor(QString color0 = "#00ff00", QString color1 = "#00ff00") { posColor0 = color0; posColor1 = color1; }
void setNegativeColor(QString color0 = "#ff0000", QString color1 = "#ff0000") { negColor0 = color0; negColor1 = color1; }
QRectF boundingRect() const;
QPainterPath shape() const;
@ -57,6 +70,9 @@ public:
double value();
signals:
void commandActivated(QString text);
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &val);
@ -64,11 +80,21 @@ protected:
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
private:
QList<Edge *> edgeList;
QPointF newPos;
MixerCurveWidget* graph;
QString posColor0;
QString posColor1;
QString negColor0;
QString negColor1;
QList<Edge *> edgeList;
QPointF newPos;
MixerCurveWidget *graph;
bool vertical;
bool vertical;
QString cmdName;
bool cmdActive;
bool cmdNode;
bool cmdToggle;
QString cmdText;
int index;
};

View File

@ -29,6 +29,7 @@
#include "mixercurveline.h"
#include "mixercurvepoint.h"
#include <QObject>
#include <QtGui>
#include <QDebug>
@ -57,7 +58,6 @@ MixerCurveWidget::MixerCurveWidget(QWidget *parent) : QGraphicsView(parent)
curveMin=0.0;
curveMax=1.0;
setFrameStyle(QFrame::NoFrame);
setStyleSheet("background:transparent");
@ -73,7 +73,111 @@ MixerCurveWidget::MixerCurveWidget(QWidget *parent) : QGraphicsView(parent)
scene->setSceneRect(plot->boundingRect());
setScene(scene);
posColor0 = "#1c870b"; //greenish?
posColor1 = "#116703"; //greenish?
negColor0 = "#ff0000"; //red
negColor1 = "#ff0000"; //red
// commmand nodes
// reset
Node* node = getCommandNode(0);
node->setName("Reset");
node->setToggle(false);
node->setPositiveColor("#ffffff", "#ffffff"); //white
node->setNegativeColor("#ffffff", "#ffffff");
scene->addItem(node);
// linear
node = getCommandNode(1);
node->setName("Linear");
node->commandText("/");
scene->addItem(node);
// log
node = getCommandNode(2);
node->setName("Log");
node->commandText("(");
scene->addItem(node);
// exp
node = getCommandNode(3);
node->setName("Exp");
node->commandText(")");
scene->addItem(node);
// flat
node = getCommandNode(4);
node->setName("Flat");
node->commandText("--");
scene->addItem(node);
// step
node = getCommandNode(5);
node->setName("Step");
node->commandText("z");
scene->addItem(node);
// curve min/max nodes
node = getCommandNode(6);
node->setName("MinPlus");
node->setToggle(false);
node->setPositiveColor("#00ff00", "#00ff00"); //green
node->setNegativeColor("#00ff00", "#00ff00");
node->commandText("+");
scene->addItem(node);
node = getCommandNode(7);
node->setName("MinMinus");
node->setToggle(false);
node->setPositiveColor("#ff0000", "#ff0000"); //red
node->setNegativeColor("#ff0000", "#ff0000");
node->commandText("-");
scene->addItem(node);
node = getCommandNode(8);
node->setName("MaxPlus");
node->setToggle(false);
node->setPositiveColor("#00ff00", "#00ff00"); //green
node->setNegativeColor("#00ff00", "#00ff00");
node->commandText("+");
scene->addItem(node);
node = getCommandNode(9);
node->setName("MaxMinus");
node->setToggle(false);
node->setPositiveColor("#ff0000", "#ff0000"); //red
node->setNegativeColor("#ff0000", "#ff0000");
node->commandText("-");
scene->addItem(node);
node = getCommandNode(10);
node->setName("StepPlus");
node->setToggle(false);
node->setPositiveColor("#00ff00", "#00ff00"); //green
node->setNegativeColor("#00ff00", "#00ff00");
node->commandText("+");
scene->addItem(node);
node = getCommandNode(11);
node->setName("StepMinus");
node->setToggle(false);
node->setPositiveColor("#ff0000", "#ff0000"); //red
node->setNegativeColor("#ff0000", "#ff0000");
node->commandText("-");
scene->addItem(node);
node = getCommandNode(12);
node->setName("StepValue");
node->setToggle(false);
node->setPositiveColor("#0000ff", "#0000ff"); //blue
node->setNegativeColor("#0000ff", "#0000ff");
scene->addItem(node);
resizeCommands();
initNodes(MixerCurveWidget::NODE_NUMELEM);
}
MixerCurveWidget::~MixerCurveWidget()
@ -83,6 +187,30 @@ MixerCurveWidget::~MixerCurveWidget()
while (!edgePool.isEmpty())
delete edgePool.takeFirst();
while (!cmdNodePool.isEmpty())
delete cmdNodePool.takeFirst();
}
Node* MixerCurveWidget::getCommandNode(int index)
{
Node* node;
if (index >= 0 && index < cmdNodePool.count())
{
node = cmdNodePool.at(index);
}
else {
node = new Node(this);
node->commandNode(true);
node->commandText("");
node->setCommandIndex(index);
node->setActive(false);
node->setPositiveColor("#ff0000", "#ff0000");
node->setNegativeColor("#0000cc", "#0000cc");
cmdNodePool.append(node);
}
return node;
}
Node* MixerCurveWidget::getNode(int index)
@ -99,7 +227,6 @@ Node* MixerCurveWidget::getNode(int index)
}
return node;
}
Edge* MixerCurveWidget::getEdge(int index, Node* sourceNode, Node* destNode)
{
Edge* edge;
@ -117,6 +244,26 @@ Edge* MixerCurveWidget::getEdge(int index, Node* sourceNode, Node* destNode)
return edge;
}
void MixerCurveWidget::setPositiveColor(QString color0, QString color1)
{
posColor0 = color0;
posColor1 = color1;
for (int i=0; i<nodePool.count(); i++) {
Node* node = nodePool.at(i);
node->setPositiveColor(color0, color1);
}
}
void MixerCurveWidget::setNegativeColor(QString color0, QString color1)
{
negColor0 = color0;
negColor1 = color1;
for (int i=0; i<nodePool.count(); i++) {
Node* node = nodePool.at(i);
node->setNegativeColor(color0, color1);
}
}
/**
Init curve: create a (flat) curve with a specified number of points.
@ -220,6 +367,10 @@ void MixerCurveWidget::setCurve(const QList<double>* points)
Node* node = nodeList.at(i);
node->setPos(w*i, h - (val*h));
node->verticalMove(true);
node->setPositiveColor(posColor0, posColor1);
node->setNegativeColor(negColor0, negColor1);
node->update();
}
curveUpdating = false;
@ -238,7 +389,7 @@ void MixerCurveWidget::showEvent(QShowEvent *event)
// the result is usually a ahrsbargraph that is way too small.
QRectF rect = plot->boundingRect();
resizeCommands();
fitInView(rect.adjusted(-15,-15,15,15), Qt::KeepAspectRatio);
}
@ -247,12 +398,54 @@ void MixerCurveWidget::resizeEvent(QResizeEvent* event)
Q_UNUSED(event);
QRectF rect = plot->boundingRect();
resizeCommands();
fitInView(rect.adjusted(-15,-15,15,15), Qt::KeepAspectRatio);
}
void MixerCurveWidget::resizeCommands()
{
QRectF rect = plot->boundingRect();
Node* node;
for (int i = 0; i<6; i++) {
node = getCommandNode(i);
node->setPos((rect.left() + rect.width() / 2) - 60 + (i * 20), rect.height() + 10);
}
//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);
node->setPos(rect.bottomRight().x() - 60, rect.bottomRight().y() + 8);
//stepminus
node = getCommandNode(11);
node->setPos(rect.bottomRight().x() - 40, rect.bottomRight().y() + 8);
//step
node = getCommandNode(12);
node->setPos(rect.bottomRight().x() - 20, rect.bottomRight().y() + 8);
}
void MixerCurveWidget::itemMoved(double itemValue)
{
Q_UNUSED(itemValue);
if (!curveUpdating) {
emit curveUpdated();
}
@ -288,3 +481,49 @@ double MixerCurveWidget::setRange(double min, double max)
curveMax = max;
return curveMax - curveMin;
}
Node* MixerCurveWidget::getCmdNode(const QString& name)
{
Node* node = 0;
for (int i=0; i<cmdNodePool.count(); i++) {
Node* n = cmdNodePool.at(i);
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++) {
Node* n = cmdNodePool.at(i);
if (n->getName() == name) {
n->commandText(text);
n->update();
}
}
}
void MixerCurveWidget::activateCommand(const QString& name)
{
for (int i=0; i<cmdNodePool.count(); i++) {
Node* node = cmdNodePool.at(i);
node->setActive(node->getName() == name);
node->update();
}
}
void MixerCurveWidget::cmdActivated(Node* node)
{
if (node->getToggle()) {
for (int i=0; i<cmdNodePool.count(); i++) {
Node* n = cmdNodePool.at(i);
n->setActive(false);
n->update();
}
node->setActive(true);
}
node->update();
emit commandActivated(node);
}

View File

@ -28,6 +28,7 @@
#ifndef MIXERCURVEWIDGET_H_
#define MIXERCURVEWIDGET_H_
#include <QObject>
#include <QGraphicsView>
#include <QtSvg/QSvgRenderer>
#include <QtSvg/QGraphicsSvgItem>
@ -57,12 +58,18 @@ public:
double getMax();
double setRange(double min, double max);
void cmdActivated(Node* node);
void activateCommand(const QString& name);
Node* getCmdNode(const QString& name);
void setCommandText(const QString& name, const QString& text);
static const int NODE_NUMELEM = 5;
signals:
void curveUpdated();
void curveMinChanged(double value);
void curveMaxChanged(double value);
void commandActivated(Node* node);
private slots:
@ -70,6 +77,7 @@ private:
QGraphicsSvgItem *plot;
QList<Node*> nodePool;
QList<Node*> cmdNodePool;
QList<Edge*> edgePool;
QList<Node*> nodeList;
@ -77,9 +85,19 @@ private:
double curveMax;
bool curveUpdating;
QString posColor0;
QString posColor1;
QString negColor0;
QString negColor1;
void initNodes(int numPoints);
Node* getNode(int index);
Node* getCommandNode(int index);
Edge* getEdge(int index, Node* sourceNode, Node* destNode);
void setPositiveColor(QString color0 = "#00ff00", QString color1 = "#00ff00");
void setNegativeColor(QString color0 = "#ff0000", QString color1 = "#ff0000");
void resizeCommands();
protected:
void showEvent(QShowEvent *event);