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

TrackerControls::TrackerControls() : 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(win32_joy_ctx::make());
        
        _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 TrackerControls::doOK() {
    int idx = ui.joylist->currentIndex();
    joys def { "", "" };
    auto val = _joys.value(idx, def);
    s.guid = val.guid;
    s.b->save();
    this->close();
}

void TrackerControls::doCancel() {
    s.b->reload();
    this->close();
}