1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

OP-60 : new options for linear dial: number of decimal places and factor (+ bug fixes)

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1025 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
edouard 2010-07-04 22:00:50 +00:00 committed by edouard
parent b13f8296dc
commit c5e540b1ff
7 changed files with 73 additions and 12 deletions

View File

@ -48,11 +48,13 @@ LineardialGadget::~LineardialGadget()
void LineardialGadget::loadConfiguration(IUAVGadgetConfiguration* config)
{
LineardialGadgetConfiguration *m = qobject_cast<LineardialGadgetConfiguration*>(config);
m_widget->setDialFont(m->getFont());
m_widget->setFactor(m->getFactor());
m_widget->setDecimalPlaces(m->getDecimalPlaces());
m_widget->setRange(m->getMin(),m->getMax());
m_widget->setGreenRange(m->getGreenMin(), m->getGreenMax());
m_widget->setYellowRange(m->getYellowMin(), m->getYellowMax());
m_widget->setRedRange(m->getRedMin(), m->getRedMax());
m_widget->setDialFile(m->getDialFile()); // Triggers widget repaint
m_widget->connectInput(m->getSourceDataObject(), m->getSourceObjectField());
m_widget->setDialFont(m->getFont());
}

View File

@ -44,7 +44,9 @@ LineardialGadgetConfiguration::LineardialGadgetConfiguration(QString classId, co
yellowMin(33),
yellowMax(66),
greenMin(66),
greenMax(100)
greenMax(100),
factor(1.00),
decimalPlaces(0)
{
//if a saved configuration exists load it
if (state.count() > 0) {
@ -61,6 +63,8 @@ LineardialGadgetConfiguration::LineardialGadgetConfiguration(QString classId, co
stream >> greenMin;
stream >> greenMax;
stream >> font;
stream >> decimalPlaces;
stream >> factor;
}
}
/**
@ -93,6 +97,8 @@ QByteArray LineardialGadgetConfiguration::saveState() const
stream << greenMin;
stream << greenMax;
stream << font;
stream << decimalPlaces;
stream << factor;
return bytes;
}

View File

@ -50,6 +50,9 @@ public:
void setFont(QString text) { font = text; }
void setFactor(double val) { factor = val; }
void setDecimalPlaces (int val) { decimalPlaces = val; }
void setSourceDataObject(QString text) {sourceDataObject = text; }
void setSourceObjField(QString text) { sourceObjectField = text; }
@ -66,6 +69,8 @@ public:
QString getSourceDataObject() { return sourceDataObject;}
QString getSourceObjectField() { return sourceObjectField;}
QString getFont() { return font;}
int getDecimalPlaces() { return decimalPlaces; }
double getFactor() { return factor; }
QByteArray saveState() const;
IUAVGadgetConfiguration *clone();
@ -91,6 +96,9 @@ private:
double yellowMax;
double greenMin;
double greenMax;
double factor;
int decimalPlaces;
};
#endif // LINEARDIALGADGETCONFIGURATION_H

View File

@ -64,6 +64,8 @@ QWidget *LineardialGadgetOptionsPage::createPage(QWidget *parent)
options_page->yellowMax->setValue(m_config->getYellowMax());
options_page->redMin->setValue(m_config->getRedMin());
options_page->redMax->setValue(m_config->getRedMax());
options_page->factor->setValue(m_config->getFactor());
options_page->decPlaces->setValue(m_config->getDecimalPlaces());
font.fromString(m_config->getFont());
// Fills the combo boxes for the UAVObjects
@ -113,6 +115,8 @@ void LineardialGadgetOptionsPage::apply()
m_config->setSourceDataObject(options_page->objectName->currentText());
m_config->setSourceObjField(options_page->objectField->currentText());
m_config->setFont(font.toString());
m_config->setDecimalPlaces(options_page->decPlaces->value());
m_config->setFactor(options_page->factor->value());
}
/**
@ -122,7 +126,7 @@ void LineardialGadgetOptionsPage::apply()
void LineardialGadgetOptionsPage::on_fontPicker_clicked()
{
bool ok;
font = QFontDialog::getFont(&ok, QFont("Arial", 12), qobject_cast<QWidget*>(this));
font = QFontDialog::getFont(&ok, font , qobject_cast<QWidget*>(this));
}

View File

@ -447,6 +447,37 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_15">
<property name="text">
<string>Decimal places:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="decPlaces">
<property name="maximum">
<number>99</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_16">
<property name="text">
<string>Factor:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="factor">
<property name="minimum">
<double>-10000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">

View File

@ -47,6 +47,8 @@ LineardialGadgetWidget::LineardialGadgetWidget(QWidget *parent) : QGraphicsView(
fieldValue = NULL;
indexTarget = 0;
indexValue = 0;
places = 0;
factor = 1;
// This timer mechanism makes the index rotate smoothly
connect(&dialTimer, SIGNAL(timeout()), this, SLOT(moveIndex()));
@ -98,9 +100,9 @@ void LineardialGadgetWidget::updateIndex(UAVObject *object1) {
if (field) {
QString s;
if (field->isNumeric()) {
double v = field->getDouble();
double v = field->getDouble()*factor;
setIndex(v);
s.sprintf("%.0f",v);
s.sprintf("%.*f",places,v);
}
if (field->isText()) {
s = field->getValue().toString();
@ -233,8 +235,11 @@ void LineardialGadgetWidget::setDialFile(QString dfn)
// Check whether the dial wants to display a moving index:
if (m_renderer->elementExists("needle")) {
QMatrix textMatrix = m_renderer->matrixForElement("needle");
startX = textMatrix.mapRect(m_renderer->boundsOnElement("needle")).x();
startY = textMatrix.mapRect(m_renderer->boundsOnElement("needle")).y();
QRectF nRect = textMatrix.mapRect(m_renderer->boundsOnElement("needle"));
startX = nRect.x();
startY = nRect.y();
//indexWidth = nRect.width();
//indexHeight = nRect.height();
QTransform matrix;
matrix.translate(startX,startY);
index = new QGraphicsSvgItem();
@ -378,12 +383,15 @@ void LineardialGadgetWidget::moveIndex()
}
QTransform matrix;
index->resetTransform();
qreal factor = indexValue*bargraphSize/100;
qreal trans = indexValue*bargraphSize/100;
if (verticalDial) {
matrix.translate(startX-indexWidth/2,factor+startY-indexHeight/2);
//matrix.translate(startX-indexWidth/2,trans+startY-indexHeight/2);
matrix.translate(startX,trans+startY);
} else {
matrix.translate(factor+startX-indexWidth/2,startY-indexHeight/2);
//matrix.translate(trans+startX-indexWidth/2,startY-indexHeight/2);
matrix.translate(trans+startX,startY);
}
index->setTransform(matrix,false);
update();
}

View File

@ -55,6 +55,8 @@ public:
void connectInput(QString obj, QString field);
void setIndex(double val);
void setDialFont(QString fontProps);
void setFactor (double val) { factor = val;}
void setDecimalPlaces(int val) { places = val;}
public slots:
void updateIndex(UAVObject *object1);
@ -92,8 +94,6 @@ private:
qreal indexHeight;
qreal indexWidth;
double testVal;
double minValue;
double maxValue;
double greenMin;
@ -102,6 +102,8 @@ private:
double yellowMax;
double redMin;
double redMax;
double factor;
int places;
// The Value and target variables
// are expressed in degrees