From 9006dd558f97dce5da4677be57f3cded0fb3cb4d Mon Sep 17 00:00:00 2001 From: Oleg Semyonov Date: Sat, 21 Jan 2012 00:52:35 +0200 Subject: [PATCH] gcscontrol: code style formatting and cleanup --- .../plugins/gcscontrol/joystickcontrol.cpp | 60 ++++++++----------- .../src/plugins/gcscontrol/joystickcontrol.h | 21 ++++--- 2 files changed, 36 insertions(+), 45 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/gcscontrol/joystickcontrol.cpp b/ground/openpilotgcs/src/plugins/gcscontrol/joystickcontrol.cpp index 3e8e111df..0596b22c1 100644 --- a/ground/openpilotgcs/src/plugins/gcscontrol/joystickcontrol.cpp +++ b/ground/openpilotgcs/src/plugins/gcscontrol/joystickcontrol.cpp @@ -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,30 +28,24 @@ #include "joystickcontrol.h" #include "extensionsystem/pluginmanager.h" #include -#include #include -#include -#include -#include -#include -#include #include -#include +#include /** * @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); + setMinimumSize(64, 64); setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); setScene(new QGraphicsScene(this)); setRenderHints(QPainter::Antialiasing); m_renderer = new QSvgRenderer(); 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->setSharedRenderer(m_renderer); @@ -82,18 +76,18 @@ JoystickControl::JoystickControl(QWidget *parent) : JoystickControl::~JoystickControl() { - + // Do nothing } -/*! - \brief Enables/Disables OpenGL +/** + * @brief Enables/Disables OpenGL */ void JoystickControl::enableOpenGL(bool flag) { - if (flag) - setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); - else - setViewport(new QWidget); + if (flag) + setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); + else + setViewport(new QWidget); } /** @@ -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); } /** @@ -132,12 +126,11 @@ void JoystickControl::mouseMoveEvent(QMouseEvent *event) */ void JoystickControl::mousePressEvent(QMouseEvent *event) { - if( event->button() == Qt::LeftButton ) { + if (event->button() == Qt::LeftButton) { mouseMoveEvent(event); } } - void JoystickControl::paint() { update(); @@ -145,9 +138,9 @@ void JoystickControl::paint() void JoystickControl::paintEvent(QPaintEvent *event) { - // Skip painting until the dial file is loaded - if (! m_renderer->isValid()) { - qDebug()<<"Image file not loaded, not rendering"; + // Skip painting until the image file is loaded + if (!m_renderer->isValid()) { + qDebug() << "Image file not loaded, not rendering"; } QGraphicsView::paintEvent(event); @@ -159,7 +152,6 @@ void JoystickControl::resizeEvent(QResizeEvent *event) fitInView(m_background, Qt::IgnoreAspectRatio ); } - /** * @} * @} diff --git a/ground/openpilotgcs/src/plugins/gcscontrol/joystickcontrol.h b/ground/openpilotgcs/src/plugins/gcscontrol/joystickcontrol.h index bd0871761..9c6ac59d0 100644 --- a/ground/openpilotgcs/src/plugins/gcscontrol/joystickcontrol.h +++ b/ground/openpilotgcs/src/plugins/gcscontrol/joystickcontrol.h @@ -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 @@ -46,27 +45,27 @@ class JoystickControl : public QGraphicsView public: explicit JoystickControl(QWidget *parent = 0); ~JoystickControl(); - void enableOpenGL(bool flag); - void paint(); + void enableOpenGL(bool flag); + void paint(); protected: - void mouseMoveEvent(QMouseEvent *event); - void mousePressEvent(QMouseEvent *event); - void paintEvent(QPaintEvent *event); - void resizeEvent(QResizeEvent *event); + void mouseMoveEvent(QMouseEvent *event); + void mousePressEvent(QMouseEvent *event); + void paintEvent(QPaintEvent *event); + 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; QGraphicsSvgItem *m_background; QGraphicsSvgItem *m_joystickArea; QGraphicsSvgItem *m_joystickEnd; - }; +}; #endif // JOYSTICKCONTROL_H