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

Bargraph dial now displays field name and value in real time. It is also capable of displaying vertical as well as horizontal dials, a new vertical dial is included in the artwork directory as an example. The gadget automatically detects if the dial is vertical or horizontal.

TODO: make fonts look nicer - if anyone can recommend a font chooser ?

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@727 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
edouard 2010-06-08 13:04:17 +00:00 committed by edouard
parent 2895925bd2
commit 6268ba26a1
3 changed files with 493 additions and 32 deletions

View File

@ -0,0 +1,428 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="47.012333"
height="322.58304"
id="svg10068"
version="1.1"
inkscape:version="0.47 r22583"
sodipodi:docname="dials-master-linear-vertical.svg"
inkscape:export-filename="H:\Documents\Hobbies\W433\My Gauges\vbat-001.png"
inkscape:export-xdpi="103.61"
inkscape:export-ydpi="103.61"
style="display:inline">
<defs
id="defs10070">
<marker
inkscape:stockid="Arrow2Sstart"
orient="auto"
refY="0"
refX="0"
id="Arrow2Sstart"
style="overflow:visible">
<path
id="path4640"
style="font-size:12px;fill-rule:evenodd;stroke-width:0.625;stroke-linejoin:round"
d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
transform="matrix(0.3,0,0,0.3,-0.69,0)" />
</marker>
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 526.18109 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="744.09448 : 526.18109 : 1"
inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
id="perspective10076" />
<inkscape:perspective
id="perspective9987"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective10250"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective10279"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective10517"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective11202"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective3720"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective3735"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective3757"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective3828"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective3889"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective3925"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective3968"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective3982"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective4682"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective3347"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective5659"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective5719"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective5810"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective3546"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective4328"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient8928"
id="linearGradient5318"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(2.2532936,0,0,2.206809,446.89077,-285.33499)"
x1="-29.837337"
y1="285.0596"
x2="-29.837337"
y2="342.60553" />
<linearGradient
id="linearGradient8928">
<stop
style="stop-color:#ffffff;stop-opacity:0.89156628;"
offset="0"
id="stop8930" />
<stop
style="stop-color:#ffffff;stop-opacity:0;"
offset="1"
id="stop8932" />
</linearGradient>
<inkscape:perspective
id="perspective4367"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective4402"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
<inkscape:perspective
id="perspective2940"
inkscape:persp3d-origin="0.5 : 0.33333333 : 1"
inkscape:vp_z="1 : 0.5 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_x="0 : 0.5 : 1"
sodipodi:type="inkscape:persp3d" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="1.4"
inkscape:cx="16.246188"
inkscape:cy="260.67259"
inkscape:document-units="px"
inkscape:current-layer="g2932"
showgrid="false"
inkscape:window-width="1280"
inkscape:window-height="998"
inkscape:window-x="-4"
inkscape:window-y="-4"
inkscape:window-maximized="1"
inkscape:object-paths="true"
showguides="true"
inkscape:guide-bbox="true"
inkscape:snap-to-guides="false"
inkscape:snap-grids="false"
inkscape:snap-global="false" />
<metadata
id="metadata10073">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
<dc:creator>
<cc:Agent>
<dc:title>Edouard Lafargue</dc:title>
</cc:Agent>
</dc:creator>
</cc:Work>
</rdf:RDF>
</metadata>
<g
style="display:inline"
inkscape:label="Dark background"
id="g2932"
inkscape:groupmode="layer"
transform="translate(-357.06525,-236.21351)">
<g
id="background"
inkscape:label="#g8543"
transform="matrix(0,-1,1,0,-8.719326,769.86218)">
<rect
style="fill:#453e3e;fill-opacity:1;stroke:#000000;stroke-width:4;stroke-miterlimit:10;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
id="rect2936"
width="318.58304"
height="43.012333"
x="213.06563"
y="367.78458"
ry="3.1741481"
inkscape:export-filename="H:\Documents\Hobbies\W433\g9905.png"
inkscape:export-xdpi="88.809998"
inkscape:export-ydpi="88.809998" />
<g
id="g2591"
transform="matrix(0,0.03233219,-0.03233219,0,600.00962,569.27364)"
style="display:inline">
<path
sodipodi:nodetypes="cccccccccccccccccccccccccccccccc"
id="path2603"
transform="translate(-6411.3421,1598.2484)"
d="m 1212.9375,688.875 c -10.0494,-0.18009 -18.8265,4.06634 -22.625,16.1875 l -34.75,117.34375 55.9063,30.59375 24.0937,-91.5 c 6.8335,-10.5642 16.8382,-6.50038 27.3437,-0.125 l 82.8438,54.5625 c 7.1912,6.0887 12.0843,14.26627 11.625,27.375 l -5.125,72.5625 c -1.0457,9.9542 -7.0498,16.15838 -11.7812,15.3125 l -130.875,-71.09375 -23.1563,87.78125 12.0937,4.375 19.75,7.15625 130.75,47.31255 c 19.5177,7.1453 36.967,-14.45887 37.5938,-46.62505 L 1387.1875,844.5 c -0.3794,-28.3851 -14.1686,-43.93703 -27.9375,-55.0625 l -109.2812,-85.34375 c -9.1011,-7.43642 -24.1106,-14.9872 -37.0313,-15.21875 z m -108.8503,112.40874 -27.4622,106.84126 18.1809,5.34624 0,-0.0312 98.1868,36.80116 28.7911,-83.5022 -117.6966,-65.45521 z m 14.194,147.06001 -23.9687,81.03125 61.7187,33.9688 24.9376,-94.68755 -62.6876,-20.3125 z"
style="fill:#ffffff;fill-opacity:1;stroke:none" />
<path
sodipodi:nodetypes="cccccccccccc"
id="path2605"
d="m -5331.9089,2431.23 -11.3323,-6.4174 9.9517,-36.7409 -25.1805,-13.7542 -55.5528,23.5818 -76.6225,-20.2729 68.1271,46.1567 26.6499,63.8068 34.5303,11.3175 10.8525,-40.7996 10.7025,1.6951 7.8741,-28.5729 z"
style="fill:#ffffff;fill-opacity:1;stroke:none"
inkscape:transform-center-x="-8.1593243"
inkscape:transform-center-y="82.140396"
inkscape:export-filename="C:\Documents and Settings\t12\My Documents\My Dropbox\graphicswork\openpilot.org\textplay.png"
inkscape:export-xdpi="122.68"
inkscape:export-ydpi="122.68" />
</g>
<rect
inkscape:label="#rect4388"
inkscape:export-ydpi="88.809998"
inkscape:export-xdpi="88.809998"
inkscape:export-filename="H:\Documents\Hobbies\W433\g9905.png"
ry="0.68289828"
y="395.16541"
x="250.30202"
height="9.2538376"
width="260.53882"
id="bargraph-outer"
style="fill:#332d2d;fill-opacity:1;stroke:#000000;stroke-width:2;stroke-miterlimit:10;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />
<rect
style="fill:#332d2d;fill-opacity:1;stroke:none"
id="bargraph"
width="260.53882"
height="9.2538376"
x="250.30202"
y="395.16541"
ry="0.68289828"
inkscape:export-filename="H:\Documents\Hobbies\W433\g9905.png"
inkscape:export-xdpi="88.809998"
inkscape:export-ydpi="88.809998"
inkscape:label="#rect4388" />
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 245.16159,372.07875 1.13642,0.12627"
id="field"
sodipodi:nodetypes="cc"
inkscape:label="#path2930" />
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;display:inline"
d="m 229.7298,372.12602 1.13642,0.12627"
id="value"
sodipodi:nodetypes="cc"
inkscape:label="#path2930" />
</g>
</g>
<g
inkscape:groupmode="layer"
id="layer5"
inkscape:label="Green Zone"
style="display:inline"
transform="translate(-129.62194,129.52019)">
<rect
inkscape:label="#rect5741"
style="fill:#04b629;fill-opacity:1;stroke:none;display:inline"
id="green"
width="260.53882"
height="9.2538376"
x="-153.97397"
y="158.98152"
ry="0.68289828"
inkscape:export-filename="H:\Documents\Hobbies\W433\g9905.png"
inkscape:export-xdpi="88.809998"
inkscape:export-ydpi="88.809998"
transform="matrix(0,-1,1,0,0,0)" />
</g>
<g
inkscape:groupmode="layer"
id="layer4"
inkscape:label="Yellow Zone"
style="display:inline"
transform="translate(-129.62194,129.52019)">
<rect
inkscape:export-ydpi="88.809998"
inkscape:export-xdpi="88.809998"
inkscape:export-filename="H:\Documents\Hobbies\W433\g9905.png"
ry="0.68289828"
y="158.98152"
x="-153.97397"
height="9.2538376"
width="260.53882"
id="yellow"
style="fill:#f1b907;fill-opacity:1;stroke:none;display:inline"
inkscape:label="#rect5741"
transform="matrix(0,-1,1,0,0,0)" />
</g>
<g
inkscape:groupmode="layer"
id="layer3"
inkscape:label="Red zone"
style="display:inline"
transform="translate(-129.62194,129.52019)">
<rect
inkscape:label="#rect5741"
style="fill:#cf0e0e;fill-opacity:1;stroke:none;display:inline"
id="red"
width="260.53882"
height="9.2538376"
x="-154.0755"
y="158.96294"
ry="0.68289828"
inkscape:export-filename="H:\Documents\Hobbies\W433\g9905.png"
inkscape:export-xdpi="88.809998"
inkscape:export-ydpi="88.809998"
transform="matrix(0,-1,1,0,0,0)" />
</g>
<g
inkscape:groupmode="layer"
id="layer6"
inkscape:label="Indicator"
style="display:inline"
transform="translate(-129.62194,129.52019)">
<path
style="fill:#ffffff;fill-opacity:1;stroke:#c2bfbf;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 143.75986,-109.1656 0,14.268407 12,-7.134207 -12,-7.1342 z"
id="needle"
sodipodi:nodetypes="cccc"
inkscape:label="#path5747" />
</g>
<g
inkscape:groupmode="layer"
id="layer1"
inkscape:label="Text"
style="display:inline"
transform="translate(-129.62194,129.52019)" />
</svg>

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -33,7 +33,7 @@
LineardialGadgetWidget::LineardialGadgetWidget(QWidget *parent) : QGraphicsView(parent)
{
setMinimumSize(128,32);
setMinimumSize(32,32);
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
setScene(new QGraphicsScene(this));
@ -46,7 +46,9 @@ LineardialGadgetWidget::LineardialGadgetWidget(QWidget *parent) : QGraphicsView(
index = new QGraphicsSvgItem();
fieldName = new QGraphicsTextItem("Field");
fieldName->setDefaultTextColor(QColor("White"));
fieldValue = new QGraphicsTextItem("3.0 V");
fieldValue = new QGraphicsTextItem("0.00");
fieldValue->setDefaultTextColor(QColor("White"));
verticalDial = false;
paint();
@ -149,54 +151,79 @@ void LineardialGadgetWidget::setDialFile(QString dfn)
fieldName->setTransform(matrix,false);
textMatrix = m_renderer->matrixForElement("value");
startX = textMatrix.mapRect(m_renderer->boundsOnElement("field")).x();
startY = textMatrix.mapRect(m_renderer->boundsOnElement("field")).y();
startX = textMatrix.mapRect(m_renderer->boundsOnElement("value")).x();
startY = textMatrix.mapRect(m_renderer->boundsOnElement("value")).y();
matrix.reset();
matrix.translate(startX,startY);
fieldValue->setTransform(matrix,false);
// 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();
textMatrix = m_renderer->matrixForElement("bargraph");
startX = textMatrix.mapRect(m_renderer->boundsOnElement("bargraph")).x();
startY = textMatrix.mapRect(m_renderer->boundsOnElement("bargraph")).y();
//std::cout << "StartX: " << startX << std::endl;
//std::cout << "StartY: " << startY << std::endl;
bargraphWidth = barMatrix.mapRect(m_renderer->boundsOnElement("bargraph")).width();
bargraphSize = textMatrix.mapRect(m_renderer->boundsOnElement("bargraph")).width();
// Detect if the bargraph is vertical or horizontal.
qreal bargraphHeight = textMatrix.mapRect(m_renderer->boundsOnElement("bargraph")).height();
if (bargraphHeight > bargraphSize) {
verticalDial = true;
bargraphSize = bargraphHeight;
} else {
verticalDial = false;
}
// Move the index to its base position:
indexHeight = m_renderer->matrixForElement("needle").mapRect(m_renderer->boundsOnElement("needle")).height();
indexWidth = m_renderer->matrixForElement("needle").mapRect(m_renderer->boundsOnElement("needle")).width();
//std::cout << "Index height: " << indexHeight << std::endl;
// QTransform matrix;
matrix.reset();
matrix.translate(startX-indexWidth/2,startY-indexHeight/2);
index->setTransform(matrix,false);
// Now adjust the red/yellow/green zones:
double range = maxValue-minValue;
green->resetTransform();
double greenScale = (greenMax-greenMin)/range;
double greenStart = (greenMin-minValue)/range*green->boundingRect().width();
double greenStart = verticalDial ? (maxValue-greenMax)/range*green->boundingRect().height() :
(greenMin-minValue)/range*green->boundingRect().width();
matrix.reset();
matrix.scale(greenScale,1);
matrix.translate((greenStart+startX)/greenScale,startY);
if (verticalDial) {
matrix.scale(1,greenScale);
matrix.translate(startX,(greenStart+startY)/greenScale);
} else {
matrix.scale(greenScale,1);
matrix.translate((greenStart+startX)/greenScale,startY);
}
green->setTransform(matrix,false);
yellow->resetTransform();
double yellowScale = (yellowMax-yellowMin)/range;
double yellowStart = (yellowMin-minValue)/range*yellow->boundingRect().width();
double yellowStart = verticalDial ? (maxValue-yellowMax)/range*yellow->boundingRect().height() :
(yellowMin-minValue)/range*yellow->boundingRect().width();
matrix.reset();
matrix.scale(yellowScale,1);
matrix.translate((yellowStart+startX)/yellowScale,startY);
if (verticalDial) {
matrix.scale(1,yellowScale);
matrix.translate(startX,(yellowStart+startY)/yellowScale);
} else {
matrix.scale(yellowScale,1);
matrix.translate((yellowStart+startX)/yellowScale,startY);
}
yellow->setTransform(matrix,false);
red->resetTransform();
double redScale = (redMax-redMin)/range;
double redStart = (redMin-minValue)/range*red->boundingRect().width();
double redStart = verticalDial ? (maxValue-redMax)/range*red->boundingRect().height() :
(redMin-minValue)/range*red->boundingRect().width();
matrix.reset();
matrix.scale(redScale,1);
matrix.translate((redStart+startX)/redScale,startY);
if (verticalDial) {
matrix.scale(1,redScale);
matrix.translate(startX,(redStart+startY)/redScale);
} else {
matrix.scale(redScale,1);
matrix.translate((redStart+startX)/redScale,startY);
}
red->setTransform(matrix,false);
l_scene->setSceneRect(background->boundingRect());
@ -209,10 +236,9 @@ void LineardialGadgetWidget::setDialFile(QString dfn)
void LineardialGadgetWidget::paint()
{
QGraphicsScene *l_scene = scene();
l_scene->clear();
l_scene->clear(); // Beware: clear also deletes all objects
// which are currently in the scene
l_scene->addItem(background);
// Order is important: red, then yellow then green
// overlayed on top of each other
@ -221,8 +247,8 @@ void LineardialGadgetWidget::paint()
l_scene->addItem(green);
l_scene->addItem(index);
l_scene->addItem(fieldName);
l_scene->addItem(fieldValue);
l_scene->addItem(foreground);
update();
}
@ -247,7 +273,11 @@ void LineardialGadgetWidget::resizeEvent(QResizeEvent *event)
// Converts the value into an percentage:
// this enables smooth movement in moveIndex below
void LineardialGadgetWidget::setIndex(double value) {
indexTarget = 100*(value-minValue)/maxValue;
if (verticalDial) {
indexTarget = 100*(maxValue-value)/(maxValue-minValue);
} else {
indexTarget = 100*(value-minValue)/(maxValue-minValue);
}
}
// Take an input value and move the index accordingly
@ -256,13 +286,15 @@ void LineardialGadgetWidget::setIndex(double value) {
void LineardialGadgetWidget::moveIndex()
{
if ((abs((indexValue-indexTarget)*10) > 3)) {
indexValue += (indexTarget - indexValue)/10;
indexValue += (indexTarget - indexValue)/5;
index->resetTransform();
// TODO: do not do so many calculations during the update
// code, precompute everything;
qreal factor = bargraphWidth/100;
qreal factor = indexValue*bargraphSize/100;
QTransform matrix;
matrix.translate(indexValue*factor+startX-indexWidth/2,startY-indexHeight/2);
if (verticalDial) {
matrix.translate(startX-indexWidth/2,factor+startY-indexHeight/2);
} else {
matrix.translate(factor+startX-indexWidth/2,startY-indexHeight/2);
}
index->setTransform(matrix,false);
update();
}

View File

@ -84,10 +84,11 @@ private:
// Simple flag to skip rendering if the
bool fgenabled; // layer does not exist.
bool verticalDial; // True if the dials scales vertically.
qreal startX; // Where we should draw the bargraph
qreal startY; // green/yellow/red zones.
qreal bargraphWidth;
qreal bargraphSize;
qreal indexHeight;
qreal indexWidth;