1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

Settings for SVG analog dials all finalized except actual connection to UAVObjects. The test code randomly assigns values to the dials to demonstrate smooth needle rotation. Let me know if you like it!

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@570 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
edouard 2010-05-02 14:07:00 +00:00 committed by edouard
parent 2ab8ea6eb3
commit 61804f91dd
5 changed files with 169 additions and 56 deletions

View File

@ -48,6 +48,11 @@ AirspeedGadget::~AirspeedGadget()
void AirspeedGadget::loadConfiguration(IUAVGadgetConfiguration* config) void AirspeedGadget::loadConfiguration(IUAVGadgetConfiguration* config)
{ {
AirspeedGadgetConfiguration *m = qobject_cast<AirspeedGadgetConfiguration*>(config); AirspeedGadgetConfiguration *m = qobject_cast<AirspeedGadgetConfiguration*>(config);
m_widget->setDialFile(m->dialFile()); m_widget->setDialFile(m->dialFile(), m->dialBackground(), m->dialForeground(), m->dialNeedle1(),
m->dialNeedle2());
m_widget->setN1Min(m->getN1Min());
m_widget->setN1Max(m->getN1Max());
m_widget->setN2Min(m->getN2Min());
m_widget->setN2Max(m->getN2Max());
} }

View File

@ -55,6 +55,10 @@ QWidget *AirspeedGadgetOptionsPage::createPage(QWidget *parent)
options_page->foregroundID->setText(m_config->dialForeground()); options_page->foregroundID->setText(m_config->dialForeground());
options_page->needle1ID->setText(m_config->dialNeedle1()); options_page->needle1ID->setText(m_config->dialNeedle1());
options_page->needle2ID->setText(m_config->dialNeedle2()); options_page->needle2ID->setText(m_config->dialNeedle2());
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());
connect(options_page->loadFile, SIGNAL(clicked()), this, SLOT(on_loadFile_clicked())); connect(options_page->loadFile, SIGNAL(clicked()), this, SLOT(on_loadFile_clicked()));
@ -70,6 +74,14 @@ QWidget *AirspeedGadgetOptionsPage::createPage(QWidget *parent)
void AirspeedGadgetOptionsPage::apply() void AirspeedGadgetOptionsPage::apply()
{ {
m_config->setDialFile(options_page->svgSourceFile->text()); m_config->setDialFile(options_page->svgSourceFile->text());
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->setN1Min(options_page->needle1Min->value());
m_config->setN1Max(options_page->needle1Max->value());
m_config->setN2Min(options_page->needle2Min->value());
m_config->setN2Max(options_page->needle2Max->value());
} }

View File

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>513</width> <width>486</width>
<height>300</height> <height>300</height>
</rect> </rect>
</property> </property>
@ -24,11 +24,14 @@
<rect> <rect>
<x>-1</x> <x>-1</x>
<y>-1</y> <y>-1</y>
<width>511</width> <width>481</width>
<height>339</height> <height>339</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0,0,0,0"> <layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0,0,0,0">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<property name="leftMargin"> <property name="leftMargin">
<number>10</number> <number>10</number>
</property> </property>
@ -137,7 +140,14 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="needle1ID"/> <widget class="QLineEdit" name="needle1ID">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_6"> <widget class="QLabel" name="label_6">
@ -147,7 +157,17 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QDoubleSpinBox" name="needle1Min"/> <widget class="QDoubleSpinBox" name="needle1Min">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_7"> <widget class="QLabel" name="label_7">
@ -157,7 +177,17 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QDoubleSpinBox" name="needle1Max"/> <widget class="QDoubleSpinBox" name="needle1Max">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item> </item>
</layout> </layout>
</item> </item>
@ -174,7 +204,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_4"/> <widget class="QLineEdit" name="uavObject1"/>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_9"> <widget class="QLabel" name="label_9">
@ -184,7 +214,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_5"/> <widget class="QLineEdit" name="objectField1"/>
</item> </item>
</layout> </layout>
</item> </item>
@ -225,7 +255,14 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="needle2ID"/> <widget class="QLineEdit" name="needle2ID">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_18"> <widget class="QLabel" name="label_18">
@ -235,7 +272,17 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QDoubleSpinBox" name="needle2Min"/> <widget class="QDoubleSpinBox" name="needle2Min">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_19"> <widget class="QLabel" name="label_19">
@ -245,7 +292,17 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QDoubleSpinBox" name="needle2Max"/> <widget class="QDoubleSpinBox" name="needle2Max">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item> </item>
</layout> </layout>
</item> </item>
@ -262,7 +319,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_10"/> <widget class="QLineEdit" name="uavObject2"/>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_21"> <widget class="QLabel" name="label_21">
@ -272,7 +329,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="lineEdit_11"/> <widget class="QLineEdit" name="objectField2"/>
</item> </item>
</layout> </layout>
</item> </item>

