From d4c19d56a1c8cee06012832c27bdafed378b864a Mon Sep 17 00:00:00 2001 From: thenobody Date: Fri, 9 Apr 2010 23:56:31 +0000 Subject: [PATCH] Settings panel for widget testing. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@462 ebee16cc-31ac-478f-84a7-5cbb03baadba --- ground/src/experimental/DialTest/DialTest.pro | 1 + ground/src/experimental/DialTest/README.txt | 4 +- .../src/experimental/DialTest/basicdial.cpp | 44 +++++- ground/src/experimental/DialTest/basicdial.h | 23 ++- .../src/experimental/DialTest/mainwindow.cpp | 43 +++++- ground/src/experimental/DialTest/mainwindow.h | 5 +- .../src/experimental/DialTest/mainwindow.ui | 145 ++++++++++++++++-- ground/src/experimental/DialTest/svg/bg.svg | 27 ++++ .../src/experimental/DialTest/svg/bg_blue.svg | 84 ++++++++++ .../experimental/DialTest/svg/bg_inkscape.svg | 84 ++++++++++ 10 files changed, 439 insertions(+), 21 deletions(-) create mode 100644 ground/src/experimental/DialTest/svg/bg.svg create mode 100644 ground/src/experimental/DialTest/svg/bg_blue.svg create mode 100644 ground/src/experimental/DialTest/svg/bg_inkscape.svg diff --git a/ground/src/experimental/DialTest/DialTest.pro b/ground/src/experimental/DialTest/DialTest.pro index e9b93546e..052f91ea0 100644 --- a/ground/src/experimental/DialTest/DialTest.pro +++ b/ground/src/experimental/DialTest/DialTest.pro @@ -10,3 +10,4 @@ SOURCES += main.cpp \ HEADERS += mainwindow.h \ basicdial.h FORMS += mainwindow.ui +RESOURCES += diff --git a/ground/src/experimental/DialTest/README.txt b/ground/src/experimental/DialTest/README.txt index 9b3e76c6c..b52cc86b0 100644 --- a/ground/src/experimental/DialTest/README.txt +++ b/ground/src/experimental/DialTest/README.txt @@ -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. \ No newline at end of file diff --git a/ground/src/experimental/DialTest/basicdial.cpp b/ground/src/experimental/DialTest/basicdial.cpp index 1b8ad0138..f8d31dc24 100644 --- a/ground/src/experimental/DialTest/basicdial.cpp +++ b/ground/src/experimental/DialTest/basicdial.cpp @@ -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); +} diff --git a/ground/src/experimental/DialTest/basicdial.h b/ground/src/experimental/DialTest/basicdial.h index e28812a25..43643b73e 100644 --- a/ground/src/experimental/DialTest/basicdial.h +++ b/ground/src/experimental/DialTest/basicdial.h @@ -3,6 +3,7 @@ #include #include +#include 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 diff --git a/ground/src/experimental/DialTest/mainwindow.cpp b/ground/src/experimental/DialTest/mainwindow.cpp index ea9dcfe9d..33dddb8e8 100644 --- a/ground/src/experimental/DialTest/mainwindow.cpp +++ b/ground/src/experimental/DialTest/mainwindow.cpp @@ -1,13 +1,23 @@ #include "mainwindow.h" #include "ui_mainwindow.h" +#include + 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); } diff --git a/ground/src/experimental/DialTest/mainwindow.h b/ground/src/experimental/DialTest/mainwindow.h index 5e857a1fe..3cd891c36 100644 --- a/ground/src/experimental/DialTest/mainwindow.h +++ b/ground/src/experimental/DialTest/mainwindow.h @@ -3,6 +3,7 @@ #include #include +#include #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(); }; diff --git a/ground/src/experimental/DialTest/mainwindow.ui b/ground/src/experimental/DialTest/mainwindow.ui index 435e68b37..4864c3ba5 100644 --- a/ground/src/experimental/DialTest/mainwindow.ui +++ b/ground/src/experimental/DialTest/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 600 - 400 + 607 + 406 @@ -19,25 +19,152 @@ - - - + + + - Test + Top value - - + + + + + 0 + 0 + + + + + 60 + 0 + + 360 + + + + + + + 80 + 0 + + + + 360 + + + + + + + Top angle + + + + + + + 360 + + + + + + + Bottom angle + + + + + + + 360 + + + + + + + Bottom value + + + + + + + Needle color + + + + + + + + black + + + + + red + + + + + green + + + + + yellow + + + + + blue + + + + + + + + + + + File + + + + + + + 100 + Qt::Horizontal - + + + + Set value + + + + + + + Update + + + + Quit diff --git a/ground/src/experimental/DialTest/svg/bg.svg b/ground/src/experimental/DialTest/svg/bg.svg new file mode 100644 index 000000000..3b119aa1f --- /dev/null +++ b/ground/src/experimental/DialTest/svg/bg.svg @@ -0,0 +1,27 @@ + + + + + + + + + + diff --git a/ground/src/experimental/DialTest/svg/bg_blue.svg b/ground/src/experimental/DialTest/svg/bg_blue.svg new file mode 100644 index 000000000..8388bde41 --- /dev/null +++ b/ground/src/experimental/DialTest/svg/bg_blue.svg @@ -0,0 +1,84 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/ground/src/experimental/DialTest/svg/bg_inkscape.svg b/ground/src/experimental/DialTest/svg/bg_inkscape.svg new file mode 100644 index 000000000..468867d1d --- /dev/null +++ b/ground/src/experimental/DialTest/svg/bg_inkscape.svg @@ -0,0 +1,84 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + +