make compile with -pedantic and use foreach in some places
This commit is contained in:
@ -17,7 +17,7 @@ if(PLAIN_KEYS)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
|
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"))
|
if(NOT(CMAKE_BUILD_TYPE STREQUAL "Debug"))
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "event.h"
|
#include "event.h"
|
||||||
|
|
||||||
//this should be initialized by main.cpp as soon as the program starts.
|
//this should be initialized by main.cpp as soon as the program starts.
|
||||||
Display* display;
|
Display* display = 0;
|
||||||
|
|
||||||
//actually creates an XWindows event :)
|
//actually creates an XWindows event :)
|
||||||
void sendevent( xevent e ) {
|
void sendevent( xevent e ) {
|
||||||
|
@ -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 )
|
:QWidget( parent )
|
||||||
{
|
{
|
||||||
if (horizontal) {
|
if (horizontal) {
|
||||||
@ -55,19 +55,23 @@ FlashRadioArray::FlashRadioArray( int count, QString names[], bool horizontal, Q
|
|||||||
LMain->setMargin(5);
|
LMain->setMargin(5);
|
||||||
LMain->setSpacing(5);
|
LMain->setSpacing(5);
|
||||||
}
|
}
|
||||||
|
// TODO: fix memleak
|
||||||
|
int count = names.size();
|
||||||
|
int i = 0;
|
||||||
Buttons = new FlashButton*[count];
|
Buttons = new FlashButton*[count];
|
||||||
for (int i = 0; i < count; i++)
|
foreach (const QString &name, names) {
|
||||||
{
|
Buttons[i] = new FlashButton( name, this, "" );
|
||||||
Buttons[i] = new FlashButton( names[i], this, "" );
|
|
||||||
//when any of the buttons is clicked, it calls the same function on this.
|
//when any of the buttons is clicked, it calls the same function on this.
|
||||||
connect( Buttons[i], SIGNAL( clicked() ), this, SLOT( clicked() ));
|
connect( Buttons[i], SIGNAL( clicked() ), this, SLOT( clicked() ));
|
||||||
LMain->addWidget(Buttons[i]);
|
LMain->addWidget(Buttons[i]);
|
||||||
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
Count = count;
|
Count = count;
|
||||||
State = 0;
|
State = 0;
|
||||||
Buttons[0]->setDown( true );
|
if (count > 0) {
|
||||||
|
Buttons[0]->setDown( true );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int FlashRadioArray::getState()
|
int FlashRadioArray::getState()
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
#include <QBoxLayout>
|
#include <QBoxLayout>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
|
||||||
//A QPushButton that can flash a color
|
//A QPushButton that can flash a color
|
||||||
@ -50,7 +51,7 @@ class FlashRadioArray : public QWidget
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
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.
|
//returns an integer returning the currently selected button.
|
||||||
//First button is 0.
|
//First button is 0.
|
||||||
int getState();
|
int getState();
|
||||||
|
@ -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( XZone, false )) < 5) result = DRAG_XZ;
|
||||||
else if (throttle >= 0 && abs( xpt - pointFor( DeadZone, false )) < 5) result = DRAG_DZ;
|
else if (throttle >= 0 && abs( xpt - pointFor( DeadZone, false )) < 5) result = DRAG_DZ;
|
||||||
dragging = result;
|
dragging = result;
|
||||||
};
|
}
|
||||||
|
|
||||||
void JoySlider::mouseReleaseEvent( QMouseEvent* )
|
void JoySlider::mouseReleaseEvent( QMouseEvent* )
|
||||||
{
|
{
|
||||||
|
@ -157,7 +157,7 @@ void LayoutManager::save() {
|
|||||||
//if it's good, start writing the file
|
//if it's good, start writing the file
|
||||||
if (file.open(QIODevice::WriteOnly)) {
|
if (file.open(QIODevice::WriteOnly)) {
|
||||||
QTextStream stream( &file );
|
QTextStream stream( &file );
|
||||||
stream << "# "NAME" Layout File\n\n";
|
stream << "# " NAME " Layout File\n\n";
|
||||||
QHashIterator<int, JoyPad*> it (joypads);
|
QHashIterator<int, JoyPad*> it (joypads);
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
|
@ -38,23 +38,14 @@ LayoutEdit::LayoutEdit( LayoutManager* l ): QWidget(NULL) {
|
|||||||
//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
|
||||||
int padcount = available.count();
|
QStringList names;
|
||||||
QString names[padcount];
|
foreach (JoyPad *joypad, available) {
|
||||||
int i = 0;
|
names.append(joypad->getName());
|
||||||
do
|
connect(this, SIGNAL(focusStateChanged(bool)), joypad, SLOT(focusChange(bool)));
|
||||||
{
|
}
|
||||||
QHashIterator<int, JoyPad*> 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);
|
|
||||||
|
|
||||||
//flash radio array
|
//flash radio array
|
||||||
JoyButtons = new FlashRadioArray(padcount, names, true, this );
|
JoyButtons = new FlashRadioArray(names, true, this );
|
||||||
LMain->addWidget( JoyButtons );
|
LMain->addWidget( JoyButtons );
|
||||||
|
|
||||||
//we have a WidgetStack to represent the multiple joypads
|
//we have a WidgetStack to represent the multiple joypads
|
||||||
@ -63,20 +54,15 @@ LayoutEdit::LayoutEdit( LayoutManager* l ): QWidget(NULL) {
|
|||||||
LMain->addWidget(PadStack);
|
LMain->addWidget(PadStack);
|
||||||
|
|
||||||
//go through each of the available joysticks
|
//go through each of the available joysticks
|
||||||
i = 0; // i is the current index into PadStack
|
// i is the current index into PadStack
|
||||||
do
|
int i = 0;
|
||||||
{
|
foreach (JoyPad *joypad, available) {
|
||||||
QHashIterator<int, JoyPad*> it(available);
|
//add a new JoyPadWidget to the stack
|
||||||
while (it.hasNext())
|
PadStack->insertWidget( i, joypad->widget(PadStack,i) );
|
||||||
{
|
//every time it "flashes", flash the associated tab.
|
||||||
it.next();
|
connect( PadStack->widget(i), SIGNAL( flashed( int ) ), JoyButtons, SLOT( flash( int )));
|
||||||
//add a new JoyPadWidget to the stack
|
++i;
|
||||||
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);
|
|
||||||
//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 )));
|
||||||
|
|
||||||
@ -118,21 +104,12 @@ void LayoutEdit::updateLayoutList() {
|
|||||||
void LayoutEdit::updateJoypadWidgets() {
|
void LayoutEdit::updateJoypadWidgets() {
|
||||||
int indexOfFlashRadio = LMain->indexOf(JoyButtons);
|
int indexOfFlashRadio = LMain->indexOf(JoyButtons);
|
||||||
FlashRadioArray *newJoyButtons;
|
FlashRadioArray *newJoyButtons;
|
||||||
int padcount = available.count();
|
QStringList names;
|
||||||
QString names[padcount];
|
foreach (JoyPad *joypad, available) {
|
||||||
int i = 0;
|
names.append(joypad->getName());
|
||||||
do
|
}
|
||||||
{
|
|
||||||
QHashIterator<int, JoyPad*> it( available );
|
|
||||||
while (it.hasNext())
|
|
||||||
{
|
|
||||||
it.next();
|
|
||||||
names[i] = it.value()->getName();
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
newJoyButtons = new FlashRadioArray(padcount, names, true, this );
|
newJoyButtons = new FlashRadioArray( names, true, this );
|
||||||
LMain->insertWidget(indexOfFlashRadio, newJoyButtons);
|
LMain->insertWidget(indexOfFlashRadio, newJoyButtons);
|
||||||
LMain->removeWidget(JoyButtons);
|
LMain->removeWidget(JoyButtons);
|
||||||
FlashRadioArray* oldJoyButtons = JoyButtons;
|
FlashRadioArray* oldJoyButtons = JoyButtons;
|
||||||
@ -143,20 +120,14 @@ void LayoutEdit::updateJoypadWidgets() {
|
|||||||
for(int i = 0; i<numberOfJoypads; i++) {
|
for(int i = 0; i<numberOfJoypads; i++) {
|
||||||
PadStack->removeWidget(PadStack->widget(0));
|
PadStack->removeWidget(PadStack->widget(0));
|
||||||
}
|
}
|
||||||
i = 0;
|
int i = 0;
|
||||||
do
|
foreach (JoyPad *joypad, available) {
|
||||||
{
|
//add a new JoyPadWidget to the stack
|
||||||
QHashIterator<int, JoyPad*> it(available);
|
PadStack->insertWidget( i, joypad->widget(PadStack,i) );
|
||||||
while (it.hasNext())
|
//every time it "flashes", flash the associated tab.
|
||||||
{
|
connect( PadStack->widget(i), SIGNAL( flashed( int ) ), JoyButtons, SLOT( flash( int )));
|
||||||
it.next();
|
++i;
|
||||||
//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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutEdit::closeEvent(QCloseEvent *event) {
|
void LayoutEdit::closeEvent(QCloseEvent *event) {
|
||||||
@ -169,12 +140,9 @@ 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);
|
||||||
QHashIterator<int, JoyPad*> it( available );
|
foreach (JoyPad *joypad, available) {
|
||||||
while (it.hasNext())
|
|
||||||
{
|
|
||||||
debug_mesg("iterating and releasing\n");
|
debug_mesg("iterating and releasing\n");
|
||||||
it.next();
|
joypad->release();
|
||||||
it.value()->release();
|
|
||||||
}
|
}
|
||||||
debug_mesg("done releasing!\n");
|
debug_mesg("done releasing!\n");
|
||||||
}
|
}
|
||||||
|
@ -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
|
|
Reference in New Issue
Block a user