1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

gcscontrol: code style formatting and cleanup

This commit is contained in:
Oleg Semyonov 2012-01-21 00:52:35 +02:00
parent 7d15cbd720
commit 9006dd558f
2 changed files with 36 additions and 45 deletions

View File

@ -7,7 +7,7 @@
* @{
* @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin
* @{
* @brief A that mimics a transmitter joystick and updates the MCC
* @brief The plugin that mimics a transmitter joystick and updates the MCC
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
@ -28,21 +28,14 @@
#include "joystickcontrol.h"
#include "extensionsystem/pluginmanager.h"
#include <QDebug>
#include <QStringList>
#include <QtGui/QWidget>
#include <QtGui/QTextEdit>
#include <QtGui/QVBoxLayout>
#include <QtGui/QPushButton>
#include <QtGui/QMessageBox>
#include <QMouseEvent>
#include <QtOpenGL/QGLWidget>
#include <QtGlobal>
#include <QMouseEvent>
/**
* @brief Constructor for JoystickControl widget. Sets up the image of a joystick
*/
JoystickControl::JoystickControl(QWidget *parent) :
QGraphicsView(parent)
JoystickControl::JoystickControl(QWidget *parent) : QGraphicsView(parent)
{
setMinimumSize(64, 64);
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
@ -51,6 +44,7 @@ JoystickControl::JoystickControl(QWidget *parent) :
m_renderer = new QSvgRenderer();
bool test = m_renderer->load(QString(":/gcscontrol/images/joystick.svg"));
Q_UNUSED(test);
Q_ASSERT(test);
m_background = new QGraphicsSvgItem();
@ -82,11 +76,11 @@ JoystickControl::JoystickControl(QWidget *parent) :
JoystickControl::~JoystickControl()
{
// Do nothing
}
/*!
\brief Enables/Disables OpenGL
/**
* @brief Enables/Disables OpenGL
*/
void JoystickControl::enableOpenGL(bool flag)
{
@ -103,8 +97,8 @@ void JoystickControl::changePosition(double x, double y)
{
QRectF areaSize = m_joystickArea->boundingRect();
QPointF point(
((1 + x) * areaSize.width() - m_joystickEnd->boundingRect().width()) * 0.5,
((1 - y) * areaSize.height() - m_joystickEnd->boundingRect().height()) * 0.5
((1.0 + x) * areaSize.width() - m_joystickEnd->boundingRect().width()) * 0.5,
((1.0 - y) * areaSize.height() - m_joystickEnd->boundingRect().height()) * 0.5
);
m_joystickEnd->setPos(m_joystickArea->mapToScene(point));
}
@ -117,14 +111,14 @@ void JoystickControl::mouseMoveEvent(QMouseEvent *event)
QPointF point = m_joystickArea->mapFromScene(mapToScene(event->pos()));
QSizeF areaSize = m_joystickArea->boundingRect().size();
double Y = - (point.y() / areaSize.height() - .5) * 2;
double X = (point.x() / areaSize.width() - .5) * 2;
if (Y<-1) Y = -1;
if (Y> 1) Y = 1;
if (X<-1) X = -1;
if (X> 1) X = 1;
double y = - (point.y() / areaSize.height() - 0.5) * 2.0;
double x = (point.x() / areaSize.width() - 0.5) * 2.0;
if (y < -1.0) y = -1.0;
if (y > 1.0) y = 1.0;
if (x < -1.0) x = -1.0;
if (x > 1.0) x = 1.0;
emit positionClicked(X, Y);
emit positionClicked(x, y);
}
/**
@ -137,7 +131,6 @@ void JoystickControl::mousePressEvent(QMouseEvent *event)
}
}
void JoystickControl::paint()
{
update();
@ -145,7 +138,7 @@ void JoystickControl::paint()
void JoystickControl::paintEvent(QPaintEvent *event)
{
// Skip painting until the dial file is loaded
// Skip painting until the image file is loaded
if (!m_renderer->isValid()) {
qDebug() << "Image file not loaded, not rendering";
}
@ -159,7 +152,6 @@ void JoystickControl::resizeEvent(QResizeEvent *event)
fitInView(m_background, Qt::IgnoreAspectRatio );
}
/**
* @}
* @}

View File

@ -7,7 +7,7 @@
* @{
* @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin
* @{
* @brief A that mimics a transmitter joystick and updates the MCC
* @brief The plugin that mimics a transmitter joystick and updates the MCC
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
@ -25,7 +25,6 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef JOYSTICKCONTROL_H
#define JOYSTICKCONTROL_H
@ -56,10 +55,10 @@ protected:
void resizeEvent(QResizeEvent *event);
public slots:
void changePosition (double X, double Y);
void changePosition(double x, double y);
signals:
void positionClicked(double X, double Y);
void positionClicked(double x, double y);
private:
QSvgRenderer *m_renderer;