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

Settings panel for widget testing.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@462 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
thenobody 2010-04-09 23:56:31 +00:00 committed by thenobody
parent 0eef1c1f31
commit d4c19d56a1
10 changed files with 439 additions and 21 deletions

View File

@ -10,3 +10,4 @@ SOURCES += main.cpp \
HEADERS += mainwindow.h \
basicdial.h
FORMS += mainwindow.ui
RESOURCES +=

View File

@ -1,4 +1,4 @@
Widget experiments. Compile and run test application
to see widget. Change bg.svg file to load different
background.
to see widget.
Simple panel lets you test new backgrounds.

View File

@ -6,6 +6,7 @@
BasicDial::BasicDial(QWidget *parent) : QWidget(parent)
{
renderer = new QSvgRenderer();
backgroundFile = "bg.svg";
angle = 0;
}
@ -34,8 +35,8 @@ void BasicDial::renderBackground(void) {
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
painter.setRenderHint(QPainter::Antialiasing);
QRectF frame( QPoint(0, 0), QPoint(side, side));
renderer->load(QString("bg.svg"));
QRectF frame( QPoint(0, 0), QPoint(side-1, side-1));
renderer->load(backgroundFile);
renderer->render(&painter, frame);
bg = pixmap;
}
@ -47,11 +48,48 @@ void BasicDial::renderNeedle(qreal angle) {
painter.translate(width() / 2, height() / 2);
painter.scale(side / 200.0, side / 200.0);
painter.rotate(angle);
painter.setPen(pen);
painter.drawLine(QPoint(0,0), QPoint(0,90));
}
void BasicDial::setAngle(int i) {
qDebug() << "BasicDial::setAngle()";
angle = (qreal)i;
angle = value2angle(i);
update();
}
void BasicDial::setRange(qreal bottom, qreal top) {
bottomValue = bottom;
topValue = top;
}
void BasicDial::setAngles(qreal bottom, qreal top) {
bottomAngle = bottom;
topAngle = top;
angleSpan = topAngle - bottomAngle;
}
qreal BasicDial::value2angle(qreal value) {
return bottomAngle + (value/topValue)*angleSpan;
}
void BasicDial::setValue(qreal value) {
angle = value2angle(value);
currentValue = value;
update();
}
qreal BasicDial::getValue(void) {
return currentValue;
}
void BasicDial::setBackgroundFile(QString file) {
backgroundFile = file;
bg = QPixmap();
update();
}
void BasicDial::setPen(QPen p) {
pen = p;
pen.setWidth(2);
}

View File

@ -3,6 +3,7 @@
#include <QSvgWidget>
#include <QSvgRenderer>
#include <QPen>
class BasicDial : public QWidget
{
@ -12,17 +13,33 @@ public:
BasicDial(QWidget *parent);
virtual void paintEvent(QPaintEvent * event);
void setAngles(qreal bottom, qreal top);
void setRange(qreal bottom, qreal top);
qreal getValue(void);
void setBackgroundFile(QString file);
void setPen(QPen p); //scrap later
public slots:
void setAngle(int i);
void setAngle(int i);
void setValue(qreal value);
private:
void renderBackground(void);
void renderNeedle(qreal angle);
void renderBackground(void);
void renderNeedle(qreal angle);
qreal value2angle(qreal value);
QSvgRenderer *renderer;
QPixmap bg;
qreal angle;
QColor needleColor;
QString backgroundFile;
QPen pen; // scrap later
qreal topValue, topAngle;
qreal bottomValue, bottomAngle;
qreal angleSpan;
qreal currentValue;
};
#endif // BASICDIAL_H

View File

