1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-17 02:52:12 +01:00

Configuration now works, much better way to display the zones - explanations to come in the wiki concerning dial design. Remaining display bug of index, will fix later.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@590 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
edouard 2010-05-05 12:17:10 +00:00 committed by edouard
parent bba2582bd3
commit 19b6c70588
5 changed files with 220 additions and 45 deletions

View File

@ -48,12 +48,11 @@ LineardialGadget::~LineardialGadget()
void LineardialGadget::loadConfiguration(IUAVGadgetConfiguration* config)
{
LineardialGadgetConfiguration *m = qobject_cast<LineardialGadgetConfiguration*>(config);
m_widget->setDialFile(m->getDialFile());
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->connectInput(m->getSourceDataObject(), m->getSourceObjectField());
m_widget->setDialFile(m->getDialFile()); // Triggers widget repaint
}

View File

@ -51,11 +51,17 @@ QWidget *LineardialGadgetOptionsPage::createPage(QWidget *parent)
// Restore the contents from the settings:
options_page->svgSourceFile->setText(m_config->getDialFile());
options_page->minValue->setValue(m_config->getMin());
options_page->maxValue->setValue(m_config->getMax());
options_page->greenMin->setValue(m_config->getGreenMin());
options_page->greenMax->setValue(m_config->getGreenMax());
options_page->yellowMin->setValue(m_config->getYellowMin());
options_page->yellowMax->setValue(m_config->getYellowMax());
options_page->redMin->setValue(m_config->getRedMin());
options_page->redMax->setValue(m_config->getRedMax());
connect(options_page->loadFile, SIGNAL(clicked()), this, SLOT(on_loadFile_clicked()));
return optionsPageWidget;
}
/**
@ -67,7 +73,10 @@ QWidget *LineardialGadgetOptionsPage::createPage(QWidget *parent)
void LineardialGadgetOptionsPage::apply()
{
m_config->setDialFile(options_page->svgSourceFile->text());
m_config->setRange(options_page->minValue->value(),options_page->maxValue->value());
m_config->setGreenRange(options_page->greenMin->value(),options_page->greenMax->value());
m_config->setYellowRange(options_page->yellowMin->value(),options_page->yellowMax->value());
m_config->setRedRange(options_page->redMin->value(),options_page->redMax->value());
}
/**

View File

@ -28,7 +28,7 @@
<height>339</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0,0,0,0,0">
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0,0,0,0,0,0,0">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
@ -74,6 +74,75 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_8">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Whole range:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_9">
<property name="text">
<string>Min:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="minValue">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-99999.000000000000000</double>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_13">
<property name="text">
<string>Max:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="maxValue">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-99999.000000000000000</double>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
@ -92,14 +161,14 @@
</sizepolicy>
</property>
<property name="text">
<string>Green</string>
<string>Green:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Min</string>
<string>Min:</string>
</property>
</widget>
</item>
@ -111,12 +180,21 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-99999.000000000000000</double>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_10">
<property name="text">
<string>Max</string>
<string>Max:</string>
</property>
</widget>
</item>
@ -128,6 +206,15 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-99999.000000000000000</double>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
</widget>
</item>
</layout>
@ -150,14 +237,14 @@
</sizepolicy>
</property>
<property name="text">
<string>Yellow</string>
<string>Yellow:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Min</string>
<string>Min:</string>
</property>
</widget>
</item>
@ -169,12 +256,21 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-99999.000000000000000</double>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_11">
<property name="text">
<string>Max</string>
<string>Max:</string>
</property>
</widget>
</item>
@ -186,6 +282,15 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-99999.000000000000000</double>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
</widget>
</item>
</layout>
@ -208,14 +313,14 @@
</sizepolicy>
</property>
<property name="text">
<string>Red</string>
<string>Red:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Min</string>
<string>Min:</string>
</property>
</widget>
</item>
@ -227,12 +332,21 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-99999.000000000000000</double>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_12">
<property name="text">
<string>Max</string>
<string>Max:</string>
</property>
</widget>
</item>
@ -244,10 +358,56 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-99999.000000000000000</double>
</property>
<property name="maximum">
<double>99999.990000000005239</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_17">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Input:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_18">
<property name="text">
<string>ObjectName</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item>
<widget class="QLabel" name="label_19">
<property name="text">
<string>ObjectField</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_2"/>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">

View File

@ -33,14 +33,13 @@
LineardialGadgetWidget::LineardialGadgetWidget(QWidget *parent) : QGraphicsView(parent)
{
setMinimumSize(64,64);
setMinimumSize(128,32);
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
setScene(new QGraphicsScene(this));
m_renderer = new QSvgRenderer();
background = new QGraphicsSvgItem();
foreground = new QGraphicsSvgItem();
bargraph = new QGraphicsSvgItem();
green = new QGraphicsSvgItem();
yellow = new QGraphicsSvgItem();
red = new QGraphicsSvgItem();
@ -50,14 +49,14 @@ LineardialGadgetWidget::LineardialGadgetWidget(QWidget *parent) : QGraphicsView(
indexTarget = 0;
indexValue = 0;
// This timer mechanism makes needles rotate smoothly
// This timer mechanism makes the index rotate smoothly
connect(&dialTimer, SIGNAL(timeout()), this, SLOT(moveIndex()));
dialTimer.start(30);
// Test code for timer to rotate the needle
// Test code for timer to move the index
testSpeed=0;
connect(&m_testTimer, SIGNAL(timeout()), this, SLOT(testRotate()));
m_testTimer.start(4000);
m_testTimer.start(1000);
}
LineardialGadgetWidget::~LineardialGadgetWidget()
@ -98,43 +97,45 @@ void LineardialGadgetWidget::setDialFile(QString dfn)
foreground->setElementId("foreground");
fgenabled = true;
}
std::cout<<"Dial file loaded"<<std::endl;
QGraphicsScene *l_scene = scene();
maxValue = 100;
minValue = 0;
redMin = 0;
redMax = 100;
yellowMin = 30;
yellowMax = 90;
greenMin = 50;
greenMax = 70;
// In order to properly render the Green/Yellow/Red graphs, we need to find out
// the starting location of the bargraph rendering area:
QMatrix barMatrix = m_renderer->matrixForElement("bargraph");
startX = barMatrix.mapRect(m_renderer->boundsOnElement("bargraph")).x();
startY = barMatrix.mapRect(m_renderer->boundsOnElement("bargraph")).y();
bargraphWidth = barMatrix.mapRect(m_renderer->boundsOnElement("bargraph")).width();
indexHeight = m_renderer->matrixForElement("needle").mapRect(m_renderer->boundsOnElement("needle")).height();
std::cout << "Index height: " << indexHeight << std::endl;
// Now adjust the red/yellow/green zones:
double range = maxValue-minValue;
green->resetTransform();
double greenScale = (greenMax-greenMin)/range;
double greenStart = greenMin/range*green->boundingRect().width();
std::cout << "Width:" << green->boundingRect().width();
double greenStart = (greenMin-minValue)/range*green->boundingRect().width();
QTransform matrix;
matrix.translate(greenStart,0);
matrix.scale(greenScale,1);
matrix.translate((greenStart+startX)/greenScale,startY);
green->setTransform(matrix,false);
yellow->resetTransform();
double yellowScale = (yellowMax-yellowMin)/range;
double yellowStart = yellowMin/range*yellow->boundingRect().width();
double yellowStart = (yellowMin-minValue)/range*yellow->boundingRect().width();
matrix.reset();
matrix.translate(yellowStart,0);
matrix.scale(yellowScale,1);
matrix.translate((yellowStart+startX)/yellowScale,startY);
yellow->setTransform(matrix,false);
red->resetTransform();
double redScale = (redMax-redMin)/range;
double redStart = redMin/range*red->boundingRect().width();
double redStart = (redMin-minValue)/range*red->boundingRect().width();
matrix.reset();
matrix.translate(redStart,0);
matrix.scale(redScale,1);
matrix.translate((redStart+startX)/redScale,startY);
red->setTransform(matrix,false);
l_scene->setSceneRect(background->boundingRect());
}
@ -193,17 +194,17 @@ void LineardialGadgetWidget::moveIndex()
if ((abs((indexValue-indexTarget)*10) > 3)) {
indexValue += (indexTarget - indexValue)/10;
index->resetTransform();
double factor = index->boundingRect().width()/100;
index->translate(indexValue*factor,0);
}
update();
qreal factor = bargraphWidth/100;
index->translate(indexValue*factor+startX,startY-indexHeight/2);
update();
}
}
// Test function for timer to rotate needles
void LineardialGadgetWidget::testRotate()
{
int testVal = rand() % (int)maxValue;
testVal+=15;
if (testVal > maxValue) testVal=minValue;
setIndex((double)testVal);
}

View File

@ -48,7 +48,7 @@ public:
void setRange(double min, double max) { minValue=min; maxValue=max;}
void setGreenRange(double min, double max) {greenMin=min; greenMax=max;}
void setYellowRange(double min, double max) {yellowMin=min; yellowMax=max;}
void setRedRange(double min, double max) {redMin=min; yellowMax=max;}
void setRedRange(double min, double max) {redMin=min; redMax=max;}
void connectInput(QString obj, QString field);
void setIndex(double val);
@ -68,7 +68,6 @@ private:
QSvgRenderer *m_renderer;
QGraphicsSvgItem *background;
QGraphicsSvgItem *foreground;
QGraphicsSvgItem *bargraph;
QGraphicsSvgItem *index;
QGraphicsSvgItem *green;
QGraphicsSvgItem *yellow;
@ -77,6 +76,13 @@ private:
// Simple flag to skip rendering if the
bool fgenabled; // layer does not exist.
qreal startX; // Where we should draw the bargraph
qreal startY; // green/yellow/red zones.
qreal bargraphWidth;
qreal indexHeight;
double testVal;
double minValue;
double maxValue;
double greenMin;