1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-19 09:54:15 +01:00

Added OpenGL option to the "Dial" and "LinearDial" plugins.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2613 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
pip 2011-01-28 20:45:45 +00:00 committed by pip
parent 6f2e45d414
commit 3c49944e73
16 changed files with 3870 additions and 3778 deletions

View File

@ -1,6 +1,7 @@
TEMPLATE = lib
TARGET = DialGadget
QT += svg
QT += opengl
include(../../openpilotgcsplugin.pri)
include(../../plugins/coreplugin/coreplugin.pri)
include(dial_dependencies.pri)

View File

@ -1,70 +1,72 @@
/**
******************************************************************************
*
* @file dialgadget.cpp
* @author Edouard Lafargue and David Carlson Copyright (C) 2010.
* @see The GNU Public License (GPL) Version 3
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup DialPlugin Dial Plugin
* @{
* @brief Plots flight information rotary style dials
*****************************************************************************/
/*
* 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 "dialgadget.h"
#include "dialgadgetwidget.h"
#include "dialgadgetconfiguration.h"
DialGadget::DialGadget(QString classId, DialGadgetWidget *widget, QWidget *parent) :
IUAVGadget(classId, parent),
m_widget(widget)
{
}
DialGadget::~DialGadget()
{
}
/*
This is called when a configuration is loaded, and updates the plugin's settings.
Careful: the plugin is already drawn before the loadConfiguration method is called the
first time, so you have to be careful not to assume all the plugin values are initialized
the first time you use them
*/
void DialGadget::loadConfiguration(IUAVGadgetConfiguration* config)
{
DialGadgetConfiguration *m = qobject_cast<DialGadgetConfiguration*>(config);
m_widget->setDialFile(m->dialFile(), m->dialBackground(), m->dialForeground(), m->dialNeedle1(),
m->dialNeedle2(),m->dialNeedle3(),m->getN1Move(), m->getN2Move(),
m->getN3Move());
m_widget->setN1Min(m->getN1Min());
m_widget->setN1Max(m->getN1Max());
m_widget->setN1Factor(m->getN1Factor());
m_widget->setN2Min(m->getN2Min());
m_widget->setN2Max(m->getN2Max());
m_widget->setN2Factor(m->getN2Factor());
m_widget->setN3Min(m->getN3Min());
m_widget->setN3Max(m->getN3Max());
m_widget->setN3Factor(m->getN3Factor());
m_widget->setDialFont(m->getFont());
m_widget->connectNeedles(m->getN1DataObject(),m->getN1ObjField(),
m->getN2DataObject(),m->getN2ObjField(),
m->getN3DataObject(),m->getN3ObjField()
);
}
/**
******************************************************************************
*
* @file dialgadget.cpp
* @author Edouard Lafargue and David Carlson Copyright (C) 2010.
* @see The GNU Public License (GPL) Version 3
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup DialPlugin Dial Plugin
* @{
* @brief Plots flight information rotary style dials
*****************************************************************************/
/*
* 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 "dialgadget.h"
#include "dialgadgetwidget.h"
#include "dialgadgetconfiguration.h"
DialGadget::DialGadget(QString classId, DialGadgetWidget *widget, QWidget *parent) :
IUAVGadget(classId, parent),
m_widget(widget)
{
}
DialGadget::~DialGadget()
{
}
/*
This is called when a configuration is loaded, and updates the plugin's settings.
Careful: the plugin is already drawn before the loadConfiguration method is called the
first time, so you have to be careful not to assume all the plugin values are initialized
the first time you use them
*/
void DialGadget::loadConfiguration(IUAVGadgetConfiguration* config)
{
DialGadgetConfiguration *m = qobject_cast<DialGadgetConfiguration*>(config);
m_widget->setDialFile(m->dialFile(), m->dialBackground(), m->dialForeground(), m->dialNeedle1(),
m->dialNeedle2(),m->dialNeedle3(),m->getN1Move(), m->getN2Move(),
m->getN3Move());
m_widget->enableOpenGL(m->useOpenGL());
m_widget->setN1Min(m->getN1Min());
m_widget->setN1Max(m->getN1Max());
m_widget->setN1Factor(m->getN1Factor());
m_widget->setN2Min(m->getN2Min());
m_widget->setN2Max(m->getN2Max());
m_widget->setN2Factor(m->getN2Factor());
m_widget->setN3Min(m->getN3Min());
m_widget->setN3Max(m->getN3Max());
m_widget->setN3Factor(m->getN3Factor());
m_widget->setDialFont(m->getFont());
m_widget->connectNeedles(m->getN1DataObject(),m->getN1ObjField(),
m->getN2DataObject(),m->getN2ObjField(),
m->getN3DataObject(),m->getN3ObjField()
);
}

View File

@ -1,163 +1,168 @@
/**
******************************************************************************
*
* @file dialgadgetconfiguration.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @see The GNU Public License (GPL) Version 3
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup DialPlugin Dial Plugin
* @{
* @brief Plots flight information rotary style dials
*****************************************************************************/
/*
* 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 "dialgadgetconfiguration.h"
#include "utils/pathutils.h"
/**
* Loads a saved configuration or defaults if non exist.
*
*/
DialGadgetConfiguration::DialGadgetConfiguration(QString classId, QSettings* qSettings, QObject *parent) :
IUAVGadgetConfiguration(classId, parent),
m_defaultDial("Unknown"),
dialBackgroundID("background"),
dialForegroundID("foreground"),
dialNeedleID1("needle"),
dialNeedleID2("needle2"),
dialNeedleID3("needle3"),
needle1MinValue(0),
needle1MaxValue(100),
needle2MinValue(0),
needle2MaxValue(100),
needle3MinValue(0),
needle3MaxValue(100),
needle1Factor(1),
needle2Factor(1),
needle3Factor(1),
needle1Move("Rotate"),
needle2Move("Rotate"),
needle3Move("Rotate")
{
//if a saved configuration exists load it
if(qSettings != 0) {
QString dialFile = qSettings->value("dialFile").toString();
m_defaultDial=Utils::PathUtils().InsertDataPath(dialFile);
dialBackgroundID = qSettings->value("dialBackgroundID").toString();
dialForegroundID = qSettings->value("dialForegroundID").toString();
dialNeedleID1 = qSettings->value("dialNeedleID1").toString();
dialNeedleID2 = qSettings->value("dialNeedleID2").toString();
dialNeedleID3 = qSettings->value("dialNeedleID3").toString();
needle1MinValue = qSettings->value("needle1MinValue").toDouble();
needle1MaxValue = qSettings->value("needle1MaxValue").toDouble();
needle2MinValue = qSettings->value("needle2MinValue").toDouble();
needle2MaxValue = qSettings->value("needle2MaxValue").toDouble();
needle3MinValue = qSettings->value("needle3MinValue").toDouble();
needle3MaxValue = qSettings->value("needle3MaxValue").toDouble();
needle1DataObject = qSettings->value("needle1DataObject").toString();
needle1ObjectField = qSettings->value("needle1ObjectField").toString();
needle2DataObject = qSettings->value("needle2DataObject").toString();
needle2ObjectField = qSettings->value("needle2ObjectField").toString();
needle3DataObject = qSettings->value("needle3DataObject").toString();
needle3ObjectField = qSettings->value("needle3ObjectField").toString();
needle1Factor = qSettings->value("needle1Factor").toDouble();
needle2Factor = qSettings->value("needle2Factor").toDouble();
needle3Factor = qSettings->value("needle3Factor").toDouble();
needle1Move = qSettings->value("needle1Move").toString();
needle2Move = qSettings->value("needle2Move").toString();
needle3Move = qSettings->value("needle3Move").toString();
font = qSettings->value("font").toString();
}
}
/**
* Clones a configuration.
*
*/
IUAVGadgetConfiguration *DialGadgetConfiguration::clone()
{
DialGadgetConfiguration *m = new DialGadgetConfiguration(this->classId());
m->m_defaultDial=m_defaultDial;
m->setDialBackgroundID(dialBackgroundID);
m->setDialForegroundID(dialForegroundID);
m->setDialNeedleID1(dialNeedleID1);
m->setDialNeedleID2(dialNeedleID2);
m->setDialNeedleID3(dialNeedleID3);
m->setN1Min(needle1MinValue);
m->setN1Max(needle1MaxValue);
m->setN2Min(needle2MinValue);
m->setN2Max(needle2MaxValue);
m->setN3Min(needle3MinValue);
m->setN3Max(needle3MaxValue);
m->setN1DataObject(needle1DataObject);
m->setN1ObjField(needle1ObjectField);
m->setN2DataObject(needle2DataObject);
m->setN2ObjField(needle2ObjectField);
m->setN3DataObject(needle3DataObject);
m->setN3ObjField(needle3ObjectField);
m->setN1Factor(needle1Factor);
m->setN2Factor(needle2Factor);
m->setN3Factor(needle3Factor);
m->setN1Move(needle1Move);
m->setN2Move(needle2Move);
m->setN3Move(needle3Move);
m->setFont(font);
return m;
}
/**
* Saves a configuration.
*
*/
void DialGadgetConfiguration::saveConfig(QSettings* settings) const {
QString dialFile = Utils::PathUtils().RemoveDataPath(m_defaultDial);
settings->setValue("dialFile", dialFile);
settings->setValue("dialBackgroundID", dialBackgroundID);
settings->setValue("dialForegroundID", dialForegroundID);
settings->setValue("dialNeedleID1", dialNeedleID1);
settings->setValue("dialNeedleID2", dialNeedleID2);
settings->setValue("dialNeedleID3", dialNeedleID3);
settings->setValue("needle1MinValue", needle1MinValue);
settings->setValue("needle1MaxValue", needle1MaxValue);
settings->setValue("needle2MinValue", needle2MinValue);
settings->setValue("needle2MaxValue", needle2MaxValue);
settings->setValue("needle3MinValue", needle3MinValue);
settings->setValue("needle3MaxValue", needle3MaxValue);
settings->setValue("needle1DataObject", needle1DataObject);
settings->setValue("needle1ObjectField", needle1ObjectField);
settings->setValue("needle2DataObject", needle2DataObject);
settings->setValue("needle2ObjectField", needle2ObjectField);
settings->setValue("needle3DataObject", needle3DataObject);
settings->setValue("needle3ObjectField", needle3ObjectField);
settings->setValue("needle1Factor", needle1Factor);
settings->setValue("needle2Factor", needle2Factor);
settings->setValue("needle3Factor", needle3Factor);
settings->setValue("needle1Move", needle1Move);
settings->setValue("needle2Move", needle2Move);
settings->setValue("needle3Move", needle3Move);
settings->setValue("font", font);
}
/**
******************************************************************************
*
* @file dialgadgetconfiguration.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @see The GNU Public License (GPL) Version 3
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup DialPlugin Dial Plugin
* @{
* @brief Plots flight information rotary style dials
*****************************************************************************/
/*
* 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 "dialgadgetconfiguration.h"
#include "utils/pathutils.h"
/**
* Loads a saved configuration or defaults if non exist.
*
*/
DialGadgetConfiguration::DialGadgetConfiguration(QString classId, QSettings* qSettings, QObject *parent) :
IUAVGadgetConfiguration(classId, parent),
m_defaultDial("Unknown"),
dialBackgroundID("background"),
dialForegroundID("foreground"),
dialNeedleID1("needle"),
dialNeedleID2("needle2"),
dialNeedleID3("needle3"),
needle1MinValue(0),
needle1MaxValue(100),
needle2MinValue(0),
needle2MaxValue(100),
needle3MinValue(0),
needle3MaxValue(100),
needle1Factor(1),
needle2Factor(1),
needle3Factor(1),
needle1Move("Rotate"),
needle2Move("Rotate"),
needle3Move("Rotate")
{
//if a saved configuration exists load it
if(qSettings != 0) {
QString dialFile = qSettings->value("dialFile").toString();
useOpenGLFlag = qSettings->value("useOpenGLFlag").toBool();
m_defaultDial=Utils::PathUtils().InsertDataPath(dialFile);
dialBackgroundID = qSettings->value("dialBackgroundID").toString();
dialForegroundID = qSettings->value("dialForegroundID").toString();
dialNeedleID1 = qSettings->value("dialNeedleID1").toString();
dialNeedleID2 = qSettings->value("dialNeedleID2").toString();
dialNeedleID3 = qSettings->value("dialNeedleID3").toString();
needle1MinValue = qSettings->value("needle1MinValue").toDouble();
needle1MaxValue = qSettings->value("needle1MaxValue").toDouble();
needle2MinValue = qSettings->value("needle2MinValue").toDouble();
needle2MaxValue = qSettings->value("needle2MaxValue").toDouble();
needle3MinValue = qSettings->value("needle3MinValue").toDouble();
needle3MaxValue = qSettings->value("needle3MaxValue").toDouble();
needle1DataObject = qSettings->value("needle1DataObject").toString();
needle1ObjectField = qSettings->value("needle1ObjectField").toString();
needle2DataObject = qSettings->value("needle2DataObject").toString();
needle2ObjectField = qSettings->value("needle2ObjectField").toString();
needle3DataObject = qSettings->value("needle3DataObject").toString();
needle3ObjectField = qSettings->value("needle3ObjectField").toString();
needle1Factor = qSettings->value("needle1Factor").toDouble();
needle2Factor = qSettings->value("needle2Factor").toDouble();
needle3Factor = qSettings->value("needle3Factor").toDouble();
needle1Move = qSettings->value("needle1Move").toString();
needle2Move = qSettings->value("needle2Move").toString();
needle3Move = qSettings->value("needle3Move").toString();
font = qSettings->value("font").toString();
}
}
/**
* Clones a configuration.
*
*/
IUAVGadgetConfiguration *DialGadgetConfiguration::clone()
{
DialGadgetConfiguration *m = new DialGadgetConfiguration(this->classId());
m->useOpenGLFlag = useOpenGLFlag;
m->m_defaultDial=m_defaultDial;
m->setDialBackgroundID(dialBackgroundID);
m->setDialForegroundID(dialForegroundID);
m->setDialNeedleID1(dialNeedleID1);
m->setDialNeedleID2(dialNeedleID2);
m->setDialNeedleID3(dialNeedleID3);
m->setN1Min(needle1MinValue);
m->setN1Max(needle1MaxValue);
m->setN2Min(needle2MinValue);
m->setN2Max(needle2MaxValue);
m->setN3Min(needle3MinValue);
m->setN3Max(needle3MaxValue);
m->setN1DataObject(needle1DataObject);
m->setN1ObjField(needle1ObjectField);
m->setN2DataObject(needle2DataObject);
m->setN2ObjField(needle2ObjectField);
m->setN3DataObject(needle3DataObject);
m->setN3ObjField(needle3ObjectField);
m->setN1Factor(needle1Factor);
m->setN2Factor(needle2Factor);
m->setN3Factor(needle3Factor);
m->setN1Move(needle1Move);
m->setN2Move(needle2Move);
m->setN3Move(needle3Move);
m->setFont(font);
return m;
}
/**
* Saves a configuration.
*
*/
void DialGadgetConfiguration::saveConfig(QSettings* settings) const {
QString dialFile = Utils::PathUtils().RemoveDataPath(m_defaultDial);
settings->setValue("dialFile", dialFile);
settings->setValue("useOpenGLFlag", useOpenGLFlag);
settings->setValue("dialBackgroundID", dialBackgroundID);
settings->setValue("dialForegroundID", dialForegroundID);
settings->setValue("dialNeedleID1", dialNeedleID1);
settings->setValue("dialNeedleID2", dialNeedleID2);
settings->setValue("dialNeedleID3", dialNeedleID3);
settings->setValue("needle1MinValue", needle1MinValue);
settings->setValue("needle1MaxValue", needle1MaxValue);
settings->setValue("needle2MinValue", needle2MinValue);
settings->setValue("needle2MaxValue", needle2MaxValue);
settings->setValue("needle3MinValue", needle3MinValue);
settings->setValue("needle3MaxValue", needle3MaxValue);
settings->setValue("needle1DataObject", needle1DataObject);
settings->setValue("needle1ObjectField", needle1ObjectField);
settings->setValue("needle2DataObject", needle2DataObject);
settings->setValue("needle2ObjectField", needle2ObjectField);
settings->setValue("needle3DataObject", needle3DataObject);
settings->setValue("needle3ObjectField", needle3ObjectField);
settings->setValue("needle1Factor", needle1Factor);
settings->setValue("needle2Factor", needle2Factor);
settings->setValue("needle3Factor", needle3Factor);
settings->setValue("needle1Move", needle1Move);
settings->setValue("needle2Move", needle2Move);
settings->setValue("needle3Move", needle3Move);
settings->setValue("font", font);
}

View File

