mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
Updates to airspeed gadget: the background SVG file is now defined in the configuration options, is properly saved and restored between sessions, etc. Several dial configurations can be defined. Next step is to enhance the configuration system to create generic dials.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@568 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
ff722b21e1
commit
06dac9cb09
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "airspeedgadget.h"
|
#include "airspeedgadget.h"
|
||||||
#include "airspeedgadgetwidget.h"
|
#include "airspeedgadgetwidget.h"
|
||||||
|
#include "airspeedgadgetconfiguration.h"
|
||||||
|
|
||||||
AirspeedGadget::AirspeedGadget(QString classId, AirspeedGadgetWidget *widget, QWidget *parent) :
|
AirspeedGadget::AirspeedGadget(QString classId, AirspeedGadgetWidget *widget, QWidget *parent) :
|
||||||
IUAVGadget(classId, parent),
|
IUAVGadget(classId, parent),
|
||||||
@ -38,3 +39,10 @@ AirspeedGadget::~AirspeedGadget()
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AirspeedGadget::loadConfiguration(IUAVGadgetConfiguration* config)
|
||||||
|
{
|
||||||
|
AirspeedGadgetConfiguration *m = qobject_cast<AirspeedGadgetConfiguration*>(config);
|
||||||
|
m_widget->setDialFile(m->dialFile());
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -46,6 +46,7 @@ public:
|
|||||||
~AirspeedGadget();
|
~AirspeedGadget();
|
||||||
|
|
||||||
QWidget *widget() { return m_widget; }
|
QWidget *widget() { return m_widget; }
|
||||||
|
void loadConfiguration(IUAVGadgetConfiguration* config);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AirspeedGadgetWidget *m_widget;
|
AirspeedGadgetWidget *m_widget;
|
||||||
|
@ -43,7 +43,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
//get port configuration functions
|
//get port configuration functions
|
||||||
QString dialFile(){return m_defaultDial;}
|
QString dialFile() {return m_defaultDial;}
|
||||||
|
|
||||||
QByteArray saveState() const;
|
QByteArray saveState() const;
|
||||||
IUAVGadgetConfiguration *clone();
|
IUAVGadgetConfiguration *clone();
|
||||||
|
@ -33,7 +33,10 @@
|
|||||||
#include <QtGui/QHBoxLayout>
|
#include <QtGui/QHBoxLayout>
|
||||||
#include <QtGui/QVBoxLayout>
|
#include <QtGui/QVBoxLayout>
|
||||||
#include <QtGui/QTextEdit>
|
#include <QtGui/QTextEdit>
|
||||||
|
#include <QtGui/QLineEdit>
|
||||||
|
#include <QtGui/QPushButton>
|
||||||
#include <QtGui/QComboBox>
|
#include <QtGui/QComboBox>
|
||||||
|
#include <QFileDialog>
|
||||||
#include <QtAlgorithms>
|
#include <QtAlgorithms>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
@ -47,33 +50,45 @@ AirspeedGadgetOptionsPage::AirspeedGadgetOptionsPage(AirspeedGadgetConfiguration
|
|||||||
QWidget *AirspeedGadgetOptionsPage::createPage(QWidget *parent)
|
QWidget *AirspeedGadgetOptionsPage::createPage(QWidget *parent)
|
||||||
{
|
{
|
||||||
//main widget
|
//main widget
|
||||||
QWidget *widget = new QWidget;
|
QWidget *optionsPageWidget = new QWidget;
|
||||||
//main layout
|
//main layout
|
||||||
QVBoxLayout *vl = new QVBoxLayout();
|
QVBoxLayout *vl = new QVBoxLayout();
|
||||||
widget->setLayout(vl);
|
optionsPageWidget->setLayout(vl);
|
||||||
|
|
||||||
//port layout and widget
|
//SVG file select layout and widget
|
||||||
QHBoxLayout *portLayout = new QHBoxLayout();
|
//choose file layout and widget
|
||||||
QWidget *x = new QWidget;
|
QHBoxLayout *FileLayout = new QHBoxLayout;
|
||||||
x->setLayout(portLayout);
|
QWidget *FileWidget = new QWidget;
|
||||||
|
FileWidget->setLayout(FileLayout);
|
||||||
QWidget *label = new QLabel("Dial SVG:");
|
QWidget *label = new QLabel("Dial SVG:");
|
||||||
m_portCB = new QComboBox(parent);
|
svgSourceFile = new QLineEdit();
|
||||||
m_portCB->setMinimumSize(200,22);
|
QPushButton* loadfile = new QPushButton("Load File");
|
||||||
portLayout->addWidget(label);
|
loadfile->setMaximumWidth(80);
|
||||||
portLayout->addWidget(m_portCB);
|
FileLayout->addWidget(label);
|
||||||
|
FileLayout->addWidget(svgSourceFile);
|
||||||
|
FileLayout->addWidget(loadfile);
|
||||||
|
|
||||||
|
|
||||||
QSpacerItem *spacer = new QSpacerItem(100, 100, QSizePolicy::Expanding, QSizePolicy::Expanding);
|
QSpacerItem *spacer = new QSpacerItem(100, 100, QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
|
|
||||||
//add partial widget to main widget
|
//add partial widget to main widget
|
||||||
vl->addWidget(x);
|
vl->addWidget(FileWidget);
|
||||||
vl->addSpacerItem(spacer);
|
vl->addSpacerItem(spacer);
|
||||||
|
|
||||||
//clears comboboxes, if not every time the user enters options page the lists
|
//clears comboboxes, if not every time the user enters options page the lists
|
||||||
//duplicate
|
//duplicate
|
||||||
m_portCB->clear();
|
svgSourceFile->clear();
|
||||||
|
|
||||||
return widget;
|
//connect signals to slots
|
||||||
|
|
||||||
|
//fires when the user presses file button
|
||||||
|
connect(loadfile, SIGNAL(clicked(bool)),
|
||||||
|
this,SLOT(setOpenFileName()));
|
||||||
|
|
||||||
|
// Restore the contents from the settings:
|
||||||
|
svgSourceFile->setText(m_config->dialFile());
|
||||||
|
|
||||||
|
return optionsPageWidget;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Called when the user presses apply or OK.
|
* Called when the user presses apply or OK.
|
||||||
@ -83,10 +98,30 @@ QWidget *AirspeedGadgetOptionsPage::createPage(QWidget *parent)
|
|||||||
*/
|
*/
|
||||||
void AirspeedGadgetOptionsPage::apply()
|
void AirspeedGadgetOptionsPage::apply()
|
||||||
{
|
{
|
||||||
m_config->setDialFile(m_portCB->currentText());
|
m_config->setDialFile(svgSourceFile->text());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
Opens an open file dialog.
|
||||||
|
|
||||||
|
*/
|
||||||
|
void AirspeedGadgetOptionsPage::setOpenFileName()
|
||||||
|
{
|
||||||
|
QFileDialog::Options options;
|
||||||
|
QString selectedFilter;
|
||||||
|
QString fileName = QFileDialog::getOpenFileName(qobject_cast<QWidget*>(this),
|
||||||
|
tr("QFileDialog::getOpenFileName()"),
|
||||||
|
svgSourceFile->text(),
|
||||||
|
tr("All Files (*);;SVG Files (*.svg)"),
|
||||||
|
&selectedFilter,
|
||||||
|
options);
|
||||||
|
if (!fileName.isEmpty()) svgSourceFile->setText(fileName);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void AirspeedGadgetOptionsPage::finish()
|
void AirspeedGadgetOptionsPage::finish()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ class IUAVGadgetConfiguration;
|
|||||||
}
|
}
|
||||||
class AirspeedGadgetConfiguration;
|
class AirspeedGadgetConfiguration;
|
||||||
class QTextEdit;
|
class QTextEdit;
|
||||||
class QComboBox;
|
class QLineEdit;
|
||||||
class QSpinBox;
|
class QSpinBox;
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
@ -55,7 +55,10 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
AirspeedGadgetConfiguration *m_config;
|
AirspeedGadgetConfiguration *m_config;
|
||||||
QComboBox *m_portCB;
|
QLineEdit* svgSourceFile;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void setOpenFileName();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // AIRSPEEDGADGETOPTIONSPAGE_H
|
#endif // AIRSPEEDGADGETOPTIONSPAGE_H
|
||||||
|
@ -42,8 +42,8 @@ AirspeedGadgetWidget::AirspeedGadgetWidget(QWidget *parent) : QGraphicsView(pare
|
|||||||
m_foreground = new QGraphicsSvgItem();
|
m_foreground = new QGraphicsSvgItem();
|
||||||
m_desired = new QGraphicsSvgItem();
|
m_desired = new QGraphicsSvgItem();
|
||||||
m_actual = new QGraphicsSvgItem();
|
m_actual = new QGraphicsSvgItem();
|
||||||
setDialFile(QFileDialog::getOpenFileName(qobject_cast<QWidget*>(this),
|
//setDialFile(QFileDialog::getOpenFileName(qobject_cast<QWidget*>(this),
|
||||||
tr("Airspeed Dial"), "../artwork/", tr("SVG File (*.svg)")) );
|
// tr("Airspeed Dial"), "../artwork/", tr("SVG File (*.svg)")) );
|
||||||
//setDialFile(QString("/usr/src/openpilot/artwork/Dials/extracts/speed-complete.svg"));
|
//setDialFile(QString("/usr/src/openpilot/artwork/Dials/extracts/speed-complete.svg"));
|
||||||
paint();
|
paint();
|
||||||
|
|
||||||
@ -76,7 +76,12 @@ void AirspeedGadgetWidget::setDialFile(QString dfn)
|
|||||||
|
|
||||||
m_actual->setSharedRenderer(m_renderer);
|
m_actual->setSharedRenderer(m_renderer);
|
||||||
m_actual->setElementId(QString("needle"));
|
m_actual->setElementId(QString("needle"));
|
||||||
}
|
|
||||||
|
std::cout<<"Dial file loaded"<<std::endl;
|
||||||
|
QGraphicsScene *l_scene = scene();
|
||||||
|
l_scene->setSceneRect(m_background->boundingRect());
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ std::cout<<"no file: "<<std::endl; }
|
{ std::cout<<"no file: "<<std::endl; }
|
||||||
@ -84,6 +89,7 @@ void AirspeedGadgetWidget::setDialFile(QString dfn)
|
|||||||
|
|
||||||
void AirspeedGadgetWidget::paint()
|
void AirspeedGadgetWidget::paint()
|
||||||
{
|
{
|
||||||
|
|
||||||
QGraphicsScene *l_scene = scene();
|
QGraphicsScene *l_scene = scene();
|
||||||
l_scene->clear();
|
l_scene->clear();
|
||||||
|
|
||||||
@ -98,6 +104,11 @@ void AirspeedGadgetWidget::paint()
|
|||||||
|
|
||||||
void AirspeedGadgetWidget::paintEvent(QPaintEvent *event)
|
void AirspeedGadgetWidget::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
|
// Skip painting until the dial file is loaded
|
||||||
|
if (! m_renderer->isValid()) {
|
||||||
|
std::cout<<"Dial file not loaded"<<std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
QGraphicsView::paintEvent(event);
|
QGraphicsView::paintEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,6 @@ private slots:
|
|||||||
// End test functions
|
// End test functions
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString dialFilename;
|
|
||||||
QSvgRenderer *m_renderer;
|
QSvgRenderer *m_renderer;
|
||||||
QGraphicsSvgItem *m_background;
|
QGraphicsSvgItem *m_background;
|
||||||
QGraphicsSvgItem *m_foreground;
|
QGraphicsSvgItem *m_foreground;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user