diff --git a/ground/src/plugins/airspeed/airspeed.pro b/ground/src/plugins/airspeed/airspeed.pro index dccfd9ed5..bc963b8cb 100644 --- a/ground/src/plugins/airspeed/airspeed.pro +++ b/ground/src/plugins/airspeed/airspeed.pro @@ -10,9 +10,13 @@ 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 diff --git a/ground/src/plugins/airspeed/airspeedgadgetconfiguration.cpp b/ground/src/plugins/airspeed/airspeedgadgetconfiguration.cpp new file mode 100644 index 000000000..358b176df --- /dev/null +++ b/ground/src/plugins/airspeed/airspeedgadgetconfiguration.cpp @@ -0,0 +1,67 @@ +/** + ****************************************************************************** + * + * @file airspeedgadgetconfiguration.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Airspeed Plugin Gadget configuration + * @see The GNU Public License (GPL) Version 3 + * @defgroup Airspeed + * @{ + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "airspeedgadgetconfiguration.h" +#include + +/** + * Loads a saved configuration or defaults if non exist. + * + */ +AirspeedGadgetConfiguration::AirspeedGadgetConfiguration(QString classId, const QByteArray &state, QObject *parent) : + IUAVGadgetConfiguration(classId, parent), + m_defaultDial("Unknown") +{ + //if a saved configuration exists load it + if (state.count() > 0) { + QDataStream stream(state); + QString dialFile; + stream >> dialFile; + m_defaultDial=dialFile; + } +} +/** + * Clones a configuration. + * + */ +IUAVGadgetConfiguration *AirspeedGadgetConfiguration::clone() +{ + AirspeedGadgetConfiguration *m = new AirspeedGadgetConfiguration(this->classId()); + m->m_defaultDial=m_defaultDial; + return m; +} +/** + * Saves a configuration. + * + */ +QByteArray AirspeedGadgetConfiguration::saveState() const +{ + QByteArray bytes; + QDataStream stream(&bytes, QIODevice::WriteOnly); + stream << m_defaultDial; + return bytes; +} diff --git a/ground/src/plugins/airspeed/airspeedgadgetconfiguration.h b/ground/src/plugins/airspeed/airspeedgadgetconfiguration.h new file mode 100644 index 000000000..324b0b0f6 --- /dev/null +++ b/ground/src/plugins/airspeed/airspeedgadgetconfiguration.h @@ -0,0 +1,56 @@ +/** + ****************************************************************************** + * + * @file airspeedgadgetconfiguration.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Airspeed Plugin Gadget configuration + * @see The GNU Public License (GPL) Version 3 + * @defgroup Airspeed + * @{ + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef AIRSPEEDGADGETCONFIGURATION_H +#define AIRSPEEDGADGETCONFIGURATION_H + +#include + +using namespace Core; + +class AirspeedGadgetConfiguration : public IUAVGadgetConfiguration +{ +Q_OBJECT +public: + explicit AirspeedGadgetConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0); + + //set dial configuration functions + void setDialFile(QString dialFile){m_defaultDial=dialFile;} + + + //get port configuration functions + QString dialFile(){return m_defaultDial;} + + QByteArray saveState() const; + IUAVGadgetConfiguration *clone(); + +private: + QString m_defaultDial; + +}; + +#endif // AIRSPEEDGADGETCONFIGURATION_H diff --git a/ground/src/plugins/airspeed/airspeedgadgetfactory.cpp b/ground/src/plugins/airspeed/airspeedgadgetfactory.cpp index 53eacaae0..0e42014d6 100644 --- a/ground/src/plugins/airspeed/airspeedgadgetfactory.cpp +++ b/ground/src/plugins/airspeed/airspeedgadgetfactory.cpp @@ -24,25 +24,37 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - #include "airspeedgadgetfactory.h" #include "airspeedgadgetwidget.h" #include "airspeedgadget.h" +#include "airspeedgadgetconfiguration.h" +#include "airspeedgadgetoptionspage.h" #include AirspeedGadgetFactory::AirspeedGadgetFactory(QObject *parent) : IUAVGadgetFactory(QString("AirspeedGadget"), - tr("Analog Airspeed Gadget"), + tr("Analog Dial Gadget"), parent) { } AirspeedGadgetFactory::~AirspeedGadgetFactory() { - } -Core::IUAVGadget* AirspeedGadgetFactory::createGadget(QWidget *parent) { +Core::IUAVGadget* AirspeedGadgetFactory::createGadget(QWidget *parent) +{ AirspeedGadgetWidget* gadgetWidget = new AirspeedGadgetWidget(parent); return new AirspeedGadget(QString("AirspeedGadget"), gadgetWidget, parent); } + +IUAVGadgetConfiguration *AirspeedGadgetFactory::createConfiguration(const QByteArray &state) +{ + return new AirspeedGadgetConfiguration(QString("AirspeedGadget"), state); +} + +IOptionsPage *AirspeedGadgetFactory::createOptionsPage(IUAVGadgetConfiguration *config) +{ + return new AirspeedGadgetOptionsPage(qobject_cast(config)); +} + diff --git a/ground/src/plugins/airspeed/airspeedgadgetfactory.h b/ground/src/plugins/airspeed/airspeedgadgetfactory.h index d23ad393d..aae9ab2be 100644 --- a/ground/src/plugins/airspeed/airspeedgadgetfactory.h +++ b/ground/src/plugins/airspeed/airspeedgadgetfactory.h @@ -44,7 +44,9 @@ public: AirspeedGadgetFactory(QObject *parent = 0); ~AirspeedGadgetFactory(); - IUAVGadget *createGadget(QWidget *parent); + Core::IUAVGadget *createGadget(QWidget *parent); + IUAVGadgetConfiguration *createConfiguration(const QByteArray &state); + IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config); }; #endif // AIRSPEEDGADGETFACTORY_H_ diff --git a/ground/src/plugins/airspeed/airspeedgadgetoptionspage.cpp b/ground/src/plugins/airspeed/airspeedgadgetoptionspage.cpp new file mode 100644 index 000000000..9205d5b44 --- /dev/null +++ b/ground/src/plugins/airspeed/airspeedgadgetoptionspage.cpp @@ -0,0 +1,93 @@ +/** + ****************************************************************************** + * + * @file airspeedgadgetoptionspage.cpp + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Airspeed Plugin Gadget options page + * @see The GNU Public License (GPL) Version 3 + * @defgroup Airspeed + * @{ + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "airspeedgadgetoptionspage.h" +#include "airspeedgadgetconfiguration.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +AirspeedGadgetOptionsPage::AirspeedGadgetOptionsPage(AirspeedGadgetConfiguration *config, QObject *parent) : + IOptionsPage(parent), + m_config(config) +{ +} + +//creates options page widget +QWidget *AirspeedGadgetOptionsPage::createPage(QWidget *parent) +{ + //main widget + QWidget *widget = new QWidget; + //main layout + QVBoxLayout *vl = new QVBoxLayout(); + widget->setLayout(vl); + + //port layout and widget + QHBoxLayout *portLayout = new QHBoxLayout(); + QWidget *x = new QWidget; + x->setLayout(portLayout); + QWidget *label = new QLabel("Dial SVG:"); + m_portCB = new QComboBox(parent); + m_portCB->setMinimumSize(200,22); + portLayout->addWidget(label); + portLayout->addWidget(m_portCB); + + + QSpacerItem *spacer = new QSpacerItem(100, 100, QSizePolicy::Expanding, QSizePolicy::Expanding); + + //add partial widget to main widget + vl->addWidget(x); + vl->addSpacerItem(spacer); + + //clears comboboxes, if not every time the user enters options page the lists + //duplicate + m_portCB->clear(); + + return widget; +} +/** + * Called when the user presses apply or OK. + * + * Saves the current values + * + */ +void AirspeedGadgetOptionsPage::apply() +{ + m_config->setDialFile(m_portCB->currentText()); + +} + +void AirspeedGadgetOptionsPage::finish() +{ + +} diff --git a/ground/src/plugins/airspeed/airspeedgadgetoptionspage.h b/ground/src/plugins/airspeed/airspeedgadgetoptionspage.h new file mode 100644 index 000000000..db9cdfc8f --- /dev/null +++ b/ground/src/plugins/airspeed/airspeedgadgetoptionspage.h @@ -0,0 +1,61 @@ +/** + ****************************************************************************** + * + * @file airspeedgadgetoptionspage.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Airspeed Plugin Gadget options page + * @see The GNU Public License (GPL) Version 3 + * @defgroup Airspeed + * @{ + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef AIRSPEEDGADGETOPTIONSPAGE_H +#define AIRSPEEDGADGETOPTIONSPAGE_H + +#include "coreplugin/dialogs/ioptionspage.h" +#include "QString" +#include +#include + +namespace Core { +class IUAVGadgetConfiguration; +} +class AirspeedGadgetConfiguration; +class QTextEdit; +class QComboBox; +class QSpinBox; + +using namespace Core; + +class AirspeedGadgetOptionsPage : public IOptionsPage +{ +Q_OBJECT +public: + explicit AirspeedGadgetOptionsPage(AirspeedGadgetConfiguration *config, QObject *parent = 0); + + QWidget *createPage(QWidget *parent); + void apply(); + void finish(); + +private: + AirspeedGadgetConfiguration *m_config; + QComboBox *m_portCB; +}; + +#endif // AIRSPEEDGADGETOPTIONSPAGE_H