@ -1,139 +1,143 @@
/**
******************************************************************************
*
* @file dialgadgetconfiguration.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @see The GNU Public License (GPL) Version 3
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup DialPlugin Dial Plugin
* @{
* @brief Plots flight information rotary style dials
*****************************************************************************/
/*
* 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
*/
#ifndef DIALGADGETCONFIGURATION_H
#define DIALGADGETCONFIGURATION_H
#include <coreplugin/iuavgadgetconfiguration.h>
using namespace Core;
/* Despite its name, this is actually a generic analog dial
supporting up to two rotating "needle" indicators.
*/
class DialGadgetConfiguration : public IUAVGadgetConfiguration
{
Q_OBJECT
public:
explicit DialGadgetConfiguration(QString classId, QSettings* qSettings = 0, QObject *parent = 0);
//set dial configuration functions
void setDialFile(QString dialFile){m_defaultDial=dialFile;}
void setDialBackgroundID(QString elementID) { dialBackgroundID = elementID;}
void setDialForegroundID(QString elementID) { dialForegroundID = elementID;}
void setDialNeedleID1(QString elementID) { dialNeedleID1 = elementID;}
void setDialNeedleID2(QString elementID) { dialNeedleID2 = elementID;}
void setDialNeedleID3(QString elementID) { dialNeedleID3 = elementID;}
void setN1Min(double val) { needle1MinValue = val;}
void setN2Min(double val) { needle2MinValue = val;}
void setN3Min(double val) { needle3MinValue = val;}
void setN1Max(double val) { needle1MaxValue = val;}
void setN2Max(double val) { needle2MaxValue = val;}
void setN3Max(double val) { needle3MaxValue = val;}
void setN1Factor(double val) { needle1Factor = val;}
void setN2Factor(double val) { needle2Factor = val;}
void setN3Factor(double val) { needle3Factor = val;}
void setN1DataObject(QString text) {needle1DataObject = text; }
void setN2DataObject(QString text){ needle2DataObject = text; }
void setN3DataObject(QString text){ needle3DataObject = text; }
void setN1ObjField(QString text) { needle1ObjectField = text; }
void setN2ObjField(QString text) { needle2ObjectField = text; }
void setN3ObjField(QString text) { needle3ObjectField = text; }
void setN1Move( QString move) { needle1Move = move; }
void setN2Move( QString move) { needle2Move = move; }
void setN3Move( QString move) { needle3Move = move; }
void setFont(QString text) { font = text; }
//get dial configuration functions
QString dialFile() {return m_defaultDial;}
QString dialBackground() {return dialBackgroundID;}
QString dialForeground() {return dialForegroundID;}
QString dialNeedle1() {return dialNeedleID1;}
QString dialNeedle2() {return dialNeedleID2;}
QString dialNeedle3() {return dialNeedleID3;}
double getN1Min() { return needle1MinValue;}
double getN2Min() { return needle2MinValue;}
double getN3Min() { return needle3MinValue;}
double getN1Max() { return needle1MaxValue;}
double getN2Max() { return needle2MaxValue;}
double getN3Max() { return needle3MaxValue;}
double getN1Factor() { return needle1Factor;}
double getN2Factor() { return needle2Factor;}
double getN3Factor() { return needle3Factor;}
QString getN1DataObject() { return needle1DataObject; }
QString getN2DataObject() { return needle2DataObject; }
QString getN3DataObject() { return needle3DataObject; }
QString getN1ObjField() { return needle1ObjectField; }
QString getN2ObjField() { return needle2ObjectField; }
QString getN3ObjField() { return needle3ObjectField; }
QString getN1Move() { return needle1Move; }
QString getN2Move() { return needle2Move; }
QString getN3Move() { return needle3Move; }
QString getFont() { return font;}
void saveConfig(QSettings* settings) const;
IUAVGadgetConfiguration *clone();
private:
QString m_defaultDial; // The name of the dial's SVG source file
QString dialBackgroundID; // SVG elementID of the background
QString dialForegroundID; // ... of the foreground
QString dialNeedleID1; // ... and the first needle
QString dialNeedleID2; // ... and the second
QString dialNeedleID3; // ... and the third
// Note: MinValue not used at the moment!
double needle1MinValue; // Value corresponding to a 0 degree angle;
double needle1MaxValue; // Value corresponding to a 360 degree angle;
double needle2MinValue;
double needle2MaxValue;
double needle3MinValue;
double needle3MaxValue;
double needle1Factor;
double needle2Factor;
double needle3Factor;
// The font used for the dial
QString font;
QString needle1DataObject;
QString needle1ObjectField;
QString needle2DataObject;
QString needle2ObjectField;
QString needle3DataObject;
QString needle3ObjectField;
// How the two dials move:
QString needle1Move;
QString needle2Move;
QString needle3Move;
};
#endif // DIALGADGETCONFIGURATION_H
/**
******************************************************************************
*
* @file dialgadgetconfiguration.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @see The GNU Public License (GPL) Version 3
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup DialPlugin Dial Plugin
* @{
* @brief Plots flight information rotary style dials
*****************************************************************************/
/*
* 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
*/
#ifndef DIALGADGETCONFIGURATION_H
#define DIALGADGETCONFIGURATION_H
#include <coreplugin/iuavgadgetconfiguration.h>
using namespace Core;
/* Despite its name, this is actually a generic analog dial
supporting up to two rotating "needle" indicators.
*/
class DialGadgetConfiguration : public IUAVGadgetConfiguration
{
Q_OBJECT
public:
explicit DialGadgetConfiguration(QString classId, QSettings* qSettings = 0, QObject *parent = 0);
//set dial configuration functions
void setDialFile(QString dialFile){m_defaultDial=dialFile;}
void setDialBackgroundID(QString elementID) { dialBackgroundID = elementID;}
void setDialForegroundID(QString elementID) { dialForegroundID = elementID;}
void setDialNeedleID1(QString elementID) { dialNeedleID1 = elementID;}
void setDialNeedleID2(QString elementID) { dialNeedleID2 = elementID;}
void setDialNeedleID3(QString elementID) { dialNeedleID3 = elementID;}
void setN1Min(double val) { needle1MinValue = val;}
void setN2Min(double val) { needle2MinValue = val;}
void setN3Min(double val) { needle3MinValue = val;}
void setN1Max(double val) { needle1MaxValue = val;}
void setN2Max(double val) { needle2MaxValue = val;}
void setN3Max(double val) { needle3MaxValue = val;}
void setN1Factor(double val) { needle1Factor = val;}
void setN2Factor(double val) { needle2Factor = val;}
void setN3Factor(double val) { needle3Factor = val;}
void setN1DataObject(QString text) {needle1DataObject = text; }
void setN2DataObject(QString text){ needle2DataObject = text; }
void setN3DataObject(QString text){ needle3DataObject = text; }
void setN1ObjField(QString text) { needle1ObjectField = text; }
void setN2ObjField(QString text) { needle2ObjectField = text; }
void setN3ObjField(QString text) { needle3ObjectField = text; }
void setN1Move( QString move) { needle1Move = move; }
void setN2Move( QString move) { needle2Move = move; }
void setN3Move( QString move) { needle3Move = move; }
void setFont(QString text) { font = text; }
void setUseOpenGL(bool flag) { useOpenGLFlag = flag; }
//get dial configuration functions
QString dialFile() {return m_defaultDial;}
QString dialBackground() {return dialBackgroundID;}
QString dialForeground() {return dialForegroundID;}
QString dialNeedle1() {return dialNeedleID1;}
QString dialNeedle2() {return dialNeedleID2;}
QString dialNeedle3() {return dialNeedleID3;}
double getN1Min() { return needle1MinValue;}
double getN2Min() { return needle2MinValue;}
double getN3Min() { return needle3MinValue;}
double getN1Max() { return needle1MaxValue;}
double getN2Max() { return needle2MaxValue;}
double getN3Max() { return needle3MaxValue;}
double getN1Factor() { return needle1Factor;}
double getN2Factor() { return needle2Factor;}
double getN3Factor() { return needle3Factor;}
QString getN1DataObject() { return needle1DataObject; }
QString getN2DataObject() { return needle2DataObject; }
QString getN3DataObject() { return needle3DataObject; }
QString getN1ObjField() { return needle1ObjectField; }
QString getN2ObjField() { return needle2ObjectField; }
QString getN3ObjField() { return needle3ObjectField; }
QString getN1Move() { return needle1Move; }
QString getN2Move() { return needle2Move; }
QString getN3Move() { return needle3Move; }
QString getFont() { return font;}
bool useOpenGL() { return useOpenGLFlag; }
void saveConfig(QSettings* settings) const;
IUAVGadgetConfiguration *clone();
private:
QString m_defaultDial; // The name of the dial's SVG source file
QString dialBackgroundID; // SVG elementID of the background
QString dialForegroundID; // ... of the foreground
QString dialNeedleID1; // ... and the first needle
QString dialNeedleID2; // ... and the second
QString dialNeedleID3; // ... and the third
// Note: MinValue not used at the moment!
double needle1MinValue; // Value corresponding to a 0 degree angle;
double needle1MaxValue; // Value corresponding to a 360 degree angle;
double needle2MinValue;
double needle2MaxValue;
double needle3MinValue;
double needle3MaxValue;
double needle1Factor;
double needle2Factor;
double needle3Factor;
// The font used for the dial
QString font;
QString needle1DataObject;
QString needle1ObjectField;
QString needle2DataObject;
QString needle2ObjectField;
QString needle3DataObject;
QString needle3ObjectField;
// How the two dials move:
QString needle1Move;
QString needle2Move;
QString needle3Move;
bool useOpenGLFlag;
};
#endif // DIALGADGETCONFIGURATION_H

View File

@ -1,273 +1,276 @@
/**
******************************************************************************
*
* @file dialgadgetoptionspage.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @see The GNU Public License (GPL) Version 3
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup DialPlugin Dial Plugin
* @{
* @brief Plots flight information rotary style dials
*****************************************************************************/
/*
* 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 "dialgadgetoptionspage.h"
#include "dialgadgetconfiguration.h"
#include "ui_dialgadgetoptionspage.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavdataobject.h"
#include <QFileDialog>
#include <QtAlgorithms>
#include <QStringList>
DialGadgetOptionsPage::DialGadgetOptionsPage(DialGadgetConfiguration *config, QObject *parent) :
IOptionsPage(parent),
m_config(config)
{
}
//creates options page widget (uses the UI file)
QWidget *DialGadgetOptionsPage::createPage(QWidget *parent)
{
Q_UNUSED(parent);
options_page = new Ui::DialGadgetOptionsPage();
//main widget
QWidget *optionsPageWidget = new QWidget;
//main layout
options_page->setupUi(optionsPageWidget);
// Fills the combo boxes for the UAVObjects
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
QList< QList<UAVDataObject*> > objList = objManager->getDataObjects();
foreach (QList<UAVDataObject*> list, objList) {
foreach (UAVDataObject* obj, list) {
options_page->uavObject1->addItem(obj->getName());
options_page->uavObject2->addItem(obj->getName());
options_page->uavObject3->addItem(obj->getName());
}
}
// Fills the combo boxes for Needle movement options
options_page->moveNeedle1->addItem("Rotate");
options_page->moveNeedle1->addItem("Horizontal");
options_page->moveNeedle1->addItem("Vertical");
options_page->moveNeedle2->addItem("Rotate");
options_page->moveNeedle2->addItem("Horizontal");
options_page->moveNeedle2->addItem("Vertical");
options_page->moveNeedle3->addItem("Rotate");
options_page->moveNeedle3->addItem("Horizontal");
options_page->moveNeedle3->addItem("Vertical");
// Restore the contents from the settings:
options_page->svgSourceFile->setExpectedKind(Utils::PathChooser::File);
options_page->svgSourceFile->setPromptDialogFilter(tr("SVG image (*.svg)"));
options_page->svgSourceFile->setPromptDialogTitle(tr("Choose SVG image"));
options_page->svgSourceFile->setPath(m_config->dialFile());
options_page->backgroundID->setText(m_config->dialBackground());
options_page->foregroundID->setText(m_config->dialForeground());
options_page->needle1ID->setText(m_config->dialNeedle1());
options_page->needle2ID->setText(m_config->dialNeedle2());
options_page->needle3ID->setText(m_config->dialNeedle3());
options_page->needle1Min->setValue(m_config->getN1Min());
options_page->needle1Max->setValue(m_config->getN1Max());
options_page->needle2Min->setValue(m_config->getN2Min());
options_page->needle2Max->setValue(m_config->getN2Max());
options_page->needle3Min->setValue(m_config->getN3Min());
options_page->needle3Max->setValue(m_config->getN3Max());
options_page->factor1->setValue(m_config->getN1Factor());
options_page->factor2->setValue(m_config->getN2Factor());
options_page->factor3->setValue(m_config->getN3Factor());
options_page->moveNeedle1->setCurrentIndex(options_page->moveNeedle1->findText(m_config->getN1Move()));
options_page->moveNeedle2->setCurrentIndex(options_page->moveNeedle2->findText(m_config->getN2Move()));
options_page->moveNeedle3->setCurrentIndex(options_page->moveNeedle3->findText(m_config->getN3Move()));
//select saved UAV Object field values
if(options_page->uavObject1->findText(m_config->getN1DataObject())!=-1){
options_page->uavObject1->setCurrentIndex(options_page->uavObject1->findText(m_config->getN1DataObject()));
// Now load the object field values - 1st check that the object saved in the config still exists
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(m_config->getN1DataObject()) );
if (obj != NULL ) {
on_uavObject1_currentIndexChanged(m_config->getN1DataObject());
// And set the highlighed value from the settings:
options_page->objectField1->setCurrentIndex(options_page->objectField1->findText(m_config->getN1ObjField()));
}
}
connect(options_page->uavObject1, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_uavObject1_currentIndexChanged(QString)));
if(options_page->uavObject2->findText(m_config->getN2DataObject())!=-1){
options_page->uavObject2->setCurrentIndex(options_page->uavObject2->findText(m_config->getN2DataObject()));
// Now load the object field values:
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(m_config->getN2DataObject()));
if (obj != NULL ) {
on_uavObject2_currentIndexChanged(m_config->getN2DataObject());
options_page->objectField2->setCurrentIndex(options_page->objectField2->findText(m_config->getN2ObjField()));
}
}
connect(options_page->uavObject2, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_uavObject2_currentIndexChanged(QString)));
if(options_page->uavObject3->findText(m_config->getN3DataObject())!=-1){
options_page->uavObject3->setCurrentIndex(options_page->uavObject3->findText(m_config->getN3DataObject()));
// Now load the object field values:
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(m_config->getN3DataObject()));
if (obj != NULL ) {
on_uavObject3_currentIndexChanged(m_config->getN3DataObject());
options_page->objectField3->setCurrentIndex(options_page->objectField3->findText(m_config->getN3ObjField()));
}
}
connect(options_page->uavObject3, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_uavObject3_currentIndexChanged(QString)));
connect(options_page->fontPicker, SIGNAL(clicked()), this, SLOT(on_fontPicker_clicked()));
return optionsPageWidget;
}
/**
* Called when the user presses apply or OK.
*
* Saves the current values
*
*/
void DialGadgetOptionsPage::apply()
{
m_config->setDialFile(options_page->svgSourceFile->path());
m_config->setDialBackgroundID(options_page->backgroundID->text());
m_config->setDialForegroundID(options_page->foregroundID->text());
m_config->setDialNeedleID1(options_page->needle1ID->text());
m_config->setDialNeedleID2(options_page->needle2ID->text());
m_config->setDialNeedleID3(options_page->needle3ID->text());
m_config->setN1Min(options_page->needle1Min->value());
m_config->setN1Max(options_page->needle1Max->value());
m_config->setN1Factor(options_page->factor1->value());
m_config->setN2Min(options_page->needle2Min->value());
m_config->setN2Max(options_page->needle2Max->value());
m_config->setN2Factor(options_page->factor2->value());
m_config->setN3Min(options_page->needle3Min->value());
m_config->setN3Max(options_page->needle3Max->value());
m_config->setN3Factor(options_page->factor3->value());
m_config->setN1DataObject(options_page->uavObject1->currentText());
m_config->setN2DataObject(options_page->uavObject2->currentText());
m_config->setN3DataObject(options_page->uavObject3->currentText());
m_config->setN1ObjField(options_page->objectField1->currentText());
m_config->setN2ObjField(options_page->objectField2->currentText());
m_config->setN3ObjField(options_page->objectField3->currentText());
m_config->setN1Move(options_page->moveNeedle1->currentText());
m_config->setN2Move(options_page->moveNeedle2->currentText());
m_config->setN3Move(options_page->moveNeedle3->currentText());
m_config->setFont(font.toString());
}
/**
* Opens a font picker.
*
*/
void DialGadgetOptionsPage::on_fontPicker_clicked()
{
bool ok;
font = QFontDialog::getFont(&ok, QFont("Arial", 12), qobject_cast<QWidget*>(this));
}
/*
Fills in the field1 combo box when value is changed in the
object1 field
*/
void DialGadgetOptionsPage::on_uavObject1_currentIndexChanged(QString val) {
options_page->objectField1->clear();
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(val) );
QList<UAVObjectField*> fieldList = obj->getFields();
foreach (UAVObjectField* field, fieldList) {
if(field->getType() == UAVObjectField::STRING || field->getType() == UAVObjectField::ENUM )
continue;
if(field->getElementNames().count() > 1)
{
foreach(QString elemName , field->getElementNames())
{
options_page->objectField1->addItem(field->getName() + "-" + elemName);
}
}
else
options_page->objectField1->addItem(field->getName());
}
}
/*
Fills in the field2 combo box when value is changed in the
object2 field
*/
void DialGadgetOptionsPage::on_uavObject2_currentIndexChanged(QString val) {
options_page->objectField2->clear();
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(val) );
QList<UAVObjectField*> fieldList = obj->getFields();
foreach (UAVObjectField* field, fieldList) {
if(field->getType() == UAVObjectField::STRING || field->getType() == UAVObjectField::ENUM )
continue;
if(field->getElementNames().count() > 1)
{
foreach(QString elemName , field->getElementNames())
{
options_page->objectField2->addItem(field->getName() + "-" + elemName);
}
}
else
options_page->objectField2->addItem(field->getName());
}
}
/*
Fills in the field3 combo box when value is changed in the
object3 field
*/
void DialGadgetOptionsPage::on_uavObject3_currentIndexChanged(QString val) {
options_page->objectField3->clear();
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(val) );
QList<UAVObjectField*> fieldList = obj->getFields();
foreach (UAVObjectField* field, fieldList) {
if(field->getType() == UAVObjectField::STRING || field->getType() == UAVObjectField::ENUM )
continue;
if(field->getElementNames().count() > 1)
{
foreach(QString elemName , field->getElementNames())
{
options_page->objectField3->addItem(field->getName() + "-" + elemName);
}
}
else
options_page->objectField3->addItem(field->getName());
}
}
void DialGadgetOptionsPage::finish()
{
}
/**
******************************************************************************
*
* @file dialgadgetoptionspage.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @see The GNU Public License (GPL) Version 3
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup DialPlugin Dial Plugin
* @{
* @brief Plots flight information rotary style dials
*****************************************************************************/
/*
* 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 "dialgadgetoptionspage.h"
#include "dialgadgetconfiguration.h"
#include "ui_dialgadgetoptionspage.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavdataobject.h"
#include <QFileDialog>
#include <QtAlgorithms>
#include <QStringList>
DialGadgetOptionsPage::DialGadgetOptionsPage(DialGadgetConfiguration *config, QObject *parent) :
IOptionsPage(parent),
m_config(config)
{
}
//creates options page widget (uses the UI file)
QWidget *DialGadgetOptionsPage::createPage(QWidget *parent)
{
Q_UNUSED(parent);
options_page = new Ui::DialGadgetOptionsPage();
//main widget
QWidget *optionsPageWidget = new QWidget;
//main layout
options_page->setupUi(optionsPageWidget);
// Fills the combo boxes for the UAVObjects
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
QList< QList<UAVDataObject*> > objList = objManager->getDataObjects();
foreach (QList<UAVDataObject*> list, objList) {
foreach (UAVDataObject* obj, list) {
options_page->uavObject1->addItem(obj->getName());
options_page->uavObject2->addItem(obj->getName());
options_page->uavObject3->addItem(obj->getName());
}
}
// Fills the combo boxes for Needle movement options
options_page->moveNeedle1->addItem("Rotate");
options_page->moveNeedle1->addItem("Horizontal");
options_page->moveNeedle1->addItem("Vertical");
options_page->moveNeedle2->addItem("Rotate");
options_page->moveNeedle2->addItem("Horizontal");
options_page->moveNeedle2->addItem("Vertical");
options_page->moveNeedle3->addItem("Rotate");
options_page->moveNeedle3->addItem("Horizontal");
options_page->moveNeedle3->addItem("Vertical");
// Restore the contents from the settings:
options_page->useOpenGL->setChecked(m_config->useOpenGL());
options_page->svgSourceFile->setExpectedKind(Utils::PathChooser::File);
options_page->svgSourceFile->setPromptDialogFilter(tr("SVG image (*.svg)"));
options_page->svgSourceFile->setPromptDialogTitle(tr("Choose SVG image"));
options_page->svgSourceFile->setPath(m_config->dialFile());
options_page->backgroundID->setText(m_config->dialBackground());
options_page->foregroundID->setText(m_config->dialForeground());
options_page->needle1ID->setText(m_config->dialNeedle1());
options_page->needle2ID->setText(m_config->dialNeedle2());
options_page->needle3ID->setText(m_config->dialNeedle3());
options_page->needle1Min->setValue(m_config->getN1Min());
options_page->needle1Max->setValue(m_config->getN1Max());
options_page->needle2Min->setValue(m_config->getN2Min());
options_page->needle2Max->setValue(m_config->getN2Max());
options_page->needle3Min->setValue(m_config->getN3Min());
options_page->needle3Max->setValue(m_config->getN3Max());
options_page->factor1->setValue(m_config->getN1Factor());
options_page->factor2->setValue(m_config->getN2Factor());
options_page->factor3->setValue(m_config->getN3Factor());
options_page->moveNeedle1->setCurrentIndex(options_page->moveNeedle1->findText(m_config->getN1Move()));
options_page->moveNeedle2->setCurrentIndex(options_page->moveNeedle2->findText(m_config->getN2Move()));
options_page->moveNeedle3->setCurrentIndex(options_page->moveNeedle3->findText(m_config->getN3Move()));
//select saved UAV Object field values
if(options_page->uavObject1->findText(m_config->getN1DataObject())!=-1){
options_page->uavObject1->setCurrentIndex(options_page->uavObject1->findText(m_config->getN1DataObject()));
// Now load the object field values - 1st check that the object saved in the config still exists
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(m_config->getN1DataObject()) );
if (obj != NULL ) {
on_uavObject1_currentIndexChanged(m_config->getN1DataObject());
// And set the highlighed value from the settings:
options_page->objectField1->setCurrentIndex(options_page->objectField1->findText(m_config->getN1ObjField()));
}
}
connect(options_page->uavObject1, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_uavObject1_currentIndexChanged(QString)));
if(options_page->uavObject2->findText(m_config->getN2DataObject())!=-1){
options_page->uavObject2->setCurrentIndex(options_page->uavObject2->findText(m_config->getN2DataObject()));
// Now load the object field values:
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(m_config->getN2DataObject()));
if (obj != NULL ) {
on_uavObject2_currentIndexChanged(m_config->getN2DataObject());
options_page->objectField2->setCurrentIndex(options_page->objectField2->findText(m_config->getN2ObjField()));
}
}
connect(options_page->uavObject2, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_uavObject2_currentIndexChanged(QString)));
if(options_page->uavObject3->findText(m_config->getN3DataObject())!=-1){
options_page->uavObject3->setCurrentIndex(options_page->uavObject3->findText(m_config->getN3DataObject()));
// Now load the object field values:
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(m_config->getN3DataObject()));
if (obj != NULL ) {
on_uavObject3_currentIndexChanged(m_config->getN3DataObject());
options_page->objectField3->setCurrentIndex(options_page->objectField3->findText(m_config->getN3ObjField()));
}
}
connect(options_page->uavObject3, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_uavObject3_currentIndexChanged(QString)));
connect(options_page->fontPicker, SIGNAL(clicked()), this, SLOT(on_fontPicker_clicked()));
return optionsPageWidget;
}
/**
* Called when the user presses apply or OK.
*
* Saves the current values
*
*/
void DialGadgetOptionsPage::apply()
{
m_config->setDialFile(options_page->svgSourceFile->path());
m_config->setUseOpenGL(options_page->useOpenGL->checkState());
m_config->setDialBackgroundID(options_page->backgroundID->text());
m_config->setDialForegroundID(options_page->foregroundID->text());
m_config->setDialNeedleID1(options_page->needle1ID->text());
m_config->setDialNeedleID2(options_page->needle2ID->text());
m_config->setDialNeedleID3(options_page->needle3ID->text());
m_config->setN1Min(options_page->needle1Min->value());
m_config->setN1Max(options_page->needle1Max->value());
m_config->setN1Factor(options_page->factor1->value());
m_config->setN2Min(options_page->needle2Min->value());
m_config->setN2Max(options_page->needle2Max->value());
m_config->setN2Factor(options_page->factor2->value());
m_config->setN3Min(options_page->needle3Min->value());
m_config->setN3Max(options_page->needle3Max->value());
m_config->setN3Factor(options_page->factor3->value());
m_config->setN1DataObject(options_page->uavObject1->currentText());
m_config->setN2DataObject(options_page->uavObject2->currentText());
m_config->setN3DataObject(options_page->uavObject3->currentText());
m_config->setN1ObjField(options_page->objectField1->currentText());
m_config->setN2ObjField(options_page->objectField2->currentText());
m_config->setN3ObjField(options_page->objectField3->currentText());
m_config->setN1Move(options_page->moveNeedle1->currentText());
m_config->setN2Move(options_page->moveNeedle2->currentText());
m_config->setN3Move(options_page->moveNeedle3->currentText());
m_config->setFont(font.toString());
}
/**
* Opens a font picker.
*
*/
void DialGadgetOptionsPage::on_fontPicker_clicked()
{
bool ok;
font = QFontDialog::getFont(&ok, QFont("Arial", 12), qobject_cast<QWidget*>(this));
}
/*
Fills in the field1 combo box when value is changed in the
object1 field
*/
void DialGadgetOptionsPage::on_uavObject1_currentIndexChanged(QString val) {
options_page->objectField1->clear();
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(val) );
QList<UAVObjectField*> fieldList = obj->getFields();
foreach (UAVObjectField* field, fieldList) {
if(field->getType() == UAVObjectField::STRING || field->getType() == UAVObjectField::ENUM )
continue;
if(field->getElementNames().count() > 1)
{
foreach(QString elemName , field->getElementNames())
{
options_page->objectField1->addItem(field->getName() + "-" + elemName);
}
}
else
options_page->objectField1->addItem(field->getName());
}
}
/*
Fills in the field2 combo box when value is changed in the
object2 field
*/
void DialGadgetOptionsPage::on_uavObject2_currentIndexChanged(QString val) {
options_page->objectField2->clear();
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(val) );
QList<UAVObjectField*> fieldList = obj->getFields();
foreach (UAVObjectField* field, fieldList) {
if(field->getType() == UAVObjectField::STRING || field->getType() == UAVObjectField::ENUM )
continue;
if(field->getElementNames().count() > 1)
{
foreach(QString elemName , field->getElementNames())
{
options_page->objectField2->addItem(field->getName() + "-" + elemName);
}
}
else
options_page->objectField2->addItem(field->getName());
}
}
/*
Fills in the field3 combo box when value is changed in the
object3 field
*/
void DialGadgetOptionsPage::on_uavObject3_currentIndexChanged(QString val) {
options_page->objectField3->clear();
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(val) );
QList<UAVObjectField*> fieldList = obj->getFields();
foreach (UAVObjectField* field, fieldList) {
if(field->getType() == UAVObjectField::STRING || field->getType() == UAVObjectField::ENUM )
continue;
if(field->getElementNames().count() > 1)
{
foreach(QString elemName , field->getElementNames())
{
options_page->objectField3->addItem(field->getName() + "-" + elemName);
}
}
else
options_page->objectField3->addItem(field->getName());
}
}
void DialGadgetOptionsPage::finish()
{
}

