now axis and buttons have their joypads as Qt parents, also if the configuration dialog is open but does not have window focus, joypad events are passed along as if the window is not open

git-svn-id: svn://svn.code.sf.net/p/qjoypad/code/trunk@119 c05e91a0-76c8-4ec0-b377-ef19ce7cc080
This commit is contained in:
John Toman
2009-11-22 22:06:28 +00:00
committed by virtuoussin13
parent 5bafd943f9
commit bdf4b21162
9 changed files with 23 additions and 8 deletions

View File

@ -7,7 +7,7 @@
((a) < (a_low) ? (a_low) : (a) > (a_high) ? (a_high) : (a)) ((a) < (a_low) ? (a_low) : (a) > (a_high) ? (a_high) : (a))
Axis::Axis( int i ) { Axis::Axis( int i, QObject *parent ) : QObject(parent) {
index = i; index = i;
isOn = false; isOn = false;
isDown = false; isDown = false;

View File

@ -26,7 +26,7 @@ class Axis : public QObject {
//so AxisEdit can manipulate fields directly. //so AxisEdit can manipulate fields directly.
friend class AxisEdit; friend class AxisEdit;
public: public:
Axis( int i ); Axis( int i, QObject *parent = 0 );
~Axis(); ~Axis();
//read axis settings from a stream //read axis settings from a stream
bool read( QTextStream* stream ); bool read( QTextStream* stream );

View File

@ -1,7 +1,7 @@
#include "button.h" #include "button.h"
#include "event.h" #include "event.h"
Button::Button( int i ) { Button::Button( int i, QObject *parent ) : QObject(parent) {
index = i; index = i;
isButtonPressed = false; isButtonPressed = false;
isDown = false; isDown = false;

View File

@ -14,7 +14,7 @@ class Button : public QObject {
Q_OBJECT Q_OBJECT
friend class ButtonEdit; friend class ButtonEdit;
public: public:
Button( int i ); Button( int i, QObject *parent = 0 );
~Button(); ~Button();
//read from stream //read from stream
bool read( QTextStream* stream ); bool read( QTextStream* stream );

View File

@ -16,6 +16,9 @@ JoyPad::JoyPad( int i, int dev ) {
debug_mesg("Valid file handle, setting up handlers and reading axis configs...\n"); debug_mesg("Valid file handle, setting up handlers and reading axis configs...\n");
resetToDev(dev); resetToDev(dev);
debug_mesg("done resetting and setting up device index %d\n", i); debug_mesg("done resetting and setting up device index %d\n", i);
char id[200];
ioctl(joydev, JSIOCGNAME(199), id);
deviceId = id;
} else { } else {
debug_mesg("This joypad does not have a valid file handle, not setting up event listeners\n"); debug_mesg("This joypad does not have a valid file handle, not setting up event listeners\n");
} }
@ -41,10 +44,10 @@ void JoyPad::resetToDev(int dev ) {
//that axis into use, the key assignment will not be lost because the axis //that axis into use, the key assignment will not be lost because the axis
//will already exist and no new axis will be created. //will already exist and no new axis will be created.
for (int i = 0; i < axes; i++) { for (int i = 0; i < axes; i++) {
if (Axes[i] == 0) Axes.insert(i, new Axis( i )); if (Axes[i] == 0) Axes.insert(i, new Axis( i, this ));
} }
for (int i = 0; i < buttons; i++) { for (int i = 0; i < buttons; i++) {
if (Buttons[i] == 0) Buttons.insert(i, new Button( i )); if (Buttons[i] == 0) Buttons.insert(i, new Button( i, this ));
} }
struct pollfd read_struct; struct pollfd read_struct;
read_struct.fd = joydev; read_struct.fd = joydev;
@ -215,7 +218,7 @@ void JoyPad::release() {
void JoyPad::jsevent( js_event msg ) { void JoyPad::jsevent( js_event msg ) {
//if there is a JoyPadWidget around, ie, if the joypad is being edited //if there is a JoyPadWidget around, ie, if the joypad is being edited
if (jpw != NULL) { if (jpw != NULL && hasFocus) {
//tell the dialog there was an event. It will use this to flash //tell the dialog there was an event. It will use this to flash
//the appropriate button, if necesary. //the appropriate button, if necesary.
jpw->jsevent(msg); jpw->jsevent(msg);
@ -291,3 +294,7 @@ void JoyPad::errorRead(int fd) {
joydev = -1; joydev = -1;
debug_mesg("Done disabling device with fd %d\n", fd); debug_mesg("Done disabling device with fd %d\n", fd);
} }
void JoyPad::focusChange(bool focusState) {
hasFocus = !focusState;
}

View File

@ -59,6 +59,7 @@ class JoyPad : public QObject{
JoyPadWidget* widget(QWidget* parent, int i); JoyPadWidget* widget(QWidget* parent, int i);
//called when the joypad is no longer being edited. //called when the joypad is no longer being edited.
void releaseWidget(); void releaseWidget();
QString getId();
protected: protected:
//lookup axes and buttons. These are dictionaries to support //lookup axes and buttons. These are dictionaries to support
//layouts with different numbers of axes/buttons than the current //layouts with different numbers of axes/buttons than the current
@ -74,9 +75,12 @@ class JoyPad : public QObject{
JoyPadWidget* jpw; JoyPadWidget* jpw;
QSocketNotifier *joydevFileHandle; QSocketNotifier *joydevFileHandle;
QSocketNotifier *joydevFileException; QSocketNotifier *joydevFileException;
QString deviceId;
bool hasFocus;
public slots: public slots:
void handleJoyEvents(int fd); void handleJoyEvents(int fd);
void errorRead(int fd); void errorRead(int fd);
void focusChange(bool windowHasFocus);
}; };
#endif #endif

View File

@ -1,5 +1,4 @@
#include "joypadw.h" #include "joypadw.h"
//Added by qt3to4:
JoyPadWidget::JoyPadWidget( JoyPad* jp, int i, QWidget* parent ) JoyPadWidget::JoyPadWidget( JoyPad* jp, int i, QWidget* parent )
: QWidget(parent) { : QWidget(parent) {

View File

@ -48,6 +48,7 @@ LayoutEdit::LayoutEdit( LayoutManager* l ): QWidget(NULL) {
{ {
it.next(); it.next();
names[i] = it.value()->getName(); names[i] = it.value()->getName();
connect(this, SIGNAL(focusChange(bool)), it.value(), SLOT(focusChange(bool)));
++i; ++i;
} }
} while (0); } while (0);
@ -157,6 +158,7 @@ void LayoutEdit::updateJoypadWidgets() {
} }
void LayoutEdit::windowActivationChange( bool oldActive ) { void LayoutEdit::windowActivationChange( bool oldActive ) {
emit focusChange(oldActive);
if (oldActive) return; if (oldActive) return;
//whenever the window becomes active, release all pressed buttons! This way //whenever the window becomes active, release all pressed buttons! This way
//you don't get any presses without releases to confuse things. //you don't get any presses without releases to confuse things.

View File

@ -16,6 +16,7 @@ class LayoutEdit;
class LayoutManager; class LayoutManager;
class LayoutEdit : public QWidget { class LayoutEdit : public QWidget {
Q_OBJECT
public: public:
LayoutEdit( LayoutManager* l ); LayoutEdit( LayoutManager* l );
//swap to a new layout //swap to a new layout
@ -23,6 +24,8 @@ class LayoutEdit : public QWidget {
//update the list of available layouts //update the list of available layouts
void updateLayoutList(); void updateLayoutList();
void updateJoypadWidgets(); void updateJoypadWidgets();
signals:
void focusChange(bool);
protected: protected:
//the layout manager this represents //the layout manager this represents
LayoutManager* lm; LayoutManager* lm;