mem leaks--, globals--, better macro names, Q_OBJECT++, other name improvemets
This commit is contained in:
@ -18,29 +18,27 @@ set(qjoypad_SOURCES
|
|||||||
main.cpp
|
main.cpp
|
||||||
quickset.cpp)
|
quickset.cpp)
|
||||||
|
|
||||||
set(qjoypad_HEADERS
|
set(qjoypad_QOBJECT_HEADERS
|
||||||
axis_edit.h
|
axis_edit.h
|
||||||
axis.h
|
axis.h
|
||||||
axisw.h
|
axisw.h
|
||||||
button_edit.h
|
button_edit.h
|
||||||
button.h
|
button.h
|
||||||
buttonw.h
|
buttonw.h
|
||||||
constant.h
|
flash.h
|
||||||
device.h
|
getkey.h
|
||||||
error.h
|
icon.h
|
||||||
event.h
|
joypad.h
|
||||||
flash.h
|
joypadw.h
|
||||||
getkey.h
|
joyslider.h
|
||||||
icon.h
|
keycode.h
|
||||||
joypad.h
|
layout_edit.h
|
||||||
joypadw.h
|
layout.h
|
||||||
joyslider.h
|
quickset.h)
|
||||||
keycode.h
|
|
||||||
layout_edit.h
|
|
||||||
layout.h
|
|
||||||
quickset.h)
|
|
||||||
|
|
||||||
QT4_WRAP_CPP(qjoypad_HEADERS_MOC ${qjoypad_HEADERS})
|
set(qjoypad_HEADERS ${qjoypad_QOBJECT_HEADERS} constant.h error.h event.h)
|
||||||
|
|
||||||
|
QT4_WRAP_CPP(qjoypad_HEADERS_MOC ${qjoypad_QOBJECT_HEADERS})
|
||||||
add_executable(qjoypad ${qjoypad_SOURCES} ${qjoypad_HEADERS_MOC})
|
add_executable(qjoypad ${qjoypad_SOURCES} ${qjoypad_HEADERS_MOC})
|
||||||
target_link_libraries(qjoypad ${QT_LIBRARIES} Xtst X11)
|
target_link_libraries(qjoypad ${QT_LIBRARIES} Xtst X11)
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef AXIS_H
|
#ifndef QJOYPAD_AXIS_H
|
||||||
#define AXIS_H
|
#define QJOYPAD_AXIS_H
|
||||||
|
|
||||||
//abs()
|
//abs()
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -178,7 +178,7 @@ void AxisEdit::accept() {
|
|||||||
axis->transferCurve = (TransferCurve)CTransferCurve->currentIndex();
|
axis->transferCurve = (TransferCurve)CTransferCurve->currentIndex();
|
||||||
axis->sensitivity = SSensitivity->value();
|
axis->sensitivity = SSensitivity->value();
|
||||||
axis->throttle = CThrottle->currentIndex() - 1;
|
axis->throttle = CThrottle->currentIndex() - 1;
|
||||||
axis->dZone = Slider->dZone();
|
axis->dZone = Slider->deadZone();
|
||||||
axis->xZone = Slider->xZone();
|
axis->xZone = Slider->xZone();
|
||||||
axis->mode = (AxisMode) CMode->currentIndex();
|
axis->mode = (AxisMode) CMode->currentIndex();
|
||||||
axis->pkeycode = BPos->getValue();
|
axis->pkeycode = BPos->getValue();
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef AXIS_EDIT_H
|
#ifndef QJOYPAD_AXIS_EDIT_H
|
||||||
#define AXIS_EDIT_H
|
#define QJOYPAD_AXIS_EDIT_H
|
||||||
//to refer to the axis we're editing
|
//to refer to the axis we're editing
|
||||||
//for building up the dialog we need
|
//for building up the dialog we need
|
||||||
#include "axis.h"
|
#include "axis.h"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef AXIS_WIDGET_H
|
#ifndef QJOYPAD_AXIS_WIDGET_H
|
||||||
#define AXIS_WIDGET_H
|
#define QJOYPAD_AXIS_WIDGET_H
|
||||||
|
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
//so we can interact with the axis this refers to
|
//so we can interact with the axis this refers to
|
||||||
@ -11,6 +11,8 @@
|
|||||||
#include "axis_edit.h"
|
#include "axis_edit.h"
|
||||||
|
|
||||||
class AxisWidget : public FlashButton {
|
class AxisWidget : public FlashButton {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AxisWidget( Axis* a, QWidget* parent );
|
AxisWidget( Axis* a, QWidget* parent );
|
||||||
//this is notified on a jsevent so it can flash if necesary.
|
//this is notified on a jsevent so it can flash if necesary.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef BUTTON_H
|
#ifndef QJOYPAD_BUTTON_H
|
||||||
#define BUTTON_H
|
#define QJOYPAD_BUTTON_H
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef BUTTON_EDIT_H
|
#ifndef QJOYPAD_BUTTON_EDIT_H
|
||||||
#define BUTTON_EDIT_H
|
#define QJOYPAD_BUTTON_EDIT_H
|
||||||
|
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef BUTTON_WIDGET_H
|
#ifndef QJOYPAD_BUTTON_WIDGET_H
|
||||||
#define BUTTON_WIDGET_H
|
#define QJOYPAD_BUTTON_WIDGET_H
|
||||||
|
|
||||||
//this represents a Button
|
//this represents a Button
|
||||||
#include "button.h"
|
#include "button.h"
|
||||||
@ -14,6 +14,8 @@
|
|||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
|
||||||
class ButtonWidget : public FlashButton {
|
class ButtonWidget : public FlashButton {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ButtonWidget( Button* b, QWidget* parent);
|
ButtonWidget( Button* b, QWidget* parent);
|
||||||
void jsevent( int val );
|
void jsevent( int val );
|
||||||
|
16
src/device.h
16
src/device.h
@ -1,16 +0,0 @@
|
|||||||
#ifndef JOY_DEVICE_H
|
|
||||||
#define JOY_DEVICE_H
|
|
||||||
|
|
||||||
#include "joypad.h"
|
|
||||||
|
|
||||||
//the purpose of this file is to make device information available to what
|
|
||||||
//needs it.
|
|
||||||
|
|
||||||
//a collection of joysticks currently available on this computer
|
|
||||||
extern QHash<int, JoyPad*> available;
|
|
||||||
|
|
||||||
//a collection of joypad objects representing all the available joysticks
|
|
||||||
//as well as the ones defined in a layout buy not currently plugged in.
|
|
||||||
extern QHash<int, JoyPad*> joypads;
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef JEVENT_H
|
#ifndef QJOYPAD_EVENT_H
|
||||||
#define JEVENT_H
|
#define QJOYPAD_EVENT_H
|
||||||
|
|
||||||
//for the functions we need to generate keypresses / mouse actions
|
//for the functions we need to generate keypresses / mouse actions
|
||||||
#include <X11/extensions/XTest.h>
|
#include <X11/extensions/XTest.h>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef FLASH_H
|
#ifndef QJOYPAD_FLASH_H
|
||||||
#define FLASH_H
|
#define QJOYPAD_FLASH_H
|
||||||
|
|
||||||
|
|
||||||
//The color the buttons flash! Feel free to change this.
|
//The color the buttons flash! Feel free to change this.
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
#ifndef QJOYPAD_GETKEY_H
|
||||||
|
#define QJOYPAD_GETKEY_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
@ -26,3 +29,5 @@ class GetKey : public QDialog {
|
|||||||
//does this dialog accept mouse clicks?
|
//does this dialog accept mouse clicks?
|
||||||
bool mouse;
|
bool mouse;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef JOY_ICON_H
|
#ifndef QJOYPAD_ICON_H
|
||||||
#define JOY_ICON_H
|
#define QJOYPAD_ICON_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
JoyPad::JoyPad( int i, int dev ) {
|
JoyPad::JoyPad( int i, int dev, QObject *parent ) : QObject(parent) {
|
||||||
debug_mesg("Constructing the joypad device with index %d and fd %d\n", i, dev);
|
debug_mesg("Constructing the joypad device with index %d and fd %d\n", i, dev);
|
||||||
//remember the index,
|
//remember the index,
|
||||||
index = i;
|
index = i;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef JOYPAD_H
|
#ifndef QJOYPAD_JOYPAD_H
|
||||||
#define JOYPAD_H
|
#define QJOYPAD_JOYPAD_H
|
||||||
|
|
||||||
//parts of the joypad
|
//parts of the joypad
|
||||||
#include "button.h"
|
#include "button.h"
|
||||||
@ -29,7 +29,7 @@ class JoyPad : public QObject {
|
|||||||
friend class QuickSet;
|
friend class QuickSet;
|
||||||
public:
|
public:
|
||||||
void setupJoyDeviceListener(int dev);
|
void setupJoyDeviceListener(int dev);
|
||||||
JoyPad( int i, int dev );
|
JoyPad( int i, int dev, QObject* parent );
|
||||||
//read from a stream
|
//read from a stream
|
||||||
bool readConfig( QTextStream &stream );
|
bool readConfig( QTextStream &stream );
|
||||||
//write to a stream
|
//write to a stream
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef JOYPAD_WIDGET_H
|
#ifndef QJOYPAD_JOYPAD_WIDGET_H
|
||||||
#define JOYPAD_WIDGET_H
|
#define QJOYPAD_JOYPAD_WIDGET_H
|
||||||
|
|
||||||
//parts for the widget
|
//parts for the widget
|
||||||
//Added by qt3to4:
|
//Added by qt3to4:
|
||||||
|
@ -5,18 +5,32 @@ JoySlider::JoySlider( int dz, int xz, int val, QWidget* parent )
|
|||||||
:QWidget( parent )
|
:QWidget( parent )
|
||||||
{
|
{
|
||||||
//initialize :)
|
//initialize :)
|
||||||
JoyVal = val;
|
|
||||||
DeadZone = dz;
|
boxwidth = 0;
|
||||||
XZone = xz;
|
boxheight = 0;
|
||||||
|
rboxstart = 0;
|
||||||
|
rboxend = 0;
|
||||||
|
lboxstart = 0;
|
||||||
|
lboxend = 0;
|
||||||
|
twidth = 0;
|
||||||
|
tend = 0;
|
||||||
|
|
||||||
|
throttle = 0;
|
||||||
|
dragState = DragNone;
|
||||||
|
|
||||||
|
joyval = val;
|
||||||
|
deadzone = dz;
|
||||||
|
xzone = xz;
|
||||||
|
|
||||||
setMinimumHeight(20);
|
setMinimumHeight(20);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JoySlider::setValue( int newval )
|
void JoySlider::setValue( int newval )
|
||||||
{
|
{
|
||||||
//adjust the new position based on the throttle settings
|
//adjust the new position based on the throttle settings
|
||||||
if (throttle == 0) JoyVal = newval;
|
if (throttle == 0) joyval = newval;
|
||||||
else if (throttle < 0) JoyVal = (newval + JOYMIN) / 2;
|
else if (throttle < 0) joyval = (newval + JOYMIN) / 2;
|
||||||
else JoyVal = (newval + JOYMAX) / 2;
|
else joyval = (newval + JOYMAX) / 2;
|
||||||
//then redraw!
|
//then redraw!
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
@ -130,18 +144,18 @@ void JoySlider::paintEvent( QPaintEvent* )
|
|||||||
|
|
||||||
//prepare to draw a bar of the appropriate color
|
//prepare to draw a bar of the appropriate color
|
||||||
QColor bar;
|
QColor bar;
|
||||||
if (abs(JoyVal) < DeadZone) bar = Qt::gray;
|
if (abs(joyval) < deadzone) bar = Qt::gray;
|
||||||
else if (abs(JoyVal) < XZone) bar = Qt::blue;
|
else if (abs(joyval) < xzone) bar = Qt::blue;
|
||||||
else bar = Qt::red;
|
else bar = Qt::red;
|
||||||
paint.setPen( bar );
|
paint.setPen( bar );
|
||||||
paint.setBrush( bar );
|
paint.setBrush( bar );
|
||||||
|
|
||||||
//find out the dimensions of the bar, then draw it
|
//find out the dimensions of the bar, then draw it
|
||||||
int width = (throttle == 0)?boxwidth:twidth;
|
int width = (throttle == 0)?boxwidth:twidth;
|
||||||
int barlen = abs(((width - 4) * JoyVal) / JOYMAX);
|
int barlen = abs(((width - 4) * joyval) / JOYMAX);
|
||||||
if (JoyVal > 0)
|
if (joyval > 0)
|
||||||
paint.drawRect( ((throttle == 0)?rboxstart:lboxstart) + 2, 3, barlen, boxheight - 3 );
|
paint.drawRect( ((throttle == 0)?rboxstart:lboxstart) + 2, 3, barlen, boxheight - 3 );
|
||||||
else if (JoyVal < 0)
|
else if (joyval < 0)
|
||||||
paint.drawRect( lboxstart + width - 2 - barlen, 3, barlen, boxheight - 3 );
|
paint.drawRect( lboxstart + width - 2 - barlen, 3, barlen, boxheight - 3 );
|
||||||
|
|
||||||
|
|
||||||
@ -154,7 +168,7 @@ void JoySlider::paintEvent( QPaintEvent* )
|
|||||||
paint.setPen( Qt::black );
|
paint.setPen( Qt::black );
|
||||||
paint.setBrush( Qt::blue );
|
paint.setBrush( Qt::blue );
|
||||||
if (throttle >= 0) {
|
if (throttle >= 0) {
|
||||||
point = pointFor(DeadZone, false);
|
point = pointFor(deadzone, false);
|
||||||
shape.putPoints(0,5,
|
shape.putPoints(0,5,
|
||||||
point, boxheight - 4,
|
point, boxheight - 4,
|
||||||
point + 3, boxheight - 1,
|
point + 3, boxheight - 1,
|
||||||
@ -165,7 +179,7 @@ void JoySlider::paintEvent( QPaintEvent* )
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (throttle <= 0) {
|
if (throttle <= 0) {
|
||||||
point = pointFor(DeadZone, true);
|
point = pointFor(deadzone, true);
|
||||||
shape.putPoints(0,5,
|
shape.putPoints(0,5,
|
||||||
point, boxheight - 4,
|
point, boxheight - 4,
|
||||||
point + 3, boxheight - 1,
|
point + 3, boxheight - 1,
|
||||||
@ -179,7 +193,7 @@ void JoySlider::paintEvent( QPaintEvent* )
|
|||||||
|
|
||||||
paint.setBrush( Qt::red );
|
paint.setBrush( Qt::red );
|
||||||
if (throttle >= 0) {
|
if (throttle >= 0) {
|
||||||
point = pointFor(XZone, false);
|
point = pointFor(xzone, false);
|
||||||
shape.putPoints(0,5,
|
shape.putPoints(0,5,
|
||||||
point, boxheight - 4,
|
point, boxheight - 4,
|
||||||
point + 3, boxheight - 1,
|
point + 3, boxheight - 1,
|
||||||
@ -190,7 +204,7 @@ void JoySlider::paintEvent( QPaintEvent* )
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (throttle <= 0) {
|
if (throttle <= 0) {
|
||||||
point = pointFor(XZone, true);
|
point = pointFor(xzone, true);
|
||||||
shape.putPoints(0,5,
|
shape.putPoints(0,5,
|
||||||
point, boxheight - 4,
|
point, boxheight - 4,
|
||||||
point + 3, boxheight - 1,
|
point + 3, boxheight - 1,
|
||||||
@ -205,19 +219,18 @@ void JoySlider::mousePressEvent( QMouseEvent* e )
|
|||||||
{
|
{
|
||||||
//store the x coordinate.
|
//store the x coordinate.
|
||||||
int xpt = e->x();
|
int xpt = e->x();
|
||||||
int result = 0;
|
|
||||||
//see if this happened near one of the tabs. If so, start dragging that tab.
|
//see if this happened near one of the tabs. If so, start dragging that tab.
|
||||||
if (throttle <= 0 && abs( xpt - pointFor( XZone, true )) < 5) result = DRAG_XZ;
|
if (throttle <= 0 && abs( xpt - pointFor( xzone, true )) < 5) dragState = DragXZ;
|
||||||
else if (throttle <= 0 && abs( xpt - pointFor( DeadZone, true )) < 5) result = DRAG_DZ;
|
else if (throttle <= 0 && abs( xpt - pointFor( deadzone, true )) < 5) dragState = DragDZ;
|
||||||
else if (throttle >= 0 && abs( xpt - pointFor( XZone, false )) < 5) result = DRAG_XZ;
|
else if (throttle >= 0 && abs( xpt - pointFor( xzone, false )) < 5) dragState = DragXZ;
|
||||||
else if (throttle >= 0 && abs( xpt - pointFor( DeadZone, false )) < 5) result = DRAG_DZ;
|
else if (throttle >= 0 && abs( xpt - pointFor( deadzone, false )) < 5) dragState = DragDZ;
|
||||||
dragging = result;
|
else dragState = DragNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JoySlider::mouseReleaseEvent( QMouseEvent* )
|
void JoySlider::mouseReleaseEvent( QMouseEvent* )
|
||||||
{
|
{
|
||||||
//when the mouse releases, all dragging stops.
|
//when the mouse releases, all dragging stops.
|
||||||
dragging = 0;
|
dragState = DragNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JoySlider::mouseMoveEvent( QMouseEvent* e )
|
void JoySlider::mouseMoveEvent( QMouseEvent* e )
|
||||||
@ -225,15 +238,18 @@ void JoySlider::mouseMoveEvent( QMouseEvent* e )
|
|||||||
//get the x coordinate
|
//get the x coordinate
|
||||||
int xpt = e->x();
|
int xpt = e->x();
|
||||||
//if we're dragging, move the appropriate tab!
|
//if we're dragging, move the appropriate tab!
|
||||||
if (dragging == DRAG_XZ)
|
switch (dragState) {
|
||||||
{
|
case DragXZ:
|
||||||
XZone = valueFrom( xpt );
|
xzone = valueFrom( xpt );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DragDZ:
|
||||||
|
deadzone = valueFrom( xpt );
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else if (dragging == DRAG_DZ)
|
|
||||||
{
|
|
||||||
DeadZone = valueFrom( xpt );
|
|
||||||
}
|
|
||||||
else return;
|
|
||||||
//if we moved a tab, redraw!
|
//if we moved a tab, redraw!
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef Q_JOYSLIDER_H
|
#ifndef QJOYPAD_JOYSLIDER_H
|
||||||
#define Q_JOYSLIDER_H
|
#define QJOYPAD_JOYSLIDER_H
|
||||||
|
|
||||||
//the parent of this
|
//the parent of this
|
||||||
|
|
||||||
@ -15,14 +15,20 @@
|
|||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
#include "constant.h"
|
#include "constant.h"
|
||||||
|
|
||||||
//dragging constants.
|
|
||||||
//When dragging == DRAG_XZ, that means we are currently dragging the xZone mark
|
|
||||||
#define DRAG_XZ 1
|
|
||||||
//When dragging == DRAG_DZ, that means we are currently dragging the dZone mark
|
|
||||||
#define DRAG_DZ 2
|
|
||||||
|
|
||||||
class JoySlider : public QWidget
|
class JoySlider : public QWidget
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
enum DragState {
|
||||||
|
DragNone = 0,
|
||||||
|
|
||||||
|
//When dragState == DragXZ, that means we are currently dragging the xZone mark
|
||||||
|
DragXZ = 1,
|
||||||
|
|
||||||
|
//When dragState == DragDZ, that means we are currently dragging the deadZone mark
|
||||||
|
DragDZ = 2
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
JoySlider( int dz, int xz, int val, QWidget* parent );
|
JoySlider( int dz, int xz, int val, QWidget* parent );
|
||||||
//set where the axis physically is
|
//set where the axis physically is
|
||||||
@ -30,8 +36,8 @@ class JoySlider : public QWidget
|
|||||||
//change the throttle mode
|
//change the throttle mode
|
||||||
void setThrottle( int );
|
void setThrottle( int );
|
||||||
//get the current settings
|
//get the current settings
|
||||||
int dZone() { return DeadZone; };
|
int deadZone() { return deadzone; }
|
||||||
int xZone() { return XZone; };
|
int xZone() { return xzone; }
|
||||||
protected:
|
protected:
|
||||||
//all for getting the widget to look right:
|
//all for getting the widget to look right:
|
||||||
void drawBox( int x, int width );
|
void drawBox( int x, int width );
|
||||||
@ -63,13 +69,13 @@ class JoySlider : public QWidget
|
|||||||
int valueFrom( int point );
|
int valueFrom( int point );
|
||||||
|
|
||||||
//the current drag and drop state
|
//the current drag and drop state
|
||||||
int dragging;
|
DragState dragState;
|
||||||
|
|
||||||
//the axis' position
|
//the axis' position
|
||||||
int JoyVal;
|
int joyval;
|
||||||
//the dead and extreme zone values
|
//the dead and extreme zone values
|
||||||
int DeadZone;
|
int deadzone;
|
||||||
int XZone;
|
int xzone;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef KEYCODE_H
|
#ifndef QJOYPAD_KEYCODE_H
|
||||||
#define KEYCODE_H
|
#define QJOYPAD_KEYCODE_H
|
||||||
|
|
||||||
//To create the "press a key" dialog:
|
//To create the "press a key" dialog:
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
@ -22,8 +22,8 @@ class KeyButton : public QPushButton {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
KeyButton(QString name, int val, QWidget* parent, bool m = false, bool nowMouse = false);
|
KeyButton(QString name, int val, QWidget* parent, bool m = false, bool nowMouse = false);
|
||||||
int getValue() {return value;};
|
int getValue() {return value;}
|
||||||
int choseMouse() {return mouseClicked;};
|
int choseMouse() {return mouseClicked;}
|
||||||
protected slots:
|
protected slots:
|
||||||
void onClick();
|
void onClick();
|
||||||
private:
|
private:
|
||||||
|
@ -94,7 +94,7 @@ bool LayoutManager::load(const QString& name) {
|
|||||||
int index = num - 1;
|
int index = num - 1;
|
||||||
//if there was no joypad defined for this index before, make it now!
|
//if there was no joypad defined for this index before, make it now!
|
||||||
if (joypads[index] == 0) {
|
if (joypads[index] == 0) {
|
||||||
joypads.insert(index, new JoyPad(index, -1));
|
joypads.insert(index, new JoyPad(index, -1, this));
|
||||||
}
|
}
|
||||||
//try to read the joypad, report error on fail.
|
//try to read the joypad, report error on fail.
|
||||||
if (!joypads[index]->readConfig(stream)) {
|
if (!joypads[index]->readConfig(stream)) {
|
||||||
@ -363,7 +363,7 @@ void LayoutManager::updateJoyDevs() {
|
|||||||
debug_mesg("reading junk data\n");
|
debug_mesg("reading junk data\n");
|
||||||
if (read(joydev, buf, 10) <= 0) break;
|
if (read(joydev, buf, 10) <= 0) break;
|
||||||
}
|
}
|
||||||
joypad = new JoyPad( index, joydev );
|
joypad = new JoyPad( index, joydev, this );
|
||||||
joypads.insert(index,joypad);
|
joypads.insert(index,joypad);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef JOY_LAYOUT_H
|
#ifndef QJOYPAD_LAYOUT_H
|
||||||
#define JOY_LAYOUT_H
|
#define QJOYPAD_LAYOUT_H
|
||||||
|
|
||||||
|
|
||||||
//to allow for interprocess communications (ie, signaling a running instance of
|
//to allow for interprocess communications (ie, signaling a running instance of
|
||||||
@ -21,8 +21,6 @@
|
|||||||
#include "joypad.h"
|
#include "joypad.h"
|
||||||
//for errors
|
//for errors
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
//so we know which joypads have RL equivalents
|
|
||||||
#include "device.h"
|
|
||||||
//For displaying a floating icon instead of a tray icon
|
//For displaying a floating icon instead of a tray icon
|
||||||
#include "icon.h"
|
#include "icon.h"
|
||||||
//So we can know if there is a graphical version of the Layout Manager displayed
|
//So we can know if there is a graphical version of the Layout Manager displayed
|
||||||
@ -85,6 +83,9 @@ class LayoutManager : public QObject {
|
|||||||
|
|
||||||
//if there is a LayoutEdit open, this points to it. Otherwise, NULL.
|
//if there is a LayoutEdit open, this points to it. Otherwise, NULL.
|
||||||
LayoutEdit* le;
|
LayoutEdit* le;
|
||||||
|
|
||||||
|
QHash<int, JoyPad*> available;
|
||||||
|
QHash<int, JoyPad*> joypads;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -7,64 +7,64 @@ LayoutEdit::LayoutEdit( LayoutManager* l ): QWidget(NULL) {
|
|||||||
setWindowTitle( NAME );
|
setWindowTitle( NAME );
|
||||||
setWindowIcon(QPixmap(ICON24));
|
setWindowIcon(QPixmap(ICON24));
|
||||||
|
|
||||||
LMain = new QVBoxLayout( this);
|
mainLayout = new QVBoxLayout( this);
|
||||||
LMain->setSpacing(5);
|
mainLayout->setSpacing(5);
|
||||||
LMain->setMargin(5);
|
mainLayout->setMargin(5);
|
||||||
|
|
||||||
QFrame* frame = new QFrame(this);
|
QFrame* frame = new QFrame(this);
|
||||||
frame->setFrameStyle(QFrame::Box | QFrame::Sunken );
|
frame->setFrameStyle(QFrame::Box | QFrame::Sunken );
|
||||||
QGridLayout* g = new QGridLayout(frame);
|
QGridLayout* g = new QGridLayout(frame);
|
||||||
g->setMargin(5);
|
g->setMargin(5);
|
||||||
g->setSpacing(5);
|
g->setSpacing(5);
|
||||||
CLayouts = new QComboBox(frame);
|
cmbLayouts = new QComboBox(frame);
|
||||||
connect( CLayouts, SIGNAL(activated( const QString& )), lm, SLOT(load(const QString&)));
|
connect( cmbLayouts, SIGNAL(activated( const QString& )), lm, SLOT(load(const QString&)));
|
||||||
g->addWidget(CLayouts,0,0,1,4);
|
g->addWidget(cmbLayouts,0,0,1,4);
|
||||||
|
|
||||||
//most of these buttons can link directly into slots in the LayoutManager
|
//most of these buttons can link directly into slots in the LayoutManager
|
||||||
BAdd = new QPushButton("Add", frame);
|
btnAdd = new QPushButton("Add", frame);
|
||||||
connect(BAdd, SIGNAL(clicked()), lm, SLOT(saveAs()));
|
connect(btnAdd, SIGNAL(clicked()), lm, SLOT(saveAs()));
|
||||||
g->addWidget(BAdd,1,0);
|
g->addWidget(btnAdd,1,0);
|
||||||
BRem = new QPushButton("Remove", frame);
|
btnRem = new QPushButton("Remove", frame);
|
||||||
connect(BRem, SIGNAL(clicked()), lm, SLOT(remove()));
|
connect(btnRem, SIGNAL(clicked()), lm, SLOT(remove()));
|
||||||
g->addWidget(BRem,1,1);
|
g->addWidget(btnRem,1,1);
|
||||||
BUpd = new QPushButton("Update", frame);
|
btnUpd = new QPushButton("Update", frame);
|
||||||
connect(BUpd, SIGNAL(clicked()), lm, SLOT(save()));
|
connect(btnUpd, SIGNAL(clicked()), lm, SLOT(save()));
|
||||||
g->addWidget(BUpd,1,2);
|
g->addWidget(btnUpd,1,2);
|
||||||
BRev = new QPushButton("Revert", frame);
|
btnRev = new QPushButton("Revert", frame);
|
||||||
connect(BRev, SIGNAL(clicked()), lm, SLOT(reload()));
|
connect(btnRev, SIGNAL(clicked()), lm, SLOT(reload()));
|
||||||
g->addWidget(BRev,1,3);
|
g->addWidget(btnRev,1,3);
|
||||||
LMain->addWidget( frame );
|
mainLayout->addWidget( frame );
|
||||||
|
|
||||||
//produce a list of names for the FlashRadioArray
|
//produce a list of names for the FlashRadioArray
|
||||||
//this is only necesary since joystick devices need not always be
|
//this is only necesary since joystick devices need not always be
|
||||||
//contiguous
|
//contiguous
|
||||||
QStringList names;
|
QStringList names;
|
||||||
foreach (JoyPad *joypad, available) {
|
foreach (JoyPad *joypad, lm->available) {
|
||||||
names.append(joypad->getName());
|
names.append(joypad->getName());
|
||||||
connect(this, SIGNAL(focusStateChanged(bool)), joypad, SLOT(focusChange(bool)));
|
connect(this, SIGNAL(focusStateChanged(bool)), joypad, SLOT(focusChange(bool)));
|
||||||
}
|
}
|
||||||
|
|
||||||
//flash radio array
|
//flash radio array
|
||||||
JoyButtons = new FlashRadioArray(names, true, this );
|
joyButtons = new FlashRadioArray(names, true, this );
|
||||||
LMain->addWidget( JoyButtons );
|
mainLayout->addWidget( joyButtons );
|
||||||
|
|
||||||
//we have a WidgetStack to represent the multiple joypads
|
//we have a WidgetStack to represent the multiple joypads
|
||||||
PadStack = new QStackedWidget( this );
|
padStack = new QStackedWidget( this );
|
||||||
PadStack->setFrameStyle(QFrame::Box | QFrame::Sunken );
|
padStack->setFrameStyle(QFrame::Box | QFrame::Sunken );
|
||||||
LMain->addWidget(PadStack);
|
mainLayout->addWidget(padStack);
|
||||||
|
|
||||||
//go through each of the available joysticks
|
//go through each of the available joysticks
|
||||||
// i is the current index into PadStack
|
// i is the current index into PadStack
|
||||||
int i = 0;
|
int i = 0;
|
||||||
foreach (JoyPad *joypad, available) {
|
foreach (JoyPad *joypad, lm->available) {
|
||||||
//add a new JoyPadWidget to the stack
|
//add a new JoyPadWidget to the stack
|
||||||
PadStack->insertWidget( i, joypad->widget(PadStack,i) );
|
padStack->insertWidget( i, joypad->widget(padStack,i) );
|
||||||
//every time it "flashes", flash the associated tab.
|
//every time it "flashes", flash the associated tab.
|
||||||
connect( PadStack->widget(i), SIGNAL( flashed( int ) ), JoyButtons, SLOT( flash( int )));
|
connect( padStack->widget(i), SIGNAL( flashed( int ) ), joyButtons, SLOT( flash( int )));
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
//whenever a new tab is selected, raise the appropriate JoyPadWidget
|
//whenever a new tab is selected, raise the appropriate JoyPadWidget
|
||||||
connect( JoyButtons, SIGNAL( changed( int ) ), PadStack, SLOT( setCurrentIndex( int )));
|
connect( joyButtons, SIGNAL( changed( int ) ), padStack, SLOT( setCurrentIndex( int )));
|
||||||
|
|
||||||
updateLayoutList();
|
updateLayoutList();
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ LayoutEdit::LayoutEdit( LayoutManager* l ): QWidget(NULL) {
|
|||||||
QPushButton* quit = new QPushButton( "-- Quit --", this );
|
QPushButton* quit = new QPushButton( "-- Quit --", this );
|
||||||
connect( quit, SIGNAL( clicked() ), qApp, SLOT(quit()));
|
connect( quit, SIGNAL( clicked() ), qApp, SLOT(quit()));
|
||||||
h->addWidget(quit);
|
h->addWidget(quit);
|
||||||
LMain->addLayout(h);
|
mainLayout->addLayout(h);
|
||||||
connect(qApp, SIGNAL(focusChanged ( QWidget * , QWidget * ) ), this,
|
connect(qApp, SIGNAL(focusChanged ( QWidget * , QWidget * ) ), this,
|
||||||
SLOT(appFocusChanged(QWidget *, QWidget *)));
|
SLOT(appFocusChanged(QWidget *, QWidget *)));
|
||||||
this->show();
|
this->show();
|
||||||
@ -86,46 +86,46 @@ LayoutEdit::LayoutEdit( LayoutManager* l ): QWidget(NULL) {
|
|||||||
|
|
||||||
void LayoutEdit::setLayout(QString layout) {
|
void LayoutEdit::setLayout(QString layout) {
|
||||||
//change the text,
|
//change the text,
|
||||||
CLayouts->setCurrentIndex(lm->getLayoutNames().indexOf(layout));
|
cmbLayouts->setCurrentIndex(lm->getLayoutNames().indexOf(layout));
|
||||||
//update all the JoyPadWidgets.
|
//update all the JoyPadWidgets.
|
||||||
for (int i = 0; i < available.count(); i++) {
|
for (int i = 0, n = lm->available.count(); i < n; i++) {
|
||||||
((JoyPadWidget*)PadStack->widget(i))->update();
|
((JoyPadWidget*)padStack->widget(i))->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutEdit::updateLayoutList() {
|
void LayoutEdit::updateLayoutList() {
|
||||||
//blank the list, then load in new names from the LayoutManager.
|
//blank the list, then load in new names from the LayoutManager.
|
||||||
CLayouts->clear();
|
cmbLayouts->clear();
|
||||||
QStringList layouts = lm->getLayoutNames();
|
QStringList layouts = lm->getLayoutNames();
|
||||||
CLayouts->insertItems(-1, layouts);
|
cmbLayouts->insertItems(-1, layouts);
|
||||||
CLayouts->setCurrentIndex(layouts.indexOf(lm->currentLayout));
|
cmbLayouts->setCurrentIndex(layouts.indexOf(lm->currentLayout));
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutEdit::updateJoypadWidgets() {
|
void LayoutEdit::updateJoypadWidgets() {
|
||||||
int indexOfFlashRadio = LMain->indexOf(JoyButtons);
|
int indexOfFlashRadio = mainLayout->indexOf(joyButtons);
|
||||||
FlashRadioArray *newJoyButtons;
|
FlashRadioArray *newJoyButtons;
|
||||||
QStringList names;
|
QStringList names;
|
||||||
foreach (JoyPad *joypad, available) {
|
foreach (JoyPad *joypad, lm->available) {
|
||||||
names.append(joypad->getName());
|
names.append(joypad->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
newJoyButtons = new FlashRadioArray( names, true, this );
|
newJoyButtons = new FlashRadioArray( names, true, this );
|
||||||
LMain->insertWidget(indexOfFlashRadio, newJoyButtons);
|
mainLayout->insertWidget(indexOfFlashRadio, newJoyButtons);
|
||||||
LMain->removeWidget(JoyButtons);
|
mainLayout->removeWidget(joyButtons);
|
||||||
FlashRadioArray* oldJoyButtons = JoyButtons;
|
FlashRadioArray* oldJoyButtons = joyButtons;
|
||||||
JoyButtons = newJoyButtons;
|
joyButtons = newJoyButtons;
|
||||||
connect( JoyButtons, SIGNAL( changed( int ) ), PadStack, SLOT( setCurrentIndex( int )));
|
connect( joyButtons, SIGNAL( changed( int ) ), padStack, SLOT( setCurrentIndex( int )));
|
||||||
oldJoyButtons->deleteLater();
|
oldJoyButtons->deleteLater();
|
||||||
int numberOfJoypads = PadStack->count();
|
int numberOfJoypads = padStack->count();
|
||||||
for(int i = 0; i<numberOfJoypads; i++) {
|
for(int i = 0; i<numberOfJoypads; i++) {
|
||||||
PadStack->removeWidget(PadStack->widget(0));
|
padStack->removeWidget(padStack->widget(0));
|
||||||
}
|
}
|
||||||
int i = 0;
|
int i = 0;
|
||||||
foreach (JoyPad *joypad, available) {
|
foreach (JoyPad *joypad, lm->available) {
|
||||||
//add a new JoyPadWidget to the stack
|
//add a new JoyPadWidget to the stack
|
||||||
PadStack->insertWidget( i, joypad->widget(PadStack,i) );
|
padStack->insertWidget( i, joypad->widget(padStack,i) );
|
||||||
//every time it "flashes", flash the associated tab.
|
//every time it "flashes", flash the associated tab.
|
||||||
connect( PadStack->widget(i), SIGNAL( flashed( int ) ), JoyButtons, SLOT( flash( int )));
|
connect( padStack->widget(i), SIGNAL( flashed( int ) ), joyButtons, SLOT( flash( int )));
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -140,7 +140,7 @@ void LayoutEdit::appFocusChanged(QWidget *old, QWidget *now) {
|
|||||||
emit focusStateChanged(false);
|
emit focusStateChanged(false);
|
||||||
} else if(old!=NULL && now==NULL) {
|
} else if(old!=NULL && now==NULL) {
|
||||||
emit focusStateChanged(true);
|
emit focusStateChanged(true);
|
||||||
foreach (JoyPad *joypad, available) {
|
foreach (JoyPad *joypad, lm->available) {
|
||||||
debug_mesg("iterating and releasing\n");
|
debug_mesg("iterating and releasing\n");
|
||||||
joypad->release();
|
joypad->release();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef LAYOUT_EDIT_H
|
#ifndef QJOYPAD_LAYOUT_EDIT_H
|
||||||
#define LAYOUT_EDIT_H
|
#define QJOYPAD_LAYOUT_EDIT_H
|
||||||
|
|
||||||
#include <QStackedWidget>
|
#include <QStackedWidget>
|
||||||
|
|
||||||
@ -8,8 +8,6 @@
|
|||||||
//this is a front end for the non-GUI LayoutManager
|
//this is a front end for the non-GUI LayoutManager
|
||||||
class LayoutEdit;
|
class LayoutEdit;
|
||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
//so we can see the available devices
|
|
||||||
#include "device.h"
|
|
||||||
//so we can use the LayoutEditer to edit key layouts :)
|
//so we can use the LayoutEditer to edit key layouts :)
|
||||||
#include "joypadw.h"
|
#include "joypadw.h"
|
||||||
|
|
||||||
@ -33,11 +31,11 @@ class LayoutEdit : public QWidget {
|
|||||||
LayoutManager* lm;
|
LayoutManager* lm;
|
||||||
virtual void closeEvent(QCloseEvent *event);
|
virtual void closeEvent(QCloseEvent *event);
|
||||||
//parts of the dialog:
|
//parts of the dialog:
|
||||||
QVBoxLayout *LMain;
|
QVBoxLayout *mainLayout;
|
||||||
QStackedWidget *PadStack;
|
QStackedWidget *padStack;
|
||||||
FlashRadioArray *JoyButtons;
|
FlashRadioArray *joyButtons;
|
||||||
QComboBox* CLayouts;
|
QComboBox* cmbLayouts;
|
||||||
QPushButton *BAdd, *BRem, *BUpd, *BRev;
|
QPushButton *btnAdd, *btnRem, *btnUpd, *btnRev;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -12,8 +12,6 @@
|
|||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
//to give event.h the current X11 display
|
//to give event.h the current X11 display
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
//to update the joystick device list
|
|
||||||
#include "device.h"
|
|
||||||
//to produce errors!
|
//to produce errors!
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include <QX11Info>
|
#include <QX11Info>
|
||||||
@ -21,10 +19,6 @@
|
|||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
|
||||||
//for making universally available variables
|
|
||||||
QHash<int, JoyPad*> available; //to device.h
|
|
||||||
QHash<int, JoyPad*> joypads; //to device.h
|
|
||||||
|
|
||||||
//variables needed in various functions in this file
|
//variables needed in various functions in this file
|
||||||
QPointer<LayoutManager> layoutManagerPtr;
|
QPointer<LayoutManager> layoutManagerPtr;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef QUICKSET_H
|
#ifndef QJOYPAD_QUICKSET_H
|
||||||
#define QUICKSET_H
|
#define QJOYPAD_QUICKSET_H
|
||||||
|
|
||||||
//for building the dialog
|
//for building the dialog
|
||||||
#include <QLayout>
|
#include <QLayout>
|
||||||
@ -18,6 +18,8 @@ class JoyPad;
|
|||||||
|
|
||||||
//a dialog to quickly set a key to a button
|
//a dialog to quickly set a key to a button
|
||||||
class QuickSet : public QDialog {
|
class QuickSet : public QDialog {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QuickSet(JoyPad* jp, QWidget *parent = 0);
|
QuickSet(JoyPad* jp, QWidget *parent = 0);
|
||||||
//this needs to see js_events so it can capture them directly
|
//this needs to see js_events so it can capture them directly
|
||||||
|
Reference in New Issue
Block a user