@ -1,13 +1,23 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPen>
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
dial = new BasicDial(this);
ui->dialLayout->addWidget(dial);
connect(ui->sliderAngle, SIGNAL(valueChanged(int)), dial, SLOT(setAngle(int)));
ui->spinBottomAngle->setValue(30);
ui->spinTopAngle->setValue(330);
ui->spinBottomValue->setValue(0);
ui->spinTopValue->setValue(100);
ui->lineFile->setText(QString("bg.svg"));
on_buttonUpdate_clicked();
dial->setValue(0);
ui->statusBar->showMessage(QString("Configure dial and hit Update! Set value with slider."));
}
MainWindow::~MainWindow()
@ -20,7 +30,34 @@ void MainWindow::on_buttonQuit_clicked()
close();
}
void MainWindow::on_buttonTest_clicked()
void MainWindow::on_buttonUpdate_clicked()
{
qDebug() << "Test!";
dial->setAngles(ui->spinBottomAngle->value(), ui->spinTopAngle->value());
dial->setRange(ui->spinBottomValue->value(), ui->spinTopValue->value());
dial->setBackgroundFile(ui->lineFile->text());
dial->setValue(dial->getValue());
QPen pen;
if( ui->comboColor->currentText() == "red" ) pen.setColor(Qt::red);
if( ui->comboColor->currentText() == "yellow" ) pen.setColor(Qt::yellow);
if( ui->comboColor->currentText() == "black" ) pen.setColor(Qt::black);
if( ui->comboColor->currentText() == "green" ) pen.setColor(Qt::green);
if( ui->comboColor->currentText() == "blue" ) pen.setColor(Qt::blue);
dial->setPen(pen);
ui->sliderValue->setRange(ui->spinBottomValue->value(), ui->spinTopValue->value());
ui->statusBar->showMessage(QString("Dial settings updated!"));
}
void MainWindow::on_sliderValue_valueChanged(int value)
{
dial->setValue((qreal)value);
ui->statusBar->showMessage(QString().sprintf("Value: %f", dial->getValue()));
}
void MainWindow::on_buttonFile_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Open Image"), "~", tr("SVG Files (*.svg)"));
ui->lineFile->setText(fileName);
}

View File

