JoystickWidget.h 3.16 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
26
 *   @brief Definition of joystick widget. Provides a UI for configuring the joystick settings.
pixhawk's avatar
pixhawk committed
27 28 29 30 31 32 33
 *   @author Lorenz Meier <mavteam@student.ethz.ch>
 *
 */

#ifndef JOYSTICKWIDGET_H
#define JOYSTICKWIDGET_H

34
#include <QWidget>
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
class JoystickWidget : public QWidget
48
{
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
    /** @brief Update the UI for a new joystick based on SDL ID. */
57
    void createUIForJoystick();
58 59 60 61 62 63
    /**
     * @brief Update a given axis with a new value
     * @param axis The index of the axis to update.
     * @param value The new value for the axis, [-1.0:1.0].
     * @see JoystickInput:axisValueChanged
     */
64
    void updateAxisValue(int axis, float value);
65 66 67
    /** @brief Update the UI with new values for the hat.
     *  @see JoystickInput::hatDirectionChanged
     */
68
    void setHat(qint8 x, qint8 y);
69 70 71 72 73
    /** @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);
    /** @brief Update the UI color scheme when the MainWindow theme changes. */
74
    void styleChanged(bool styleIsDark);
75 76
    /** Update the UI assuming the joystick has stayed the same. */
    void updateUI();
pixhawk's avatar
pixhawk committed
77 78

protected:
pixhawk's avatar
pixhawk committed
79
    /** @brief UI change event */
pixhawk's avatar
pixhawk committed
80
    virtual void changeEvent(QEvent *e);
pixhawk's avatar
pixhawk committed
81
    JoystickInput* joystick;  ///< Reference to the joystick
82
    /** @brief a list of all button labels generated for this joystick. */
83 84 85
    QList<JoystickButton*> buttons;
    /** @brief a lit of all joystick axes generated for this joystick. */
    QList<JoystickAxis*> axes;
86 87
    /** @brief The color to use for button labels when their corresponding button is pressed */
    QColor buttonLabelColor;
pixhawk's avatar
pixhawk committed
88 89 90

private:
    Ui::JoystickWidget *m_ui;
91 92 93
    /** @brief Initialize all dynamic UI elements (button list, joystick names, etc.).
     * Only done once at startup.
     */
94
    void initUI();
pixhawk's avatar
pixhawk committed
95 96 97
};

#endif // JOYSTICKWIDGET_H