1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

Added the beginning of an options page for the airspeed gadget: eventually this should become a more generic "analog dial" gadget supporting any sort of analog indicator with one or more rotating needles and text display. The options do nothing at the moment, it is just ground work for later.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@559 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
edouard 2010-04-29 16:08:58 +00:00 committed by edouard
parent 99b67388bf
commit c9ef6dcfeb
7 changed files with 300 additions and 5 deletions

View File

@ -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

View File

@ -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 <QtCore/QDataStream>
/**
* 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;
}

View File

@ -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 <coreplugin/iuavgadgetconfiguration.h>
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

View File

@ -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 <coreplugin/iuavgadget.h>
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<AirspeedGadgetConfiguration*>(config));
}

View File

@ -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_

View File

@ -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 <QtGui/QLabel>
#include <QtGui/QSpinBox>
#include <QtGui/QDoubleSpinBox>
#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>
#include <QtGui/QTextEdit>
#include <QtGui/QComboBox>
#include <QtAlgorithms>
#include <QStringList>
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()
{
}

View File

@ -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 <QStringList>
#include <QDebug>
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