mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-11-29 07:24:13 +01:00
Experimental Dial skeleton. First commit.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@452 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
9ff764056a
commit
e57aa1a38a
12
ground/src/experimental/DialTest/DialTest.pro
Normal file
12
ground/src/experimental/DialTest/DialTest.pro
Normal file
@ -0,0 +1,12 @@
|
||||
# -------------------------------------------------
|
||||
# Project created by QtCreator 2010-04-09T22:11:43
|
||||
# -------------------------------------------------
|
||||
QT += svg
|
||||
TARGET = DialTest
|
||||
TEMPLATE = app
|
||||
SOURCES += main.cpp \
|
||||
mainwindow.cpp \
|
||||
basicdial.cpp
|
||||
HEADERS += mainwindow.h \
|
||||
basicdial.h
|
||||
FORMS += mainwindow.ui
|
57
ground/src/experimental/DialTest/basicdial.cpp
Normal file
57
ground/src/experimental/DialTest/basicdial.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
#include "basicdial.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QDebug>
|
||||
|
||||
BasicDial::BasicDial(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
renderer = new QSvgRenderer();
|
||||
angle = 0;
|
||||
}
|
||||
|
||||
void BasicDial::paintEvent(QPaintEvent *event) {
|
||||
qDebug() << "in painEvent()";
|
||||
renderBackground();
|
||||
int side = qMin(width(), height());
|
||||
QPainter painter(this);
|
||||
QSize ps = bg.size();
|
||||
QSize ws = this->size();
|
||||
QSize fs = (ws-ps)/2;
|
||||
painter.drawPixmap(QPoint(fs.width(), fs.height()), bg);
|
||||
|
||||
renderNeedle(angle);
|
||||
|
||||
qDebug() << "out paintEvent()";
|
||||
}
|
||||
|
||||
void BasicDial::renderBackground(void) {
|
||||
int side = qMin(width(), height());
|
||||
if( bg.size() == QSize(side, side) ) {
|
||||
qDebug() << "BasicDial::renderBackground(): Size not changed! Abort rerendering stuff";
|
||||
return;
|
||||
}
|
||||
QPixmap pixmap(QSize(side, side));
|
||||
pixmap.fill(Qt::transparent);
|
||||
QPainter painter(&pixmap);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
QRectF frame( QPoint(0, 0), QPoint(side, side));
|
||||
renderer->load(QString("bg.svg"));
|
||||
renderer->render(&painter, frame);
|
||||
bg = pixmap;
|
||||
}
|
||||
|
||||
void BasicDial::renderNeedle(qreal angle) {
|
||||
int side = qMin(width(), height());
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.translate(width() / 2, height() / 2);
|
||||
painter.scale(side / 200.0, side / 200.0);
|
||||
painter.rotate(angle);
|
||||
painter.drawLine(QPoint(0,0), QPoint(0,90));
|
||||
}
|
||||
|
||||
void BasicDial::setAngle(int i) {
|
||||
qDebug() << "BasicDial::setAngle()";
|
||||
angle = (qreal)i;
|
||||
update();
|
||||
}
|
28
ground/src/experimental/DialTest/basicdial.h
Normal file
28
ground/src/experimental/DialTest/basicdial.h
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef BASICDIAL_H
|
||||
#define BASICDIAL_H
|
||||
|
||||
#include <QSvgWidget>
|
||||
#include <QSvgRenderer>
|
||||
|
||||
class BasicDial : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
BasicDial(QWidget *parent);
|
||||
virtual void paintEvent(QPaintEvent * event);
|
||||
|
||||
public slots:
|
||||
void setAngle(int i);
|
||||
|
||||
private:
|
||||
void renderBackground(void);
|
||||
void renderNeedle(qreal angle);
|
||||
|
||||
QSvgRenderer *renderer;
|
||||
QPixmap bg;
|
||||
qreal angle;
|
||||
|
||||
};
|
||||
|
||||
#endif // BASICDIAL_H
|
27
ground/src/experimental/DialTest/bg.svg
Normal file
27
ground/src/experimental/DialTest/bg.svg
Normal 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 |
84
ground/src/experimental/DialTest/bg_inkscape.svg
Normal file
84
ground/src/experimental/DialTest/bg_inkscape.svg
Normal 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.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="112.58141"
|
||||
inkscape:cy="106.92773"
|
||||
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:#cccccc;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 |
10
ground/src/experimental/DialTest/main.cpp
Normal file
10
ground/src/experimental/DialTest/main.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include <QtGui/QApplication>
|
||||
#include "mainwindow.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
MainWindow w;
|
||||
w.show();
|
||||
return a.exec();
|
||||
}
|
26
ground/src/experimental/DialTest/mainwindow.cpp
Normal file
26
ground/src/experimental/DialTest/mainwindow.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MainWindow::on_buttonQuit_clicked()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
void MainWindow::on_buttonTest_clicked()
|
||||
{
|
||||
qDebug() << "Test!";
|
||||
}
|
31
ground/src/experimental/DialTest/mainwindow.h
Normal file
31
ground/src/experimental/DialTest/mainwindow.h
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QtGui/QMainWindow>
|
||||
#include <QDebug>
|
||||
|
||||
#include "basicdial.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
BasicDial *dial;
|
||||
|
||||
private slots:
|
||||
void on_buttonTest_clicked();
|
||||
void on_buttonQuit_clicked();
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
64
ground/src/experimental/DialTest/mainwindow.ui
Normal file
64
ground/src/experimental/DialTest/mainwindow.ui
Normal file
@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>600</width>
|
||||
<height>400</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="dialLayout"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="controlLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonTest">
|
||||
<property name="text">
|
||||
<string>Test</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSlider" name="sliderAngle">
|
||||
<property name="maximum">
|
||||
<number>360</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonQuit">
|
||||
<property name="text">
|
||||
<string>Quit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="mainToolBar">
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
</attribute>
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
Reference in New Issue
Block a user