View File

@ -1,796 +1,814 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DialGadgetOptionsPage</class>
<widget class="QWidget" name="DialGadgetOptionsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>545</width>
<height>341</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QWidget" name="verticalLayoutWidget">
<property name="geometry">
<rect>
<x>-1</x>
<y>-1</y>
<width>511</width>
<height>311</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<property name="leftMargin">
<number>10</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>10</number>
</property>
<property name="bottomMargin">
<number>10</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0,0">
<property name="spacing">
<number>10</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<property name="bottomMargin">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Dial SVG: </string>
</property>
</widget>
</item>
<item>
<widget class="Utils::PathChooser" name="svgSourceFile" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_28">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Dial font:</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="fontPicker">
<property name="text">
<string>Select...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>BackgroundID</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="backgroundID"/>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>ForegroundID</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="foregroundID"/>
</item>
</layout>
</item>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Indicator 1</string>
</attribute>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>478</width>
<height>151</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>4</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Indicator 1</string>
</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>
<item>
<widget class="QLabel" name="label_12">
<property name="text">
<string>Movement:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="moveNeedle1"/>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>ID:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="needle1ID">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="topMargin">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>Min:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="needle1Min">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Max:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="needle1Max">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_10">
<property name="text">
<string>Factor:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="factor1">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>5</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="topMargin">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>DataObject</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="uavObject1">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_9">
<property name="text">
<string>ObjectField</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="objectField1">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Indicator 2</string>
</attribute>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>473</width>
<height>139</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="label_16">
<property name="text">
<string>Indicator 2</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_13">
<property name="text">
<string>Movement:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="moveNeedle2"/>
</item>
<item>
<widget class="QLabel" name="label_17">
<property name="text">
<string>ID:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="needle2ID">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<property name="topMargin">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="label_18">
<property name="text">
<string>Min:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="needle2Min">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-10000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_19">
<property name="text">
<string>Max:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="needle2Max">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_11">
<property name="text">
<string>Factor:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="factor2">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>5</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<property name="topMargin">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="label_20">
<property name="text">
<string>DataObject</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="uavObject2">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_21">
<property name="text">
<string>ObjectField</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="objectField2">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QWidget" name="tab_3">
<attribute name="title">
<string>Indicator 3</string>
</attribute>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>473</width>
<height>139</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QLabel" name="label_22">
<property name="text">
<string>Indicator 3</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_14">
<property name="text">
<string>Movement:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="moveNeedle3"/>
</item>
<item>
<widget class="QLabel" name="label_23">
<property name="text">
<string>ID:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="needle3ID">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<property name="topMargin">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="label_24">
<property name="text">
<string>Min:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="needle3Min">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-10000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_25">
<property name="text">
<string>Max:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="needle3Max">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_15">
<property name="text">
<string>Factor:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="factor3">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>5</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<property name="topMargin">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="label_26">
<property name="text">
<string>DataObject</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="uavObject3">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_27">
<property name="text">
<string>ObjectField</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="objectField3">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
</item>
</layout>
</widget>
</widget>
<customwidgets>
<customwidget>
<class>Utils::PathChooser</class>
<extends>QWidget</extends>
<header>utils/pathchooser.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DialGadgetOptionsPage</class>
<widget class="QWidget" name="DialGadgetOptionsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>545</width>
<height>341</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QWidget" name="verticalLayoutWidget">
<property name="geometry">
<rect>
<x>-1</x>
<y>-1</y>
<width>511</width>
<height>311</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0,0,0">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<property name="leftMargin">
<number>10</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>10</number>
</property>
<property name="bottomMargin">
<number>10</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
<widget class="QCheckBox" name="useOpenGL">
<property name="text">
<string>Use OpenGL</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0,0">
<property name="spacing">
<number>10</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<property name="bottomMargin">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Dial SVG: </string>
</property>
</widget>
</item>
<item>
<widget class="Utils::PathChooser" name="svgSourceFile" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_28">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Dial font:</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="fontPicker">
<property name="text">
<string>Select...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>BackgroundID</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="backgroundID"/>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>ForegroundID</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="foregroundID"/>
</item>
</layout>
</item>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Indicator 1</string>
</attribute>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>478</width>
<height>151</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>4</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Indicator 1</string>
</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>
<item>
<widget class="QLabel" name="label_12">
<property name="text">
<string>Movement:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="moveNeedle1"/>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>ID:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="needle1ID">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="topMargin">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>Min:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="needle1Min">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Max:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="needle1Max">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_10">
<property name="text">
<string>Factor:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="factor1">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>5</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="topMargin">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>DataObject</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="uavObject1">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_9">
<property name="text">
<string>ObjectField</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="objectField1">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Indicator 2</string>
</attribute>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>473</width>
<height>139</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="label_16">
<property name="text">
<string>Indicator 2</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_13">
<property name="text">
<string>Movement:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="moveNeedle2"/>
</item>
<item>
<widget class="QLabel" name="label_17">
<property name="text">
<string>ID:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="needle2ID">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<property name="topMargin">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="label_18">
<property name="text">
<string>Min:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="needle2Min">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-10000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_19">
<property name="text">
<string>Max:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="needle2Max">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_11">
<property name="text">
<string>Factor:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="factor2">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>5</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<property name="topMargin">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="label_20">
<property name="text">
<string>DataObject</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="uavObject2">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_21">
<property name="text">
<string>ObjectField</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="objectField2">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QWidget" name="tab_3">
<attribute name="title">
<string>Indicator 3</string>
</attribute>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>473</width>
<height>139</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QLabel" name="label_22">
<property name="text">
<string>Indicator 3</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_14">
<property name="text">
<string>Movement:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="moveNeedle3"/>
</item>
<item>
<widget class="QLabel" name="label_23">
<property name="text">
<string>ID:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="needle3ID">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<property name="topMargin">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="label_24">
<property name="text">
<string>Min:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="needle3Min">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-10000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_25">
<property name="text">
<string>Max:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="needle3Max">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_15">
<property name="text">
<string>Factor:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="factor3">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>5</number>
</property>
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<property name="topMargin">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="label_26">
<property name="text">
<string>DataObject</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="uavObject3">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_27">
<property name="text">
<string>ObjectField</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="objectField3">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
</item>
</layout>
</widget>
</widget>
<customwidgets>
<customwidget>
<class>Utils::PathChooser</class>
<extends>QWidget</extends>
<header>utils/pathchooser.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -1,623 +1,635 @@
/**
******************************************************************************
*
* @file dialgadgetwidget.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @see The GNU Public License (GPL) Version 3
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup DialPlugin Dial Plugin
* @{
* @brief Plots flight information rotary style dials
*****************************************************************************/
/*
* 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 "dialgadgetwidget.h"
#include <utils/stylehelper.h>
#include <iostream>
#include <QDebug>
DialGadgetWidget::DialGadgetWidget(QWidget *parent) : QGraphicsView(parent)
{
// TODO: create a proper "needle" object instead of hardcoding all this
// which is ugly (but easy).
setMinimumSize(64,64);
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
setScene(new QGraphicsScene(this));
setRenderHints(QPainter::Antialiasing);
m_renderer = new QSvgRenderer();
obj1 = NULL;
obj2 = NULL;
obj3 = NULL;
m_text1 = NULL;
m_text2 = NULL;
m_text3 = NULL; // Should be initialized to NULL otherwise the setFont method
// might segfault upon initialization if called before SetDialFile
needle1Target = 0;
needle2Target = 0;
needle3Target = 0;
// This timer mechanism makes needles rotate smoothly
connect(&dialTimer, SIGNAL(timeout()), this, SLOT(rotateNeedles()));
}
DialGadgetWidget::~DialGadgetWidget()
{
// Do nothing
}
/*!
\brief Connects the widget to the relevant UAVObjects
*/
void DialGadgetWidget::connectNeedles(QString object1, QString nfield1,
QString object2, QString nfield2,
QString object3, QString nfield3) {
if (obj1 != NULL)
disconnect(obj1,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(updateNeedle1(UAVObject*)));
if (obj2 != NULL)
disconnect(obj2,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(updateNeedle2(UAVObject*)));
if (obj3 != NULL)
disconnect(obj3,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(updateNeedle3(UAVObject*)));
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
// Check validity of arguments first, reject empty args and unknown fields.
if (!(object1.isEmpty() || nfield1.isEmpty())) {
obj1 = dynamic_cast<UAVDataObject*>( objManager->getObject(object1) );
if (obj1 != NULL ) {
// qDebug() << "Connected Object 1 (" << object1 << ").";
connect(obj1, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(updateNeedle1(UAVObject*)));
if(nfield1.contains("-"))
{
QStringList fieldSubfield = nfield1.split("-", QString::SkipEmptyParts);
field1 = fieldSubfield.at(0);
subfield1 = fieldSubfield.at(1);
haveSubField1 = true;
}
else
{
field1= nfield1;
haveSubField1 = false;
}
} else {
qDebug() << "Error: Object is unknown (" << object1 << ").";
}
}
// And do the same for the second needle.
if (!(object2.isEmpty() || nfield2.isEmpty())) {
obj2 = dynamic_cast<UAVDataObject*>( objManager->getObject(object2) );
if (obj2 != NULL ) {
// qDebug() << "Connected Object 2 (" << object2 << ").";
connect(obj2, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(updateNeedle2(UAVObject*)));
if(nfield2.contains("-"))
{
QStringList fieldSubfield = nfield2.split("-", QString::SkipEmptyParts);
field2 = fieldSubfield.at(0);
subfield2 = fieldSubfield.at(1);
haveSubField2 = true;
}
else
{
field2= nfield2;
haveSubField2 = false;
}
} else {
qDebug() << "Error: Object is unknown (" << object2 << ").";
}
}
// And do the same for the third needle.
if (!(object3.isEmpty() || nfield3.isEmpty())) {
obj3 = dynamic_cast<UAVDataObject*>( objManager->getObject(object3) );
if (obj3 != NULL ) {
// qDebug() << "Connected Object 3 (" << object3 << ").";
connect(obj3, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(updateNeedle3(UAVObject*)));
if(nfield3.contains("-"))
{
QStringList fieldSubfield = nfield3.split("-", QString::SkipEmptyParts);
field3 = fieldSubfield.at(0);
subfield3 = fieldSubfield.at(1);
haveSubField3 = true;
}
else
{
field3= nfield3;
haveSubField3 = false;
}
} else {
qDebug() << "Error: Object is unknown (" << object3 << ").";
}
}
}
/*!
\brief Called by the UAVObject which got updated
*/
void DialGadgetWidget::updateNeedle1(UAVObject *object1) {
// Double check that the field exists:
double value;
UAVObjectField* field = object1->getField(field1);
if (field) {
if(haveSubField1){
int indexOfSubField = field->getElementNames().indexOf(QRegExp(subfield1, Qt::CaseSensitive, QRegExp::FixedString));
value = field->getDouble(indexOfSubField);
} else
value = field->getDouble();
if (value != value) {
qDebug() << "Dial widget: encountered NaN !!";
return;
}
setNeedle1(value);
} else {
qDebug() << "Wrong field, maybe an issue with object disconnection ?";
}
}
/*!
\brief Called by the UAVObject which got updated
*/
void DialGadgetWidget::updateNeedle2(UAVObject *object2) {
double value;
UAVObjectField* field = object2->getField(field2);
if (field) {
if(haveSubField2){
int indexOfSubField = field->getElementNames().indexOf(QRegExp(subfield2, Qt::CaseSensitive, QRegExp::FixedString));
value = field->getDouble(indexOfSubField);
} else
value = field->getDouble();
if (value != value) {
qDebug() << "Dial widget: encountered NaN !!";
return;
}
setNeedle2(value);
} else {
qDebug() << "Wrong field, maybe an issue with object disconnection ?";
}
}
/*!
\brief Called by the UAVObject which got updated
*/
void DialGadgetWidget::updateNeedle3(UAVObject *object3) {
double value;
UAVObjectField* field = object3->getField(field3);
if (field) {
if(haveSubField3){
int indexOfSubField = field->getElementNames().indexOf(QRegExp(subfield3, Qt::CaseSensitive, QRegExp::FixedString));
value = field->getDouble(indexOfSubField);
} else
value = field->getDouble();
if (value != value) {
qDebug() << "Dial widget: encountered NaN !!";
return;
}
setNeedle3(value);
} else {
qDebug() << "Wrong field, maybe an issue with object disconnection ?";
}
}
/*
Initializes the dial file, and does all the one-time calculations for
display later. This is the method which really initializes the dial.
*/
void DialGadgetWidget::setDialFile(QString dfn, QString bg, QString fg, QString n1, QString n2,
QString n3, QString n1Move, QString n2Move, QString n3Move)
{
fgenabled = false;
n2enabled = false;
n3enabled = false;
QGraphicsScene *l_scene = scene();
setBackgroundBrush(QBrush(Utils::StyleHelper::baseColor()));
if (QFile::exists(dfn) && m_renderer->load(dfn) && m_renderer->isValid())
{
l_scene->clear(); // This also deletes all items contained in the scene.
m_background = new QGraphicsSvgItem();
// All other items will be clipped to the shape of the background
m_background->setFlags(QGraphicsItem::ItemClipsChildrenToShape|
QGraphicsItem::ItemClipsToShape);
m_foreground = new QGraphicsSvgItem();
m_needle1 = new QGraphicsSvgItem();
m_needle2 = new QGraphicsSvgItem();
m_needle3 = new QGraphicsSvgItem();
m_needle1->setParentItem(m_background);
m_needle2->setParentItem(m_background);
m_needle3->setParentItem(m_background);
m_foreground->setParentItem(m_background);
// We assume the dial contains at least the background
// and needle1
m_background->setSharedRenderer(m_renderer);
m_background->setElementId(bg);
l_scene->addItem(m_background);
m_needle1->setSharedRenderer(m_renderer);
m_needle1->setElementId(n1);
// Note: no need to add the item explicitely because it
// is done automatically since it's a child item of the
// background.
//l_scene->addItem(m_needle1);
// The dial gadget allows Needle1 and Needle2 to be
// the same element, for combined movement. Needle3
// is always independent.
if (n1 == n2) {
m_needle2 = m_needle1;
n2enabled = true;
} else {
if (m_renderer->elementExists(n2)) {
m_needle2->setSharedRenderer(m_renderer);
m_needle2->setElementId(n2);
//l_scene->addItem(m_needle2);
n2enabled = true;
}
}
if (m_renderer->elementExists(n3)) {
m_needle3->setSharedRenderer(m_renderer);
m_needle3->setElementId(n3);
//l_scene->addItem(m_needle3);
n3enabled = true;
}
if (m_renderer->elementExists(fg)) {
m_foreground->setSharedRenderer(m_renderer);
m_foreground->setElementId(fg);
// Center it on the scene
QRectF rectB = m_background->boundingRect();
QRectF rectF = m_foreground->boundingRect();
m_foreground->setPos(rectB.width()/2-rectF.width()/2,rectB.height()/2-rectF.height()/2);
//l_scene->addItem(m_foreground);
fgenabled = true;
}
rotateN1 = false;
horizN1 = false;
vertN1 = false;
rotateN2 = false;
horizN2 = false;
vertN2 = false;
rotateN3 = false;
horizN3 = false;
vertN3 = false;
// Now setup the rotation/translation settings:
// this is UGLY UGLY UGLY, sorry...
if (n1Move.contains("Rotate")) {
rotateN1 = true;
} else if (n1Move.contains("Horizontal")) {
horizN1 = true;
} else if (n1Move.contains("Vertical")) {
vertN1 = true;
}
if (n2Move.contains("Rotate")) {
rotateN2 = true;
} else if (n2Move.contains("Horizontal")) {
horizN2 = true;
} else if (n2Move.contains("Vertical")) {
vertN2 = true;
}
if (n3Move.contains("Rotate")) {
rotateN3 = true;
} else if (n3Move.contains("Horizontal")) {
horizN3 = true;
} else if (n3Move.contains("Vertical")) {
vertN3 = true;
}
l_scene->setSceneRect(m_background->boundingRect());
// Now Initialize the center for all transforms of the dial needles to the
// center of the background:
// - Move the center of the needle to the center of the background.
QRectF rectB = m_background->boundingRect();
QRectF rectN = m_needle1->boundingRect();
m_needle1->setPos(rectB.width()/2-rectN.width()/2,rectB.height()/2-rectN.height()/2);
// - Put the transform origin point of the needle at its center.
m_needle1->setTransformOriginPoint(rectN.width()/2,rectN.height()/2);
// Check whether the dial also wants display the numeric value:
if (m_renderer->elementExists(n1+"-text")) {
QMatrix textMatrix = m_renderer->matrixForElement(n1+"-text");
qreal startX = textMatrix.mapRect(m_renderer->boundsOnElement(n1+"-text")).x();
qreal startY = textMatrix.mapRect(m_renderer->boundsOnElement(n1+"-text")).y();
QTransform matrix;
matrix.translate(startX,startY);
m_text1 = new QGraphicsTextItem("0.00");
m_text1->setDefaultTextColor(QColor("White"));
m_text1->setTransform(matrix,false);
l_scene->addItem(m_text1);
} else {
m_text1 = NULL;
}
if ((n1 != n2) && n2enabled) {
// Only do it for needle2 if it is not the same as n1
rectN = m_needle2->boundingRect();
m_needle2->setPos(rectB.width()/2-rectN.width()/2,rectB.height()/2-rectN.height()/2);
m_needle2->setTransformOriginPoint(rectN.width()/2,rectN.height()/2);
// Check whether the dial also wants display the numeric value:
if (m_renderer->elementExists(n2+"-text")) {
QMatrix textMatrix = m_renderer->matrixForElement(n2+"-text");
qreal startX = textMatrix.mapRect(m_renderer->boundsOnElement(n2+"-text")).x();
qreal startY = textMatrix.mapRect(m_renderer->boundsOnElement(n2+"-text")).y();
QTransform matrix;
matrix.translate(startX,startY);
m_text2 = new QGraphicsTextItem("0.00");
m_text2->setDefaultTextColor(QColor("White"));
m_text2->setTransform(matrix,false);
l_scene->addItem(m_text2);
} else {
m_text2 = NULL;
}
}
if (n3enabled) {
rectN = m_needle3->boundingRect();
m_needle3->setPos(rectB.width()/2-rectN.width()/2,rectB.height()/2-rectN.height()/2);
m_needle3->setTransformOriginPoint(rectN.width()/2,rectN.height()/2);
// Check whether the dial also wants display the numeric value:
if (m_renderer->elementExists(n3+"-text")) {
QMatrix textMatrix = m_renderer->matrixForElement(n3+"-text");
qreal startX = textMatrix.mapRect(m_renderer->boundsOnElement(n3+"-text")).x();
qreal startY = textMatrix.mapRect(m_renderer->boundsOnElement(n3+"-text")).y();
QTransform matrix;
matrix.translate(startX,startY);
m_text3 = new QGraphicsTextItem("0.00");
m_text3->setDefaultTextColor(QColor("White"));
m_text3->setTransform(matrix,false);
l_scene->addItem(m_text3);
} else {
m_text3 = NULL;
}
}
// Last: we just loaded the dial file which is by default positioned on a "zero" value
// of the needles, so we have to reset the needle values too upon dial file loading, otherwise
// we would end up with an offset whenever we change a dial file and the needle value
// is not zero at that time.
needle1Value = 0;
needle2Value = 0;
needle3Value = 0;
if (!dialTimer.isActive())
dialTimer.start();
dialError = false;
}
else
{
qDebug()<<"no file: display default background.";
m_renderer->load(QString(":/dial/images/empty.svg"));
l_scene->clear(); // This also deletes all items contained in the scene.
m_background = new QGraphicsSvgItem();
m_background->setSharedRenderer(m_renderer);
l_scene->addItem(m_background);
m_text1 = NULL;
m_text2 = NULL;
m_text3 = NULL;
m_needle1 = NULL;
m_needle2 = NULL;
m_needle3 = NULL;
dialError = true;
}
}
void DialGadgetWidget::paint()
{
update();
}
void DialGadgetWidget::paintEvent(QPaintEvent *event)
{
// Skip painting until the dial file is loaded
if (! m_renderer->isValid()) {
qDebug()<<"Dial file not loaded, not rendering";
return;
}
QGraphicsView::paintEvent(event);
}
// This event enables the dial to be dynamically resized
// whenever the gadget is resized, taking advantage of the vector
// nature of SVG dials.
void DialGadgetWidget::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event);
fitInView(m_background, Qt::KeepAspectRatio );
}
void DialGadgetWidget::setDialFont(QString fontProps)
{
QFont font = QFont("Arial",12);
font.fromString(fontProps);
if (m_text1) {
m_text1->setFont(font);
}
}
// Converts the value into an angle:
// this enables smooth rotation in rotateNeedles below
void DialGadgetWidget::setNeedle1(double value) {
if (rotateN1) {
needle1Target = 360*(value*n1Factor-n1MinValue)/(n1MaxValue-n1MinValue);
}
if (horizN1) {
needle1Target = (value*n1Factor-n1MinValue)/(n1MaxValue-n1MinValue);
}
if (vertN1) {
needle1Target = (value*n1Factor-n1MinValue)/(n1MaxValue-n1MinValue);
}
if (!dialTimer.isActive())
dialTimer.start();
if (m_text1) {
QString s;
s.sprintf("%.2f",value*n1Factor);
m_text1->setPlainText(s);
}
}
void DialGadgetWidget::setNeedle2(double value) {
if (rotateN2) {
needle2Target = 360*(value*n2Factor-n2MinValue)/(n2MaxValue-n2MinValue);
}
if (horizN2) {
needle2Target = (value*n2Factor-n2MinValue)/(n2MaxValue-n2MinValue);
}
if (vertN2) {
needle2Target = (value*n2Factor-n2MinValue)/(n2MaxValue-n2MinValue);
}
if (!dialTimer.isActive())
dialTimer.start();
if (m_text2) {
QString s;
s.sprintf("%.2f",value*n2Factor);
m_text2->setPlainText(s);
}
}
void DialGadgetWidget::setNeedle3(double value) {
if (rotateN3) {
needle3Target = 360*(value*n3Factor-n3MinValue)/(n3MaxValue-n3MinValue);
}
if (horizN3) {
needle3Target = (value*n3Factor-n3MinValue)/(n3MaxValue-n3MinValue);
}
if (vertN3) {
needle3Target = (value*n3Factor-n3MinValue)/(n3MaxValue-n3MinValue);
}
if (!dialTimer.isActive())
dialTimer.start();
if (m_text3) {
QString s;
s.sprintf("%.2f",value*n3Factor);
m_text3->setPlainText(s);
}
}
// Take an input value and rotate the dial accordingly
// Rotation is smooth, starts fast and slows down when
// approaching the target.
// We aim for a 0.5 degree precision.
//
// Note: this code is valid even if needle1 and needle2 point
// to the same element.
void DialGadgetWidget::rotateNeedles()
{
if (dialError) {
// We get there in case the dial file is missing or corrupt.
dialTimer.stop();
return;
}
int dialRun = 3;
if (n2enabled) {
double needle2Diff;
if (abs((needle2Value-needle2Target)*10) > 5) {
needle2Diff =(needle2Target - needle2Value)/5;
} else {
needle2Diff = needle2Target - needle2Value;
dialRun--;
}
if (rotateN2) {
m_needle2->setRotation(m_needle2->rotation()+needle2Diff);
} else {
QPointF opd = QPointF(0,0);
if (horizN2) {
opd = QPointF(needle2Diff,0);
}
if (vertN2) {
opd = QPointF(0,needle2Diff);
}
m_needle2->setTransform(QTransform::fromTranslate(opd.x(),opd.y()), true);
// Since we have moved the needle, we need to move
// the transform origin point the opposite way
// so that it keeps rotating from the same point.
// (this is only useful if needle1 and needle2 are the
// same object, for combined movement such as attitude indicator).
QPointF oop = m_needle2->transformOriginPoint();
m_needle2->setTransformOriginPoint(oop.x()-opd.x(),oop.y()-opd.y());
}
needle2Value += needle2Diff;
} else {
dialRun--;
}
// We assume that needle1 always exists!
double needle1Diff;
if ((abs((needle1Value-needle1Target)*10) > 5)) {
needle1Diff = (needle1Target - needle1Value)/5;
} else {
needle1Diff = needle1Target - needle1Value;
dialRun--;
}
if (rotateN1) {
m_needle1->setRotation(m_needle1->rotation()+needle1Diff);
} else {
QPointF opd = QPointF(0,0);
if (horizN1) {
opd = QPointF(needle1Diff,0);
}
if (vertN1) {
opd = QPointF(0,needle1Diff);
}
m_needle1->setTransform(QTransform::fromTranslate(opd.x(),opd.y()), true);
QPointF oop = m_needle1->transformOriginPoint();
m_needle1->setTransformOriginPoint((oop.x()-opd.x()),(oop.y()-opd.y()));
}
needle1Value += needle1Diff;
if (n3enabled) {
double needle3Diff;
if ((abs((needle3Value-needle3Target)*10) > 5)) {
needle3Diff = (needle3Target - needle3Value)/5;
} else {
needle3Diff = needle3Target - needle3Value;
dialRun--;
}
if (rotateN3) {
m_needle3->setRotation(m_needle3->rotation()+needle3Diff);
} else {
QPointF opd = QPointF(0,0);
if (horizN3) {
opd = QPointF(needle3Diff,0);
}
if (vertN3) {
opd = QPointF(0,needle3Diff);
}
m_needle3->setTransform(QTransform::fromTranslate(opd.x(),opd.y()), true);
QPointF oop = m_needle3->transformOriginPoint();
m_needle3->setTransformOriginPoint((oop.x()-opd.x()),(oop.y()-opd.y()));
}
needle3Value += needle3Diff;
} else {
dialRun--;
}
// Now check: if dialRun is now zero, we should
// just stop the timer since all needles have finished moving
if (!dialRun) dialTimer.stop();
}
/**
******************************************************************************
*
* @file dialgadgetwidget.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @see The GNU Public License (GPL) Version 3
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup DialPlugin Dial Plugin
* @{
* @brief Plots flight information rotary style dials
*****************************************************************************/
/*
* 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 "dialgadgetwidget.h"
#include <utils/stylehelper.h>
#include <iostream>
#include <QtOpenGL/QGLWidget>
#include <QDebug>
DialGadgetWidget::DialGadgetWidget(QWidget *parent) : QGraphicsView(parent)
{
// TODO: create a proper "needle" object instead of hardcoding all this
// which is ugly (but easy).
setMinimumSize(64,64);
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
setScene(new QGraphicsScene(this));
setRenderHints(QPainter::Antialiasing);
m_renderer = new QSvgRenderer();
obj1 = NULL;
obj2 = NULL;
obj3 = NULL;
m_text1 = NULL;
m_text2 = NULL;
m_text3 = NULL; // Should be initialized to NULL otherwise the setFont method
// might segfault upon initialization if called before SetDialFile
needle1Target = 0;
needle2Target = 0;
needle3Target = 0;
// This timer mechanism makes needles rotate smoothly
connect(&dialTimer, SIGNAL(timeout()), this, SLOT(rotateNeedles()));
}
DialGadgetWidget::~DialGadgetWidget()
{
// Do nothing
}
/*!
\brief Enables/Disables OpenGL
*/
void DialGadgetWidget::enableOpenGL(bool flag)
{
if (flag)
setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
else
setViewport(new QWidget);
}
/*!
\brief Connects the widget to the relevant UAVObjects
*/
void DialGadgetWidget::connectNeedles(QString object1, QString nfield1,
QString object2, QString nfield2,
QString object3, QString nfield3) {
if (obj1 != NULL)
disconnect(obj1,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(updateNeedle1(UAVObject*)));
if (obj2 != NULL)
disconnect(obj2,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(updateNeedle2(UAVObject*)));
if (obj3 != NULL)
disconnect(obj3,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(updateNeedle3(UAVObject*)));
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
// Check validity of arguments first, reject empty args and unknown fields.
if (!(object1.isEmpty() || nfield1.isEmpty())) {
obj1 = dynamic_cast<UAVDataObject*>( objManager->getObject(object1) );
if (obj1 != NULL ) {
// qDebug() << "Connected Object 1 (" << object1 << ").";
connect(obj1, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(updateNeedle1(UAVObject*)));
if(nfield1.contains("-"))
{
QStringList fieldSubfield = nfield1.split("-", QString::SkipEmptyParts);
field1 = fieldSubfield.at(0);
subfield1 = fieldSubfield.at(1);
haveSubField1 = true;
}
else
{
field1= nfield1;
haveSubField1 = false;
}
} else {
qDebug() << "Error: Object is unknown (" << object1 << ").";
}
}
// And do the same for the second needle.
if (!(object2.isEmpty() || nfield2.isEmpty())) {
obj2 = dynamic_cast<UAVDataObject*>( objManager->getObject(object2) );
if (obj2 != NULL ) {
// qDebug() << "Connected Object 2 (" << object2 << ").";
connect(obj2, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(updateNeedle2(UAVObject*)));
if(nfield2.contains("-"))
{
QStringList fieldSubfield = nfield2.split("-", QString::SkipEmptyParts);
field2 = fieldSubfield.at(0);
subfield2 = fieldSubfield.at(1);
haveSubField2 = true;
}
else
{
field2= nfield2;
haveSubField2 = false;
}
} else {
qDebug() << "Error: Object is unknown (" << object2 << ").";
}
}
// And do the same for the third needle.
if (!(object3.isEmpty() || nfield3.isEmpty())) {
obj3 = dynamic_cast<UAVDataObject*>( objManager->getObject(object3) );
if (obj3 != NULL ) {
// qDebug() << "Connected Object 3 (" << object3 << ").";
connect(obj3, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(updateNeedle3(UAVObject*)));
if(nfield3.contains("-"))
{
QStringList fieldSubfield = nfield3.split("-", QString::SkipEmptyParts);
field3 = fieldSubfield.at(0);
subfield3 = fieldSubfield.at(1);
haveSubField3 = true;
}
else
{
field3= nfield3;
haveSubField3 = false;
}
} else {
qDebug() << "Error: Object is unknown (" << object3 << ").";
}
}
}
/*!
\brief Called by the UAVObject which got updated
*/
void DialGadgetWidget::updateNeedle1(UAVObject *object1) {
// Double check that the field exists:
double value;
UAVObjectField* field = object1->getField(field1);
if (field) {
if(haveSubField1){
int indexOfSubField = field->getElementNames().indexOf(QRegExp(subfield1, Qt::CaseSensitive, QRegExp::FixedString));
value = field->getDouble(indexOfSubField);
} else
value = field->getDouble();
if (value != value) {
qDebug() << "Dial widget: encountered NaN !!";
return;
}
setNeedle1(value);
} else {
qDebug() << "Wrong field, maybe an issue with object disconnection ?";
}
}
/*!
\brief Called by the UAVObject which got updated
*/
void DialGadgetWidget::updateNeedle2(UAVObject *object2) {
double value;
UAVObjectField* field = object2->getField(field2);
if (field) {
if(haveSubField2){
int indexOfSubField = field->getElementNames().indexOf(QRegExp(subfield2, Qt::CaseSensitive, QRegExp::FixedString));
value = field->getDouble(indexOfSubField);
} else
value = field->getDouble();
if (value != value) {
qDebug() << "Dial widget: encountered NaN !!";
return;
}
setNeedle2(value);
} else {
qDebug() << "Wrong field, maybe an issue with object disconnection ?";
}
}
/*!
\brief Called by the UAVObject which got updated
*/
void DialGadgetWidget::updateNeedle3(UAVObject *object3) {
double value;
UAVObjectField* field = object3->getField(field3);
if (field) {
if(haveSubField3){
int indexOfSubField = field->getElementNames().indexOf(QRegExp(subfield3, Qt::CaseSensitive, QRegExp::FixedString));
value = field->getDouble(indexOfSubField);
} else
value = field->getDouble();
if (value != value) {
qDebug() << "Dial widget: encountered NaN !!";
return;
}
setNeedle3(value);
} else {
qDebug() << "Wrong field, maybe an issue with object disconnection ?";
}
}
/*
Initializes the dial file, and does all the one-time calculations for
display later. This is the method which really initializes the dial.
*/
void DialGadgetWidget::setDialFile(QString dfn, QString bg, QString fg, QString n1, QString n2,
QString n3, QString n1Move, QString n2Move, QString n3Move)
{
fgenabled = false;
n2enabled = false;
n3enabled = false;
QGraphicsScene *l_scene = scene();
setBackgroundBrush(QBrush(Utils::StyleHelper::baseColor()));
if (QFile::exists(dfn) && m_renderer->load(dfn) && m_renderer->isValid())
{
l_scene->clear(); // This also deletes all items contained in the scene.
m_background = new QGraphicsSvgItem();
// All other items will be clipped to the shape of the background
m_background->setFlags(QGraphicsItem::ItemClipsChildrenToShape|
QGraphicsItem::ItemClipsToShape);
m_foreground = new QGraphicsSvgItem();
m_needle1 = new QGraphicsSvgItem();
m_needle2 = new QGraphicsSvgItem();
m_needle3 = new QGraphicsSvgItem();
m_needle1->setParentItem(m_background);
m_needle2->setParentItem(m_background);
m_needle3->setParentItem(m_background);
m_foreground->setParentItem(m_background);
// We assume the dial contains at least the background
// and needle1
m_background->setSharedRenderer(m_renderer);
m_background->setElementId(bg);
l_scene->addItem(m_background);
m_needle1->setSharedRenderer(m_renderer);
m_needle1->setElementId(n1);
// Note: no need to add the item explicitely because it
// is done automatically since it's a child item of the
// background.
//l_scene->addItem(m_needle1);
// The dial gadget allows Needle1 and Needle2 to be
// the same element, for combined movement. Needle3
// is always independent.
if (n1 == n2) {
m_needle2 = m_needle1;
n2enabled = true;
} else {
if (m_renderer->elementExists(n2)) {
m_needle2->setSharedRenderer(m_renderer);
m_needle2->setElementId(n2);
//l_scene->addItem(m_needle2);
n2enabled = true;
}
}
if (m_renderer->elementExists(n3)) {
m_needle3->setSharedRenderer(m_renderer);
m_needle3->setElementId(n3);
//l_scene->addItem(m_needle3);
n3enabled = true;
}
if (m_renderer->elementExists(fg)) {
m_foreground->setSharedRenderer(m_renderer);
m_foreground->setElementId(fg);
// Center it on the scene
QRectF rectB = m_background->boundingRect();
QRectF rectF = m_foreground->boundingRect();
m_foreground->setPos(rectB.width()/2-rectF.width()/2,rectB.height()/2-rectF.height()/2);
//l_scene->addItem(m_foreground);
fgenabled = true;
}
rotateN1 = false;
horizN1 = false;
vertN1 = false;
rotateN2 = false;
horizN2 = false;
vertN2 = false;
rotateN3 = false;
horizN3 = false;
vertN3 = false;
// Now setup the rotation/translation settings:
// this is UGLY UGLY UGLY, sorry...
if (n1Move.contains("Rotate")) {
rotateN1 = true;
} else if (n1Move.contains("Horizontal")) {
horizN1 = true;
} else if (n1Move.contains("Vertical")) {
vertN1 = true;
}
if (n2Move.contains("Rotate")) {
rotateN2 = true;
} else if (n2Move.contains("Horizontal")) {
horizN2 = true;
} else if (n2Move.contains("Vertical")) {
vertN2 = true;
}
if (n3Move.contains("Rotate")) {
rotateN3 = true;
} else if (n3Move.contains("Horizontal")) {
horizN3 = true;
} else if (n3Move.contains("Vertical")) {
vertN3 = true;
}
l_scene->setSceneRect(m_background->boundingRect());
// Now Initialize the center for all transforms of the dial needles to the
// center of the background:
// - Move the center of the needle to the center of the background.
QRectF rectB = m_background->boundingRect();
QRectF rectN = m_needle1->boundingRect();
m_needle1->setPos(rectB.width()/2-rectN.width()/2,rectB.height()/2-rectN.height()/2);
// - Put the transform origin point of the needle at its center.
m_needle1->setTransformOriginPoint(rectN.width()/2,rectN.height()/2);
// Check whether the dial also wants display the numeric value:
if (m_renderer->elementExists(n1+"-text")) {
QMatrix textMatrix = m_renderer->matrixForElement(n1+"-text");
qreal startX = textMatrix.mapRect(m_renderer->boundsOnElement(n1+"-text")).x();
qreal startY = textMatrix.mapRect(m_renderer->boundsOnElement(n1+"-text")).y();
QTransform matrix;
matrix.translate(startX,startY);
m_text1 = new QGraphicsTextItem("0.00");
m_text1->setDefaultTextColor(QColor("White"));
m_text1->setTransform(matrix,false);
l_scene->addItem(m_text1);
} else {
m_text1 = NULL;
}
if ((n1 != n2) && n2enabled) {
// Only do it for needle2 if it is not the same as n1
rectN = m_needle2->boundingRect();
m_needle2->setPos(rectB.width()/2-rectN.width()/2,rectB.height()/2-rectN.height()/2);
m_needle2->setTransformOriginPoint(rectN.width()/2,rectN.height()/2);
// Check whether the dial also wants display the numeric value:
if (m_renderer->elementExists(n2+"-text")) {
QMatrix textMatrix = m_renderer->matrixForElement(n2+"-text");
qreal startX = textMatrix.mapRect(m_renderer->boundsOnElement(n2+"-text")).x();
qreal startY = textMatrix.mapRect(m_renderer->boundsOnElement(n2+"-text")).y();
QTransform matrix;
matrix.translate(startX,startY);
m_text2 = new QGraphicsTextItem("0.00");
m_text2->setDefaultTextColor(QColor("White"));
m_text2->setTransform(matrix,false);
l_scene->addItem(m_text2);
} else {
m_text2 = NULL;
}
}
if (n3enabled) {
rectN = m_needle3->boundingRect();
m_needle3->setPos(rectB.width()/2-rectN.width()/2,rectB.height()/2-rectN.height()/2);
m_needle3->setTransformOriginPoint(rectN.width()/2,rectN.height()/2);
// Check whether the dial also wants display the numeric value:
if (m_renderer->elementExists(n3+"-text")) {
QMatrix textMatrix = m_renderer->matrixForElement(n3+"-text");
qreal startX = textMatrix.mapRect(m_renderer->boundsOnElement(n3+"-text")).x();
qreal startY = textMatrix.mapRect(m_renderer->boundsOnElement(n3+"-text")).y();
QTransform matrix;
matrix.translate(startX,startY);
m_text3 = new QGraphicsTextItem("0.00");
m_text3->setDefaultTextColor(QColor("White"));
m_text3->setTransform(matrix,false);
l_scene->addItem(m_text3);
} else {
m_text3 = NULL;
}
}
// Last: we just loaded the dial file which is by default positioned on a "zero" value
// of the needles, so we have to reset the needle values too upon dial file loading, otherwise
// we would end up with an offset whenever we change a dial file and the needle value
// is not zero at that time.
needle1Value = 0;
needle2Value = 0;
needle3Value = 0;
if (!dialTimer.isActive())
dialTimer.start();
dialError = false;
}
else
{
qDebug()<<"no file: display default background.";
m_renderer->load(QString(":/dial/images/empty.svg"));
l_scene->clear(); // This also deletes all items contained in the scene.
m_background = new QGraphicsSvgItem();
m_background->setSharedRenderer(m_renderer);
l_scene->addItem(m_background);
m_text1 = NULL;
m_text2 = NULL;
m_text3 = NULL;
m_needle1 = NULL;
m_needle2 = NULL;
m_needle3 = NULL;
dialError = true;
}
}
void DialGadgetWidget::paint()
{
update();
}
void DialGadgetWidget::paintEvent(QPaintEvent *event)
{
// Skip painting until the dial file is loaded
if (! m_renderer->isValid()) {
qDebug()<<"Dial file not loaded, not rendering";
return;
}
QGraphicsView::paintEvent(event);
}
// This event enables the dial to be dynamically resized
// whenever the gadget is resized, taking advantage of the vector
// nature of SVG dials.
void DialGadgetWidget::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event);
fitInView(m_background, Qt::KeepAspectRatio );
}
void DialGadgetWidget::setDialFont(QString fontProps)
{
QFont font = QFont("Arial",12);
font.fromString(fontProps);
if (m_text1) {
m_text1->setFont(font);
}
}
// Converts the value into an angle:
// this enables smooth rotation in rotateNeedles below
void DialGadgetWidget::setNeedle1(double value) {
if (rotateN1) {
needle1Target = 360*(value*n1Factor-n1MinValue)/(n1MaxValue-n1MinValue);
}
if (horizN1) {
needle1Target = (value*n1Factor-n1MinValue)/(n1MaxValue-n1MinValue);
}
if (vertN1) {
needle1Target = (value*n1Factor-n1MinValue)/(n1MaxValue-n1MinValue);
}
if (!dialTimer.isActive())
dialTimer.start();
if (m_text1) {
QString s;
s.sprintf("%.2f",value*n1Factor);
m_text1->setPlainText(s);
}
}
void DialGadgetWidget::setNeedle2(double value) {
if (rotateN2) {
needle2Target = 360*(value*n2Factor-n2MinValue)/(n2MaxValue-n2MinValue);
}
if (horizN2) {
needle2Target = (value*n2Factor-n2MinValue)/(n2MaxValue-n2MinValue);
}
if (vertN2) {
needle2Target = (value*n2Factor-n2MinValue)/(n2MaxValue-n2MinValue);
}
if (!dialTimer.isActive())
dialTimer.start();
if (m_text2) {
QString s;
s.sprintf("%.2f",value*n2Factor);
m_text2->setPlainText(s);
}
}
void DialGadgetWidget::setNeedle3(double value) {
if (rotateN3) {
needle3Target = 360*(value*n3Factor-n3MinValue)/(n3MaxValue-n3MinValue);
}
if (horizN3) {
needle3Target = (value*n3Factor-n3MinValue)/(n3MaxValue-n3MinValue);
}
if (vertN3) {
needle3Target = (value*n3Factor-n3MinValue)/(n3MaxValue-n3MinValue);
}
if (!dialTimer.isActive())
dialTimer.start();
if (m_text3) {
QString s;
s.sprintf("%.2f",value*n3Factor);
m_text3->setPlainText(s);
}
}
// Take an input value and rotate the dial accordingly
// Rotation is smooth, starts fast and slows down when
// approaching the target.
// We aim for a 0.5 degree precision.
//
// Note: this code is valid even if needle1 and needle2 point
// to the same element.
void DialGadgetWidget::rotateNeedles()
{
if (dialError) {
// We get there in case the dial file is missing or corrupt.
dialTimer.stop();
return;
}
int dialRun = 3;
if (n2enabled) {
double needle2Diff;
if (abs((needle2Value-needle2Target)*10) > 5) {
needle2Diff =(needle2Target - needle2Value)/5;
} else {
needle2Diff = needle2Target - needle2Value;
dialRun--;
}
if (rotateN2) {
m_needle2->setRotation(m_needle2->rotation()+needle2Diff);
} else {
QPointF opd = QPointF(0,0);
if (horizN2) {
opd = QPointF(needle2Diff,0);
}
if (vertN2) {
opd = QPointF(0,needle2Diff);
}
m_needle2->setTransform(QTransform::fromTranslate(opd.x(),opd.y()), true);
// Since we have moved the needle, we need to move
// the transform origin point the opposite way
// so that it keeps rotating from the same point.
// (this is only useful if needle1 and needle2 are the
// same object, for combined movement such as attitude indicator).
QPointF oop = m_needle2->transformOriginPoint();
m_needle2->setTransformOriginPoint(oop.x()-opd.x(),oop.y()-opd.y());
}
needle2Value += needle2Diff;
} else {
dialRun--;
}
// We assume that needle1 always exists!
double needle1Diff;
if ((abs((needle1Value-needle1Target)*10) > 5)) {
needle1Diff = (needle1Target - needle1Value)/5;
} else {
needle1Diff = needle1Target - needle1Value;
dialRun--;
}
if (rotateN1) {
m_needle1->setRotation(m_needle1->rotation()+needle1Diff);
} else {
QPointF opd = QPointF(0,0);
if (horizN1) {
opd = QPointF(needle1Diff,0);
}
if (vertN1) {
opd = QPointF(0,needle1Diff);
}
m_needle1->setTransform(QTransform::fromTranslate(opd.x(),opd.y()), true);
QPointF oop = m_needle1->transformOriginPoint();
m_needle1->setTransformOriginPoint((oop.x()-opd.x()),(oop.y()-opd.y()));
}
needle1Value += needle1Diff;
if (n3enabled) {
double needle3Diff;
if ((abs((needle3Value-needle3Target)*10) > 5)) {
needle3Diff = (needle3Target - needle3Value)/5;
} else {
needle3Diff = needle3Target - needle3Value;
dialRun--;
}
if (rotateN3) {
m_needle3->setRotation(m_needle3->rotation()+needle3Diff);
} else {
QPointF opd = QPointF(0,0);
if (horizN3) {
opd = QPointF(needle3Diff,0);
}
if (vertN3) {
opd = QPointF(0,needle3Diff);
}
m_needle3->setTransform(QTransform::fromTranslate(opd.x(),opd.y()), true);
QPointF oop = m_needle3->transformOriginPoint();
m_needle3->setTransformOriginPoint((oop.x()-opd.x()),(oop.y()-opd.y()));
}
needle3Value += needle3Diff;
} else {
dialRun--;
}
// Now check: if dialRun is now zero, we should
// just stop the timer since all needles have finished moving
if (!dialRun) dialTimer.stop();
}

