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

Full featured option page for analog dials up to two analog indicators. Ongoing work, the settings are not fully active yet.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@569 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
edouard 2010-05-02 11:13:18 +00:00 committed by edouard
parent 06dac9cb09
commit 2ab8ea6eb3
8 changed files with 414 additions and 80 deletions

View File

@ -1,22 +1,20 @@
TEMPLATE = lib
TARGET = AirspeedGadget
QT += svg
include(../../openpilotgcsplugin.pri)
include(../../plugins/coreplugin/coreplugin.pri)
include(../../libs/qwt/qwt.pri)
HEADERS += airspeedplugin.h
HEADERS += airspeedgadget.h
HEADERS += airspeedgadgetwidget.h
HEADERS += airspeedgadgetfactory.h
HEADERS += airspeedgadgetconfiguration.h
HEADERS += airspeedgadgetoptionspage.h
SOURCES += airspeedplugin.cpp
SOURCES += airspeedgadget.cpp
SOURCES += airspeedgadgetfactory.cpp
SOURCES += airspeedgadgetwidget.cpp
SOURCES += airspeedgadgetconfiguration.cpp
SOURCES += airspeedgadgetoptionspage.cpp
OTHER_FILES += AirspeedGadget.pluginspec
TEMPLATE = lib
TARGET = AirspeedGadget
QT += svg
include(../../openpilotgcsplugin.pri)
include(../../plugins/coreplugin/coreplugin.pri)
include(../../libs/qwt/qwt.pri)
HEADERS += airspeedplugin.h
HEADERS += airspeedgadget.h
HEADERS += airspeedgadgetwidget.h
HEADERS += airspeedgadgetfactory.h
HEADERS += airspeedgadgetconfiguration.h
HEADERS += airspeedgadgetoptionspage.h
SOURCES += airspeedplugin.cpp
SOURCES += airspeedgadget.cpp
SOURCES += airspeedgadgetfactory.cpp
SOURCES += airspeedgadgetwidget.cpp
SOURCES += airspeedgadgetconfiguration.cpp
SOURCES += airspeedgadgetoptionspage.cpp
OTHER_FILES += AirspeedGadget.pluginspec
FORMS += airspeedgadgetoptionspage.ui

View File

