From 06dac9cb091fbe6cc690b3590ab61b87980da774 Mon Sep 17 00:00:00 2001 From: edouard Date: Sat, 1 May 2010 22:19:12 +0000 Subject: [PATCH] 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 --- .../src/plugins/airspeed/airspeedgadget.cpp | 8 +++ ground/src/plugins/airspeed/airspeedgadget.h | 1 + .../airspeed/airspeedgadgetconfiguration.h | 2 +- .../airspeed/airspeedgadgetoptionspage.cpp | 63 ++++++++++++++----- .../airspeed/airspeedgadgetoptionspage.h | 7 ++- .../plugins/airspeed/airspeedgadgetwidget.cpp | 17 ++++- .../plugins/airspeed/airspeedgadgetwidget.h | 1 - 7 files changed, 78 insertions(+), 21 deletions(-) diff --git a/ground/src/plugins/airspeed/airspeedgadget.cpp b/ground/src/plugins/airspeed/airspeedgadget.cpp index 2096e499a..63587b02e 100644 --- a/ground/src/plugins/airspeed/airspeedgadget.cpp +++ b/ground/src/plugins/airspeed/airspeedgadget.cpp @@ -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(config); + m_widget->setDialFile(m->dialFile()); + +} diff --git a/ground/src/plugins/airspeed/airspeedgadget.h b/ground/src/plugins/airspeed/airspeedgadget.h index f3108e233..4784eab75 100644 --- a/ground/src/plugins/airspeed/airspeedgadget.h +++ b/ground/src/plugins/airspeed/airspeedgadget.h @@ -46,6 +46,7 @@ public: ~AirspeedGadget(); QWidget *widget() { return m_widget; } + void loadConfiguration(IUAVGadgetConfiguration* config); private: AirspeedGadgetWidget *m_widget; diff --git a/ground/src/plugins/airspeed/airspeedgadgetconfiguration.h b/ground/src/plugins/airspeed/airspeedgadgetconfiguration.h index 324b0b0f6..1c6a1536d 100644 --- a/ground/src/plugins/airspeed/airspeedgadgetconfiguration.h +++ b/ground/src/plugins/airspeed/airspeedgadgetconfiguration.h @@ -43,7 +43,7 @@ public: //get port configuration functions - QString dialFile(){return m_defaultDial;} + QString dialFile() {return m_defaultDial;} QByteArray saveState() const; IUAVGadgetConfiguration *clone(); diff --git a/ground/src/plugins/airspeed/airspeedgadgetoptionspage.cpp b/ground/src/plugins/airspeed/airspeedgadgetoptionspage.cpp index 9205d5b44..d1a7a0a28 100644 --- a/ground/src/plugins/airspeed/airspeedgadgetoptionspage.cpp +++ b/ground/src/plugins/airspeed/airspeedgadgetoptionspage.cpp @@ -33,7 +33,10 @@ #include #include #include +#include +#include #include +#include #include #include @@ -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(this), + tr("QFileDialog::getOpenFileName()"), + svgSourceFile->text(), + tr("All Files (*);;SVG Files (*.svg)"), + &selectedFilter, + options); + if (!fileName.isEmpty()) svgSourceFile->setText(fileName); + +} + + void AirspeedGadgetOptionsPage::finish() { diff --git a/ground/src/plugins/airspeed/airspeedgadgetoptionspage.h b/ground/src/plugins/airspeed/airspeedgadgetoptionspage.h index db9cdfc8f..b587a806b 100644 --- a/ground/src/plugins/airspeed/airspeedgadgetoptionspage.h +++ b/ground/src/plugins/airspeed/airspeedgadgetoptionspage.h @@ -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 diff --git a/ground/src/plugins/airspeed/airspeedgadgetwidget.cpp b/ground/src/plugins/airspeed/airspeedgadgetwidget.cpp index d42368a80..6a8c5b855 100644 --- a/ground/src/plugins/airspeed/airspeedgadgetwidget.cpp +++ b/ground/src/plugins/airspeed/airspeedgadgetwidget.cpp @@ -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(this), - tr("Airspeed Dial"), "../artwork/", tr("SVG File (*.svg)")) ); + //setDialFile(QFileDialog::getOpenFileName(qobject_cast(this), + // tr("Airspeed Dial"), "../artwork/", tr("SVG File (*.svg)")) ); //setDialFile(QString("/usr/src/openpilot/artwork/Dials/extracts/speed-complete.svg")); paint(); @@ -76,7 +76,12 @@ void AirspeedGadgetWidget::setDialFile(QString dfn) m_actual->setSharedRenderer(m_renderer); m_actual->setElementId(QString("needle")); - } + + std::cout<<"Dial file loaded"<setSceneRect(m_background->boundingRect()); + + } } else { std::cout<<"no file: "<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"<