View File

@ -40,17 +40,22 @@ AirspeedGadgetWidget::AirspeedGadgetWidget(QWidget *parent) : QGraphicsView(pare
m_renderer = new QSvgRenderer(); m_renderer = new QSvgRenderer();
m_background = new QGraphicsSvgItem(); m_background = new QGraphicsSvgItem();
m_foreground = new QGraphicsSvgItem(); m_foreground = new QGraphicsSvgItem();
m_desired = new QGraphicsSvgItem(); m_needle1 = new QGraphicsSvgItem();
m_actual = new QGraphicsSvgItem(); m_needle2 = new QGraphicsSvgItem();
//setDialFile(QFileDialog::getOpenFileName(qobject_cast<QWidget*>(this),
// tr("Airspeed Dial"), "../artwork/", tr("SVG File (*.svg)")) );
//setDialFile(QString("/usr/src/openpilot/artwork/Dials/extracts/speed-complete.svg"));
paint(); paint();
needle1Target = 0;
needle2Target = 0;
needle1Value = 0;
needle2Value = 0;
connect(&dialTimer, SIGNAL(timeout()), this, SLOT(rotateNeedles()));
dialTimer.start(30);
// Test code for timer to rotate the needle // Test code for timer to rotate the needle
testSpeed=0; testSpeed=0;
connect(&m_testTimer, SIGNAL(timeout()), this, SLOT(testRotate())); connect(&m_testTimer, SIGNAL(timeout()), this, SLOT(testRotate()));
m_testTimer.start(60); m_testTimer.start(4000);
} }
AirspeedGadgetWidget::~AirspeedGadgetWidget() AirspeedGadgetWidget::~AirspeedGadgetWidget()
@ -58,24 +63,26 @@ AirspeedGadgetWidget::~AirspeedGadgetWidget()
// Do nothing // Do nothing
} }
void AirspeedGadgetWidget::setDialFile(QString dfn) void AirspeedGadgetWidget::setDialFile(QString dfn, QString bg, QString fg, QString n1, QString n2)
{ {
if (QFile::exists(dfn)) if (QFile::exists(dfn))
{ {
m_renderer->load(dfn); m_renderer->load(dfn);
if(m_renderer->isValid()) if(m_renderer->isValid())
{ {
m_background->setSharedRenderer(m_renderer); m_background->setSharedRenderer(m_renderer);
m_background->setElementId(QString("background")); m_background->setElementId(bg);
m_foreground->setSharedRenderer(m_renderer); m_foreground->setSharedRenderer(m_renderer);
m_foreground->setElementId(QString("foreground")); m_foreground->setElementId(fg);
m_desired->setSharedRenderer(m_renderer); m_needle1->setSharedRenderer(m_renderer);
m_desired->setElementId(QString("desired")); m_needle1->setElementId(n1);
m_needle2->setSharedRenderer(m_renderer);
m_needle2->setElementId(n2);
m_actual->setSharedRenderer(m_renderer);
m_actual->setElementId(QString("needle"));
std::cout<<"Dial file loaded"<<std::endl; std::cout<<"Dial file loaded"<<std::endl;
QGraphicsScene *l_scene = scene(); QGraphicsScene *l_scene = scene();
@ -94,8 +101,8 @@ void AirspeedGadgetWidget::paint()
l_scene->clear(); l_scene->clear();
l_scene->addItem(m_background); l_scene->addItem(m_background);
l_scene->addItem(m_desired); l_scene->addItem(m_needle1);
l_scene->addItem(m_actual); l_scene->addItem(m_needle2);
l_scene->addItem(m_foreground); l_scene->addItem(m_foreground);
l_scene->setSceneRect(m_background->boundingRect()); l_scene->setSceneRect(m_background->boundingRect());
@ -120,33 +127,46 @@ void AirspeedGadgetWidget::resizeEvent(QResizeEvent *event)
fitInView(m_background, Qt::KeepAspectRatio ); fitInView(m_background, Qt::KeepAspectRatio );
} }
// Take a unitless speed value and sets the actual needle accordingly void AirspeedGadgetWidget::setNeedle1(double value) {
// scale fixed at 0-90 for now needle1Target = value;
void AirspeedGadgetWidget::setActual(int speed) }
void AirspeedGadgetWidget::setNeedle2(double value) {
needle2Target = value;
}
// Take an input value and rotate the dial accordingly
void AirspeedGadgetWidget::rotateNeedles()
{ {
m_actual->resetTransform(); if (needle2Value != needle2Target) {
QRectF rect = m_actual->boundingRect(); (needle2Value > needle2Target) ? needle2Value-- : needle2Value++;
m_actual->translate(rect.width()/2,rect.height()/2); m_needle2->resetTransform();
m_actual->rotate(speed*3); QRectF rect = m_needle2->boundingRect();
m_actual->translate(-rect.width()/2,-rect.height()/2); m_needle2->translate(rect.width()/2,rect.height()/2);
m_needle2->rotate(360*needle2Value/n2MaxValue);
m_needle2->translate(-rect.width()/2,-rect.height()/2);
}
if (needle1Value != needle1Target) {
(needle1Value > needle1Target) ? needle1Value-- : needle1Value++;
m_needle1->resetTransform();
QRectF rect = m_needle1->boundingRect();
m_needle1->translate(rect.width()/2,rect.height()/2);
m_needle1->rotate(360*needle1Value/n1MaxValue);
m_needle1->translate(-rect.width()/2,-rect.height()/2);
}
update(); update();
} }
// Take a unitless speed value and sets the desired needle accordingly
// scale fixed at 0-90 for now
void AirspeedGadgetWidget::setDesired(int speed)
{
m_desired->resetTransform();
QRectF rect = m_desired->boundingRect();
m_desired->translate(rect.width()/2,rect.height()/2);
m_desired->rotate(speed*3);
m_desired->translate(-rect.width()/2,-rect.height()/2);
update();
}
// Test function for timer to rotate needles // Test function for timer to rotate needles
void AirspeedGadgetWidget::testRotate() void AirspeedGadgetWidget::testRotate()
{ {
if(testSpeed==90) testSpeed=0; int testVal1 = rand() % (int)n1MaxValue;
setActual(testSpeed++); int testVal2 = rand() % (int)n2MaxValue;
setNeedle1((double)testVal1);
setNeedle2((double)testVal2);
} }

View File

@ -28,6 +28,7 @@
#ifndef AIRSPEEDGADGETWIDGET_H_ #ifndef AIRSPEEDGADGETWIDGET_H_
#define AIRSPEEDGADGETWIDGET_H_ #define AIRSPEEDGADGETWIDGET_H_
#include "airspeedgadgetconfiguration.h"
#include <QGraphicsView> #include <QGraphicsView>
#include <QtSvg/QSvgRenderer> #include <QtSvg/QSvgRenderer>
#include <QtSvg/QGraphicsSvgItem> #include <QtSvg/QGraphicsSvgItem>
@ -43,10 +44,16 @@ class AirspeedGadgetWidget : public QGraphicsView
public: public:
AirspeedGadgetWidget(QWidget *parent = 0); AirspeedGadgetWidget(QWidget *parent = 0);
~AirspeedGadgetWidget(); ~AirspeedGadgetWidget();
void setDialFile(QString dfn); void setDialFile(QString dfn, QString bg, QString fg, QString n1, QString n2);
void paint(); void paint();
void setActual(int speed); // setNeedle1 and setNeedle2 use a timer to simulate
void setDesired(int speed); // needle inertia
void setNeedle1(double value);
void setNeedle2(double value);
void setN1Min(double value) {n1MinValue = value;}
void setN1Max(double value) {n1MaxValue = value;}
void setN2Min(double value) {n1MinValue = value;}
void setN2Max(double value) {n2MaxValue = value;}
protected: protected:
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event);
@ -54,17 +61,29 @@ protected:
private: private:
// Test functions
private slots: private slots:
// Test function
void testRotate(); void testRotate();
// End test functions void rotateNeedles();
private: private:
QSvgRenderer *m_renderer; QSvgRenderer *m_renderer;
QGraphicsSvgItem *m_background; QGraphicsSvgItem *m_background;
QGraphicsSvgItem *m_foreground; QGraphicsSvgItem *m_foreground;
QGraphicsSvgItem *m_desired; QGraphicsSvgItem *m_needle1;
QGraphicsSvgItem *m_actual; QGraphicsSvgItem *m_needle2;
double n1MinValue;
double n1MaxValue;
double n2MinValue;
double n2MaxValue;
double needle1Target;
double needle1Value;
double needle2Target;
double needle2Value;
// Rotation timer
QTimer dialTimer;
// Test variables // Test variables
int testSpeed; int testSpeed;