JoystickWidget.h 2.99 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*=====================================================================

PIXHAWK Micro Air Vehicle Flying Robotics Toolkit

(c) 2009, 2010 PIXHAWK PROJECT  <http://pixhawk.ethz.ch>

This file is part of the PIXHAWK project

    PIXHAWK is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    PIXHAWK is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with PIXHAWK. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

/**
 * @file
pixhawk's avatar
pixhawk committed
26
 *   @brief Definition of joystick widget
pixhawk's avatar
pixhawk committed
27 28 29 30 31 32 33 34
 *   @author Lorenz Meier <mavteam@student.ethz.ch>
 *
 */

#ifndef JOYSTICKWIDGET_H
#define JOYSTICKWIDGET_H

#include <QtGui/QDialog>
35
#include <QLabel>
36
#include <QMap>
pixhawk's avatar
pixhawk committed
37
#include "JoystickInput.h"
38
#include "MainWindow.h"
39 40
#include "JoystickAxis.h"
#include "JoystickButton.h"
pixhawk's avatar
pixhawk committed
41

42 43 44
namespace Ui
{
class JoystickWidget;
pixhawk's avatar
pixhawk committed
45 46
}

47 48
class JoystickWidget : public QDialog
{
pixhawk's avatar
pixhawk committed
49 50 51 52 53 54
    Q_OBJECT
    Q_DISABLE_COPY(JoystickWidget)
public:
    explicit JoystickWidget(JoystickInput* joystick, QWidget *parent = 0);
    virtual ~JoystickWidget();

55
public slots:
56
    void updateAxisValue(int axis, float value);
pixhawk's avatar
pixhawk committed
57
    void setHat(float x, float y);
58 59 60 61
    /** @brief Trigger a UI change based on a button being pressed */
    void joystickButtonPressed(int key);
    /** @brief Trigger a UI change based on a button being released */
    void joystickButtonReleased(int key);
62 63
    /** @brief Update status string */
    void updateStatus(const QString& status);
64 65
    /** @brief Update the UI color scheme when the MainWindow theme changes. */
    void styleChanged(MainWindow::QGC_MAINWINDOW_STYLE);
pixhawk's avatar
pixhawk committed
66 67

protected:
68 69
    /** @brief Update the proper number of buttons for the current joystick. */
    void updateButtons();
pixhawk's avatar
pixhawk committed
70
    /** @brief UI change event */
pixhawk's avatar
pixhawk committed
71
    virtual void changeEvent(QEvent *e);
pixhawk's avatar
pixhawk committed
72
    JoystickInput* joystick;  ///< Reference to the joystick
73
    /** @brief a list of all button labels generated for this joystick. */
74 75 76
    QList<JoystickButton*> buttons;
    /** @brief a lit of all joystick axes generated for this joystick. */
    QList<JoystickAxis*> axes;
77 78
    /** @brief The color to use for button labels when their corresponding button is pressed */
    QColor buttonLabelColor;
pixhawk's avatar
pixhawk committed
79

80 81 82
protected slots:
    /** @brief Update the UI for a new joystick based on SDL ID. */
    void updateUIForJoystick(int id);
83 84
    /** @brief Change the stored mapping for a given axis. */
    void setMappingAxis(int axisID, int newMapping);
85

pixhawk's avatar
pixhawk committed
86 87
private:
    Ui::JoystickWidget *m_ui;
88 89
    /** @brief Initialize all dynamic UI elements (button list, joystick names, etc.) */
    void initUI();
pixhawk's avatar
pixhawk committed
90 91 92
};

#endif // JOYSTICKWIDGET_H