@ -3,6 +3,7 @@
#include <QtGui/QMainWindow>
#include <QDebug>
#include <QFileDialog>
#include "basicdial.h"
@ -24,7 +25,9 @@ private:
BasicDial *dial;
private slots:
void on_buttonTest_clicked();
void on_buttonFile_clicked();
void on_sliderValue_valueChanged(int value);
void on_buttonUpdate_clicked();
void on_buttonQuit_clicked();
};

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>400</height>
<width>607</width>
<height>406</height>
</rect>
</property>
<property name="windowTitle">
@ -19,25 +19,152 @@
<layout class="QHBoxLayout" name="dialLayout"/>
</item>
<item>
<layout class="QHBoxLayout" name="controlLayout">
<item>
<widget class="QPushButton" name="buttonTest">
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QLabel" name="labelTopValue">
<property name="text">
<string>Test</string>
<string>Top value</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="sliderAngle">
<item row="1" column="1">
<widget class="QSpinBox" name="spinTopValue">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="maximum">
<number>360</number>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QSpinBox" name="spinTopAngle">
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="maximum">
<number>360</number>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="labelTopAngle">
<property name="text">
<string>Top angle</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QSpinBox" name="spinBottomAngle">
<property name="maximum">
<number>360</number>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="labelBottomAngle">
<property name="text">
<string>Bottom angle</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="spinBottomValue">
<property name="maximum">
<number>360</number>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelBottomValue">
<property name="text">
<string>Bottom value</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelColor">
<property name="text">
<string>Needle color</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="comboColor">
<item>
<property name="text">
<string>black</string>
</property>
</item>
<item>
<property name="text">
<string>red</string>
</property>
</item>
<item>
<property name="text">
<string>green</string>
</property>
</item>
<item>
<property name="text">
<string>yellow</string>
</property>
</item>
<item>
<property name="text">
<string>blue</string>
</property>
</item>
</widget>
</item>
<item row="2" column="2" colspan="2">
<widget class="QLineEdit" name="lineFile"/>
</item>
<item row="2" column="4">
<widget class="QPushButton" name="buttonFile">
<property name="text">
<string>File</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="4">
<widget class="QSlider" name="sliderValue">
<property name="maximum">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<item row="3" column="0">
<widget class="QLabel" name="labelValueSlider">
<property name="text">
<string>Set value</string>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QPushButton" name="buttonUpdate">
<property name="text">
<string>Update</string>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QPushButton" name="buttonQuit">
<property name="text">
<string>Quit</string>

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
version="1.1"
width="200"
height="200"
id="svg2826">
<defs
id="defs2828" />
<g
transform="translate(0,-852.36218)"
id="layer1">
<path
d="m 514.28571,535.2193 a 301.42856,285.71429 0 1 1 -602.857121,0 301.42856,285.71429 0 1 1 602.857121,0 z"
transform="matrix(0.32950794,0,0,0.34763085,29.861879,766.30342)"
id="path2840"
style="fill:#cccccc;fill-opacity:1;fill-rule:nonzero;stroke:#1a1a1a;stroke-width:4;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none" />
<path
d="m -103.9447,825.02734 a 5.3033009,5.3033009 0 1 1 -10.6066,0 5.3033009,5.3033009 0 1 1 10.6066,0 z"
transform="matrix(0.68462193,0,0,0.68462194,174.79358,387.53036)"
id="path3614"
style="fill:#cccccc;fill-opacity:1;fill-rule:nonzero;stroke:#1a1a1a;stroke-width:4;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -0,0 +1,84 @@
<?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:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="200"
height="200"
id="svg2826"
version="1.1"
inkscape:version="0.47 r22583"
sodipodi:docname="bg_inkscape.svg">
<defs
id="defs2828">
<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="perspective2834" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#ffffff"
borderopacity="0.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="0"
inkscape:zoom="1.4142136"
inkscape:cx="-36.97167"
inkscape:cy="50.359189"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="1141"
inkscape:window-height="783"
inkscape:window-x="247"
inkscape:window-y="113"
inkscape:window-maximized="0" />
<metadata
id="metadata2831">
<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:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-852.36218)">
<path
sodipodi:type="arc"
style="fill:#95a1d0;fill-opacity:1;fill-rule:nonzero;stroke:#1a1a1a;stroke-width:4;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none"
id="path2840"
sodipodi:cx="212.85715"
sodipodi:cy="535.2193"
sodipodi:rx="301.42856"
sodipodi:ry="285.71429"
d="m 514.28571,535.2193 c 0,157.79565 -134.95417,285.71429 -301.42856,285.71429 -166.474399,0 -301.428561,-127.91864 -301.428561,-285.71429 0,-157.79565 134.954162,-285.7143 301.428561,-285.7143 166.47439,0 301.42856,127.91865 301.42856,285.7143 z"
transform="matrix(0.32950794,0,0,0.34763085,29.861879,766.30342)" />
<path
sodipodi:type="arc"
style="fill:#cccccc;fill-opacity:1;fill-rule:nonzero;stroke:#1a1a1a;stroke-width:4;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
id="path3614"
sodipodi:cx="-109.248"
sodipodi:cy="825.02734"
sodipodi:rx="5.3033009"
sodipodi:ry="5.3033009"
d="m -103.9447,825.02734 c 0,2.92894 -2.37437,5.3033 -5.3033,5.3033 -2.92893,0 -5.3033,-2.37436 -5.3033,-5.3033 0,-2.92893 2.37437,-5.3033 5.3033,-5.3033 2.92893,0 5.3033,2.37437 5.3033,5.3033 z"
transform="matrix(0.68462193,0,0,0.68462194,174.79358,387.53036)" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -0,0 +1,84 @@
<?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:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="200"
height="200"
id="svg2826"
version="1.1"
inkscape:version="0.47 r22583"
sodipodi:docname="bg_inkscape.svg">
<defs
id="defs2828">
<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="perspective2834" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#ffffff"
borderopacity="0.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="0"
inkscape:zoom="1.4142136"
inkscape:cx="-36.97167"
inkscape:cy="50.359189"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="1141"
inkscape:window-height="783"
inkscape:window-x="247"
inkscape:window-y="113"
inkscape:window-maximized="0" />
<metadata
id="metadata2831">
<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 />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-852.36218)">
<path
sodipodi:type="arc"
style="fill:#95a1d0;fill-opacity:1;fill-rule:nonzero;stroke:#1a1a1a;stroke-width:4;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none"
id="path2840"
sodipodi:cx="212.85715"
sodipodi:cy="535.2193"
sodipodi:rx="301.42856"
sodipodi:ry="285.71429"
d="m 514.28571,535.2193 c 0,157.79565 -134.95417,285.71429 -301.42856,285.71429 -166.474399,0 -301.428561,-127.91864 -301.428561,-285.71429 0,-157.79565 134.954162,-285.7143 301.428561,-285.7143 166.47439,0 301.42856,127.91865 301.42856,285.7143 z"
transform="matrix(0.32950794,0,0,0.34763085,29.861879,766.30342)" />
<path
sodipodi:type="arc"
style="fill:#cccccc;fill-opacity:1;fill-rule:nonzero;stroke:#1a1a1a;stroke-width:4;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
id="path3614"
sodipodi:cx="-109.248"
sodipodi:cy="825.02734"
sodipodi:rx="5.3033009"
sodipodi:ry="5.3033009"
d="m -103.9447,825.02734 c 0,2.92894 -2.37437,5.3033 -5.3033,5.3033 -2.92893,0 -5.3033,-2.37436 -5.3033,-5.3033 0,-2.92893 2.37437,-5.3033 5.3033,-5.3033 2.92893,0 5.3033,2.37437 5.3033,5.3033 z"
transform="matrix(0.68462193,0,0,0.68462194,174.79358,387.53036)" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.1 KiB