1
0
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:
edouard 2010-05-01 22:19:12 +00:00 committed by edouard
parent ff722b21e1
commit 06dac9cb09
7 changed files with 78 additions and 21 deletions

View File

@ -27,6 +27,7 @@
#include "airspeedgadget.h"
#include "airspeedgadgetwidget.h"
#include "airspeedgadgetconfiguration.h"
AirspeedGadget::AirspeedGadget(QString classId, AirspeedGadgetWidget *widget, QWidget *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());
}

View File

@ -46,6 +46,7 @@ public:
~AirspeedGadget();
QWidget *widget() { return m_widget; }
void loadConfiguration(IUAVGadgetConfiguration* config);
private:
AirspeedGadgetWidget *m_widget;

View File

@ -33,7 +33,10 @@
#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>
#include <QtGui/QTextEdit>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QComboBox>
#include <QFileDialog>
#include <QtAlgorithms>
#include <QStringList>
@ -47,33 +50,45 @@ AirspeedGadgetOptionsPage::AirspeedGadgetOptionsPage(AirspeedGadgetConfiguration
QWidget *AirspeedGadgetOptionsPage::createPage(QWidget *parent)
{
//main widget
QWidget *widget = new QWidget;
QWidget *optionsPageWidget = new QWidget;
//main layout
QVBoxLayout *vl = new QVBoxLayout();
widget->setLayout(vl);
optionsPageWidget->setLayout(vl);
//port layout and widget
QHBoxLayout *portLayout = new QHBoxLayout();
QWidget *x = new QWidget;
x->setLayout(portLayout);
//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:");
m_portCB = new QComboBox(parent);
m_portCB->setMinimumSize(200,22);
portLayout->addWidget(label);
portLayout->addWidget(m_portCB);
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(x);
vl->addWidget(FileWidget);
vl->addSpacerItem(spacer);
//clears comboboxes, if not every time the user enters options page the lists
//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.
@ -83,10 +98,30 @@ QWidget *AirspeedGadgetOptionsPage::createPage(QWidget *parent)
*/
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()
{

View File

@ -38,7 +38,7 @@ class IUAVGadgetConfiguration;
}
class AirspeedGadgetConfiguration;
class QTextEdit;
class QComboBox;
class QLineEdit;
class QSpinBox;
using namespace Core;
@ -55,7 +55,10 @@ public:
private:
AirspeedGadgetConfiguration *m_config;
QComboBox *m_portCB;
QLineEdit* svgSourceFile;
private slots:
void setOpenFileName();
};
#endif // AIRSPEEDGADGETOPTIONSPAGE_H

View File

@ -42,8 +42,8 @@ AirspeedGadgetWidget::AirspeedGadgetWidget(QWidget *parent) : QGraphicsView(pare
m_foreground = new QGraphicsSvgItem();
m_desired = new QGraphicsSvgItem();
m_actual = new QGraphicsSvgItem();
setDialFile(QFileDialog::getOpenFileName(qobject_cast<QWidget*>(this),
tr("Airspeed Dial"), "../artwork/", tr("SVG File (*.svg)")) );
//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();
@ -76,6 +76,11 @@ void AirspeedGadgetWidget::setDialFile(QString dfn)
m_actual->setSharedRenderer(m_renderer);
m_actual->setElementId(QString("needle"));
std::cout<<"Dial file loaded"<<std::endl;
QGraphicsScene *l_scene = scene();
l_scene->setSceneRect(m_background->boundingRect());
}
}
else
@ -84,6 +89,7 @@ void AirspeedGadgetWidget::setDialFile(QString dfn)
void AirspeedGadgetWidget::paint()
{
QGraphicsScene *l_scene = scene();
l_scene->clear();
@ -98,6 +104,11 @@ void AirspeedGadgetWidget::paint()
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);
}

View File

@ -60,7 +60,6 @@ private slots:
// End test functions
private:
QString dialFilename;
QSvgRenderer *m_renderer;
QGraphicsSvgItem *m_background;
QGraphicsSvgItem *m_foreground;