View File

@ -1,150 +1,151 @@
/**
******************************************************************************
*
* @file dialgadgetwidget.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @see The GNU Public License (GPL) Version 3
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup DialPlugin Dial Plugin
* @{
* @brief Plots flight information rotary style dials
*****************************************************************************/
/*
* 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
*/
#ifndef DIALGADGETWIDGET_H_
#define DIALGADGETWIDGET_H_
#include "dialgadgetconfiguration.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"
#include <QGraphicsView>
#include <QtSvg/QSvgRenderer>
#include <QtSvg/QGraphicsSvgItem>
#include <QFile>
#include <QTimer>
class DialGadgetWidget : public QGraphicsView
{
Q_OBJECT
public:
DialGadgetWidget(QWidget *parent = 0);
~DialGadgetWidget();
void setDialFile(QString dfn, QString bg, QString fg, QString n1, QString n2, QString n3,
QString n1Move, QString n2Move, QString n3Move);
void paint();
// setNeedle1 and setNeedle2 use a timer to simulate
// needle inertia
void setNeedle1(double value);
void setNeedle2(double value);
void setNeedle3(double value);
void setN1Min(double value) {n1MinValue = value;}
void setN1Max(double value) {n1MaxValue = value;}
void setN1Factor(double value) {n1Factor = value;}
void setN2Min(double value) {n2MinValue = value;}
void setN2Max(double value) {n2MaxValue = value;}
void setN2Factor(double value) {n2Factor = value;}
void setN3Min(double value) {n3MinValue = value;}
void setN3Max(double value) {n3MaxValue = value;}
void setN3Factor(double value) {n3Factor = value;}
// Sets up needle/UAVObject connections:
void connectNeedles(QString object1, QString field1,
QString object2, QString field2,
QString object3, QString field3);
void setDialFont(QString fontProps);
public slots:
void updateNeedle1(UAVObject *object1); // Called by the UAVObject
void updateNeedle2(UAVObject *object2); // Called by the UAVObject
void updateNeedle3(UAVObject *object3); // Called by the UAVObject
protected:
void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent *event);
private slots:
void rotateNeedles();
private:
QSvgRenderer *m_renderer;
QGraphicsSvgItem *m_background;
QGraphicsSvgItem *m_foreground;
QGraphicsSvgItem *m_needle1;
QGraphicsSvgItem *m_needle2;
QGraphicsSvgItem *m_needle3;
QGraphicsTextItem *m_text1;
QGraphicsTextItem *m_text2;
QGraphicsTextItem *m_text3;
bool n3enabled;
bool n2enabled; // Simple flag to skip rendering if the
bool fgenabled; // layer does not exist.
bool dialError ;
// Settings concerning move of the dials
bool rotateN1;
bool rotateN2;
bool rotateN3;
bool horizN1;
bool horizN2;
bool horizN3;
bool vertN1;
bool vertN2;
bool vertN3;
double n1MinValue;
double n1MaxValue;
double n1Factor;
double n2MinValue;
double n2MaxValue;
double n2Factor;
double n3MinValue;
double n3MaxValue;
double n3Factor;
// The Value and target variables
// are expressed in degrees
double needle1Target;
double needle1Value;
double needle2Target;
double needle2Value;
double needle3Target;
double needle3Value;
// Name of the fields to read when an update is received:
UAVDataObject* obj1;
UAVDataObject* obj2;
UAVDataObject* obj3;
QString field1;
QString subfield1;
bool haveSubField1;
QString field2;
QString subfield2;
bool haveSubField2;
QString field3;
QString subfield3;
bool haveSubField3;
// Rotation timer
QTimer dialTimer;
};
#endif /* DIALGADGETWIDGET_H_ */
/**
******************************************************************************
*
* @file dialgadgetwidget.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @see The GNU Public License (GPL) Version 3
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup DialPlugin Dial Plugin
* @{
* @brief Plots flight information rotary style dials
*****************************************************************************/
/*
* 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
*/
#ifndef DIALGADGETWIDGET_H_
#define DIALGADGETWIDGET_H_
#include "dialgadgetconfiguration.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"
#include <QGraphicsView>
#include <QtSvg/QSvgRenderer>
#include <QtSvg/QGraphicsSvgItem>
#include <QFile>
#include <QTimer>
class DialGadgetWidget : public QGraphicsView
{
Q_OBJECT
public:
DialGadgetWidget(QWidget *parent = 0);
~DialGadgetWidget();
void enableOpenGL(bool flag);
void setDialFile(QString dfn, QString bg, QString fg, QString n1, QString n2, QString n3,
QString n1Move, QString n2Move, QString n3Move);
void paint();
// setNeedle1 and setNeedle2 use a timer to simulate
// needle inertia
void setNeedle1(double value);
void setNeedle2(double value);
void setNeedle3(double value);
void setN1Min(double value) {n1MinValue = value;}
void setN1Max(double value) {n1MaxValue = value;}
void setN1Factor(double value) {n1Factor = value;}
void setN2Min(double value) {n2MinValue = value;}
void setN2Max(double value) {n2MaxValue = value;}
void setN2Factor(double value) {n2Factor = value;}
void setN3Min(double value) {n3MinValue = value;}
void setN3Max(double value) {n3MaxValue = value;}
void setN3Factor(double value) {n3Factor = value;}
// Sets up needle/UAVObject connections:
void connectNeedles(QString object1, QString field1,
QString object2, QString field2,
QString object3, QString field3);
void setDialFont(QString fontProps);
public slots:
void updateNeedle1(UAVObject *object1); // Called by the UAVObject
void updateNeedle2(UAVObject *object2); // Called by the UAVObject
void updateNeedle3(UAVObject *object3); // Called by the UAVObject
protected:
void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent *event);
private slots:
void rotateNeedles();
private:
QSvgRenderer *m_renderer;
QGraphicsSvgItem *m_background;
QGraphicsSvgItem *m_foreground;
QGraphicsSvgItem *m_needle1;
QGraphicsSvgItem *m_needle2;
QGraphicsSvgItem *m_needle3;
QGraphicsTextItem *m_text1;
QGraphicsTextItem *m_text2;
QGraphicsTextItem *m_text3;
bool n3enabled;
bool n2enabled; // Simple flag to skip rendering if the
bool fgenabled; // layer does not exist.
bool dialError ;
// Settings concerning move of the dials
bool rotateN1;
bool rotateN2;
bool rotateN3;
bool horizN1;
bool horizN2;
bool horizN3;
bool vertN1;
bool vertN2;
bool vertN3;
double n1MinValue;
double n1MaxValue;
double n1Factor;
double n2MinValue;
double n2MaxValue;
double n2Factor;
double n3MinValue;
double n3MaxValue;
double n3Factor;
// The Value and target variables
// are expressed in degrees
double needle1Target;
double needle1Value;
double needle2Target;
double needle2Value;
double needle3Target;
double needle3Value;
// Name of the fields to read when an update is received:
UAVDataObject* obj1;
UAVDataObject* obj2;
UAVDataObject* obj3;
QString field1;
QString subfield1;
bool haveSubField1;
QString field2;
QString subfield2;
bool haveSubField2;
QString field3;
QString subfield3;
bool haveSubField3;
// Rotation timer
QTimer dialTimer;
};
#endif /* DIALGADGETWIDGET_H_ */

