mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-29 14:52:12 +01:00
New "bargraph" dial. Use with the recently uploaded linear dial SVG. Settings to not work at the moment, I'll add them later.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@585 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
5d20bfd802
commit
10215c96c3
10
ground/src/plugins/lineardial/LineardialGadget.pluginspec
Normal file
10
ground/src/plugins/lineardial/LineardialGadget.pluginspec
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<plugin name="LineardialGadget" version="1.0.0" compatVersion="1.0.0">
|
||||||
|
<vendor>The OpenPilot Project</vendor>
|
||||||
|
<copyright>(C)Edouard Lafargue</copyright>
|
||||||
|
<license>The GNU Public License (GPL) Version 3</license>
|
||||||
|
<description>An bargraph gadget with red/yellow/green zones</description>
|
||||||
|
<url>http://www.openpilot.org</url>
|
||||||
|
<dependencyList>
|
||||||
|
<dependency name="Core" version="1.0.0"/>
|
||||||
|
</dependencyList>
|
||||||
|
</plugin>
|
20
ground/src/plugins/lineardial/lineardial.pro
Normal file
20
ground/src/plugins/lineardial/lineardial.pro
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
TEMPLATE = lib
|
||||||
|
TARGET = lineardialGadget
|
||||||
|
QT += svg
|
||||||
|
include(../../openpilotgcsplugin.pri)
|
||||||
|
include(../../plugins/coreplugin/coreplugin.pri)
|
||||||
|
include(../../libs/qwt/qwt.pri)
|
||||||
|
HEADERS += lineardialplugin.h
|
||||||
|
HEADERS += lineardialgadget.h
|
||||||
|
HEADERS += lineardialgadgetwidget.h
|
||||||
|
HEADERS += lineardialgadgetfactory.h
|
||||||
|
HEADERS += lineardialgadgetconfiguration.h
|
||||||
|
HEADERS += lineardialgadgetoptionspage.h
|
||||||
|
SOURCES += lineardialplugin.cpp
|
||||||
|
SOURCES += lineardialgadget.cpp
|
||||||
|
SOURCES += lineardialgadgetfactory.cpp
|
||||||
|
SOURCES += lineardialgadgetwidget.cpp
|
||||||
|
SOURCES += lineardialgadgetconfiguration.cpp
|
||||||
|
SOURCES += lineardialgadgetoptionspage.cpp
|
||||||
|
OTHER_FILES += LineardialGadget.pluginspec
|
||||||
|
FORMS += lineardialgadgetoptionspage.ui
|
59
ground/src/plugins/lineardial/lineardialgadget.cpp
Normal file
59
ground/src/plugins/lineardial/lineardialgadget.cpp
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
*
|
||||||
|
* @file lineardialgadget.cpp
|
||||||
|
* @author Edouard Lafargue Copyright (C) 2010.
|
||||||
|
* @brief
|
||||||
|
* @see The GNU Public License (GPL) Version 3
|
||||||
|
* @defgroup lineardial
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
/*
|
||||||
|
* 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->setDialFile(m->getDialFile());
|
||||||
|
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->connectInput(m->getSourceDataObject(), m->getSourceObjectField());
|
||||||
|
|
||||||
|
}
|
56
ground/src/plugins/lineardial/lineardialgadget.h
Normal file
56
ground/src/plugins/lineardial/lineardialgadget.h
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
*
|
||||||
|
* @file lineardialgadget.h
|
||||||
|
* @author Edouard Lafargue Copyright (C) 2010.
|
||||||
|
* @brief Bargraph gadget with red/yellow/green zones
|
||||||
|
* @see The GNU Public License (GPL) Version 3
|
||||||
|
* @defgroup lineardial
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
/*
|
||||||
|
* 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 LINEARDIALGADGET_H_
|
||||||
|
#define LINEARDIALGADGET_H_
|
||||||
|
|
||||||
|
#include <coreplugin/iuavgadget.h>
|
||||||
|
#include "lineardialgadgetwidget.h"
|
||||||
|
|
||||||
|
class IUAVGadget;
|
||||||
|
class QWidget;
|
||||||
|
class QString;
|
||||||
|
class LineardialGadgetWidget;
|
||||||
|
|
||||||
|
using namespace Core;
|
||||||
|
|
||||||
|
class LineardialGadget : public Core::IUAVGadget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
LineardialGadget(QString classId, LineardialGadgetWidget *widget, QWidget *parent = 0);
|
||||||
|
~LineardialGadget();
|
||||||
|
|
||||||
|
QWidget *widget() { return m_widget; }
|
||||||
|
void loadConfiguration(IUAVGadgetConfiguration* config);
|
||||||
|
|
||||||
|
private:
|
||||||
|
LineardialGadgetWidget *m_widget;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // LINEARDIALGADGET_H_
|
@ -0,0 +1,96 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
*
|
||||||
|
* @file lineardialgadgetconfiguration.cpp
|
||||||
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||||
|
* @brief Linear dial Plugin Gadget configuration
|
||||||
|
* @see The GNU Public License (GPL) Version 3
|
||||||
|
* @defgroup lineardial
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
/*
|
||||||
|
* 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 <QtCore/QDataStream>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads a saved configuration or defaults if non exist.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
LineardialGadgetConfiguration::LineardialGadgetConfiguration(QString classId, const QByteArray &state, 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)
|
||||||
|
{
|
||||||
|
//if a saved configuration exists load it
|
||||||
|
if (state.count() > 0) {
|
||||||
|
QDataStream stream(state);
|
||||||
|
stream >> dialFile;
|
||||||
|
stream >> sourceDataObject;
|
||||||
|
stream >> sourceObjectField;
|
||||||
|
stream >> minValue;
|
||||||
|
stream >> maxValue;
|
||||||
|
stream >> redMin;
|
||||||
|
stream >> redMax;
|
||||||
|
stream >> yellowMin;
|
||||||
|
stream >> yellowMax;
|
||||||
|
stream >> greenMin;
|
||||||
|
stream >> greenMax;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Clones a configuration.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
IUAVGadgetConfiguration *LineardialGadgetConfiguration::clone()
|
||||||
|
{
|
||||||
|
LineardialGadgetConfiguration *m = new LineardialGadgetConfiguration(this->classId());
|
||||||
|
m->dialFile=dialFile;
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Saves a configuration.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
QByteArray LineardialGadgetConfiguration::saveState() const
|
||||||
|
{
|
||||||
|
QByteArray bytes;
|
||||||
|
QDataStream stream(&bytes, QIODevice::WriteOnly);
|
||||||
|
stream << dialFile;
|
||||||
|
stream << sourceDataObject;
|
||||||
|
stream << sourceObjectField;
|
||||||
|
stream << minValue;
|
||||||
|
stream << maxValue;
|
||||||
|
stream << redMin;
|
||||||
|
stream << redMax;
|
||||||
|
stream << yellowMin;
|
||||||
|
stream << yellowMax;
|
||||||
|
stream << greenMin;
|
||||||
|
stream << greenMax;
|
||||||
|
|
||||||
|
return bytes;
|
||||||
|
}
|
@ -0,0 +1,91 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
*
|
||||||
|
* @file lineardialgadgetconfiguration.h
|
||||||
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||||
|
* @brief Airspeed Plugin Gadget configuration
|
||||||
|
* @see The GNU Public License (GPL) Version 3
|
||||||
|
* @defgroup lineardial
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
/*
|
||||||
|
* 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, const QByteArray &state = 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 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;}
|
||||||
|
|
||||||
|
QByteArray saveState() 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 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;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // LINEARDIALGADGETCONFIGURATION_H
|
60
ground/src/plugins/lineardial/lineardialgadgetfactory.cpp
Normal file
60
ground/src/plugins/lineardial/lineardialgadgetfactory.cpp
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
*
|
||||||
|
* @file lineardialgadgetfactory.cpp
|
||||||
|
* @author Edouard Lafargue Copyright (C) 2010.
|
||||||
|
* @brief
|
||||||
|
* @see The GNU Public License (GPL) Version 3
|
||||||
|
* @defgroup lineardial
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
/*
|
||||||
|
* 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 "lineardialgadgetfactory.h"
|
||||||
|
#include "lineardialgadgetwidget.h"
|
||||||
|
#include "lineardialgadget.h"
|
||||||
|
#include "lineardialgadgetconfiguration.h"
|
||||||
|
#include "lineardialgadgetoptionspage.h"
|
||||||
|
#include <coreplugin/iuavgadget.h>
|
||||||
|
|
||||||
|
LineardialGadgetFactory::LineardialGadgetFactory(QObject *parent) :
|
||||||
|
IUAVGadgetFactory(QString("LineardialGadget"),
|
||||||
|
tr("Bargraph Dial Gadget"),
|
||||||
|
parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
LineardialGadgetFactory::~LineardialGadgetFactory()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Core::IUAVGadget* LineardialGadgetFactory::createGadget(QWidget *parent)
|
||||||
|
{
|
||||||
|
LineardialGadgetWidget* gadgetWidget = new LineardialGadgetWidget(parent);
|
||||||
|
return new LineardialGadget(QString("LineardialGadget"), gadgetWidget, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
IUAVGadgetConfiguration *LineardialGadgetFactory::createConfiguration(const QByteArray &state)
|
||||||
|
{
|
||||||
|
return new LineardialGadgetConfiguration(QString("LineardialGadget"), state);
|
||||||
|
}
|
||||||
|
|
||||||
|
IOptionsPage *LineardialGadgetFactory::createOptionsPage(IUAVGadgetConfiguration *config)
|
||||||
|
{
|
||||||
|
return new LineardialGadgetOptionsPage(qobject_cast<LineardialGadgetConfiguration*>(config));
|
||||||
|
}
|
||||||
|
|
52
ground/src/plugins/lineardial/lineardialgadgetfactory.h
Normal file
52
ground/src/plugins/lineardial/lineardialgadgetfactory.h
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
*
|
||||||
|
* @file lineardialgadgetfactory.h
|
||||||
|
* @author Edouard Lafargue Copyright (C) 2010.
|
||||||
|
* @brief
|
||||||
|
* @see The GNU Public License (GPL) Version 3
|
||||||
|
* @defgroup lineardial
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
/*
|
||||||
|
* 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 LINEARDIALGADGETFACTORY_H_
|
||||||
|
#define LINEARDIALGADGETFACTORY_H_
|
||||||
|
|
||||||
|
#include <coreplugin/iuavgadgetfactory.h>
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
class IUAVGadget;
|
||||||
|
class IUAVGadgetFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
using namespace Core;
|
||||||
|
|
||||||
|
class LineardialGadgetFactory : public IUAVGadgetFactory
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
LineardialGadgetFactory(QObject *parent = 0);
|
||||||
|
~LineardialGadgetFactory();
|
||||||
|
|
||||||
|
Core::IUAVGadget *createGadget(QWidget *parent);
|
||||||
|
IUAVGadgetConfiguration *createConfiguration(const QByteArray &state);
|
||||||
|
IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // LINEARDIALGADGETFACTORY_H_
|
@ -0,0 +1,96 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
*
|
||||||
|
* @file lineardialgadgetoptionspage.cpp
|
||||||
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||||
|
* @brief Airspeed Plugin Gadget options page
|
||||||
|
* @see The GNU Public License (GPL) Version 3
|
||||||
|
* @defgroup lineardial
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
/*
|
||||||
|
* 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 <QFileDialog>
|
||||||
|
#include <QtAlgorithms>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
LineardialGadgetOptionsPage::LineardialGadgetOptionsPage(LineardialGadgetConfiguration *config, QObject *parent) :
|
||||||
|
IOptionsPage(parent),
|
||||||
|
m_config(config)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//creates options page widget (uses the UI file)
|
||||||
|
QWidget *LineardialGadgetOptionsPage::createPage(QWidget *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->setText(m_config->getDialFile());
|
||||||
|
|
||||||
|
|
||||||
|
connect(options_page->loadFile, SIGNAL(clicked()), this, SLOT(on_loadFile_clicked()));
|
||||||
|
|
||||||
|
|
||||||
|
return optionsPageWidget;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Called when the user presses apply or OK.
|
||||||
|
*
|
||||||
|
* Saves the current values
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void LineardialGadgetOptionsPage::apply()
|
||||||
|
{
|
||||||
|
m_config->setDialFile(options_page->svgSourceFile->text());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
Opens an open file dialog.
|
||||||
|
|
||||||
|
*/
|
||||||
|
void LineardialGadgetOptionsPage::on_loadFile_clicked()
|
||||||
|
{
|
||||||
|
QFileDialog::Options options;
|
||||||
|
QString selectedFilter;
|
||||||
|
QString fileName = QFileDialog::getOpenFileName(qobject_cast<QWidget*>(this),
|
||||||
|
tr("QFileDialog::getOpenFileName()"),
|
||||||
|
options_page->svgSourceFile->text(),
|
||||||
|
tr("All Files (*);;SVG Files (*.svg)"),
|
||||||
|
&selectedFilter,
|
||||||
|
options);
|
||||||
|
if (!fileName.isEmpty()) options_page->svgSourceFile->setText(fileName);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LineardialGadgetOptionsPage::finish()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
66
ground/src/plugins/lineardial/lineardialgadgetoptionspage.h
Normal file
66
ground/src/plugins/lineardial/lineardialgadgetoptionspage.h
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
*
|
||||||
|
* @file lineardialgadgetoptionspage.h
|
||||||
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||||
|
* @brief Airspeed Plugin Gadget options page
|
||||||
|
* @see The GNU Public License (GPL) Version 3
|
||||||
|
* @defgroup lineardial
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
/*
|
||||||
|
* 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 LINEARDIALGADGETOPTIONSPAGE_H
|
||||||
|
#define LINEARDIALGADGETOPTIONSPAGE_H
|
||||||
|
|
||||||
|
#include "coreplugin/dialogs/ioptionspage.h"
|
||||||
|
#include "QString"
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
class IUAVGadgetConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
class LineardialGadgetConfiguration;
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class LineardialGadgetOptionsPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
using namespace Core;
|
||||||
|
|
||||||
|
class LineardialGadgetOptionsPage : public IOptionsPage
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit LineardialGadgetOptionsPage(LineardialGadgetConfiguration *config, QObject *parent = 0);
|
||||||
|
|
||||||
|
QWidget *createPage(QWidget *parent);
|
||||||
|
void apply();
|
||||||
|
void finish();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::LineardialGadgetOptionsPage *options_page;
|
||||||
|
LineardialGadgetConfiguration *m_config;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void on_loadFile_clicked();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // LINEARDIALGADGETOPTIONSPAGE_H
|
269
ground/src/plugins/lineardial/lineardialgadgetoptionspage.ui
Normal file
269
ground/src/plugins/lineardial/lineardialgadgetoptionspage.ui
Normal file
@ -0,0 +1,269 @@
|
|||||||
|
<?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>486</width>
|
||||||
|
<height>300</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>481</width>
|
||||||
|
<height>339</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout" stretch="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,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="QLineEdit" name="svgSourceFile"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="loadFile">
|
||||||
|
<property name="text">
|
||||||
|
<string>Load file...</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="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>
|
||||||
|
</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>
|
||||||
|
</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>
|
||||||
|
</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>
|
||||||
|
</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>
|
||||||
|
</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>
|
||||||
|
</widget>
|
||||||
|
</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>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
209
ground/src/plugins/lineardial/lineardialgadgetwidget.cpp
Normal file
209
ground/src/plugins/lineardial/lineardialgadgetwidget.cpp
Normal file
@ -0,0 +1,209 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
*
|
||||||
|
* @file lineardialgadgetwidget.cpp
|
||||||
|
* @author Edouard Lafargue Copyright (C) 2010.
|
||||||
|
* @brief
|
||||||
|
* @see The GNU Public License (GPL) Version 3
|
||||||
|
* @defgroup lineardial
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
/*
|
||||||
|
* 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 <iostream>
|
||||||
|
#include <QtGui/QFileDialog>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
LineardialGadgetWidget::LineardialGadgetWidget(QWidget *parent) : QGraphicsView(parent)
|
||||||
|
{
|
||||||
|
setMinimumSize(64,64);
|
||||||
|
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||||
|
setScene(new QGraphicsScene(this));
|
||||||
|
|
||||||
|
m_renderer = new QSvgRenderer();
|
||||||
|
background = new QGraphicsSvgItem();
|
||||||
|
foreground = new QGraphicsSvgItem();
|
||||||
|
bargraph = new QGraphicsSvgItem();
|
||||||
|
green = new QGraphicsSvgItem();
|
||||||
|
yellow = new QGraphicsSvgItem();
|
||||||
|
red = new QGraphicsSvgItem();
|
||||||
|
index = new QGraphicsSvgItem();
|
||||||
|
paint();
|
||||||
|
|
||||||
|
indexTarget = 0;
|
||||||
|
indexValue = 0;
|
||||||
|
|
||||||
|
// This timer mechanism makes needles rotate smoothly
|
||||||
|
connect(&dialTimer, SIGNAL(timeout()), this, SLOT(moveIndex()));
|
||||||
|
dialTimer.start(30);
|
||||||
|
|
||||||
|
// Test code for timer to rotate the needle
|
||||||
|
testSpeed=0;
|
||||||
|
connect(&m_testTimer, SIGNAL(timeout()), this, SLOT(testRotate()));
|
||||||
|
m_testTimer.start(4000);
|
||||||
|
}
|
||||||
|
|
||||||
|
LineardialGadgetWidget::~LineardialGadgetWidget()
|
||||||
|
{
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
void LineardialGadgetWidget::connectInput(QString object1, QString field1) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void LineardialGadgetWidget::setDialFile(QString dfn)
|
||||||
|
{
|
||||||
|
if (QFile::exists(dfn))
|
||||||
|
{
|
||||||
|
m_renderer->load(dfn);
|
||||||
|
if(m_renderer->isValid())
|
||||||
|
{
|
||||||
|
fgenabled = false;
|
||||||
|
|
||||||
|
background->setSharedRenderer(m_renderer);
|
||||||
|
background->setElementId("background");
|
||||||
|
index->setSharedRenderer(m_renderer);
|
||||||
|
index->setElementId("needle");
|
||||||
|
// TODO: transform the green, yellow & red zones
|
||||||
|
// according to their min/max.
|
||||||
|
green->setSharedRenderer(m_renderer);
|
||||||
|
green->setElementId("green");
|
||||||
|
yellow->setSharedRenderer(m_renderer);
|
||||||
|
yellow->setElementId("yellow");
|
||||||
|
red->setSharedRenderer(m_renderer);
|
||||||
|
red->setElementId("red");
|
||||||
|
|
||||||
|
if (m_renderer->elementExists("foreground")) {
|
||||||
|
foreground->setSharedRenderer(m_renderer);
|
||||||
|
foreground->setElementId("foreground");
|
||||||
|
fgenabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout<<"Dial file loaded"<<std::endl;
|
||||||
|
QGraphicsScene *l_scene = scene();
|
||||||
|
|
||||||
|
maxValue = 100;
|
||||||
|
minValue = 0;
|
||||||
|
redMin = 0;
|
||||||
|
redMax = 100;
|
||||||
|
yellowMin = 30;
|
||||||
|
yellowMax = 90;
|
||||||
|
greenMin = 50;
|
||||||
|
greenMax = 70;
|
||||||
|
// Now adjust the red/yellow/green zones:
|
||||||
|
double range = maxValue-minValue;
|
||||||
|
double greenScale = (greenMax-greenMin)/range;
|
||||||
|
double greenStart = greenMin/range*green->boundingRect().width();
|
||||||
|
std::cout << "Width:" << green->boundingRect().width();
|
||||||
|
QTransform matrix;
|
||||||
|
matrix.translate(greenStart,0);
|
||||||
|
matrix.scale(greenScale,1);
|
||||||
|
green->setTransform(matrix,false);
|
||||||
|
|
||||||
|
double yellowScale = (yellowMax-yellowMin)/range;
|
||||||
|
double yellowStart = yellowMin/range*yellow->boundingRect().width();
|
||||||
|
matrix.reset();
|
||||||
|
matrix.translate(yellowStart,0);
|
||||||
|
matrix.scale(yellowScale,1);
|
||||||
|
yellow->setTransform(matrix,false);
|
||||||
|
|
||||||
|
double redScale = (redMax-redMin)/range;
|
||||||
|
double redStart = redMin/range*red->boundingRect().width();
|
||||||
|
matrix.reset();
|
||||||
|
matrix.translate(redStart,0);
|
||||||
|
matrix.scale(redScale,1);
|
||||||
|
red->setTransform(matrix,false);
|
||||||
|
|
||||||
|
|
||||||
|
l_scene->setSceneRect(background->boundingRect());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ std::cout<<"no file: "<<std::endl; }
|
||||||
|
}
|
||||||
|
|
||||||
|
void LineardialGadgetWidget::paint()
|
||||||
|
{
|
||||||
|
|
||||||
|
QGraphicsScene *l_scene = scene();
|
||||||
|
l_scene->clear();
|
||||||
|
|
||||||
|
l_scene->addItem(background);
|
||||||
|
// Order is important: red, then yellow then green
|
||||||
|
// overlayed on top of each other
|
||||||
|
l_scene->addItem(red);
|
||||||
|
l_scene->addItem(yellow);
|
||||||
|
l_scene->addItem(green);
|
||||||
|
l_scene->addItem(index);
|
||||||
|
l_scene->addItem(foreground);
|
||||||
|
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LineardialGadgetWidget::paintEvent(QPaintEvent *event)
|
||||||
|
{
|
||||||
|
// Skip painting until the dial file is loaded
|
||||||
|
if (! m_renderer->isValid()) {
|
||||||
|
std::cout<<"Dial file not loaded, not rendering"<<std::endl;
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
fitInView(background, Qt::KeepAspectRatio );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Converts the value into an percentage:
|
||||||
|
// this enables smooth movement in moveIndex below
|
||||||
|
void LineardialGadgetWidget::setIndex(double value) {
|
||||||
|
indexTarget = 100*(value-minValue)/maxValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 ((abs((indexValue-indexTarget)*10) > 3)) {
|
||||||
|
indexValue += (indexTarget - indexValue)/10;
|
||||||
|
index->resetTransform();
|
||||||
|
double factor = index->boundingRect().width()/100;
|
||||||
|
index->translate(indexValue*factor,0);
|
||||||
|
}
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Test function for timer to rotate needles
|
||||||
|
void LineardialGadgetWidget::testRotate()
|
||||||
|
{
|
||||||
|
int testVal = rand() % (int)maxValue;
|
||||||
|
setIndex((double)testVal);
|
||||||
|
|
||||||
|
}
|
102
ground/src/plugins/lineardial/lineardialgadgetwidget.h
Normal file
102
ground/src/plugins/lineardial/lineardialgadgetwidget.h
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
*
|
||||||
|
* @file lineardialgadgetwidget.h
|
||||||
|
* @author Edouard Lafargue Copyright (C) 2010.
|
||||||
|
* @brief
|
||||||
|
* @see The GNU Public License (GPL) Version 3
|
||||||
|
* @defgroup lineardial
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
/*
|
||||||
|
* 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 <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; yellowMax=max;}
|
||||||
|
void connectInput(QString obj, QString field);
|
||||||
|
|
||||||
|
void setIndex(double val);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paintEvent(QPaintEvent *event);
|
||||||
|
void resizeEvent(QResizeEvent *event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
// Test function
|
||||||
|
void testRotate();
|
||||||
|
void moveIndex();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QSvgRenderer *m_renderer;
|
||||||
|
QGraphicsSvgItem *background;
|
||||||
|
QGraphicsSvgItem *foreground;
|
||||||
|
QGraphicsSvgItem *bargraph;
|
||||||
|
QGraphicsSvgItem *index;
|
||||||
|
QGraphicsSvgItem *green;
|
||||||
|
QGraphicsSvgItem *yellow;
|
||||||
|
QGraphicsSvgItem *red;
|
||||||
|
|
||||||
|
// Simple flag to skip rendering if the
|
||||||
|
bool fgenabled; // layer does not exist.
|
||||||
|
|
||||||
|
double minValue;
|
||||||
|
double maxValue;
|
||||||
|
double greenMin;
|
||||||
|
double greenMax;
|
||||||
|
double yellowMin;
|
||||||
|
double yellowMax;
|
||||||
|
double redMin;
|
||||||
|
double redMax;
|
||||||
|
|
||||||
|
// The Value and target variables
|
||||||
|
// are expressed in degrees
|
||||||
|
double indexTarget;
|
||||||
|
double indexValue;
|
||||||
|
|
||||||
|
// Rotation timer
|
||||||
|
QTimer dialTimer;
|
||||||
|
|
||||||
|
// Test variables
|
||||||
|
int testSpeed;
|
||||||
|
QTimer m_testTimer;
|
||||||
|
// End test variables
|
||||||
|
};
|
||||||
|
#endif /* LINEARDIALGADGETWIDGET_H_ */
|
66
ground/src/plugins/lineardial/lineardialplugin.cpp
Normal file
66
ground/src/plugins/lineardial/lineardialplugin.cpp
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
*
|
||||||
|
* @file lineardialplugin.h
|
||||||
|
* @author Edouard Lafargue Copyright (C) 2010.
|
||||||
|
* @brief
|
||||||
|
* @see The GNU Public License (GPL) Version 3
|
||||||
|
* @defgroup lineardial
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
/*
|
||||||
|
* 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 "lineardialplugin.h"
|
||||||
|
#include "lineardialgadgetfactory.h"
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QtPlugin>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
|
||||||
|
|
||||||
|
LineardialPlugin::LineardialPlugin()
|
||||||
|
{
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
LineardialPlugin::~LineardialPlugin()
|
||||||
|
{
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LineardialPlugin::initialize(const QStringList& args, QString *errMsg)
|
||||||
|
{
|
||||||
|
Q_UNUSED(args);
|
||||||
|
Q_UNUSED(errMsg);
|
||||||
|
mf = new LineardialGadgetFactory(this);
|
||||||
|
addAutoReleasedObject(mf);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LineardialPlugin::extensionsInitialized()
|
||||||
|
{
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
void LineardialPlugin::shutdown()
|
||||||
|
{
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
Q_EXPORT_PLUGIN(LineardialPlugin)
|
||||||
|
|
47
ground/src/plugins/lineardial/lineardialplugin.h
Normal file
47
ground/src/plugins/lineardial/lineardialplugin.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
*
|
||||||
|
* @file lineardialplugin.h
|
||||||
|
* @author Edouard Lafargue Copyright (C) 2010.
|
||||||
|
* @brief
|
||||||
|
* @see The GNU Public License (GPL) Version 3
|
||||||
|
* @defgroup lineardial
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
/*
|
||||||
|
* 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 LINEARDIALPLUGIN_H_
|
||||||
|
#define LINEARDIALPLUGIN_H_
|
||||||
|
|
||||||
|
#include <extensionsystem/iplugin.h>
|
||||||
|
|
||||||
|
class LineardialGadgetFactory;
|
||||||
|
|
||||||
|
class LineardialPlugin : public ExtensionSystem::IPlugin
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LineardialPlugin();
|
||||||
|
~LineardialPlugin();
|
||||||
|
|
||||||
|
void extensionsInitialized();
|
||||||
|
bool initialize(const QStringList & arguments, QString * errorString);
|
||||||
|
void shutdown();
|
||||||
|
private:
|
||||||
|
LineardialGadgetFactory *mf;
|
||||||
|
};
|
||||||
|
#endif /* LINEARDIALPLUGIN_H_ */
|
@ -75,6 +75,11 @@ plugin_airspeed.subdir = airspeed
|
|||||||
plugin_airspeed.depends = plugin_coreplugin
|
plugin_airspeed.depends = plugin_coreplugin
|
||||||
SUBDIRS += plugin_airspeed
|
SUBDIRS += plugin_airspeed
|
||||||
|
|
||||||
|
#Linear Dial Gadget
|
||||||
|
plugin_lineardial.subdir = lineardial
|
||||||
|
plugin_lineardial.depends = plugin_coreplugin
|
||||||
|
SUBDIRS += plugin_lineardial
|
||||||
|
|
||||||
#Config Gadget
|
#Config Gadget
|
||||||
plugin_config.subdir = config
|
plugin_config.subdir = config
|
||||||
plugin_config.depends = plugin_coreplugin
|
plugin_config.depends = plugin_coreplugin
|
||||||
|
Loading…
x
Reference in New Issue
Block a user