summaryrefslogtreecommitdiffhomepage
path: root/gui/curve-config.cpp
blob: 19237c3c72e4cfc4532f45164633c2a83550eac5 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* Copyright (c) 2014-2015, Stanislaw Halik <sthalik@misaki.pl>

 * Permission to use, copy, modify, and/or distribute this
 * software for any purpose with or without fee is hereby granted,
 * provided that the above copyright notice and this permission
 * notice appear in all copies.
 */

#include "curve-config.h"
#include "opentrack-logic/main-settings.hpp"
MapWidget::MapWidget(Mappings& m) :
    m(m)
{
    ui.setupUi( this );

    m.load_mappings();

    reload();

    setFont(qApp->font());
    connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK()));
    connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel()));

    main_settings s;

    tie_setting(s.a_x.altp, ui.tx_altp);
    tie_setting(s.a_y.altp, ui.ty_altp);
    tie_setting(s.a_z.altp, ui.tz_altp);
    tie_setting(s.a_yaw.altp, ui.rx_altp);
    tie_setting(s.a_pitch.altp, ui.ry_altp);
    tie_setting(s.a_roll.altp, ui.rz_altp);
}

void MapWidget::reload()
{
    {
        struct {
            QFunctionConfigurator* qfc;
            Axis axis;
            QCheckBox* checkbox;
            bool altp;
        } qfcs[] =
        {
            { ui.rxconfig, Yaw,   nullptr, false },
            { ui.ryconfig, Pitch, nullptr, false },
            { ui.rzconfig, Roll,  nullptr, false },
            { ui.txconfig, TX,    nullptr, false },
            { ui.tyconfig, TY,    nullptr, false },
            { ui.tzconfig, TZ,    nullptr, false },

            { ui.rxconfig_alt, Yaw,   ui.rx_altp, true },
            { ui.ryconfig_alt, Pitch, ui.ry_altp, true },
            { ui.rzconfig_alt, Roll,  ui.rz_altp, true },
            { ui.txconfig_alt, TX,    ui.tx_altp, true },
            { ui.tyconfig_alt, TY,    ui.ty_altp, true },
            { ui.tzconfig_alt, TZ,    ui.tz_altp, true },
            { nullptr, Yaw, nullptr, false }
        };

        for (int i = 0; qfcs[i].qfc; i++)
        {
            const bool altp = qfcs[i].altp;
            Mapping& axis = m(qfcs[i].axis);
            Map* conf = altp ? &axis.curveAlt : &axis.curve;
            const auto& name = qfcs[i].altp ? axis.name2 : axis.name1;
            if (altp)
            {
                QFunctionConfigurator& qfc = *qfcs[i].qfc;
                connect(qfcs[i].checkbox, &QCheckBox::toggled,
                        [&](bool f) -> void {qfc.setEnabled(f); qfc.force_redraw();});
                qfc.setEnabled(qfcs[i].checkbox->isChecked());
                qfc.force_redraw();
            }

            if (qfcs[i].axis >= 3)
                qfcs[i].qfc->set_snap(2, 5);
            else
                qfcs[i].qfc->set_snap(1, 5);

            qfcs[i].qfc->setConfig(conf, name);
        }
    }
}

void MapWidget::doOK() {
    m.save_mappings();
    close();
}

void MapWidget::doCancel() {
    m.invalidate_unsaved();
    close();
}