View File

@ -1,6 +1,7 @@
TEMPLATE = lib
TARGET = LineardialGadget
QT += svg
QT += opengl
include(../../openpilotgcsplugin.pri)
include(../../plugins/coreplugin/coreplugin.pri)
include(lineardial_dependencies.pri)

View File

@ -1,60 +1,61 @@
/**
******************************************************************************
*
* @file lineardialgadget.cpp
* @author Edouard Lafargue Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup LinearDialPlugin Linear Dial Plugin
* @{
* @brief Impliments a gadget that displays linear gauges
*****************************************************************************/
/*
* 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 "lineardialgadget.h"
#include "lineardialgadgetwidget.h"
#include "lineardialgadgetconfiguration.h"
LineardialGadget::LineardialGadget(QString classId, LineardialGadgetWidget *widget, QWidget *parent) :
IUAVGadget(classId, parent),
m_widget(widget)
{
}
LineardialGadget::~LineardialGadget()
{
}
/*
This is called when a configuration is loaded, and updates the plugin's settings.
Careful: the plugin is already drawn before the loadConfiguration method is called the
first time, so you have to be careful not to assume all the plugin values are initialized
the first time you use them
*/
void LineardialGadget::loadConfiguration(IUAVGadgetConfiguration* config)
{
LineardialGadgetConfiguration *m = qobject_cast<LineardialGadgetConfiguration*>(config);
m_widget->setFactor(m->getFactor());
m_widget->setDecimalPlaces(m->getDecimalPlaces());
m_widget->setRange(m->getMin(),m->getMax());
m_widget->setGreenRange(m->getGreenMin(), m->getGreenMax());
m_widget->setYellowRange(m->getYellowMin(), m->getYellowMax());
m_widget->setRedRange(m->getRedMin(), m->getRedMax());
m_widget->setDialFile(m->getDialFile()); // Triggers widget repaint
m_widget->setDialFont(m->getFont());
m_widget->connectInput(m->getSourceDataObject(), m->getSourceObjectField());
}
/**
******************************************************************************
*
* @file lineardialgadget.cpp
* @author Edouard Lafargue Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup LinearDialPlugin Linear Dial Plugin
* @{
* @brief Impliments a gadget that displays linear gauges
*****************************************************************************/
/*
* 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 "lineardialgadget.h"
#include "lineardialgadgetwidget.h"
#include "lineardialgadgetconfiguration.h"
LineardialGadget::LineardialGadget(QString classId, LineardialGadgetWidget *widget, QWidget *parent) :
IUAVGadget(classId, parent),
m_widget(widget)
{
}
LineardialGadget::~LineardialGadget()
{
}
/*
This is called when a configuration is loaded, and updates the plugin's settings.
Careful: the plugin is already drawn before the loadConfiguration method is called the
first time, so you have to be careful not to assume all the plugin values are initialized
the first time you use them
*/
void LineardialGadget::loadConfiguration(IUAVGadgetConfiguration* config)
{
LineardialGadgetConfiguration *m = qobject_cast<LineardialGadgetConfiguration*>(config);
m_widget->setFactor(m->getFactor());
m_widget->setDecimalPlaces(m->getDecimalPlaces());
m_widget->setRange(m->getMin(),m->getMax());
m_widget->setGreenRange(m->getGreenMin(), m->getGreenMax());
m_widget->setYellowRange(m->getYellowMin(), m->getYellowMax());
m_widget->setRedRange(m->getRedMin(), m->getRedMax());
m_widget->setDialFile(m->getDialFile()); // Triggers widget repaint
m_widget->setDialFont(m->getFont());
m_widget->connectInput(m->getSourceDataObject(), m->getSourceObjectField());
m_widget->enableOpenGL(m->useOpenGL());
}

View File

