Commit 295b8a25 authored by Bryant's avatar Bryant

The joystick settings window has now been reworked to be a fixed minimum size...

The joystick settings window has now been reworked to be a fixed minimum size and dynamically scale with both the number of buttons and axes on a given joystick/controller. Mapping functionality is incomplete at this point still, though the UI exists for it.
parent f4c1eaab
...@@ -233,7 +233,9 @@ FORMS += src/ui/MainWindow.ui \ ...@@ -233,7 +233,9 @@ FORMS += src/ui/MainWindow.ui \
src/ui/uas/UASActionsWidget.ui \ src/ui/uas/UASActionsWidget.ui \
src/ui/QGCTabbedInfoView.ui \ src/ui/QGCTabbedInfoView.ui \
src/ui/UASRawStatusView.ui \ src/ui/UASRawStatusView.ui \
src/ui/uas/QGCMessageView.ui src/ui/uas/QGCMessageView.ui \
src/ui/JoystickButton.ui \
src/ui/JoystickAxis.ui
INCLUDEPATH += src \ INCLUDEPATH += src \
src/ui \ src/ui \
src/ui/linechart \ src/ui/linechart \
...@@ -391,7 +393,9 @@ HEADERS += src/MG.h \ ...@@ -391,7 +393,9 @@ HEADERS += src/MG.h \
src/ui/QGCTabbedInfoView.h \ src/ui/QGCTabbedInfoView.h \
src/ui/UASRawStatusView.h \ src/ui/UASRawStatusView.h \
src/ui/PrimaryFlightDisplay.h \ src/ui/PrimaryFlightDisplay.h \
src/ui/uas/QGCMessageView.h src/ui/uas/QGCMessageView.h \
src/ui/JoystickButton.h \
src/ui/JoystickAxis.h
# Google Earth is only supported on Mac OS and Windows with Visual Studio Compiler # Google Earth is only supported on Mac OS and Windows with Visual Studio Compiler
macx|macx-g++|macx-g++42|win32-msvc2008|win32-msvc2010|win32-msvc2012::HEADERS += src/ui/map3D/QGCGoogleEarthView.h macx|macx-g++|macx-g++42|win32-msvc2008|win32-msvc2010|win32-msvc2012::HEADERS += src/ui/map3D/QGCGoogleEarthView.h
...@@ -567,7 +571,9 @@ SOURCES += src/main.cc \ ...@@ -567,7 +571,9 @@ SOURCES += src/main.cc \
src/ui/QGCTabbedInfoView.cpp \ src/ui/QGCTabbedInfoView.cpp \
src/ui/UASRawStatusView.cpp \ src/ui/UASRawStatusView.cpp \
src/ui/PrimaryFlightDisplay.cpp \ src/ui/PrimaryFlightDisplay.cpp \
src/ui/uas/QGCMessageView.cc src/ui/uas/QGCMessageView.cc \
src/ui/JoystickButton.cc \
src/ui/JoystickAxis.cc
# Enable Google Earth only on Mac OS and Windows with Visual Studio compiler # Enable Google Earth only on Mac OS and Windows with Visual Studio compiler
macx|macx-g++|macx-g++42|win32-msvc2008|win32-msvc2010|win32-msvc2012::SOURCES += src/ui/map3D/QGCGoogleEarthView.cc macx|macx-g++|macx-g++42|win32-msvc2008|win32-msvc2010|win32-msvc2012::SOURCES += src/ui/map3D/QGCGoogleEarthView.cc
......
...@@ -332,7 +332,8 @@ void JoystickInput::setActiveJoystick(int id) ...@@ -332,7 +332,8 @@ void JoystickInput::setActiveJoystick(int id)
{ {
joystickName = QString(SDL_JoystickName(joystickID)); joystickName = QString(SDL_JoystickName(joystickID));
joystickButtons = SDL_JoystickNumButtons(joystick); joystickButtons = SDL_JoystickNumButtons(joystick);
qDebug() << QString("Switching to joystick '%1' with %2 buttons").arg(joystickName, QString::number(joystickButtons)); joystickAxes = SDL_JoystickNumAxes(joystick);
qDebug() << QString("Switching to joystick '%1' with %2 buttons/%3 axes").arg(joystickName, QString::number(joystickButtons), QString::number(joystickAxes));
} }
buttonState = 0; buttonState = 0;
} }
......
...@@ -109,6 +109,11 @@ public: ...@@ -109,6 +109,11 @@ public:
return joystickButtons; return joystickButtons;
} }
int getJoystickNumAxes() const
{
return joystickAxes;
}
int getJoystickID() const int getJoystickID() const
{ {
return joystickID; return joystickID;
...@@ -147,6 +152,7 @@ protected: ...@@ -147,6 +152,7 @@ protected:
int stabilizeButtonMapping; int stabilizeButtonMapping;
SDL_Event event; SDL_Event event;
QString joystickName; QString joystickName;
int joystickAxes;
int joystickButtons; int joystickButtons;
int joystickID; int joystickID;
int joysticksFound; int joysticksFound;
......
#include "JoystickAxis.h"
#include "ui_JoystickAxis.h"
#include <QString>
JoystickAxis::JoystickAxis(int id, QWidget *parent) :
QWidget(parent),
ui(new Ui::JoystickAxis)
{
ui->setupUi(this);
ui->label->setText(QString::number(id));
}
JoystickAxis::~JoystickAxis()
{
delete ui;
}
void JoystickAxis::setValue(int value)
{
ui->progressBar->setValue(value);
}
#ifndef JOYSTICKAXIS_H
#define JOYSTICKAXIS_H
#include <QWidget>
namespace Ui {
class JoystickAxis;
}
class JoystickAxis : public QWidget
{
Q_OBJECT
public:
explicit JoystickAxis(int id, QWidget *parent = 0);
~JoystickAxis();
public slots:
void setValue(int value);
private:
Ui::JoystickAxis *ui;
};
#endif // JOYSTICKAXIS_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>JoystickAxis</class>
<widget class="QWidget" name="JoystickAxis">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>40</width>
<height>200</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>40</width>
<height>200</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<property name="leftMargin">
<number>1</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>1</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>--</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QProgressBar" name="progressBar">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
</size>
</property>
<property name="value">
<number>0</number>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="textVisible">
<bool>false</bool>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
#include "JoystickButton.h"
#include "ui_JoystickButton.h"
JoystickButton::JoystickButton(int id, QWidget *parent) :
QWidget(parent),
id(id),
m_ui(new Ui::JoystickButton)
{
m_ui->setupUi(this);
m_ui->joystickButtonLabel->setText(QString::number(id));
}
JoystickButton::~JoystickButton()
{
delete m_ui;
}
#ifndef JOYSTICKBUTTON_H
#define JOYSTICKBUTTON_H
#include <QWidget>
namespace Ui
{
class JoystickButton;
}
class JoystickButton : public QWidget
{
Q_OBJECT
public:
explicit JoystickButton(int id, QWidget *parent = 0);
virtual ~JoystickButton();
private:
int id;
Ui::JoystickButton *m_ui;
};
#endif // JOYSTICKBUTTON_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>JoystickButton</class>
<widget class="QWidget" name="JoystickButton">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>125</width>
<height>27</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>1</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>1</number>
</property>
<item>
<widget class="QComboBox" name="joystickAction">
<item>
<property name="text">
<string>--</string>
</property>
</item>
<item>
<property name="text">
<string>Yaw</string>
</property>
</item>
<item>
<property name="text">
<string>Pitch</string>
</property>
</item>
<item>
<property name="text">
<string>Roll</string>
</property>
</item>
<item>
<property name="text">
<string>Throttle</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="joystickButtonLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
#include "JoystickWidget.h" #include "JoystickWidget.h"
#include "MainWindow.h" #include "MainWindow.h"
#include "ui_JoystickWidget.h" #include "ui_JoystickWidget.h"
#include "JoystickButton.h"
#include "JoystickAxis.h"
#include <QDebug> #include <QDebug>
#include <QDesktopWidget> #include <QDesktopWidget>
...@@ -25,15 +27,18 @@ JoystickWidget::JoystickWidget(JoystickInput* joystick, QWidget *parent) : ...@@ -25,15 +27,18 @@ JoystickWidget::JoystickWidget(JoystickInput* joystick, QWidget *parent) :
connect(this->joystick, SIGNAL(buttonReleased(int)), this, SLOT(joystickButtonReleased(int))); connect(this->joystick, SIGNAL(buttonReleased(int)), this, SLOT(joystickButtonReleased(int)));
// Watch for changes to the button/axis mappings // Watch for changes to the button/axis mappings
connect(m_ui->rollMapSpinBox, SIGNAL(valueChanged(int)), this->joystick, SLOT(setMappingXAxis(int))); // connect(m_ui->rollMapSpinBox, SIGNAL(valueChanged(int)), this->joystick, SLOT(setMappingXAxis(int)));
connect(m_ui->pitchMapSpinBox, SIGNAL(valueChanged(int)), this->joystick, SLOT(setMappingYAxis(int))); // connect(m_ui->pitchMapSpinBox, SIGNAL(valueChanged(int)), this->joystick, SLOT(setMappingYAxis(int)));
connect(m_ui->yawMapSpinBox, SIGNAL(valueChanged(int)), this->joystick, SLOT(setMappingYawAxis(int))); // connect(m_ui->yawMapSpinBox, SIGNAL(valueChanged(int)), this->joystick, SLOT(setMappingYawAxis(int)));
connect(m_ui->throttleMapSpinBox, SIGNAL(valueChanged(int)), this->joystick, SLOT(setMappingThrustAxis(int))); // connect(m_ui->throttleMapSpinBox, SIGNAL(valueChanged(int)), this->joystick, SLOT(setMappingThrustAxis(int)));
connect(m_ui->autoMapSpinBox, SIGNAL(valueChanged(int)), this->joystick, SLOT(setMappingAutoButton(int))); // connect(m_ui->autoMapSpinBox, SIGNAL(valueChanged(int)), this->joystick, SLOT(setMappingAutoButton(int)));
// Update the UI if the joystick changes. // Update the UI if the joystick changes.
connect(m_ui->joystickNameComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUIForJoystick(int))); connect(m_ui->joystickNameComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUIForJoystick(int)));
// Enable/disable the UI based on the enable checkbox
connect(m_ui->enableCheckBox, SIGNAL(toggled(bool)), m_ui->joystickFrame, SLOT(setEnabled(bool)));
// Update the button label colors based on the current theme and watch for future theme changes. // Update the button label colors based on the current theme and watch for future theme changes.
styleChanged(MainWindow::instance()->getStyle()); styleChanged(MainWindow::instance()->getStyle());
connect(MainWindow::instance(), SIGNAL(styleChanged(MainWindow::QGC_MAINWINDOW_STYLE)), this, SLOT(styleChanged(MainWindow::QGC_MAINWINDOW_STYLE))); connect(MainWindow::instance(), SIGNAL(styleChanged(MainWindow::QGC_MAINWINDOW_STYLE)), this, SLOT(styleChanged(MainWindow::QGC_MAINWINDOW_STYLE)));
...@@ -55,6 +60,11 @@ void JoystickWidget::initUI() ...@@ -55,6 +60,11 @@ void JoystickWidget::initUI()
m_ui->joystickNameComboBox->addItem(joystick->getJoystickNameById(i)); m_ui->joystickNameComboBox->addItem(joystick->getJoystickNameById(i));
} }
m_ui->joystickNameComboBox->setCurrentIndex(joystick->getJoystickID()); m_ui->joystickNameComboBox->setCurrentIndex(joystick->getJoystickID());
// And if joystick support is enabled, show the UI.
if (m_ui->enableCheckBox->isChecked())
{
m_ui->joystickFrame->setEnabled(true);
}
} }
else else
{ {
...@@ -104,56 +114,71 @@ void JoystickWidget::changeEvent(QEvent *e) ...@@ -104,56 +114,71 @@ void JoystickWidget::changeEvent(QEvent *e)
void JoystickWidget::updateUIForJoystick(int id) void JoystickWidget::updateUIForJoystick(int id)
{ {
// Delete all the old buttonlabels // Delete all the old UI elements
foreach (QLabel* l, buttonLabels) foreach (JoystickButton* b, buttons)
{ {
delete l; delete b;
} }
buttonLabels.clear(); buttons.clear();
foreach (JoystickAxis* a, axes)
{
delete a;
}
axes.clear();
// Set the JoystickInput to listen to the new joystick instead. // Set the JoystickInput to listen to the new joystick instead.
joystick->setActiveJoystick(id); joystick->setActiveJoystick(id);
// And add new ones for every new button found. // And add the necessary button displays for this joystick.
for (int i = 0; i < joystick->getJoystickNumButtons(); i++) int newButtons = joystick->getJoystickNumButtons();
for (int i = 0; i < newButtons; i++)
{ {
QLabel* buttonLabel = new QLabel(m_ui->buttonLabelBox); JoystickButton* button = new JoystickButton(i, m_ui->buttonBox);
buttonLabel->setText(QString::number(i));
buttonLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
buttonLabel->setAlignment(Qt::AlignCenter);
// And make sure we insert BEFORE the vertical spacer. // And make sure we insert BEFORE the vertical spacer.
m_ui->buttonLabelLayout->insertWidget(i, buttonLabel); m_ui->buttonLayout->insertWidget(i, button);
buttonLabels.append(buttonLabel); buttons.append(button);
} }
// Update the mapping UI // Do the same for the axes supported by this joystick.
m_ui->rollMapSpinBox->setValue(joystick->getMappingXAxis()); for (int i = 0; i < joystick->getJoystickNumAxes(); i++)
m_ui->pitchMapSpinBox->setValue(joystick->getMappingYAxis()); {
m_ui->yawMapSpinBox->setValue(joystick->getMappingYawAxis()); JoystickAxis* axis = new JoystickAxis(i, m_ui->axesBox);
m_ui->throttleMapSpinBox->setValue(joystick->getMappingThrustAxis()); // And make sure we insert BEFORE the vertical spacer.
m_ui->autoMapSpinBox->setValue(joystick->getMappingAutoButton()); m_ui->axesLayout->insertWidget(i, axis);
} axes.append(axis);
}
void JoystickWidget::setThrottle(float thrust)
{
m_ui->thrust->setValue(thrust*100);
} }
void JoystickWidget::setX(float x) void JoystickWidget::setX(float x)
{ {
m_ui->xSlider->setValue(x*100); if (axes.size() > 0)
m_ui->xValue->display(x*100); {
axes.at(0)->setValue(x * 100);
}
} }
void JoystickWidget::setY(float y) void JoystickWidget::setY(float y)
{ {
m_ui->ySlider->setValue(y*100); if (axes.size() > 1)
m_ui->yValue->display(y*100); {
axes.at(1)->setValue(y * 100);
}
} }
void JoystickWidget::setZ(float z) void JoystickWidget::setZ(float z)
{ {
m_ui->dial->setValue(z*100); if (axes.size() > 2)
{
axes.at(2)->setValue(z * 100);
}
}
void JoystickWidget::setThrottle(float t)
{
if (axes.size() > 3)
{
axes.at(3)->setValue(t * 100);
}
} }
void JoystickWidget::setHat(float x, float y) void JoystickWidget::setHat(float x, float y)
...@@ -164,15 +189,14 @@ void JoystickWidget::setHat(float x, float y) ...@@ -164,15 +189,14 @@ void JoystickWidget::setHat(float x, float y)
void JoystickWidget::joystickButtonPressed(int key) void JoystickWidget::joystickButtonPressed(int key)
{ {
QString colorStyle = QString("QLabel { background-color: %1;}").arg(buttonLabelColor.name()); QString colorStyle = QString("QLabel { background-color: %1;}").arg(buttonLabelColor.name());
buttonLabels.at(key)->setStyleSheet(colorStyle); buttons.at(key)->setStyleSheet(colorStyle);
} }
void JoystickWidget::joystickButtonReleased(int key) void JoystickWidget::joystickButtonReleased(int key)
{ {
buttonLabels.at(key)->setStyleSheet(""); buttons.at(key)->setStyleSheet("");
} }
void JoystickWidget::updateStatus(const QString& status) void JoystickWidget::updateStatus(const QString& status)
{ {
m_ui->statusLabel->setText(status);
} }
...@@ -35,6 +35,8 @@ This file is part of the PIXHAWK project ...@@ -35,6 +35,8 @@ This file is part of the PIXHAWK project
#include <QLabel> #include <QLabel>
#include "JoystickInput.h" #include "JoystickInput.h"
#include "MainWindow.h" #include "MainWindow.h"
#include "JoystickAxis.h"
#include "JoystickButton.h"
namespace Ui namespace Ui
{ {
...@@ -61,14 +63,14 @@ public slots: ...@@ -61,14 +63,14 @@ public slots:
* @param yHat hat vector in left-right direction, -1 left, 0 center, +1 right * @param yHat hat vector in left-right direction, -1 left, 0 center, +1 right
*/ */
void updateJoystick(double roll, double pitch, double yaw, double thrust, int xHat, int yHat); void updateJoystick(double roll, double pitch, double yaw, double thrust, int xHat, int yHat);
/** @brief Throttle lever */
void setThrottle(float thrust);
/** @brief Back/forth movement */ /** @brief Back/forth movement */
void setX(float x); void setX(float x);
/** @brief Left/right movement */ /** @brief Left/right movement */
void setY(float y); void setY(float y);
/** @brief Wrist rotation */ /** @brief Wrist rotation */
void setZ(float z); void setZ(float z);
/** @brief Throttle lever */
void setThrottle(float thrust);
/** @brief Hat switch position */ /** @brief Hat switch position */
void setHat(float x, float y); void setHat(float x, float y);
/** @brief Trigger a UI change based on a button being pressed */ /** @brief Trigger a UI change based on a button being pressed */
...@@ -87,7 +89,9 @@ protected: ...@@ -87,7 +89,9 @@ protected:
virtual void changeEvent(QEvent *e); virtual void changeEvent(QEvent *e);
JoystickInput* joystick; ///< Reference to the joystick JoystickInput* joystick; ///< Reference to the joystick
/** @brief a list of all button labels generated for this joystick. */ /** @brief a list of all button labels generated for this joystick. */
QList<QLabel*> buttonLabels; QList<JoystickButton*> buttons;
/** @brief a lit of all joystick axes generated for this joystick. */
QList<JoystickAxis*> axes;
/** @brief The color to use for button labels when their corresponding button is pressed */ /** @brief The color to use for button labels when their corresponding button is pressed */
QColor buttonLabelColor; QColor buttonLabelColor;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment