diff --git a/CMakeLists.txt b/CMakeLists.txt index 46759e6..a055611 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ if(PLAIN_KEYS) endif() if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wno-deprecated-declarations") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -pedantic -Wno-deprecated-declarations") if(NOT(CMAKE_BUILD_TYPE STREQUAL "Debug")) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") diff --git a/src/event.cpp b/src/event.cpp index 6191807..6ace5fc 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -1,7 +1,7 @@ #include "event.h" //this should be initialized by main.cpp as soon as the program starts. -Display* display; +Display* display = 0; //actually creates an XWindows event :) void sendevent( xevent e ) { diff --git a/src/flash.cpp b/src/flash.cpp index 58eccbe..02c4078 100644 --- a/src/flash.cpp +++ b/src/flash.cpp @@ -43,7 +43,7 @@ void FlashButton::flash() } -FlashRadioArray::FlashRadioArray( int count, QString names[], bool horizontal, QWidget* parent) +FlashRadioArray::FlashRadioArray( const QStringList &names, bool horizontal, QWidget* parent) :QWidget( parent ) { if (horizontal) { @@ -55,19 +55,23 @@ FlashRadioArray::FlashRadioArray( int count, QString names[], bool horizontal, Q LMain->setMargin(5); LMain->setSpacing(5); } - +// TODO: fix memleak + int count = names.size(); + int i = 0; Buttons = new FlashButton*[count]; - for (int i = 0; i < count; i++) - { - Buttons[i] = new FlashButton( names[i], this, "" ); + foreach (const QString &name, names) { + Buttons[i] = new FlashButton( name, this, "" ); //when any of the buttons is clicked, it calls the same function on this. connect( Buttons[i], SIGNAL( clicked() ), this, SLOT( clicked() )); LMain->addWidget(Buttons[i]); + ++i; } Count = count; State = 0; - Buttons[0]->setDown( true ); + if (count > 0) { + Buttons[0]->setDown( true ); + } } int FlashRadioArray::getState() diff --git a/src/flash.h b/src/flash.h index b37595d..282d8e6 100644 --- a/src/flash.h +++ b/src/flash.h @@ -18,6 +18,7 @@ #include #include #include +#include //A QPushButton that can flash a color @@ -50,7 +51,7 @@ class FlashRadioArray : public QWidget { Q_OBJECT public: - FlashRadioArray( int count, QString names[], bool horizontal, QWidget* parent); + FlashRadioArray( const QStringList &names, bool horizontal, QWidget* parent); //returns an integer returning the currently selected button. //First button is 0. int getState(); diff --git a/src/joyslider.cpp b/src/joyslider.cpp index 03d87c6..7767adc 100644 --- a/src/joyslider.cpp +++ b/src/joyslider.cpp @@ -212,7 +212,7 @@ void JoySlider::mousePressEvent( QMouseEvent* e ) 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; -}; +} void JoySlider::mouseReleaseEvent( QMouseEvent* ) { diff --git a/src/layout.cpp b/src/layout.cpp index c145f20..c957ab5 100644 --- a/src/layout.cpp +++ b/src/layout.cpp @@ -157,7 +157,7 @@ void LayoutManager::save() { //if it's good, start writing the file if (file.open(QIODevice::WriteOnly)) { QTextStream stream( &file ); - stream << "# "NAME" Layout File\n\n"; + stream << "# " NAME " Layout File\n\n"; QHashIterator it (joypads); while (it.hasNext()) { diff --git a/src/layout_edit.cpp b/src/layout_edit.cpp index 8603435..af90047 100644 --- a/src/layout_edit.cpp +++ b/src/layout_edit.cpp @@ -38,23 +38,14 @@ LayoutEdit::LayoutEdit( LayoutManager* l ): QWidget(NULL) { //produce a list of names for the FlashRadioArray //this is only necesary since joystick devices need not always be //contiguous - int padcount = available.count(); - QString names[padcount]; - int i = 0; - do - { - QHashIterator it( available ); - while (it.hasNext()) - { - it.next(); - names[i] = it.value()->getName(); - connect(this, SIGNAL(focusStateChanged(bool)), it.value(), SLOT(focusChange(bool))); - ++i; - } - } while (0); + QStringList names; + foreach (JoyPad *joypad, available) { + names.append(joypad->getName()); + connect(this, SIGNAL(focusStateChanged(bool)), joypad, SLOT(focusChange(bool))); + } //flash radio array - JoyButtons = new FlashRadioArray(padcount, names, true, this ); + JoyButtons = new FlashRadioArray(names, true, this ); LMain->addWidget( JoyButtons ); //we have a WidgetStack to represent the multiple joypads @@ -63,20 +54,15 @@ LayoutEdit::LayoutEdit( LayoutManager* l ): QWidget(NULL) { LMain->addWidget(PadStack); //go through each of the available joysticks - i = 0; // i is the current index into PadStack - do - { - QHashIterator it(available); - while (it.hasNext()) - { - it.next(); - //add a new JoyPadWidget to the stack - PadStack->insertWidget( i,it.value()->widget(PadStack,i) ); - //every time it "flashes", flash the associated tab. - connect( PadStack->widget(i), SIGNAL( flashed( int ) ), JoyButtons, SLOT( flash( int ))); - ++i; - } - } while (0); + // i is the current index into PadStack + int i = 0; + foreach (JoyPad *joypad, available) { + //add a new JoyPadWidget to the stack + 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 ))); + ++i; + } //whenever a new tab is selected, raise the appropriate JoyPadWidget connect( JoyButtons, SIGNAL( changed( int ) ), PadStack, SLOT( setCurrentIndex( int ))); @@ -118,21 +104,12 @@ void LayoutEdit::updateLayoutList() { void LayoutEdit::updateJoypadWidgets() { int indexOfFlashRadio = LMain->indexOf(JoyButtons); FlashRadioArray *newJoyButtons; - int padcount = available.count(); - QString names[padcount]; - int i = 0; - do - { - QHashIterator it( available ); - while (it.hasNext()) - { - it.next(); - names[i] = it.value()->getName(); - ++i; - } - } while (0); + QStringList names; + foreach (JoyPad *joypad, available) { + names.append(joypad->getName()); + } - newJoyButtons = new FlashRadioArray(padcount, names, true, this ); + newJoyButtons = new FlashRadioArray( names, true, this ); LMain->insertWidget(indexOfFlashRadio, newJoyButtons); LMain->removeWidget(JoyButtons); FlashRadioArray* oldJoyButtons = JoyButtons; @@ -143,20 +120,14 @@ void LayoutEdit::updateJoypadWidgets() { for(int i = 0; iremoveWidget(PadStack->widget(0)); } - i = 0; - do - { - QHashIterator it(available); - while (it.hasNext()) - { - it.next(); - //add a new JoyPadWidget to the stack - PadStack->insertWidget( i,it.value()->widget(PadStack,i) ); - //every time it "flashes", flash the associated tab. - connect( PadStack->widget(i), SIGNAL( flashed( int ) ), JoyButtons, SLOT( flash( int ))); - ++i; - } - } while (0); + int i = 0; + foreach (JoyPad *joypad, available) { + //add a new JoyPadWidget to the stack + 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 ))); + ++i; + } } void LayoutEdit::closeEvent(QCloseEvent *event) { @@ -169,12 +140,9 @@ void LayoutEdit::appFocusChanged(QWidget *old, QWidget *now) { emit focusStateChanged(false); } else if(old!=NULL && now==NULL) { emit focusStateChanged(true); - QHashIterator it( available ); - while (it.hasNext()) - { + foreach (JoyPad *joypad, available) { debug_mesg("iterating and releasing\n"); - it.next(); - it.value()->release(); + joypad->release(); } debug_mesg("done releasing!\n"); } diff --git a/src/qjoypad.pro b/src/qjoypad.pro deleted file mode 100644 index c4b9140..0000000 --- a/src/qjoypad.pro +++ /dev/null @@ -1,80 +0,0 @@ -######################################## -# # -# QMake project file for QJoyPad # -# # -######################################## - - - - - - -##### Setup Targets ##### - -icons.path = $$INSTALL_PREFIX/share/pixmaps/qjoypad -icons.conf_path = $$PREFIX/share/pixmaps/qjoypad -icons.extra = cp ../icons/* $${icons.path}; cd $${icons.path}; ln -sf gamepad4-24x24.png icon24.png; ln -sf gamepad3-64x64.png icon64.png; chmod -R a+r $${icons.path} - -doc.path = $$INSTALL_PREFIX/share/doc/qjoypad4 -doc.extra = cp ../README.txt ../LICENSE.txt $${doc.path} -target.path = $$INSTALL_PREFIX/bin - - - - - -##### Setup Compile ##### - -DEFINES += DEVDIR='\\\"$$DEVDIR\\\"' -DEFINES += ICON24='\\\"$${icons.conf_path}/icon24.png\\\"' -DEFINES += ICON64='\\\"$${icons.conf_path}/icon64.png\\\"' - -TEMPLATE = app -INCLUDEPATH += . -QMAKE_LIBS += -lXtst -lX11 -QMAKE_CXXFLAGS += -Werror -Wno-deprecated-declarations - -# Input -HEADERS += axis.h \ - axis_edit.h \ - axisw.h \ - button.h \ - button_edit.h \ - buttonw.h \ - constant.h \ - device.h \ - error.h \ - event.h \ - flash.h \ - icon.h \ - joypad.h \ - joypadw.h \ - joyslider.h \ - keycode.h \ - layout.h \ - getkey.h \ - layout_edit.h \ - quickset.h -SOURCES += axis.cpp \ - axis_edit.cpp \ - axisw.cpp \ - button.cpp \ - button_edit.cpp \ - buttonw.cpp \ - event.cpp \ - flash.cpp \ - icon.cpp \ - joypad.cpp \ - joypadw.cpp \ - joyslider.cpp \ - keycode.cpp \ - layout.cpp \ - layout_edit.cpp \ - main.cpp \ - quickset.cpp \ - getkey.cpp - - -##### Install ##### - -INSTALLS += target icons doc