From f2a566cc06691ef933bf4d8fbc0bde94f21cd418 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20Panzenb=C3=B6ck?= Date: Sun, 16 Feb 2014 01:12:41 +0100 Subject: [PATCH] mem leaks--, globals--, better macro names, Q_OBJECT++, other name improvemets --- src/CMakeLists.txt | 42 +++++++++---------- src/axis.h | 4 +- src/axis_edit.cpp | 2 +- src/axis_edit.h | 4 +- src/axisw.h | 6 ++- src/button.h | 4 +- src/button_edit.h | 4 +- src/buttonw.h | 6 ++- src/device.h | 16 -------- src/event.h | 4 +- src/flash.h | 4 +- src/getkey.h | 5 +++ src/icon.h | 4 +- src/joypad.cpp | 2 +- src/joypad.h | 6 +-- src/joypadw.h | 4 +- src/joyslider.cpp | 76 +++++++++++++++++++++-------------- src/joyslider.h | 34 +++++++++------- src/keycode.h | 8 ++-- src/layout.cpp | 4 +- src/layout.h | 9 +++-- src/layout_edit.cpp | 98 ++++++++++++++++++++++----------------------- src/layout_edit.h | 16 ++++---- src/main.cpp | 6 --- src/quickset.h | 6 ++- 25 files changed, 191 insertions(+), 183 deletions(-) delete mode 100644 src/device.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 32590d4..eb21e4e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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) diff --git a/src/axis.h b/src/axis.h index 5df77c8..30ac761 100644 --- a/src/axis.h +++ b/src/axis.h @@ -1,5 +1,5 @@ -#ifndef AXIS_H -#define AXIS_H +#ifndef QJOYPAD_AXIS_H +#define QJOYPAD_AXIS_H //abs() #include diff --git a/src/axis_edit.cpp b/src/axis_edit.cpp index af0543d..c2c1a90 100644 --- a/src/axis_edit.cpp +++ b/src/axis_edit.cpp @@ -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(); diff --git a/src/axis_edit.h b/src/axis_edit.h index a875a4c..90571d4 100644 --- a/src/axis_edit.h +++ b/src/axis_edit.h @@ -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" diff --git a/src/axisw.h b/src/axisw.h index 0c2b540..3210cac 100644 --- a/src/axisw.h +++ b/src/axisw.h @@ -1,5 +1,5 @@ -#ifndef AXIS_WIDGET_H -#define AXIS_WIDGET_H +#ifndef QJOYPAD_AXIS_WIDGET_H +#define QJOYPAD_AXIS_WIDGET_H #include //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. diff --git a/src/button.h b/src/button.h index 9f3a066..879dbc9 100644 --- a/src/button.h +++ b/src/button.h @@ -1,5 +1,5 @@ -#ifndef BUTTON_H -#define BUTTON_H +#ifndef QJOYPAD_BUTTON_H +#define QJOYPAD_BUTTON_H #include #include diff --git a/src/button_edit.h b/src/button_edit.h index 4248a0b..92ff3a8 100644 --- a/src/button_edit.h +++ b/src/button_edit.h @@ -1,5 +1,5 @@ -#ifndef BUTTON_EDIT_H -#define BUTTON_EDIT_H +#ifndef QJOYPAD_BUTTON_EDIT_H +#define QJOYPAD_BUTTON_EDIT_H #include #include diff --git a/src/buttonw.h b/src/buttonw.h index 856df81..a3ddac8 100644 --- a/src/buttonw.h +++ b/src/buttonw.h @@ -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 class ButtonWidget : public FlashButton { + Q_OBJECT + public: ButtonWidget( Button* b, QWidget* parent); void jsevent( int val ); diff --git a/src/device.h b/src/device.h deleted file mode 100644 index b7158a6..0000000 --- a/src/device.h +++ /dev/null @@ -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 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 joypads; - -#endif diff --git a/src/event.h b/src/event.h index b9c0eec..d1917bf 100644 --- a/src/event.h +++ b/src/event.h @@ -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 diff --git a/src/flash.h b/src/flash.h index 282d8e6..65c0e4a 100644 --- a/src/flash.h +++ b/src/flash.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. diff --git a/src/getkey.h b/src/getkey.h index 54edce4..eac03e0 100644 --- a/src/getkey.h +++ b/src/getkey.h @@ -1,3 +1,6 @@ +#ifndef QJOYPAD_GETKEY_H +#define QJOYPAD_GETKEY_H + #include #include #include @@ -26,3 +29,5 @@ class GetKey : public QDialog { //does this dialog accept mouse clicks? bool mouse; }; + +#endif diff --git a/src/icon.h b/src/icon.h index fa5689d..feb7d91 100644 --- a/src/icon.h +++ b/src/icon.h @@ -1,5 +1,5 @@ -#ifndef JOY_ICON_H -#define JOY_ICON_H +#ifndef QJOYPAD_ICON_H +#define QJOYPAD_ICON_H #include #include diff --git a/src/joypad.cpp b/src/joypad.cpp index 6d0a9ad..6a5b5c4 100644 --- a/src/joypad.cpp +++ b/src/joypad.cpp @@ -6,7 +6,7 @@ #include #include -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; diff --git a/src/joypad.h b/src/joypad.h index 229eb84..cb8f8f5 100644 --- a/src/joypad.h +++ b/src/joypad.h @@ -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 diff --git a/src/joypadw.h b/src/joypadw.h index b75240e..a758309 100644 --- a/src/joypadw.h +++ b/src/joypadw.h @@ -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: diff --git a/src/joyslider.cpp b/src/joyslider.cpp index 7767adc..262d0f2 100644 --- a/src/joyslider.cpp +++ b/src/joyslider.cpp @@ -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(); } diff --git a/src/joyslider.h b/src/joyslider.h index b48081d..405966f 100644 --- a/src/joyslider.h +++ b/src/joyslider.h @@ -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 #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; }; diff --git a/src/keycode.h b/src/keycode.h index 3bb0216..ab7f253 100644 --- a/src/keycode.h +++ b/src/keycode.h @@ -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 @@ -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: diff --git a/src/layout.cpp b/src/layout.cpp index 6ac43fe..e848f25 100644 --- a/src/layout.cpp +++ b/src/layout.cpp @@ -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 { diff --git a/src/layout.h b/src/layout.h index 64ef938..1d59d6f 100644 --- a/src/layout.h +++ b/src/layout.h @@ -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 available; + QHash joypads; }; #endif diff --git a/src/layout_edit.cpp b/src/layout_edit.cpp index cc18dca..08c048a 100644 --- a/src/layout_edit.cpp +++ b/src/layout_edit.cpp @@ -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; iremoveWidget(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(); } diff --git a/src/layout_edit.h b/src/layout_edit.h index 11c9309..43b9a6d 100644 --- a/src/layout_edit.h +++ b/src/layout_edit.h @@ -1,5 +1,5 @@ -#ifndef LAYOUT_EDIT_H -#define LAYOUT_EDIT_H +#ifndef QJOYPAD_LAYOUT_EDIT_H +#define QJOYPAD_LAYOUT_EDIT_H #include @@ -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 diff --git a/src/main.cpp b/src/main.cpp index 2a69cc7..d68cbcc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 @@ -21,10 +19,6 @@ #include #include -//for making universally available variables -QHash available; //to device.h -QHash joypads; //to device.h - //variables needed in various functions in this file QPointer layoutManagerPtr; diff --git a/src/quickset.h b/src/quickset.h index 398cc65..1d53342 100644 --- a/src/quickset.h +++ b/src/quickset.h @@ -1,5 +1,5 @@ -#ifndef QUICKSET_H -#define QUICKSET_H +#ifndef QJOYPAD_QUICKSET_H +#define QJOYPAD_QUICKSET_H //for building the dialog #include @@ -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