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))
Axis::Axis( int i ) {
Axis::Axis( int i, QObject *parent ) : QObject(parent) {
index = i;
isOn = false;
isDown = false;

View File

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

View File

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

View File

@ -14,7 +14,7 @@ class Button : public QObject {
Q_OBJECT
friend class ButtonEdit;
public:
Button( int i );
Button( int i, QObject *parent = 0 );
~Button();
//read from 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");
resetToDev(dev);
debug_mesg("done resetting and setting up device index %d\n", i);
char id[200];
ioctl(joydev, JSIOCGNAME(199), id);
deviceId = id;
} else {
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
//will already exist and no new axis will be created.
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++) {
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;
read_struct.fd = joydev;
@ -215,7 +218,7 @@ void JoyPad::release() {
void JoyPad::jsevent( js_event msg ) {
//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
//the appropriate button, if necesary.
jpw->jsevent(msg);
@ -291,3 +294,7 @@ void JoyPad::errorRead(int fd) {
joydev = -1;
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);
//called when the joypad is no longer being edited.
void releaseWidget();
QString getId();
protected:
//lookup axes and buttons. These are dictionaries to support
//layouts with different numbers of axes/buttons than the current
@ -74,9 +75,12 @@ class JoyPad : public QObject{
JoyPadWidget* jpw;
QSocketNotifier *joydevFileHandle;
QSocketNotifier *joydevFileException;
QString deviceId;
bool hasFocus;
public slots:
void handleJoyEvents(int fd);
void errorRead(int fd);
void focusChange(bool windowHasFocus);
};
#endif

View File

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

View File

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

View File

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