summaryrefslogtreecommitdiffhomepage
path: root/tracker-joystick/ftnoir_tracker_joystick_dialog.cpp
blob: aa4b783ad4d9200b590488a58ed74d068c25dd14 (plain)
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
#include "ftnoir_tracker_joystick.h"
#include "api/plugin-api.hpp"

dialog_joystick::dialog_joystick() : tracker(nullptr)
{
    ui.setupUi( this );

    // Connect Qt signals to member-functions
    connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK()));
    connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel()));

    {
        win32_joy_ctx joy_ctx;

        _joys = QList<joys>();

        for (auto j : joy_ctx.get_joy_info())
            _joys.push_back(joys { j.name, j.guid });
    }

    {
        const QString guid = s.guid;
        int idx = 0;
        for (int i = 0; i < _joys.size(); i++)
        {
            const joys& j = _joys[i];
            if (j.guid == guid)
                idx = i;
            ui.joylist->addItem(j.name + " " + j.guid);
        }
        ui.joylist->setCurrentIndex(idx);
    }

    tie_setting(s.joy_1, ui.joy_1);
    tie_setting(s.joy_2, ui.joy_2);
    tie_setting(s.joy_3, ui.joy_3);
    tie_setting(s.joy_4, ui.joy_4);
    tie_setting(s.joy_5, ui.joy_5);
    tie_setting(s.joy_6, ui.joy_6);
}

void dialog_joystick::doOK() {
    int idx = ui.joylist->currentIndex();
    joys def { "", "" };
    auto val = _joys.value(idx, def);
    s.guid = val.guid;
    s.b->save();
    close();
}

void dialog_joystick::doCancel() {
    close();
}