@ -1,116 +1,119 @@
/**
******************************************************************************
*
* @file lineardialgadgetconfiguration.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup LinearDialPlugin Linear Dial Plugin
* @{
* @brief Implements a gadget that displays linear gauges
*****************************************************************************/
/*
* 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 "lineardialgadgetconfiguration.h"
#include "utils/pathutils.h"
/**
* Loads a saved configuration or defaults if non exist.
*
*/
LineardialGadgetConfiguration::LineardialGadgetConfiguration(QString classId, QSettings* qSettings, QObject *parent) :
IUAVGadgetConfiguration(classId, parent),
dialFile("Unknown"),
sourceDataObject("Unknown"),
sourceObjectField("Unknown"),
minValue(0),
maxValue(100),
redMin(0),
redMax(33),
yellowMin(33),
yellowMax(66),
greenMin(66),
greenMax(100),
factor(1.00),
decimalPlaces(0)
{
//if a saved configuration exists load it
if(qSettings != 0) {
QString dFile = qSettings->value("dFile").toString();
dialFile = Utils::PathUtils().InsertDataPath(dFile);
sourceDataObject = qSettings->value("sourceDataObject").toString();
sourceObjectField = qSettings->value("sourceObjectField").toString();
minValue = qSettings->value("minValue").toDouble();
maxValue = qSettings->value("maxValue").toDouble();
redMin = qSettings->value("redMin").toDouble();
redMax = qSettings->value("redMax").toDouble();
yellowMin = qSettings->value("yellowMin").toDouble();
yellowMax = qSettings->value("yellowMax").toDouble();
greenMin = qSettings->value("greenMin").toDouble();
greenMax = qSettings->value("greenMax").toDouble();
font = qSettings->value("font").toString();
decimalPlaces = qSettings->value("decimalPlaces").toInt();
factor = qSettings->value("factor").toDouble();
}
}
/**
* Clones a configuration.
*
*/
IUAVGadgetConfiguration *LineardialGadgetConfiguration::clone()
{
LineardialGadgetConfiguration *m = new LineardialGadgetConfiguration(this->classId());
m->dialFile=dialFile;
m->sourceDataObject = sourceDataObject;
m->sourceObjectField = sourceObjectField;
m->minValue = minValue;
m->maxValue = maxValue;
m->redMin = redMin;
m->redMax = redMax;
m->yellowMin = yellowMin;
m->yellowMax = yellowMax;
m->greenMin = greenMin;
m->greenMax = greenMax;
m->font = font;
m->decimalPlaces = decimalPlaces;
m->factor = factor;
return m;
}
/**
* Saves a configuration.
*
*/
void LineardialGadgetConfiguration::saveConfig(QSettings* qSettings) const {
QString dFile = Utils::PathUtils().RemoveDataPath(dialFile);
qSettings->setValue("dFile", dFile);
qSettings->setValue("sourceDataObject", sourceDataObject);
qSettings->setValue("sourceObjectField", sourceObjectField);
qSettings->setValue("minValue", minValue);
qSettings->setValue("maxValue", maxValue);
qSettings->setValue("redMin", redMin);
qSettings->setValue("redMax", redMax);
qSettings->setValue("yellowMin", yellowMin);
qSettings->setValue("yellowMax", yellowMax);
qSettings->setValue("greenMin", greenMin);
qSettings->setValue("greenMax", greenMax);
qSettings->setValue("font", font);
qSettings->setValue("decimalPlaces", decimalPlaces);
qSettings->setValue("factor", factor);
}
/**
******************************************************************************
*
* @file lineardialgadgetconfiguration.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup LinearDialPlugin Linear Dial Plugin
* @{
* @brief Implements a gadget that displays linear gauges
*****************************************************************************/
/*
* 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 "lineardialgadgetconfiguration.h"
#include "utils/pathutils.h"
/**
* Loads a saved configuration or defaults if non exist.
*
*/
LineardialGadgetConfiguration::LineardialGadgetConfiguration(QString classId, QSettings* qSettings, QObject *parent) :
IUAVGadgetConfiguration(classId, parent),
dialFile("Unknown"),
sourceDataObject("Unknown"),
sourceObjectField("Unknown"),
minValue(0),
maxValue(100),
redMin(0),
redMax(33),
yellowMin(33),
yellowMax(66),
greenMin(66),
greenMax(100),
factor(1.00),
decimalPlaces(0)
{
//if a saved configuration exists load it
if(qSettings != 0) {
QString dFile = qSettings->value("dFile").toString();
dialFile = Utils::PathUtils().InsertDataPath(dFile);
sourceDataObject = qSettings->value("sourceDataObject").toString();
sourceObjectField = qSettings->value("sourceObjectField").toString();
minValue = qSettings->value("minValue").toDouble();
maxValue = qSettings->value("maxValue").toDouble();
redMin = qSettings->value("redMin").toDouble();
redMax = qSettings->value("redMax").toDouble();
yellowMin = qSettings->value("yellowMin").toDouble();
yellowMax = qSettings->value("yellowMax").toDouble();
greenMin = qSettings->value("greenMin").toDouble();
greenMax = qSettings->value("greenMax").toDouble();
font = qSettings->value("font").toString();
decimalPlaces = qSettings->value("decimalPlaces").toInt();
factor = qSettings->value("factor").toDouble();
useOpenGLFlag = qSettings->value("useOpenGLFlag").toBool();
}
}
/**
* Clones a configuration.
*
*/
IUAVGadgetConfiguration *LineardialGadgetConfiguration::clone()
{
LineardialGadgetConfiguration *m = new LineardialGadgetConfiguration(this->classId());
m->dialFile=dialFile;
m->sourceDataObject = sourceDataObject;
m->sourceObjectField = sourceObjectField;
m->minValue = minValue;
m->maxValue = maxValue;
m->redMin = redMin;
m->redMax = redMax;
m->yellowMin = yellowMin;
m->yellowMax = yellowMax;
m->greenMin = greenMin;
m->greenMax = greenMax;
m->font = font;
m->decimalPlaces = decimalPlaces;
m->factor = factor;
m->useOpenGLFlag = useOpenGLFlag;
return m;
}
/**
* Saves a configuration.
*
*/
void LineardialGadgetConfiguration::saveConfig(QSettings* qSettings) const {
QString dFile = Utils::PathUtils().RemoveDataPath(dialFile);
qSettings->setValue("dFile", dFile);
qSettings->setValue("sourceDataObject", sourceDataObject);
qSettings->setValue("sourceObjectField", sourceObjectField);
qSettings->setValue("minValue", minValue);
qSettings->setValue("maxValue", maxValue);
qSettings->setValue("redMin", redMin);
qSettings->setValue("redMax", redMax);
qSettings->setValue("yellowMin", yellowMin);
qSettings->setValue("yellowMax", yellowMax);
qSettings->setValue("greenMin", greenMin);
qSettings->setValue("greenMax", greenMax);
qSettings->setValue("font", font);
qSettings->setValue("decimalPlaces", decimalPlaces);
qSettings->setValue("factor", factor);
qSettings->setValue("useOpenGLFlag", useOpenGLFlag);
}

View File

@ -1,104 +1,109 @@
/**
******************************************************************************
*
* @file lineardialgadgetconfiguration.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup LinearDialPlugin Linear Dial Plugin
* @{
* @brief Impliments a gadget that displays linear gauges
*****************************************************************************/
/*
* 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
*/
#ifndef LINEARDIALGADGETCONFIGURATION_H
#define LINEARDIALGADGETCONFIGURATION_H
#include <coreplugin/iuavgadgetconfiguration.h>
using namespace Core;
/* This is a generic bargraph dial
supporting one indicator.
*/
class LineardialGadgetConfiguration : public IUAVGadgetConfiguration
{
Q_OBJECT
public:
explicit LineardialGadgetConfiguration(QString classId, QSettings* qSettings = 0, QObject *parent = 0);
//set dial configuration functions
void setDialFile(QString filename){dialFile=filename;}
void setRange(double min, double max) { minValue = min; maxValue = max;}
void setGreenRange(double min, double max) { greenMin = min; greenMax = max;}
void setYellowRange(double min, double max) { yellowMin = min; yellowMax = max;}
void setRedRange(double min, double max) { redMin = min; redMax = max;}
void setFont(QString text) { font = text; }
void setFactor(double val) { factor = val; }
void setDecimalPlaces (int val) { decimalPlaces = val; }
void setSourceDataObject(QString text) {sourceDataObject = text; }
void setSourceObjField(QString text) { sourceObjectField = text; }
//get dial configuration functions
QString getDialFile() {return dialFile;}
double getMin() { return minValue;}
double getMax() { return maxValue;}
double getGreenMin(){ return greenMin;}
double getGreenMax(){ return greenMax;}
double getYellowMin(){ return yellowMin;}
double getYellowMax(){ return yellowMax;}
double getRedMin(){ return redMin;}
double getRedMax(){ return redMax;}
QString getSourceDataObject() { return sourceDataObject;}
QString getSourceObjectField() { return sourceObjectField;}
QString getFont() { return font;}
int getDecimalPlaces() { return decimalPlaces; }
double getFactor() { return factor; }
void saveConfig(QSettings* settings) const;
IUAVGadgetConfiguration *clone();
private:
// A linear or "bargraph" dial contains:
// * A SVG background file
// The source file should have at least the following IDs
// defined: "background", "green", "yellow", "red", "needle"
QString dialFile;
// * The name of the UAVObject field to display
QString sourceDataObject;
QString sourceObjectField;
// The font used for the dial
QString font;
// * The minimum and maximum values to be displayed
double minValue;
double maxValue;
// * Three start-stop values for green/yellow/red
double redMin;
double redMax;
double yellowMin;
double yellowMax;
double greenMin;
double greenMax;
double factor;
int decimalPlaces;
};
#endif // LINEARDIALGADGETCONFIGURATION_H
/**
******************************************************************************
*
* @file lineardialgadgetconfiguration.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup LinearDialPlugin Linear Dial Plugin
* @{
* @brief Impliments a gadget that displays linear gauges
*****************************************************************************/
/*
* 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
*/
#ifndef LINEARDIALGADGETCONFIGURATION_H
#define LINEARDIALGADGETCONFIGURATION_H
#include <coreplugin/iuavgadgetconfiguration.h>
using namespace Core;
/* This is a generic bargraph dial
supporting one indicator.
*/
class LineardialGadgetConfiguration : public IUAVGadgetConfiguration
{
Q_OBJECT
public:
explicit LineardialGadgetConfiguration(QString classId, QSettings* qSettings = 0, QObject *parent = 0);
//set dial configuration functions
void setDialFile(QString filename){dialFile=filename;}
void setRange(double min, double max) { minValue = min; maxValue = max;}
void setGreenRange(double min, double max) { greenMin = min; greenMax = max;}
void setYellowRange(double min, double max) { yellowMin = min; yellowMax = max;}
void setRedRange(double min, double max) { redMin = min; redMax = max;}
void setFont(QString text) { font = text; }
void setFactor(double val) { factor = val; }
void setDecimalPlaces (int val) { decimalPlaces = val; }
void setSourceDataObject(QString text) {sourceDataObject = text; }
void setSourceObjField(QString text) { sourceObjectField = text; }
void setUseOpenGL(bool flag) { useOpenGLFlag = flag; }
//get dial configuration functions
QString getDialFile() {return dialFile;}
double getMin() { return minValue;}
double getMax() { return maxValue;}
double getGreenMin(){ return greenMin;}
double getGreenMax(){ return greenMax;}
double getYellowMin(){ return yellowMin;}
double getYellowMax(){ return yellowMax;}
double getRedMin(){ return redMin;}
double getRedMax(){ return redMax;}
QString getSourceDataObject() { return sourceDataObject;}
QString getSourceObjectField() { return sourceObjectField;}
QString getFont() { return font;}
int getDecimalPlaces() { return decimalPlaces; }
double getFactor() { return factor; }
bool useOpenGL() { return useOpenGLFlag; }
void saveConfig(QSettings* settings) const;
IUAVGadgetConfiguration *clone();
private:
// A linear or "bargraph" dial contains:
// * A SVG background file
// The source file should have at least the following IDs
// defined: "background", "green", "yellow", "red", "needle"
QString dialFile;
// * The name of the UAVObject field to display
QString sourceDataObject;
QString sourceObjectField;
// The font used for the dial
QString font;
// * The minimum and maximum values to be displayed
double minValue;
double maxValue;
// * Three start-stop values for green/yellow/red
double redMin;
double redMax;
double yellowMin;
double yellowMax;
double greenMin;
double greenMax;
double factor;
bool useOpenGLFlag;
int decimalPlaces;
};
#endif // LINEARDIALGADGETCONFIGURATION_H

View File

@ -1,205 +1,207 @@
/**
******************************************************************************
*
* @file lineardialgadgetoptionspage.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup LinearDialPlugin Linear Dial Plugin
* @{
* @brief Impliments a gadget that displays linear gauges
*****************************************************************************/
/*
* 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 "lineardialgadgetoptionspage.h"
#include "lineardialgadgetconfiguration.h"
#include "ui_lineardialgadgetoptionspage.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavdataobject.h"
#include <QFileDialog>
#include <QtAlgorithms>
#include <QStringList>
#include <QFontDialog>
LineardialGadgetOptionsPage::LineardialGadgetOptionsPage(LineardialGadgetConfiguration *config, QObject *parent) :
IOptionsPage(parent),
m_config(config)
{
font = QFont("Arial", 12); // Default in case nothing exists yet.
}
//creates options page widget (uses the UI file)
QWidget *LineardialGadgetOptionsPage::createPage(QWidget *parent)
{
Q_UNUSED(parent);
options_page = new Ui::LineardialGadgetOptionsPage();
//main widget
QWidget *optionsPageWidget = new QWidget;
//main layout
options_page->setupUi(optionsPageWidget);
// Restore the contents from the settings:
options_page->svgSourceFile->setExpectedKind(Utils::PathChooser::File);
options_page->svgSourceFile->setPromptDialogFilter(tr("SVG image (*.svg)"));
options_page->svgSourceFile->setPromptDialogTitle(tr("Choose SVG image"));
options_page->svgSourceFile->setPath(m_config->getDialFile());
options_page->minValue->setValue(m_config->getMin());
options_page->maxValue->setValue(m_config->getMax());
// Do this by hand (in case value is zero, no signal would
// be sent!
on_rangeMin_valueChanged(m_config->getMin());
on_rangeMax_valueChanged(m_config->getMax());
options_page->greenMin->setValue(m_config->getGreenMin());
options_page->greenMax->setValue(m_config->getGreenMax());
options_page->yellowMin->setValue(m_config->getYellowMin());
options_page->yellowMax->setValue(m_config->getYellowMax());
options_page->redMin->setValue(m_config->getRedMin());
options_page->redMax->setValue(m_config->getRedMax());
options_page->factor->setValue(m_config->getFactor());
options_page->decPlaces->setValue(m_config->getDecimalPlaces());
font.fromString(m_config->getFont());
// Fills the combo boxes for the UAVObjects
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
QList< QList<UAVDataObject*> > objList = objManager->getDataObjects();
foreach (QList<UAVDataObject*> list, objList) {
foreach (UAVDataObject* obj, list) {
options_page->objectName->addItem(obj->getName());
}
}
//select saved UAV Object field values
if(options_page->objectName->findText(m_config->getSourceDataObject())!=-1){
options_page->objectName->setCurrentIndex(options_page->objectName->findText(m_config->getSourceDataObject()));
// Now load the object field values:
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(m_config->getSourceDataObject()) );
if (obj != NULL ) {
on_objectName_currentIndexChanged(m_config->getSourceDataObject());
// And set the highlighed value from the settings:
options_page->objectField->setCurrentIndex(options_page->objectField->findText(m_config->getSourceObjectField()));
}
}
connect(options_page->objectName, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_objectName_currentIndexChanged(QString)));
connect(options_page->fontPicker, SIGNAL(clicked()), this, SLOT(on_fontPicker_clicked()));
connect(options_page->minValue, SIGNAL(valueChanged(double)), this, SLOT(on_rangeMin_valueChanged(double)));
connect(options_page->maxValue, SIGNAL(valueChanged(double)), this, SLOT(on_rangeMax_valueChanged(double)));
return optionsPageWidget;
}
/**
* Used to make sure the green/yellow/red ranges are consistent
* with the overall dial range
*/
void LineardialGadgetOptionsPage::on_rangeMin_valueChanged(double val)
{
options_page->maxValue->setMinimum(val);
options_page->greenMin->setMinimum(val);
options_page->yellowMin->setMinimum(val);
options_page->redMin->setMinimum(val);
options_page->greenMax->setMinimum(val);
options_page->yellowMax->setMinimum(val);
options_page->redMax->setMinimum(val);
}
/**
* Used to make sure the green/yellow/red ranges are consistent
* with the overall dial range
*/
void LineardialGadgetOptionsPage::on_rangeMax_valueChanged(double val)
{
options_page->minValue->setMaximum(val);
options_page->greenMax->setMaximum(val);
options_page->yellowMax->setMaximum(val);
options_page->redMax->setMaximum(val);
options_page->greenMin->setMaximum(val);
options_page->yellowMin->setMaximum(val);
options_page->redMin->setMaximum(val);
}
/**
* Called when the user presses apply or OK.
*
* Saves the current values
*
*/
void LineardialGadgetOptionsPage::apply()
{
m_config->setDialFile(options_page->svgSourceFile->path());
double rangeMin = options_page->minValue->value();
double rangeMax = options_page->maxValue->value();
m_config->setRange(rangeMin,rangeMax);
m_config->setGreenRange(options_page->greenMin->value(),options_page->greenMax->value());
m_config->setYellowRange(options_page->yellowMin->value(),options_page->yellowMax->value());
m_config->setRedRange(options_page->redMin->value(),options_page->redMax->value());
m_config->setSourceDataObject(options_page->objectName->currentText());
m_config->setSourceObjField(options_page->objectField->currentText());
m_config->setFont(font.toString());
m_config->setDecimalPlaces(options_page->decPlaces->value());
m_config->setFactor(options_page->factor->value());
}
/**
* Opens a font picker.
*
*/
void LineardialGadgetOptionsPage::on_fontPicker_clicked()
{
bool ok;
font = QFontDialog::getFont(&ok, font , qobject_cast<QWidget*>(this));
}
/*
Fills in the field1 combo box when value is changed in the
object1 field
*/
void LineardialGadgetOptionsPage::on_objectName_currentIndexChanged(QString val) {
options_page->objectField->clear();
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(val) );
QList<UAVObjectField*> fieldList = obj->getFields();
foreach (UAVObjectField* field, fieldList) {
if(field->getElementNames().count() > 1)
{
foreach(QString elemName , field->getElementNames())
{
options_page->objectField->addItem(field->getName() + "-" + elemName);
}
}
else
options_page->objectField->addItem(field->getName());
}
}
void LineardialGadgetOptionsPage::finish()
{
}
/**
******************************************************************************
*
* @file lineardialgadgetoptionspage.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup LinearDialPlugin Linear Dial Plugin
* @{
* @brief Impliments a gadget that displays linear gauges
*****************************************************************************/
/*
* 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 "lineardialgadgetoptionspage.h"
#include "lineardialgadgetconfiguration.h"
#include "ui_lineardialgadgetoptionspage.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavdataobject.h"
#include <QFileDialog>
#include <QtAlgorithms>
#include <QStringList>
#include <QFontDialog>
LineardialGadgetOptionsPage::LineardialGadgetOptionsPage(LineardialGadgetConfiguration *config, QObject *parent) :
IOptionsPage(parent),
m_config(config)
{
font = QFont("Arial", 12); // Default in case nothing exists yet.
}
//creates options page widget (uses the UI file)
QWidget *LineardialGadgetOptionsPage::createPage(QWidget *parent)
{
Q_UNUSED(parent);
options_page = new Ui::LineardialGadgetOptionsPage();
//main widget
QWidget *optionsPageWidget = new QWidget;
//main layout
options_page->setupUi(optionsPageWidget);
// Restore the contents from the settings:
options_page->svgSourceFile->setExpectedKind(Utils::PathChooser::File);
options_page->svgSourceFile->setPromptDialogFilter(tr("SVG image (*.svg)"));
options_page->svgSourceFile->setPromptDialogTitle(tr("Choose SVG image"));
options_page->svgSourceFile->setPath(m_config->getDialFile());
options_page->minValue->setValue(m_config->getMin());
options_page->maxValue->setValue(m_config->getMax());
// Do this by hand (in case value is zero, no signal would
// be sent!
on_rangeMin_valueChanged(m_config->getMin());
on_rangeMax_valueChanged(m_config->getMax());
options_page->greenMin->setValue(m_config->getGreenMin());
options_page->greenMax->setValue(m_config->getGreenMax());
options_page->yellowMin->setValue(m_config->getYellowMin());
options_page->yellowMax->setValue(m_config->getYellowMax());
options_page->redMin->setValue(m_config->getRedMin());
options_page->redMax->setValue(m_config->getRedMax());
options_page->factor->setValue(m_config->getFactor());
options_page->decPlaces->setValue(m_config->getDecimalPlaces());
options_page->useOpenGL->setChecked(m_config->useOpenGL());
font.fromString(m_config->getFont());
// Fills the combo boxes for the UAVObjects
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
QList< QList<UAVDataObject*> > objList = objManager->getDataObjects();
foreach (QList<UAVDataObject*> list, objList) {
foreach (UAVDataObject* obj, list) {
options_page->objectName->addItem(obj->getName());
}
}
//select saved UAV Object field values
if(options_page->objectName->findText(m_config->getSourceDataObject())!=-1){
options_page->objectName->setCurrentIndex(options_page->objectName->findText(m_config->getSourceDataObject()));
// Now load the object field values:
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(m_config->getSourceDataObject()) );
if (obj != NULL ) {
on_objectName_currentIndexChanged(m_config->getSourceDataObject());
// And set the highlighed value from the settings:
options_page->objectField->setCurrentIndex(options_page->objectField->findText(m_config->getSourceObjectField()));
}
}
connect(options_page->objectName, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_objectName_currentIndexChanged(QString)));
connect(options_page->fontPicker, SIGNAL(clicked()), this, SLOT(on_fontPicker_clicked()));
connect(options_page->minValue, SIGNAL(valueChanged(double)), this, SLOT(on_rangeMin_valueChanged(double)));
connect(options_page->maxValue, SIGNAL(valueChanged(double)), this, SLOT(on_rangeMax_valueChanged(double)));
return optionsPageWidget;
}
/**
* Used to make sure the green/yellow/red ranges are consistent
* with the overall dial range
*/
void LineardialGadgetOptionsPage::on_rangeMin_valueChanged(double val)
{
options_page->maxValue->setMinimum(val);
options_page->greenMin->setMinimum(val);
options_page->yellowMin->setMinimum(val);
options_page->redMin->setMinimum(val);
options_page->greenMax->setMinimum(val);
options_page->yellowMax->setMinimum(val);
options_page->redMax->setMinimum(val);
}
/**
* Used to make sure the green/yellow/red ranges are consistent
* with the overall dial range
*/
void LineardialGadgetOptionsPage::on_rangeMax_valueChanged(double val)
{
options_page->minValue->setMaximum(val);
options_page->greenMax->setMaximum(val);
options_page->yellowMax->setMaximum(val);
options_page->redMax->setMaximum(val);
options_page->greenMin->setMaximum(val);
options_page->yellowMin->setMaximum(val);
options_page->redMin->setMaximum(val);
}
/**
* Called when the user presses apply or OK.
*
* Saves the current values
*
*/
void LineardialGadgetOptionsPage::apply()
{
m_config->setDialFile(options_page->svgSourceFile->path());
double rangeMin = options_page->minValue->value();
double rangeMax = options_page->maxValue->value();
m_config->setRange(rangeMin,rangeMax);
m_config->setGreenRange(options_page->greenMin->value(),options_page->greenMax->value());
m_config->setYellowRange(options_page->yellowMin->value(),options_page->yellowMax->value());
m_config->setRedRange(options_page->redMin->value(),options_page->redMax->value());
m_config->setSourceDataObject(options_page->objectName->currentText());
m_config->setSourceObjField(options_page->objectField->currentText());
m_config->setFont(font.toString());
m_config->setDecimalPlaces(options_page->decPlaces->value());
m_config->setFactor(options_page->factor->value());
m_config->setUseOpenGL(options_page->useOpenGL->checkState());
}
/**
* Opens a font picker.
*
*/
void LineardialGadgetOptionsPage::on_fontPicker_clicked()
{
bool ok;
font = QFontDialog::getFont(&ok, font , qobject_cast<QWidget*>(this));
}
/*
Fills in the field1 combo box when value is changed in the
object1 field
*/
void LineardialGadgetOptionsPage::on_objectName_currentIndexChanged(QString val) {
options_page->objectField->clear();
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(val) );
QList<UAVObjectField*> fieldList = obj->getFields();
foreach (UAVObjectField* field, fieldList) {
if(field->getElementNames().count() > 1)
{
foreach(QString elemName , field->getElementNames())
{
options_page->objectField->addItem(field->getName() + "-" + elemName);
}
}
else
options_page->objectField->addItem(field->getName());
}
}
void LineardialGadgetOptionsPage::finish()
{
}

