mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-17 02:52:12 +01:00
MixerCurve bugs and tweeks: don't popup if already a popup; enable drawing only text in nodes;
trap close/done/accept/reject events as closePopup();
This commit is contained in:
parent
cb66f5000a
commit
685fb4e1d4
@ -133,6 +133,13 @@ void MixerCurve::UpdateCurveUI()
|
||||
//get the user settings
|
||||
QString curveType = m_mixerUI->CurveType->currentText();
|
||||
|
||||
m_curve->activateCommand(curveType);
|
||||
bool cmdsActive = m_curve->isCommandActive("Commands");
|
||||
|
||||
m_curve->showCommand("StepPlus", cmdsActive && curveType != "Linear");
|
||||
m_curve->showCommand("StepMinus", cmdsActive && curveType != "Linear");
|
||||
m_curve->showCommand("StepValue", cmdsActive && curveType != "Linear");
|
||||
|
||||
m_mixerUI->CurveStep->setMinimum(0.0);
|
||||
m_mixerUI->CurveStep->setMaximum(100.0);
|
||||
m_mixerUI->CurveStep->setSingleStep(1.00);
|
||||
@ -147,6 +154,10 @@ void MixerCurve::UpdateCurveUI()
|
||||
|
||||
if ( curveType.compare("Flat")==0)
|
||||
{
|
||||
m_mixerUI->minLabel->setVisible(false);
|
||||
m_mixerUI->CurveMin->setVisible(false);
|
||||
m_mixerUI->stepLabel->setVisible(true);
|
||||
m_mixerUI->CurveStep->setVisible(true);
|
||||
m_mixerUI->CurveStep->setMinimum(m_mixerUI->CurveMin->minimum());
|
||||
m_mixerUI->CurveStep->setMaximum(m_mixerUI->CurveMax->maximum());
|
||||
m_mixerUI->CurveStep->setSingleStep(0.01);
|
||||
@ -352,17 +363,18 @@ void MixerCurve::CommandActivated(Node* node)
|
||||
else if (name == "Commands") {
|
||||
|
||||
}
|
||||
else if (name == "Popup") {
|
||||
else if (name == "Popup" && !m_curve->isCommandActive("Popup")) {
|
||||
m_mixerUI->SettingsGroup->show();
|
||||
m_mixerUI->ValuesGroup->show();
|
||||
m_curve->showCommand("Popup", false);
|
||||
|
||||
PopupWidget* popup = new PopupWidget();
|
||||
popup->setWidget(this);
|
||||
popup->exec();
|
||||
popup->popUp(this);
|
||||
|
||||
m_mixerUI->SettingsGroup->hide();
|
||||
m_mixerUI->ValuesGroup->hide();
|
||||
m_curve->showCommands(false);
|
||||
m_curve->showCommand("Popup", true);
|
||||
}
|
||||
else if (name == "Linear") {
|
||||
m_mixerUI->CurveType->setCurrentIndex(m_mixerUI->CurveType->findText("Linear"));
|
||||
@ -412,24 +424,8 @@ void MixerCurve::CurveTypeChanged()
|
||||
void MixerCurve::CurveMinChanged(double value)
|
||||
{
|
||||
QList<double> points = m_curve->getCurve();
|
||||
QString CurveType = m_mixerUI->CurveType->currentText();
|
||||
|
||||
if ( CurveType.compare("Flat")==0) {
|
||||
// the min changed so redraw the curve
|
||||
// but since the curve is flat make all points = value
|
||||
// because we use curveMin for the flat value in ui
|
||||
for (int i = 0; i < points.count(); i++) {
|
||||
points.pop_back();
|
||||
points.push_front(value);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// the min changed so redraw the curve
|
||||
// mixercurvewidget::setCurve will trim any points below min
|
||||
|
||||
points.removeFirst();
|
||||
points.push_front(value);
|
||||
}
|
||||
points.removeFirst();
|
||||
points.push_front(value);
|
||||
setCurve(&points);
|
||||
}
|
||||
|
||||
|
@ -47,6 +47,8 @@ Node::Node(MixerCurveWidget *graphWidget)
|
||||
vertical = false;
|
||||
cmdNode = false;
|
||||
cmdToggle = true;
|
||||
drawNode = true;
|
||||
drawText = true;
|
||||
|
||||
posColor0 = "#1c870b"; //greenish?
|
||||
posColor1 = "#116703"; //greenish?
|
||||
@ -81,43 +83,48 @@ QPainterPath Node::shape() const
|
||||
|
||||
void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
|
||||
{
|
||||
QString text = cmdNode ? cmdText : QString().sprintf("% .2f", value());
|
||||
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);
|
||||
if (drawNode) {
|
||||
QRadialGradient gradient(-3, -3, 10);
|
||||
if (option->state & QStyle::State_Sunken) {
|
||||
gradient.setCenter(3, 3);
|
||||
gradient.setFocalPoint(3, 3);
|
||||
|
||||
gradient.setColorAt(1, Qt::darkBlue);
|
||||
gradient.setColorAt(0, Qt::darkBlue);
|
||||
} else {
|
||||
if (cmdNode) {
|
||||
gradient.setColorAt(0, cmdActive ? posColor0 : negColor0);
|
||||
gradient.setColorAt(1, cmdActive ? posColor1 : negColor1);
|
||||
}
|
||||
else {
|
||||
if (value() < 0) {
|
||||
gradient.setColorAt(0, negColor0);
|
||||
gradient.setColorAt(1, negColor1);
|
||||
gradient.setColorAt(1, Qt::darkBlue);
|
||||
gradient.setColorAt(0, Qt::darkBlue);
|
||||
} else {
|
||||
if (cmdNode) {
|
||||
gradient.setColorAt(0, cmdActive ? posColor0 : negColor0);
|
||||
gradient.setColorAt(1, cmdActive ? posColor1 : negColor1);
|
||||
}
|
||||
else {
|
||||
gradient.setColorAt(0, posColor0);
|
||||
gradient.setColorAt(1, posColor1);
|
||||
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(boundingRect());
|
||||
if (!image.isNull())
|
||||
painter->drawImage(boundingRect().adjusted(1,1,-1,-1), image);
|
||||
painter->setBrush(gradient);
|
||||
painter->setPen(QPen(Qt::black, 0));
|
||||
painter->drawEllipse(boundingRect());
|
||||
|
||||
painter->setPen(QPen(Qt::white, 0));
|
||||
if (cmdNode) {
|
||||
painter->drawText(0,4,text);
|
||||
if (!image.isNull())
|
||||
painter->drawImage(boundingRect().adjusted(1,1,-1,-1), image);
|
||||
}
|
||||
else {
|
||||
painter->drawText(-13, 4, text);
|
||||
|
||||
if (drawText) {
|
||||
painter->setPen(QPen(drawNode ? Qt::white : Qt::black, 0));
|
||||
if (cmdNode) {
|
||||
painter->drawText(0,4,text);
|
||||
}
|
||||
else {
|
||||
painter->drawText(-13, 4, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,6 +66,8 @@ public:
|
||||
void setPositiveColor(QString color0 = "#00ff00", QString color1 = "#00ff00") { posColor0 = color0; posColor1 = color1; }
|
||||
void setNegativeColor(QString color0 = "#ff0000", QString color1 = "#ff0000") { negColor0 = color0; negColor1 = color1; }
|
||||
void setImage(QImage img) { image = img; }
|
||||
void setDrawNode(bool draw) { drawNode = draw; }
|
||||
void setDrawText(bool draw) { drawText = draw; }
|
||||
|
||||
QRectF boundingRect() const;
|
||||
QPainterPath shape() const;
|
||||
@ -98,6 +100,8 @@ private:
|
||||
bool cmdNode;
|
||||
bool cmdToggle;
|
||||
QString cmdText;
|
||||
bool drawNode;
|
||||
bool drawText;
|
||||
int index;
|
||||
|
||||
};
|
||||
|
@ -230,6 +230,7 @@ MixerCurveWidget::MixerCurveWidget(QWidget *parent) : QGraphicsView(parent)
|
||||
|
||||
node = getCommandNode(12);
|
||||
node->setName("StepValue");
|
||||
node->setDrawNode(false);
|
||||
node->setToolTip("Current Step/Power Value");
|
||||
node->setToggle(false);
|
||||
node->setPositiveColor("#0000aa", "#0000aa"); //blue
|
||||
@ -249,6 +250,7 @@ MixerCurveWidget::MixerCurveWidget(QWidget *parent) : QGraphicsView(parent)
|
||||
node = getCommandNode(14);
|
||||
node->setName("Popup");
|
||||
node->setToolTip("Advanced Mode...");
|
||||
node->commandText("");
|
||||
node->setToggle(false);
|
||||
node->setPositiveColor("#ff0000", "#ff0000"); //red
|
||||
node->setNegativeColor("#ff0000", "#ff0000");
|
||||
@ -449,9 +451,6 @@ void MixerCurveWidget::setCurve(const QList<double>* points)
|
||||
node->setPos(w*i, h - (val*h));
|
||||
node->verticalMove(true);
|
||||
|
||||
// node->setPositiveColor(posColor0, posColor1);
|
||||
// node->setNegativeColor(negColor0, negColor1);
|
||||
|
||||
node->update();
|
||||
}
|
||||
curveUpdating = false;
|
||||
@ -498,16 +497,13 @@ void MixerCurveWidget::resizeCommands()
|
||||
|
||||
//commands on/off
|
||||
node = getCommandNode(13);
|
||||
node->setPos((rect.left() + rect.width() / 2) + 40, rect.height() + 10);
|
||||
node->setPos(rect.right() - 15, rect.bottomRight().x() - 14);
|
||||
|
||||
for (int i = 1; i<6; i++) {
|
||||
node = getCommandNode(i);
|
||||
|
||||
//centered under widget
|
||||
//node->setPos((rect.left() + rect.width() / 2) - 60 + (i * 20), rect.height() + 10);
|
||||
|
||||
//bottom right of widget
|
||||
node->setPos(rect.right() - 120 + (i * 20), rect.bottomRight().x() - 14);
|
||||
node->setPos(rect.right() - 130 + (i * 18), rect.bottomRight().x() - 14);
|
||||
}
|
||||
|
||||
//curveminplus
|
||||
@ -528,15 +524,15 @@ void MixerCurveWidget::resizeCommands()
|
||||
|
||||
//stepplus
|
||||
node = getCommandNode(10);
|
||||
node->setPos(rect.bottomRight().x() - 38, rect.bottomRight().y() + 5);
|
||||
node->setPos(rect.bottomRight().x() - 40, rect.bottomRight().y() + 5);
|
||||
|
||||
//stepminus
|
||||
node = getCommandNode(11);
|
||||
node->setPos(rect.bottomRight().x() - 38, rect.bottomRight().y() + 15);
|
||||
node->setPos(rect.bottomRight().x() - 40, rect.bottomRight().y() + 15);
|
||||
|
||||
//step
|
||||
node = getCommandNode(12);
|
||||
node->setPos(rect.bottomRight().x() - 20, rect.bottomRight().y() + 9);
|
||||
node->setPos(rect.bottomRight().x() - 22, rect.bottomRight().y() + 9);
|
||||
}
|
||||
|
||||
void MixerCurveWidget::itemMoved(double itemValue)
|
||||
@ -609,6 +605,16 @@ void MixerCurveWidget::activateCommand(const QString& name)
|
||||
}
|
||||
}
|
||||
|
||||
void MixerCurveWidget::showCommand(const QString& name, bool show)
|
||||
{
|
||||
Node* node = getCmdNode(name);
|
||||
if (node) {
|
||||
if (show)
|
||||
node->show();
|
||||
else
|
||||
node->hide();
|
||||
}
|
||||
}
|
||||
void MixerCurveWidget::showCommands(bool show)
|
||||
{
|
||||
for (int i=1; i<cmdNodePool.count()-2; i++) {
|
||||
@ -621,6 +627,16 @@ void MixerCurveWidget::showCommands(bool show)
|
||||
node->update();
|
||||
}
|
||||
}
|
||||
bool MixerCurveWidget::isCommandActive(const QString& name)
|
||||
{
|
||||
bool active = false;
|
||||
Node* node = getCmdNode(name);
|
||||
if (node) {
|
||||
active = node->getCommandActive();
|
||||
}
|
||||
return active;
|
||||
}
|
||||
|
||||
void MixerCurveWidget::cmdActivated(Node* node)
|
||||
{
|
||||
if (node->getToggle()) {
|
||||
|
@ -61,6 +61,8 @@ public:
|
||||
|
||||
void cmdActivated(Node* node);
|
||||
void activateCommand(const QString& name);
|
||||
bool isCommandActive(const QString& name);
|
||||
void showCommand(const QString& name, bool show);
|
||||
void showCommands(bool show);
|
||||
Node* getCmdNode(const QString& name);
|
||||
void setCommandText(const QString& name, const QString& text);
|
||||
|
@ -21,7 +21,15 @@ PopupWidget::PopupWidget(QWidget *parent) :
|
||||
|
||||
setLayout(mainLayout);
|
||||
|
||||
connect(m_closeButton,SIGNAL(clicked()), this, SLOT(closePopup()));
|
||||
connect(m_closeButton,SIGNAL(clicked()), this, SLOT(close()));
|
||||
connect(this, SIGNAL(accepted()),this,SLOT(close()));
|
||||
connect(this,SIGNAL(rejected()), this, SLOT(close()));
|
||||
}
|
||||
|
||||
void PopupWidget::popUp(QWidget* widget)
|
||||
{
|
||||
setWidget(widget);
|
||||
exec();
|
||||
}
|
||||
|
||||
void PopupWidget::setWidget(QWidget* widget)
|
||||
@ -32,6 +40,19 @@ void PopupWidget::setWidget(QWidget* widget)
|
||||
m_layout->addWidget(m_widget);
|
||||
}
|
||||
|
||||
bool PopupWidget::close()
|
||||
{
|
||||
closePopup();
|
||||
|
||||
return QDialog::close();
|
||||
}
|
||||
|
||||
void PopupWidget::done(int result)
|
||||
{
|
||||
closePopup();
|
||||
|
||||
QDialog::done(result);
|
||||
}
|
||||
|
||||
void PopupWidget::closePopup()
|
||||
{
|
||||
@ -41,6 +62,4 @@ void PopupWidget::closePopup()
|
||||
w->layout()->addWidget(m_widget);
|
||||
}
|
||||
}
|
||||
|
||||
close();
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ class UAVOBJECTWIDGETUTILS_EXPORT PopupWidget : public QDialog
|
||||
public:
|
||||
explicit PopupWidget(QWidget *parent = 0);
|
||||
|
||||
void popUp(QWidget* widget = 0);
|
||||
void setWidget(QWidget* widget);
|
||||
QWidget* getWidget() { return m_widget; }
|
||||
QHBoxLayout* getLayout() { return m_layout; }
|
||||
@ -25,7 +26,9 @@ public:
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
bool close();
|
||||
void done(int result);
|
||||
|
||||
private slots:
|
||||
void closePopup();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user