@ -37,9 +37,14 @@ AirspeedGadget::AirspeedGadget(QString classId, AirspeedGadgetWidget *widget, QW
AirspeedGadget::~AirspeedGadget()
{
}
/*
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 AirspeedGadget::loadConfiguration(IUAVGadgetConfiguration* config)
{
AirspeedGadgetConfiguration *m = qobject_cast<AirspeedGadgetConfiguration*>(config);

View File

@ -34,7 +34,15 @@
*/
AirspeedGadgetConfiguration::AirspeedGadgetConfiguration(QString classId, const QByteArray &state, QObject *parent) :
IUAVGadgetConfiguration(classId, parent),
m_defaultDial("Unknown")
m_defaultDial("Unknown"),
dialBackgroundID("background"),
dialForegroundID("foreground"),
dialNeedleID1("needle"),
dialNeedleID2("needle-2"),
needle1MinValue(0),
needle1MaxValue(100),
needle2MinValue(0),
needle2MaxValue(100)
{
//if a saved configuration exists load it
if (state.count() > 0) {
@ -42,6 +50,15 @@ AirspeedGadgetConfiguration::AirspeedGadgetConfiguration(QString classId, const
QString dialFile;
stream >> dialFile;
m_defaultDial=dialFile;
stream >> dialBackgroundID;
stream >> dialForegroundID;
stream >> dialNeedleID1;
stream >> dialNeedleID2;
stream >> needle1MinValue;
stream >> needle1MaxValue;
stream >> needle2MinValue;
stream >> needle2MaxValue;
}
}
/**
@ -63,5 +80,13 @@ QByteArray AirspeedGadgetConfiguration::saveState() const
QByteArray bytes;
QDataStream stream(&bytes, QIODevice::WriteOnly);
stream << m_defaultDial;
stream << dialBackgroundID;
stream << dialForegroundID;
stream << dialNeedleID1;
stream << dialNeedleID2;
stream << needle1MinValue;
stream << needle1MaxValue;
stream << needle2MinValue;
stream << needle2MaxValue;
return bytes;
}

View File

@ -32,6 +32,9 @@
using namespace Core;
/* Despite its name, this is actually a generic analog dial
supporting up to two rotating "needle" indicators.
*/
class AirspeedGadgetConfiguration : public IUAVGadgetConfiguration
{
Q_OBJECT
@ -40,17 +43,41 @@ public:
//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 setN1Min(double val) { needle1MinValue = val;}
void setN2Min(double val) { needle2MinValue = val;}
void setN1Max(double val) { needle1MaxValue = val;}
void setN2Max(double val) { needle2MaxValue = val;}
//get port configuration functions
//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;}
double getN1Min() { return needle1MinValue;}
double getN2Min() { return needle2MinValue;}
double getN1Max() { return needle1MaxValue;}
double getN2Max() { return needle2MaxValue;}
QByteArray saveState() const;
IUAVGadgetConfiguration *clone();
private:
QString m_defaultDial;
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
// TODO: define additional elements such as secondary needle
double needle1MinValue; // Value corresponding to a 0 degree angle;
double needle1MaxValue; // Value corresponding to a 360 degree angle;
double needle2MinValue;
double needle2MaxValue;
};
#endif // AIRSPEEDGADGETCONFIGURATION_H

View File

@ -27,15 +27,8 @@
#include "airspeedgadgetoptionspage.h"
#include "airspeedgadgetconfiguration.h"
#include <QtGui/QLabel>
#include <QtGui/QSpinBox>
#include <QtGui/QDoubleSpinBox>
#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>
#include <QtGui/QTextEdit>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QComboBox>
#include "ui_airspeedgadgetoptionspage.h"
#include <QFileDialog>
#include <QtAlgorithms>
#include <QStringList>
@ -46,47 +39,25 @@ AirspeedGadgetOptionsPage::AirspeedGadgetOptionsPage(AirspeedGadgetConfiguration
{
}
//creates options page widget
//creates options page widget (uses the UI file)
QWidget *AirspeedGadgetOptionsPage::createPage(QWidget *parent)
{
options_page = new Ui::AirspeedGadgetOptionsPage();
//main widget
QWidget *optionsPageWidget = new QWidget;
//main layout
QVBoxLayout *vl = new QVBoxLayout();
optionsPageWidget->setLayout(vl);
//SVG file select layout and widget
//choose file layout and widget
QHBoxLayout *FileLayout = new QHBoxLayout;
QWidget *FileWidget = new QWidget;
FileWidget->setLayout(FileLayout);
QWidget *label = new QLabel("Dial SVG:");
svgSourceFile = new QLineEdit();
QPushButton* loadfile = new QPushButton("Load File");
loadfile->setMaximumWidth(80);
FileLayout->addWidget(label);
FileLayout->addWidget(svgSourceFile);
FileLayout->addWidget(loadfile);
QSpacerItem *spacer = new QSpacerItem(100, 100, QSizePolicy::Expanding, QSizePolicy::Expanding);
//add partial widget to main widget
vl->addWidget(FileWidget);
vl->addSpacerItem(spacer);
//clears comboboxes, if not every time the user enters options page the lists
//duplicate
svgSourceFile->clear();
//connect signals to slots
//fires when the user presses file button
connect(loadfile, SIGNAL(clicked(bool)),
this,SLOT(setOpenFileName()));
options_page->setupUi(optionsPageWidget);
// Restore the contents from the settings:
svgSourceFile->setText(m_config->dialFile());
options_page->svgSourceFile->setText(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());
connect(options_page->loadFile, SIGNAL(clicked()), this, SLOT(on_loadFile_clicked()));
return optionsPageWidget;
}
@ -98,7 +69,7 @@ QWidget *AirspeedGadgetOptionsPage::createPage(QWidget *parent)
*/
void AirspeedGadgetOptionsPage::apply()
{
m_config->setDialFile(svgSourceFile->text());
m_config->setDialFile(options_page->svgSourceFile->text());
}
@ -107,17 +78,17 @@ void AirspeedGadgetOptionsPage::apply()
Opens an open file dialog.
*/
void AirspeedGadgetOptionsPage::setOpenFileName()
void AirspeedGadgetOptionsPage::on_loadFile_clicked()
{
QFileDialog::Options options;
QString selectedFilter;
QString fileName = QFileDialog::getOpenFileName(qobject_cast<QWidget*>(this),
tr("QFileDialog::getOpenFileName()"),
svgSourceFile->text(),
options_page->svgSourceFile->text(),
tr("All Files (*);;SVG Files (*.svg)"),
&selectedFilter,
options);
if (!fileName.isEmpty()) svgSourceFile->setText(fileName);
if (!fileName.isEmpty()) options_page->svgSourceFile->setText(fileName);
}

View File

@ -36,10 +36,12 @@
namespace Core {
class IUAVGadgetConfiguration;
}
class AirspeedGadgetConfiguration;
class QTextEdit;
class QLineEdit;
class QSpinBox;
namespace Ui {
class AirspeedGadgetOptionsPage;
}
using namespace Core;
@ -54,11 +56,11 @@ public:
void finish();
private:
Ui::AirspeedGadgetOptionsPage *options_page;
AirspeedGadgetConfiguration *m_config;
QLineEdit* svgSourceFile;
private slots:
void setOpenFileName();
void on_loadFile_clicked();
};
#endif // AIRSPEEDGADGETOPTIONSPAGE_H

View File

@ -0,0 +1,306 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AirspeedGadgetOptionsPage</class>
<widget class="QWidget" name="AirspeedGadgetOptionsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>513</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>511</width>
<height>339</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0,0,0,0">
<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="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="Line" name="line_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Indicator 1</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="topMargin">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>ID</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="needle1ID"/>
</item>
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>Min</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="needle1Min"/>
</item>
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Max</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="needle1Max"/>
</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="QLineEdit" name="lineEdit_4"/>
</item>
<item>
<widget class="QLabel" name="label_9">
<property name="text">
<string>ObjectField</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_5"/>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="label_16">
<property name="text">
<string>Indicator 2</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<property name="topMargin">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="label_17">
<property name="text">
<string>ID</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="needle2ID"/>
</item>
<item>
<widget class="QLabel" name="label_18">
<property name="text">
<string>Min</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="needle2Min"/>
</item>
<item>
<widget class="QLabel" name="label_19">
<property name="text">
<string>Max</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="needle2Max"/>
</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="QLineEdit" name="lineEdit_10"/>
</item>
<item>
<widget class="QLabel" name="label_21">
<property name="text">
<string>ObjectField</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_11"/>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</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>

View File

@ -94,9 +94,9 @@ void AirspeedGadgetWidget::paint()
l_scene->clear();
l_scene->addItem(m_background);
l_scene->addItem(m_foreground);
l_scene->addItem(m_desired);
l_scene->addItem(m_actual);
l_scene->addItem(m_foreground);
l_scene->setSceneRect(m_background->boundingRect());
update();