File: quickset.cpp

package info (click to toggle)
qjoypad 4.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 436 kB
  • sloc: cpp: 3,121; makefile: 3
file content (61 lines) | stat: -rw-r--r-- 2,165 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "quickset.h"
#include "keydialog.hpp"

//build the dialog
QuickSet::QuickSet( JoyPad* jp, QWidget *parent)
        : QDialog(parent), joypad(jp), setting(false) {
    setWindowTitle(tr("Set %1").arg(jp->getName()));
    QVBoxLayout* LMain = new QVBoxLayout(this);
    LMain->setMargin(5);
    LMain->setSpacing(5);
    //LMain->setAutoAdd(true);

    QLabel *temp = new QLabel(tr("Press any button or axis and\nyou will be prompted for a key."),this);
    LMain->addWidget(temp);
    QPushButton* button = new QPushButton(tr("Done"),this);
    LMain->addWidget(button);
    connect( button, SIGNAL(clicked()), this, SLOT(accept()));
}

void QuickSet::jsevent(const js_event &msg ) {
    //ignore any joystick events if we're waiting for a keypress
    if (setting) return;

    //if a button was pressed on the joystick
    unsigned int type = msg.type & ~JS_EVENT_INIT;
    if (type == JS_EVENT_BUTTON) {
        //capture that button.
        if (msg.number < joypad->buttons.size()) {
            Button* button = joypad->buttons[msg.number];
            //go into setting mode and request a key/mousebutton
            setting = true;
            bool isMouse = false;
            int code = KeyDialog::getKey(button->getName(), true, &isMouse, this);
            setting = false;

            if (code >= 0) {
                button->setKey(isMouse, code);
            }
        }
    }
    else if (type == JS_EVENT_AXIS) {
        //require a signal strength of at least 5000 to consider an axis moved.
        if (abs(msg.value) < 5000) return;

        //capture the axis that moved
        if (msg.number < joypad->axes.size()) {
            Axis* axis = joypad->axes[msg.number];

            //grab a keycode for that axis and that direction
            setting = true;
            bool isMouse = false;
            int code = KeyDialog::getKey((msg.value >= 0 ? tr("%1, positive") : tr("%1, negative")).arg(axis->getName()), true, &isMouse, this);
            setting = false;

            //assign the key to the axis.
            if (code >= 0) {
                axis->setKey(isMouse, (msg.value > 0), code);
            }
        }
    }
}