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