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 * @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 * This program is free software; you can redistribute it and/or modify
@ -28,30 +28,24 @@
#include "joystickcontrol.h" #include "joystickcontrol.h"
#include "extensionsystem/pluginmanager.h" #include "extensionsystem/pluginmanager.h"
#include <QDebug> #include <QDebug>
#include <QStringList>
#include <QtGui/QWidget> #include <QtGui/QWidget>
#include <QtGui/QTextEdit>
#include <QtGui/QVBoxLayout>
#include <QtGui/QPushButton>
#include <QtGui/QMessageBox>
#include <QMouseEvent>
#include <QtOpenGL/QGLWidget> #include <QtOpenGL/QGLWidget>
#include <QtGlobal> #include <QMouseEvent>
/** /**
* @brief Constructor for JoystickControl widget. Sets up the image of a joystick * @brief Constructor for JoystickControl widget. Sets up the image of a joystick
*/ */
JoystickControl::JoystickControl(QWidget *parent) : JoystickControl::JoystickControl(QWidget *parent) : QGraphicsView(parent)
QGraphicsView(parent)
{ {
setMinimumSize(64,64); setMinimumSize(64, 64);
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
setScene(new QGraphicsScene(this)); setScene(new QGraphicsScene(this));
setRenderHints(QPainter::Antialiasing); setRenderHints(QPainter::Antialiasing);
m_renderer = new QSvgRenderer(); m_renderer = new QSvgRenderer();
bool test = m_renderer->load(QString(":/gcscontrol/images/joystick.svg")); bool test = m_renderer->load(QString(":/gcscontrol/images/joystick.svg"));
Q_ASSERT( test ); Q_UNUSED(test);
Q_ASSERT(test);
m_background = new QGraphicsSvgItem(); m_background = new QGraphicsSvgItem();
m_background->setSharedRenderer(m_renderer); m_background->setSharedRenderer(m_renderer);
@ -82,18 +76,18 @@ JoystickControl::JoystickControl(QWidget *parent) :
JoystickControl::~JoystickControl() JoystickControl::~JoystickControl()
{ {
// Do nothing
} }
/*! /**
\brief Enables/Disables OpenGL * @brief Enables/Disables OpenGL
*/ */
void JoystickControl::enableOpenGL(bool flag) void JoystickControl::enableOpenGL(bool flag)
{ {
if (flag) if (flag)
setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
else else
setViewport(new QWidget); setViewport(new QWidget);
} }
/** /**
@ -103,8 +97,8 @@ void JoystickControl::changePosition(double x, double y)
{ {
QRectF areaSize = m_joystickArea->boundingRect(); QRectF areaSize = m_joystickArea->boundingRect();
QPointF point( QPointF point(
((1 + x) * areaSize.width() - m_joystickEnd->boundingRect().width()) * 0.5, ((1.0 + x) * areaSize.width() - m_joystickEnd->boundingRect().width()) * 0.5,
((1 - y) * areaSize.height() - m_joystickEnd->boundingRect().height()) * 0.5 ((1.0 - y) * areaSize.height() - m_joystickEnd->boundingRect().height()) * 0.5
); );
m_joystickEnd->setPos(m_joystickArea->mapToScene(point)); m_joystickEnd->setPos(m_joystickArea->mapToScene(point));
} }
@ -117,14 +111,14 @@ void JoystickControl::mouseMoveEvent(QMouseEvent *event)
QPointF point = m_joystickArea->mapFromScene(mapToScene(event->pos())); QPointF point = m_joystickArea->mapFromScene(mapToScene(event->pos()));
QSizeF areaSize = m_joystickArea->boundingRect().size(); QSizeF areaSize = m_joystickArea->boundingRect().size();
double Y = - (point.y() / areaSize.height() - .5) * 2; double y = - (point.y() / areaSize.height() - 0.5) * 2.0;
double X = (point.x() / areaSize.width() - .5) * 2; double x = (point.x() / areaSize.width() - 0.5) * 2.0;
if (Y<-1) Y = -1; if (y < -1.0) y = -1.0;
if (Y> 1) Y = 1; if (y > 1.0) y = 1.0;
if (X<-1) X = -1; if (x < -1.0) x = -1.0;
if (X> 1) X = 1; if (x > 1.0) x = 1.0;
emit positionClicked(X, Y); emit positionClicked(x, y);
} }
/** /**
@ -132,12 +126,11 @@ void JoystickControl::mouseMoveEvent(QMouseEvent *event)
*/ */
void JoystickControl::mousePressEvent(QMouseEvent *event) void JoystickControl::mousePressEvent(QMouseEvent *event)
{ {
if( event->button() == Qt::LeftButton ) { if (event->button() == Qt::LeftButton) {
mouseMoveEvent(event); mouseMoveEvent(event);
} }
} }
void JoystickControl::paint() void JoystickControl::paint()
{ {
update(); update();
@ -145,9 +138,9 @@ void JoystickControl::paint()
void JoystickControl::paintEvent(QPaintEvent *event) 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()) { if (!m_renderer->isValid()) {
qDebug()<<"Image file not loaded, not rendering"; qDebug() << "Image file not loaded, not rendering";
} }
QGraphicsView::paintEvent(event); QGraphicsView::paintEvent(event);
@ -159,7 +152,6 @@ void JoystickControl::resizeEvent(QResizeEvent *event)
fitInView(m_background, Qt::IgnoreAspectRatio ); fitInView(m_background, Qt::IgnoreAspectRatio );
} }
/** /**
* @} * @}
* @} * @}

View File

@ -7,7 +7,7 @@
* @{ * @{
* @addtogroup GCSControlGadgetPlugin GCSControl Gadget Plugin * @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 * 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 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef JOYSTICKCONTROL_H #ifndef JOYSTICKCONTROL_H
#define JOYSTICKCONTROL_H #define JOYSTICKCONTROL_H
@ -46,27 +45,27 @@ class JoystickControl : public QGraphicsView
public: public:
explicit JoystickControl(QWidget *parent = 0); explicit JoystickControl(QWidget *parent = 0);
~JoystickControl(); ~JoystickControl();
void enableOpenGL(bool flag); void enableOpenGL(bool flag);
void paint(); void paint();
protected: protected:
void mouseMoveEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event);
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent *event); void resizeEvent(QResizeEvent *event);
public slots: public slots:
void changePosition (double X, double Y); void changePosition(double x, double y);
signals: signals:
void positionClicked(double X, double Y); void positionClicked(double x, double y);
private: private:
QSvgRenderer *m_renderer; QSvgRenderer *m_renderer;
QGraphicsSvgItem *m_background; QGraphicsSvgItem *m_background;
QGraphicsSvgItem *m_joystickArea; QGraphicsSvgItem *m_joystickArea;
QGraphicsSvgItem *m_joystickEnd; QGraphicsSvgItem *m_joystickEnd;
}; };
#endif // JOYSTICKCONTROL_H #endif // JOYSTICKCONTROL_H