an axis may now press a mouse button and fix many warnings

This commit is contained in:
Mathias Panzenböck
2014-01-31 02:38:47 +01:00
parent ca7da9dad6
commit 6fa91c4529
9 changed files with 78 additions and 30 deletions

View File

@ -97,6 +97,26 @@ bool Axis::read( QTextStream* stream ) {
if (ok && val >= 0 && val <= MAXKEY) nkeycode = val;
else return false;
}
else if (*it == "+mouse") {
++it;
if (it == words.end()) return false;
val = (*it).toInt(&ok);
if (ok && val >= 0 && val <= MAXKEY) {
puseMouse = true;
pkeycode = val;
}
else return false;
}
else if (*it == "-mouse") {
++it;
if (it == words.end()) return false;
val = (*it).toInt(&ok);
if (ok && val >= 0 && val <= MAXKEY) {
nuseMouse = true;
nkeycode = val;
}
else return false;
}
//the rest of the options are keywords without integers
else if (*it == "gradient") {
gradient = true;
@ -144,8 +164,9 @@ void Axis::write( QTextStream* stream ) {
if (dZone != DZONE) *stream << "dZone " << dZone << ", ";
if (xZone != XZONE) *stream << "xZone " << xZone << ", ";
if (mode == keybd) {
*stream << "+key " << pkeycode << ", "
<< "-key " << nkeycode << "\n";
*stream
<< (puseMouse ? "+mouse " : "+key ") << pkeycode << ", "
<< (nuseMouse ? "-mouse " : "-key ") << nkeycode << "\n";
}
else {
if (gradient) *stream << "maxSpeed " << maxSpeed << ", ";
@ -226,6 +247,8 @@ void Axis::toDefault() {
mode = keybd;
pkeycode = 0;
nkeycode = 0;
puseMouse = false;
nuseMouse = false;
downkey = 0;
state = 0;
adjustGradient();
@ -239,7 +262,9 @@ bool Axis::isDefault() {
(xZone == XZONE) &&
(mode == keybd) &&
(pkeycode == 0) &&
(nkeycode == 0);
(nkeycode == 0) &&
(puseMouse == false) &&
(nuseMouse == false) ;
}
bool Axis::inDeadZone( int val ) {
@ -256,19 +281,34 @@ bool Axis::inDeadZone( int val ) {
QString Axis::status() {
QString result = getName() + " : [";
if (mode == keybd) {
if (throttle == 0)
if (throttle == 0) {
if (puseMouse != nuseMouse) {
result += "KEYBOARD/MOUSE";
}
else if (puseMouse) {
result += "MOUSE";
}
else {
result += "KEYBOARD";
else result += "THROTTLE";
}
}
else {
result += "THROTTLE";
}
}
else result += "MOUSE";
return result + "]";
}
void Axis::setKey(bool positive, int value) {
if (positive)
if (positive) {
pkeycode = value;
else
puseMouse = false;
}
else {
nkeycode = value;
nuseMouse = false;
}
}
void Axis::timerTick( int tick ) {
@ -310,12 +350,13 @@ void Axis::move( bool press ) {
//dialog being open and blocking events from happening.
if (isDown == press) return;
isDown = press;
bool useMouse = (state > 0)?puseMouse:nuseMouse;
if (press) {
e.type = KPRESS;
e.type = useMouse?BPRESS:KPRESS;
downkey = (state > 0)?pkeycode:nkeycode;
}
else {
e.type = KREL;
e.type = useMouse?BREL:KREL;
}
e.value1 = downkey;
e.value2 = 0;

View File

@ -85,6 +85,8 @@ class Axis : public QObject {
int pkeycode;
//negative keycode
int nkeycode;
bool puseMouse;
bool nuseMouse;
//the key that is currently pressed
int downkey;
//the position of the axis, as from jsevent

View File

@ -28,7 +28,7 @@ AxisEdit::AxisEdit( Axis* ax )
v2->addWidget(CGradient);
CMode = new QComboBox(this);
CMode->insertItem((int)keybd, QString("Keyboard"), Qt::DisplayRole);
CMode->insertItem((int)keybd, QString("Keyboard/Mouse Button"), Qt::DisplayRole);
CMode->insertItem((int) mousepv,QString("Mouse (Vert.)"),Qt::DisplayRole);
CMode->insertItem((int) mousenv, QString("Mouse (Vert. Rev.)"), Qt::DisplayRole);
CMode->insertItem((int) mouseph, "Mouse (Hor.)", Qt::DisplayRole);
@ -80,7 +80,7 @@ AxisEdit::AxisEdit( Axis* ax )
h->setSpacing(5);
h->setMargin(5);
//h->setAutoAdd(true);
BNeg = new KeyButton(axis->getName(),axis->nkeycode,KeyBox);
BNeg = new KeyButton(axis->getName(),axis->nkeycode,KeyBox,true,axis->nuseMouse);
CThrottle = new QComboBox(KeyBox);
CThrottle->insertItem(0,"Neg. Throttle",Qt::DisplayRole);
@ -89,7 +89,7 @@ AxisEdit::AxisEdit( Axis* ax )
CThrottle->setCurrentIndex(axis->throttle + 1);
connect( CThrottle, SIGNAL( activated( int )), this, SLOT( CThrottleChanged( int )));
BPos = new KeyButton(axis->getName(),axis->pkeycode,KeyBox);
BPos = new KeyButton(axis->getName(),axis->pkeycode,KeyBox,true,axis->puseMouse);
h->addWidget(BNeg);
h->addWidget(CThrottle);
h->addWidget(BPos);
@ -183,6 +183,8 @@ void AxisEdit::accept() {
axis->mode = (AxisMode) CMode->currentIndex();
axis->pkeycode = BPos->getValue();
axis->nkeycode = BNeg->getValue();
axis->puseMouse = BPos->choseMouse();
axis->nuseMouse = BNeg->choseMouse();
axis->adjustGradient();
QDialog::accept();

View File

@ -5,20 +5,20 @@
#include <stdarg.h>
//a nice simple way of throwing up an error message if something goes wrong.
static void error(QString type, QString message ) {
inline void error(QString type, QString message ) {
QMessageBox::warning(0,NAME" - " + type,
message, QMessageBox::Ok, Qt::NoButton);
}
#ifdef _DEBUG
static void debug_mesg(const char *fmt, ...) {
inline void debug_mesg(const char *fmt, ...) {
va_list ap;
va_start(ap, NULL);
vprintf(fmt, ap);
va_end(ap);
}
#else
static void debug_mesg(...) {
inline void debug_mesg(...) {
return;
}
#endif

View File

@ -55,7 +55,7 @@ void JoyPad::resetToDev(int dev ) {
char buf[10];
while(poll(&read_struct, 1, 5)!=0) {
debug_mesg("reading junk data\n");
read(joydev, buf, 10);
if (read(joydev, buf, 10) <= 0) break;
}
setupJoyDeviceListener(dev);
debug_mesg("done resetting to dev\n");
@ -249,6 +249,8 @@ JoyPadWidget* JoyPad::widget( QWidget* parent, int i) {
}
void JoyPad::handleJoyEvents(int fd) {
Q_UNUSED(fd);
js_event msg;
int len;

View File

@ -357,7 +357,7 @@ void LayoutManager::updateJoyDevs() {
char buf[10];
while(poll(&read_struct, 1, 5)!=0) {
debug_mesg("reading junk data\n");
read(joydev, buf, 10);
if (read(joydev, buf, 10) <= 0) break;
}
joypad = new JoyPad( index, joydev );
joypads.insert(index,joypad);

View File

@ -102,7 +102,7 @@ void LayoutEdit::setLayout(QString layout) {
//change the text,
CLayouts->setCurrentIndex(lm->getLayoutNames().indexOf(layout));
//update all the JoyPadWidgets.
for (uint i = 0; i < available.count(); i++) {
for (int i = 0; i < available.count(); i++) {
((JoyPadWidget*)PadStack->widget(i))->update();
}
}

View File

@ -147,7 +147,7 @@ int main( int argc, char **argv )
if (pidFile.exists())
{
int pid;
if (pidFile.open( QIODevice::ReadOnly ));
if (pidFile.open( QIODevice::ReadOnly ))
{
//try to get that pid...
QTextStream( &pidFile ) >> pid;

View File

@ -32,6 +32,7 @@ DEFINES += ICON64='\\\"$${icons.conf_path}/icon64.png\\\"'
TEMPLATE = app
INCLUDEPATH += .
QMAKE_LIBS += -lXtst -lX11
QMAKE_CXXFLAGS += -Werror -Wno-deprecated-declarations
# Input
HEADERS += axis.h \