View File

@ -1,525 +1,546 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LineardialGadgetOptionsPage</class>
<widget class="QWidget" name="LineardialGadgetOptionsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>540</width>
<height>347</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QWidget" name="verticalLayoutWidget">
<property name="geometry">
<rect>
<x>-1</x>
<y>-1</y>
<width>533</width>
<height>321</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0,0,0,0,0,0,0,0">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<property name="leftMargin">
<number>10</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>10</number>
</property>
<property name="bottomMargin">
<number>10</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0">
<property name="spacing">
<number>10</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<property name="bottomMargin">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Dial SVG: </string>
</property>
</widget>
</item>
<item>
<widget class="Utils::PathChooser" name="svgSourceFile" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_8">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Whole range:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_9">
<property name="text">
<string>Min:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="minValue">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-99999.000000000000000</double>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_13">
<property name="text">
<string>Max:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="maxValue">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-99999.000000000000000</double>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Green:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Min:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="greenMin">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-99999.000000000000000</double>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_10">
<property name="text">
<string>Max:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="greenMax">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-99999.000000000000000</double>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_4">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Yellow:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Min:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="yellowMin">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-99999.000000000000000</double>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_11">
<property name="text">
<string>Max:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="yellowMax">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-99999.000000000000000</double>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_6">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Red:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Min:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="redMin">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-99999.000000000000000</double>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_12">
<property name="text">
<string>Max:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="redMax">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-99999.000000000000000</double>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_17">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Input:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_18">
<property name="text">
<string>ObjectName</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="objectName">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_19">
<property name="text">
<string>ObjectField</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="objectField">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_14">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Dial font:</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="fontPicker">
<property name="text">
<string>Select...</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_15">
<property name="text">
<string>Decimal places:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="decPlaces">
<property name="maximum">
<number>99</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_16">
<property name="text">
<string>Factor:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="factor">
<property name="decimals">
<number>6</number>
</property>
<property name="minimum">
<double>-10000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.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>
</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>
</layout>
</widget>
</widget>
<customwidgets>
<customwidget>
<class>Utils::PathChooser</class>
<extends>QWidget</extends>
<header>utils/pathchooser.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LineardialGadgetOptionsPage</class>
<widget class="QWidget" name="LineardialGadgetOptionsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>540</width>
<height>347</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QWidget" name="verticalLayoutWidget">
<property name="geometry">
<rect>
<x>-1</x>
<y>-1</y>
<width>533</width>
<height>321</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0,0,0,0,0,0,0,0,0,0">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<property name="leftMargin">
<number>10</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>10</number>
</property>
<property name="bottomMargin">
<number>10</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QCheckBox" name="useOpenGL">
<property name="text">
<string>Use OpenGL</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0">
<property name="spacing">
<number>10</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<property name="bottomMargin">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Dial SVG: </string>
</property>
</widget>
</item>
<item>
<widget class="Utils::PathChooser" name="svgSourceFile" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_8">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Whole range:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_9">
<property name="text">
<string>Min:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="minValue">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-99999.000000000000000</double>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_13">
<property name="text">
<string>Max:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="maxValue">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-99999.000000000000000</double>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Green:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Min:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="greenMin">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-99999.000000000000000</double>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_10">
<property name="text">
<string>Max:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="greenMax">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-99999.000000000000000</double>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_4">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Yellow:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Min:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="yellowMin">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-99999.000000000000000</double>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_11">
<property name="text">
<string>Max:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="yellowMax">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-99999.000000000000000</double>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_6">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Red:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Min:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="redMin">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-99999.000000000000000</double>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_12">
<property name="text">
<string>Max:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="redMax">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-99999.000000000000000</double>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_17">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Input:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_18">
<property name="text">
<string>ObjectName</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="objectName">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_19">
<property name="text">
<string>ObjectField</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="objectField">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_14">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Dial font:</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="fontPicker">
<property name="text">
<string>Select...</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_15">
<property name="text">
<string>Decimal places:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="decPlaces">
<property name="maximum">
<number>99</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_16">
<property name="text">
<string>Factor:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="factor">
<property name="decimals">
<number>6</number>
</property>
<property name="minimum">
<double>-10000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.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>
</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>
</layout>
</widget>
</widget>
<customwidgets>
<customwidget>
<class>Utils::PathChooser</class>
<extends>QWidget</extends>
<header>utils/pathchooser.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -1,431 +1,443 @@
/**
******************************************************************************
*
* @file lineardialgadgetwidget.cpp
* @author Edouard Lafargue Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup LinearDialPlugin Linear Dial Plugin
* @{
* @brief Implements a gadget that displays linear gauges and generic indicators
*****************************************************************************/
/*
* 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 "lineardialgadgetwidget.h"
#include <utils/stylehelper.h>
#include <QtGui/QFileDialog>
#include <QDebug>
LineardialGadgetWidget::LineardialGadgetWidget(QWidget *parent) : QGraphicsView(parent)
{
setMinimumSize(32,32);
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
setScene(new QGraphicsScene(this));
setRenderHints(QPainter::Antialiasing);
m_renderer = new QSvgRenderer();
verticalDial = false;
paint();
obj1 = NULL;
fieldName = NULL;
fieldValue = NULL;
indexTarget = 0;
indexValue = 0;
places = 0;
factor = 1;
// This timer mechanism makes the index rotate smoothly
connect(&dialTimer, SIGNAL(timeout()), this, SLOT(moveIndex()));
dialTimer.start(30);
}
LineardialGadgetWidget::~LineardialGadgetWidget()
{
// Do nothing
}
/*!
\brief Connects the widget to the relevant UAVObjects
*/
void LineardialGadgetWidget::connectInput(QString object1, QString nfield1) {
if (obj1 != NULL)
disconnect(obj1,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(updateIndex(UAVObject*)));
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
// qDebug() << "Lineardial Connect needles - " << object1 << "-"<< nfield1;
// Check validity of arguments first, reject empty args and unknown fields.
if (!(object1.isEmpty() || nfield1.isEmpty())) {
obj1 = dynamic_cast<UAVDataObject*>( objManager->getObject(object1) );
if (obj1 != NULL ) {
connect(obj1, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(updateIndex(UAVObject*)));
if(nfield1.contains("-"))
{
QStringList fieldSubfield = nfield1.split("-", QString::SkipEmptyParts);
field1 = fieldSubfield.at(0);
subfield1 = fieldSubfield.at(1);
haveSubField1 = true;
}
else
{
field1= nfield1;
haveSubField1 = false;
}
if (fieldName)
fieldName->setPlainText(nfield1);
updateIndex(obj1);
} else {
qDebug() << "Error: Object is unknown (" << object1 << ") this should not happen.";
}
}
}
/*!
\brief Called by the UAVObject which got updated
Updates the numeric value and/or the icon if the dial wants this.
*/
void LineardialGadgetWidget::updateIndex(UAVObject *object1) {
// Double check that the field exists:
UAVObjectField* field = object1->getField(field1);
if (field) {
QString s;
if (field->isNumeric()) {
double v;
if(haveSubField1){
int indexOfSubField = field->getElementNames().indexOf(QRegExp(subfield1, Qt::CaseSensitive, QRegExp::FixedString));
v = field->getDouble(indexOfSubField)*factor;
}else
v = field->getDouble()*factor;
setIndex(v);
s.sprintf("%.*f",places,v);
}
if (field->isText()) {
s = field->getValue().toString();
if (fieldSymbol) {
// If we defined a symbol, we will look for a matching
// SVG element to display:
if (m_renderer->elementExists("symbol-" + s)) {
fieldSymbol->setElementId("symbol-" + s);
} else {
fieldSymbol->setElementId("symbol");
}
}
}
if (fieldValue)
fieldValue->setPlainText(s);
if (index && !dialTimer.isActive())
dialTimer.start();
} else {
qDebug() << "Wrong field, maybe an issue with object disconnection ?";
}
}
/*!
\brief Setup dial using its master SVG template.
Should only be called after the min/max ranges have been set.
*/
void LineardialGadgetWidget::setDialFile(QString dfn)
{
QGraphicsScene *l_scene = scene();
setBackgroundBrush(QBrush(Utils::StyleHelper::baseColor()));
if (QFile::exists(dfn) && m_renderer->load(dfn) && m_renderer->isValid() )
{
l_scene->clear(); // Beware: clear also deletes all objects
// which are currently in the scene
background = new QGraphicsSvgItem();
background->setSharedRenderer(m_renderer);
background->setElementId("background");
background->setFlags(QGraphicsItem::ItemClipsChildrenToShape|
QGraphicsItem::ItemClipsToShape);
l_scene->addItem(background);
// The red/yellow/green zones are optional, we just
// test on the presence of "red"
if (m_renderer->elementExists("red")) {
// Order is important: red, then yellow then green
// overlayed on top of each other
red = new QGraphicsSvgItem();
red->setSharedRenderer(m_renderer);
red->setElementId("red");
red->setParentItem(background);
yellow = new QGraphicsSvgItem();
yellow->setSharedRenderer(m_renderer);
yellow->setElementId("yellow");
yellow->setParentItem(background);
green = new QGraphicsSvgItem();
green->setSharedRenderer(m_renderer);
green->setElementId("green");
green->setParentItem(background);
// In order to properly render the Green/Yellow/Red graphs, we need to find out
// the starting location of the bargraph rendering area:
QMatrix textMatrix = m_renderer->matrixForElement("bargraph");
qreal bgX = textMatrix.mapRect(m_renderer->boundsOnElement("bargraph")).x();
qreal bgY = textMatrix.mapRect(m_renderer->boundsOnElement("bargraph")).y();
bargraphSize = textMatrix.mapRect(m_renderer->boundsOnElement("bargraph")).width();
// Detect if the bargraph is vertical or horizontal.
qreal bargraphHeight = textMatrix.mapRect(m_renderer->boundsOnElement("bargraph")).height();
if (bargraphHeight > bargraphSize) {
verticalDial = true;
bargraphSize = bargraphHeight;
} else {
verticalDial = false;
}
// Now adjust the red/yellow/green zones:
double range = maxValue-minValue;
green->resetTransform();
double greenScale = (greenMax-greenMin)/range;
double greenStart = verticalDial ? (maxValue-greenMax)/range*green->boundingRect().height() :
(greenMin-minValue)/range*green->boundingRect().width();
QTransform matrix;
matrix.reset();
if (verticalDial) {
matrix.scale(1,greenScale);
matrix.translate(bgX,(greenStart+bgY)/greenScale);
} else {
matrix.scale(greenScale,1);
matrix.translate((greenStart+bgX)/greenScale,bgY);
}
green->setTransform(matrix,false);
yellow->resetTransform();
double yellowScale = (yellowMax-yellowMin)/range;
double yellowStart = verticalDial ? (maxValue-yellowMax)/range*yellow->boundingRect().height() :
(yellowMin-minValue)/range*yellow->boundingRect().width();
matrix.reset();
if (verticalDial) {
matrix.scale(1,yellowScale);
matrix.translate(bgX,(yellowStart+bgY)/yellowScale);
} else {
matrix.scale(yellowScale,1);
matrix.translate((yellowStart+bgX)/yellowScale,bgY);
}
yellow->setTransform(matrix,false);
red->resetTransform();
double redScale = (redMax-redMin)/range;
double redStart = verticalDial ? (maxValue-redMax)/range*red->boundingRect().height() :
(redMin-minValue)/range*red->boundingRect().width();
matrix.reset();
if (verticalDial) {
matrix.scale(1,redScale);
matrix.translate(bgX,(redStart+bgY)/redScale);
} else {
matrix.scale(redScale,1);
matrix.translate((redStart+bgX)/redScale,bgY);
}
red->setTransform(matrix,false);
} else {
red = NULL;
yellow = NULL;
green = NULL;
}
// Check whether the dial wants to display a moving index:
if (m_renderer->elementExists("needle")) {
QMatrix textMatrix = m_renderer->matrixForElement("needle");
QRectF nRect = textMatrix.mapRect(m_renderer->boundsOnElement("needle"));
startX = nRect.x();
startY = nRect.y();
QTransform matrix;
matrix.translate(startX,startY);
index = new QGraphicsSvgItem();
index->setSharedRenderer(m_renderer);
index->setElementId("needle");
index->setTransform(matrix,false);
index->setParentItem(background);
} else {
index = NULL;
}
// Check whether the dial wants display its field name:
if (m_renderer->elementExists("field")) {
QMatrix textMatrix = m_renderer->matrixForElement("field");
QRectF rect = textMatrix.mapRect(m_renderer->boundsOnElement("field"));
qreal startX = rect.x();
qreal startY = rect.y();
qreal elHeight = rect.height();
QTransform matrix;
matrix.translate(startX,startY-elHeight/2);
fieldName = new QGraphicsTextItem("field");
fieldName->setFont(QFont("Arial",(int)elHeight));
fieldName->setDefaultTextColor(QColor("White"));
fieldName->setTransform(matrix,false);
fieldName->setParentItem(background);
} else {
fieldName = NULL;
}
// Check whether the dial wants display the numeric value:
if (m_renderer->elementExists("value")) {
QMatrix textMatrix = m_renderer->matrixForElement("value");
QRectF nRect = textMatrix.mapRect(m_renderer->boundsOnElement("value"));
qreal startX = nRect.x();
qreal startY = nRect.y();
qreal elHeight = nRect.height();
QTransform matrix;
matrix.translate(startX,startY-elHeight/2);
fieldValue = new QGraphicsTextItem("0.00");
fieldValue->setFont(QFont("Arial",(int)elHeight));
fieldValue->setDefaultTextColor(QColor("White"));
fieldValue->setTransform(matrix,false);
fieldValue->setParentItem(background);
} else {
fieldValue = NULL;
}
// Check whether the dial wants to display the value as a
// symbol (only works for text values):
if (m_renderer->elementExists("symbol")) {
QMatrix textMatrix = m_renderer->matrixForElement("symbol");
qreal startX = textMatrix.mapRect(m_renderer->boundsOnElement("symbol")).x();
qreal startY = textMatrix.mapRect(m_renderer->boundsOnElement("symbol")).y();
QTransform matrix;
matrix.translate(startX,startY);
fieldSymbol = new QGraphicsSvgItem();
fieldSymbol->setElementId("symbol");
fieldSymbol->setSharedRenderer(m_renderer);
fieldSymbol->setTransform(matrix,false);
fieldSymbol->setParentItem(background);
} else {
fieldSymbol = NULL;
}
if (m_renderer->elementExists("foreground")) {
foreground = new QGraphicsSvgItem();
foreground->setSharedRenderer(m_renderer);
foreground->setElementId("foreground");
foreground->setParentItem(background);
fgenabled = true;
} else {
fgenabled = false;
}
l_scene->setSceneRect(background->boundingRect());
// Reset the current index value:
indexValue = 0;
if (!dialTimer.isActive() && index)
dialTimer.start();
}
else
{
qDebug() << "no file ";
m_renderer->load(QString(":/lineardial/images/empty.svg"));
l_scene->clear(); // This also deletes all items contained in the scene.
background = new QGraphicsSvgItem();
background->setSharedRenderer(m_renderer);
l_scene->addItem(background);
fieldName = NULL;
fieldValue = NULL;
fieldSymbol = NULL;
index = NULL;
}
}
void LineardialGadgetWidget::setDialFont(QString fontProps)
{
// Note: a bit of juggling to preserve the automatic
// font size which was calculated upon dial initialization.
QFont font = QFont("Arial",12);
font.fromString(fontProps);
if (fieldName) {
int fieldSize = fieldName->font().pointSize();
font.setPointSize(fieldSize);
fieldName->setFont(font);
}
if (fieldValue) {
int fieldSize = fieldValue->font().pointSize();
font.setPointSize(fieldSize);
fieldValue->setFont(font);
}
}
void LineardialGadgetWidget::paint()
{
update();
}
void LineardialGadgetWidget::paintEvent(QPaintEvent *event)
{
// Skip painting until the dial file is loaded
if (! m_renderer->isValid()) {
qDebug()<<"Dial file not loaded, not rendering";
return;
}
QGraphicsView::paintEvent(event);
}
// This event enables the dial to be dynamically resized
// whenever the gadget is resized, taking advantage of the vector
// nature of SVG dials.
void LineardialGadgetWidget::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event);
fitInView(background, Qt::KeepAspectRatio );
}
// Converts the value into an percentage:
// this enables smooth movement in moveIndex below
void LineardialGadgetWidget::setIndex(double value) {
if (verticalDial) {
indexTarget = 100*(maxValue-value)/(maxValue-minValue);
} else {
indexTarget = 100*(value-minValue)/(maxValue-minValue);
}
}
// Take an input value and move the index accordingly
// Move is smooth, starts fast and slows down when
// approaching the target.
void LineardialGadgetWidget::moveIndex()
{
if (!index) { // Safeguard
dialTimer.stop();
return;
}
if ((abs((indexValue-indexTarget)*10) > 3)) {
indexValue += (indexTarget - indexValue)/5;
} else {
indexValue = indexTarget;
dialTimer.stop();
}
QTransform matrix;
index->resetTransform();
qreal trans = indexValue*bargraphSize/100;
if (verticalDial) {
matrix.translate(startX,trans+startY);
} else {
matrix.translate(trans+startX,startY);
}
index->setTransform(matrix,false);
update();
}
/**
******************************************************************************
*
* @file lineardialgadgetwidget.cpp
* @author Edouard Lafargue Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup LinearDialPlugin Linear Dial Plugin
* @{
* @brief Implements a gadget that displays linear gauges and generic indicators
*****************************************************************************/
/*
* 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 "lineardialgadgetwidget.h"
#include <utils/stylehelper.h>
#include <QtGui/QFileDialog>
#include <QtOpenGL/QGLWidget>
#include <QDebug>
LineardialGadgetWidget::LineardialGadgetWidget(QWidget *parent) : QGraphicsView(parent)
{
setMinimumSize(32,32);
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
setScene(new QGraphicsScene(this));
setRenderHints(QPainter::Antialiasing);
m_renderer = new QSvgRenderer();
verticalDial = false;
paint();
obj1 = NULL;
fieldName = NULL;
fieldValue = NULL;
indexTarget = 0;
indexValue = 0;
places = 0;
factor = 1;
// This timer mechanism makes the index rotate smoothly
connect(&dialTimer, SIGNAL(timeout()), this, SLOT(moveIndex()));
dialTimer.start(30);
}
LineardialGadgetWidget::~LineardialGadgetWidget()
{
// Do nothing
}
/*!
\brief Enables/Disables OpenGL
*/
void LineardialGadgetWidget::enableOpenGL(bool flag)
{
if (flag)
setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
else
setViewport(new QWidget);
}
/*!
\brief Connects the widget to the relevant UAVObjects
*/
void LineardialGadgetWidget::connectInput(QString object1, QString nfield1) {
if (obj1 != NULL)
disconnect(obj1,SIGNAL(objectUpdated(UAVObject*)),this,SLOT(updateIndex(UAVObject*)));
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
// qDebug() << "Lineardial Connect needles - " << object1 << "-"<< nfield1;
// Check validity of arguments first, reject empty args and unknown fields.
if (!(object1.isEmpty() || nfield1.isEmpty())) {
obj1 = dynamic_cast<UAVDataObject*>( objManager->getObject(object1) );
if (obj1 != NULL ) {
connect(obj1, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(updateIndex(UAVObject*)));
if(nfield1.contains("-"))
{
QStringList fieldSubfield = nfield1.split("-", QString::SkipEmptyParts);
field1 = fieldSubfield.at(0);
subfield1 = fieldSubfield.at(1);
haveSubField1 = true;
}
else
{
field1= nfield1;
haveSubField1 = false;
}
if (fieldName)
fieldName->setPlainText(nfield1);
updateIndex(obj1);
} else {
qDebug() << "Error: Object is unknown (" << object1 << ") this should not happen.";
}
}
}
/*!
\brief Called by the UAVObject which got updated
Updates the numeric value and/or the icon if the dial wants this.
*/
void LineardialGadgetWidget::updateIndex(UAVObject *object1) {
// Double check that the field exists:
UAVObjectField* field = object1->getField(field1);
if (field) {
QString s;
if (field->isNumeric()) {
double v;
if(haveSubField1){
int indexOfSubField = field->getElementNames().indexOf(QRegExp(subfield1, Qt::CaseSensitive, QRegExp::FixedString));
v = field->getDouble(indexOfSubField)*factor;
}else
v = field->getDouble()*factor;
setIndex(v);
s.sprintf("%.*f",places,v);
}
if (field->isText()) {
s = field->getValue().toString();
if (fieldSymbol) {
// If we defined a symbol, we will look for a matching
// SVG element to display:
if (m_renderer->elementExists("symbol-" + s)) {
fieldSymbol->setElementId("symbol-" + s);
} else {
fieldSymbol->setElementId("symbol");
}
}
}
if (fieldValue)
fieldValue->setPlainText(s);
if (index && !dialTimer.isActive())
dialTimer.start();
} else {
qDebug() << "Wrong field, maybe an issue with object disconnection ?";
}
}
/*!
\brief Setup dial using its master SVG template.
Should only be called after the min/max ranges have been set.
*/
void LineardialGadgetWidget::setDialFile(QString dfn)
{
QGraphicsScene *l_scene = scene();
setBackgroundBrush(QBrush(Utils::StyleHelper::baseColor()));
if (QFile::exists(dfn) && m_renderer->load(dfn) && m_renderer->isValid() )
{
l_scene->clear(); // Beware: clear also deletes all objects
// which are currently in the scene
background = new QGraphicsSvgItem();
background->setSharedRenderer(m_renderer);
background->setElementId("background");
background->setFlags(QGraphicsItem::ItemClipsChildrenToShape|
QGraphicsItem::ItemClipsToShape);
l_scene->addItem(background);
// The red/yellow/green zones are optional, we just
// test on the presence of "red"
if (m_renderer->elementExists("red")) {
// Order is important: red, then yellow then green
// overlayed on top of each other
red = new QGraphicsSvgItem();
red->setSharedRenderer(m_renderer);
red->setElementId("red");
red->setParentItem(background);
yellow = new QGraphicsSvgItem();
yellow->setSharedRenderer(m_renderer);
yellow->setElementId("yellow");
yellow->setParentItem(background);
green = new QGraphicsSvgItem();
green->setSharedRenderer(m_renderer);
green->setElementId("green");
green->setParentItem(background);
// In order to properly render the Green/Yellow/Red graphs, we need to find out
// the starting location of the bargraph rendering area:
QMatrix textMatrix = m_renderer->matrixForElement("bargraph");
qreal bgX = textMatrix.mapRect(m_renderer->boundsOnElement("bargraph")).x();
qreal bgY = textMatrix.mapRect(m_renderer->boundsOnElement("bargraph")).y();
bargraphSize = textMatrix.mapRect(m_renderer->boundsOnElement("bargraph")).width();
// Detect if the bargraph is vertical or horizontal.
qreal bargraphHeight = textMatrix.mapRect(m_renderer->boundsOnElement("bargraph")).height();
if (bargraphHeight > bargraphSize) {
verticalDial = true;
bargraphSize = bargraphHeight;
} else {
verticalDial = false;
}
// Now adjust the red/yellow/green zones:
double range = maxValue-minValue;
green->resetTransform();
double greenScale = (greenMax-greenMin)/range;
double greenStart = verticalDial ? (maxValue-greenMax)/range*green->boundingRect().height() :
(greenMin-minValue)/range*green->boundingRect().width();
QTransform matrix;
matrix.reset();
if (verticalDial) {
matrix.scale(1,greenScale);
matrix.translate(bgX,(greenStart+bgY)/greenScale);
} else {
matrix.scale(greenScale,1);
matrix.translate((greenStart+bgX)/greenScale,bgY);
}
green->setTransform(matrix,false);
yellow->resetTransform();
double yellowScale = (yellowMax-yellowMin)/range;
double yellowStart = verticalDial ? (maxValue-yellowMax)/range*yellow->boundingRect().height() :
(yellowMin-minValue)/range*yellow->boundingRect().width();
matrix.reset();
if (verticalDial) {
matrix.scale(1,yellowScale);
matrix.translate(bgX,(yellowStart+bgY)/yellowScale);
} else {
matrix.scale(yellowScale,1);
matrix.translate((yellowStart+bgX)/yellowScale,bgY);
}
yellow->setTransform(matrix,false);
red->resetTransform();
double redScale = (redMax-redMin)/range;
double redStart = verticalDial ? (maxValue-redMax)/range*red->boundingRect().height() :
(redMin-minValue)/range*red->boundingRect().width();
matrix.reset();
if (verticalDial) {
matrix.scale(1,redScale);
matrix.translate(bgX,(redStart+bgY)/redScale);
} else {
matrix.scale(redScale,1);
matrix.translate((redStart+bgX)/redScale,bgY);
}
red->setTransform(matrix,false);
} else {
red = NULL;
yellow = NULL;
green = NULL;
}
// Check whether the dial wants to display a moving index:
if (m_renderer->elementExists("needle")) {
QMatrix textMatrix = m_renderer->matrixForElement("needle");
QRectF nRect = textMatrix.mapRect(m_renderer->boundsOnElement("needle"));
startX = nRect.x();
startY = nRect.y();
QTransform matrix;
matrix.translate(startX,startY);
index = new QGraphicsSvgItem();
index->setSharedRenderer(m_renderer);
index->setElementId("needle");
index->setTransform(matrix,false);
index->setParentItem(background);
} else {
index = NULL;
}
// Check whether the dial wants display its field name:
if (m_renderer->elementExists("field")) {
QMatrix textMatrix = m_renderer->matrixForElement("field");
QRectF rect = textMatrix.mapRect(m_renderer->boundsOnElement("field"));
qreal startX = rect.x();
qreal startY = rect.y();
qreal elHeight = rect.height();
QTransform matrix;
matrix.translate(startX,startY-elHeight/2);
fieldName = new QGraphicsTextItem("field");
fieldName->setFont(QFont("Arial",(int)elHeight));
fieldName->setDefaultTextColor(QColor("White"));
fieldName->setTransform(matrix,false);
fieldName->setParentItem(background);
} else {
fieldName = NULL;
}
// Check whether the dial wants display the numeric value:
if (m_renderer->elementExists("value")) {
QMatrix textMatrix = m_renderer->matrixForElement("value");
QRectF nRect = textMatrix.mapRect(m_renderer->boundsOnElement("value"));
qreal startX = nRect.x();
qreal startY = nRect.y();
qreal elHeight = nRect.height();
QTransform matrix;
matrix.translate(startX,startY-elHeight/2);
fieldValue = new QGraphicsTextItem("0.00");
fieldValue->setFont(QFont("Arial",(int)elHeight));
fieldValue->setDefaultTextColor(QColor("White"));
fieldValue->setTransform(matrix,false);
fieldValue->setParentItem(background);
} else {
fieldValue = NULL;
}
// Check whether the dial wants to display the value as a
// symbol (only works for text values):
if (m_renderer->elementExists("symbol")) {
QMatrix textMatrix = m_renderer->matrixForElement("symbol");
qreal startX = textMatrix.mapRect(m_renderer->boundsOnElement("symbol")).x();
qreal startY = textMatrix.mapRect(m_renderer->boundsOnElement("symbol")).y();
QTransform matrix;
matrix.translate(startX,startY);
fieldSymbol = new QGraphicsSvgItem();
fieldSymbol->setElementId("symbol");
fieldSymbol->setSharedRenderer(m_renderer);
fieldSymbol->setTransform(matrix,false);
fieldSymbol->setParentItem(background);
} else {
fieldSymbol = NULL;
}
if (m_renderer->elementExists("foreground")) {
foreground = new QGraphicsSvgItem();
foreground->setSharedRenderer(m_renderer);
foreground->setElementId("foreground");
foreground->setParentItem(background);
fgenabled = true;
} else {
fgenabled = false;
}
l_scene->setSceneRect(background->boundingRect());
// Reset the current index value:
indexValue = 0;
if (!dialTimer.isActive() && index)
dialTimer.start();
}
else
{
qDebug() << "no file ";
m_renderer->load(QString(":/lineardial/images/empty.svg"));
l_scene->clear(); // This also deletes all items contained in the scene.
background = new QGraphicsSvgItem();
background->setSharedRenderer(m_renderer);
l_scene->addItem(background);
fieldName = NULL;
fieldValue = NULL;
fieldSymbol = NULL;
index = NULL;
}
}
void LineardialGadgetWidget::setDialFont(QString fontProps)
{
// Note: a bit of juggling to preserve the automatic
// font size which was calculated upon dial initialization.
QFont font = QFont("Arial",12);
font.fromString(fontProps);
if (fieldName) {
int fieldSize = fieldName->font().pointSize();
font.setPointSize(fieldSize);
fieldName->setFont(font);
}
if (fieldValue) {
int fieldSize = fieldValue->font().pointSize();
font.setPointSize(fieldSize);
fieldValue->setFont(font);
}
}
void LineardialGadgetWidget::paint()
{
update();
}
void LineardialGadgetWidget::paintEvent(QPaintEvent *event)
{
// Skip painting until the dial file is loaded
if (! m_renderer->isValid()) {
qDebug()<<"Dial file not loaded, not rendering";
return;
}
QGraphicsView::paintEvent(event);
}
// This event enables the dial to be dynamically resized
// whenever the gadget is resized, taking advantage of the vector
// nature of SVG dials.
void LineardialGadgetWidget::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event);
fitInView(background, Qt::KeepAspectRatio );
}
// Converts the value into an percentage:
// this enables smooth movement in moveIndex below
void LineardialGadgetWidget::setIndex(double value) {
if (verticalDial) {
indexTarget = 100*(maxValue-value)/(maxValue-minValue);
} else {
indexTarget = 100*(value-minValue)/(maxValue-minValue);
}
}
// Take an input value and move the index accordingly
// Move is smooth, starts fast and slows down when
// approaching the target.
void LineardialGadgetWidget::moveIndex()
{
if (!index) { // Safeguard
dialTimer.stop();
return;
}
if ((abs((indexValue-indexTarget)*10) > 3)) {
indexValue += (indexTarget - indexValue)/5;
} else {
indexValue = indexTarget;
dialTimer.stop();
}
QTransform matrix;
index->resetTransform();
qreal trans = indexValue*bargraphSize/100;
if (verticalDial) {
matrix.translate(startX,trans+startY);
} else {
matrix.translate(trans+startX,startY);
}
index->setTransform(matrix,false);
update();
}

View File

@ -1,123 +1,124 @@
/**
******************************************************************************
*
* @file lineardialgadgetwidget.h
* @author Edouard Lafargue Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup LinearDialPlugin Linear Dial Plugin
* @{
* @brief Impliments a gadget that displays linear gauges
*****************************************************************************/
/*
* 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
*/
#ifndef LINEARDIALGADGETWIDGET_H_
#define LINEARDIALGADGETWIDGET_H_
#include "lineardialgadgetconfiguration.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"
#include <QGraphicsView>
#include <QtSvg/QSvgRenderer>
#include <QtSvg/QGraphicsSvgItem>
#include <QFile>
#include <QTimer>
class LineardialGadgetWidget : public QGraphicsView
{
Q_OBJECT
public:
LineardialGadgetWidget(QWidget *parent = 0);
~LineardialGadgetWidget();
void setDialFile(QString dfn);
void paint();
void setRange(double min, double max) { minValue=min; maxValue=max;}
void setGreenRange(double min, double max) {greenMin=min; greenMax=max;}
void setYellowRange(double min, double max) {yellowMin=min; yellowMax=max;}
void setRedRange(double min, double max) {redMin=min; redMax=max;}
void connectInput(QString obj, QString field);
void setIndex(double val);
void setDialFont(QString fontProps);
void setFactor (double val) { factor = val;}
void setDecimalPlaces(int val) { places = val;}
public slots:
void updateIndex(UAVObject *object1);
protected:
void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent *event);
private:
private slots:
void moveIndex();
private:
QSvgRenderer *m_renderer;
QGraphicsSvgItem *background;
QGraphicsSvgItem *foreground;
QGraphicsSvgItem *index;
QGraphicsSvgItem *green;
QGraphicsSvgItem *yellow;
QGraphicsSvgItem *red;
QGraphicsSvgItem *fieldSymbol;
QGraphicsTextItem *fieldName;
QGraphicsTextItem *fieldValue;
// Simple flag to skip rendering if the
bool fgenabled; // layer does not exist.
bool verticalDial; // True if the dials scales vertically.
qreal startX; // Where we should draw the bargraph
qreal startY; // green/yellow/red zones.
qreal bargraphSize;
qreal indexHeight;
qreal indexWidth;
double minValue;
double maxValue;
double greenMin;
double greenMax;
double yellowMin;
double yellowMax;
double redMin;
double redMax;
double factor;
int places;
// The Value and target variables
// are expressed in degrees
double indexTarget;
double indexValue;
// Rotation timer
QTimer dialTimer;
// Name of the fields to read when an update is received:
UAVDataObject* obj1;
QString field1;
QString subfield1;
bool haveSubField1;
};
#endif /* LINEARDIALGADGETWIDGET_H_ */
/**
******************************************************************************
*
* @file lineardialgadgetwidget.h
* @author Edouard Lafargue Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup LinearDialPlugin Linear Dial Plugin
* @{
* @brief Impliments a gadget that displays linear gauges
*****************************************************************************/
/*
* 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
*/
#ifndef LINEARDIALGADGETWIDGET_H_
#define LINEARDIALGADGETWIDGET_H_
#include "lineardialgadgetconfiguration.h"
#include "extensionsystem/pluginmanager.h"
#include "uavobjectmanager.h"
#include "uavobject.h"
#include <QGraphicsView>
#include <QtSvg/QSvgRenderer>
#include <QtSvg/QGraphicsSvgItem>
#include <QFile>
#include <QTimer>
class LineardialGadgetWidget : public QGraphicsView
{
Q_OBJECT
public:
LineardialGadgetWidget(QWidget *parent = 0);
~LineardialGadgetWidget();
void enableOpenGL(bool flag);
void setDialFile(QString dfn);
void paint();
void setRange(double min, double max) { minValue=min; maxValue=max;}
void setGreenRange(double min, double max) {greenMin=min; greenMax=max;}
void setYellowRange(double min, double max) {yellowMin=min; yellowMax=max;}
void setRedRange(double min, double max) {redMin=min; redMax=max;}
void connectInput(QString obj, QString field);
void setIndex(double val);
void setDialFont(QString fontProps);
void setFactor (double val) { factor = val;}
void setDecimalPlaces(int val) { places = val;}
public slots:
void updateIndex(UAVObject *object1);
protected:
void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent *event);
private:
private slots:
void moveIndex();
private:
QSvgRenderer *m_renderer;
QGraphicsSvgItem *background;
QGraphicsSvgItem *foreground;
QGraphicsSvgItem *index;
QGraphicsSvgItem *green;
QGraphicsSvgItem *yellow;
QGraphicsSvgItem *red;
QGraphicsSvgItem *fieldSymbol;
QGraphicsTextItem *fieldName;
QGraphicsTextItem *fieldValue;
// Simple flag to skip rendering if the
bool fgenabled; // layer does not exist.
bool verticalDial; // True if the dials scales vertically.
qreal startX; // Where we should draw the bargraph
qreal startY; // green/yellow/red zones.
qreal bargraphSize;
qreal indexHeight;
qreal indexWidth;
double minValue;
double maxValue;
double greenMin;
double greenMax;
double yellowMin;
double yellowMax;
double redMin;
double redMax;
double factor;
int places;
// The Value and target variables
// are expressed in degrees
double indexTarget;
double indexValue;
// Rotation timer
QTimer dialTimer;
// Name of the fields to read when an update is received:
UAVDataObject* obj1;
QString field1;
QString subfield1;
bool haveSubField1;
};
#endif /* LINEARDIALGADGETWIDGET_H_ */