summaryrefslogtreecommitdiffhomepage
path: root/filter-accela/ftnoir_filter_accela_dialog.cpp
blob: c8262dd5dd11ecc2c3bc9cfbcb9754fccaaf0b4c (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* Copyright (c) 2012-2015 Stanislaw Halik
 *
 * 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 "ftnoir_filter_accela.h"
#include <cmath>
#include <QDebug>
#include <algorithm>
#include <QDoubleSpinBox>
#include "api/plugin-api.hpp"
#include "spline-widget/spline-widget.hpp"
#include <QDialog>

FilterControls::FilterControls()
{
    ui.setupUi(this);

    connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK()));
    connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel()));

    connect(&s.rot_sensitivity, SIGNAL(valueChanged(const slider_value&)), this, SLOT(update_rot_display(const slider_value&)));
    connect(&s.trans_sensitivity, SIGNAL(valueChanged(const slider_value&)), this, SLOT(update_trans_display(const slider_value&)));
    connect(&s.ewma, SIGNAL(valueChanged(const slider_value&)), this, SLOT(update_ewma_display(const slider_value&)));
    connect(&s.rot_deadzone, SIGNAL(valueChanged(const slider_value&)), this, SLOT(update_rot_dz_display(const slider_value&)));
    connect(&s.trans_deadzone, SIGNAL(valueChanged(const slider_value&)), this, SLOT(update_trans_dz_display(const slider_value&)));
    connect(&s.rot_nonlinearity, SIGNAL(valueChanged(const slider_value&)), this, SLOT(update_rot_nl_slider(const slider_value&)));

    tie_setting(s.rot_sensitivity, ui.rotation_slider);
    tie_setting(s.trans_sensitivity, ui.translation_slider);
    tie_setting(s.ewma, ui.ewma_slider);
    tie_setting(s.rot_deadzone, ui.rot_dz_slider);
    tie_setting(s.trans_deadzone, ui.trans_dz_slider);
    tie_setting(s.rot_nonlinearity, ui.rot_nl_slider);

    update_rot_display(s.rot_sensitivity);
    update_trans_display(s.trans_sensitivity);
    update_ewma_display(s.ewma);
    update_rot_dz_display(s.rot_deadzone);
    update_trans_dz_display(s.trans_deadzone);
    update_rot_nl_slider(s.rot_nonlinearity);

    {
//#define SPLINE_ROT_DEBUG
//#define SPLINE_TRANS_DEBUG
#if defined(SPLINE_ROT_DEBUG) || defined(SPLINE_TRANS_DEBUG)
    spline rot, trans;
    s.make_splines(rot, trans);
    QDialog d;

    spline_widget r(&d);
    r.set_preview_only(true);
    r.setEnabled(false);
    r.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);

#if defined(SPLINE_TRANS_DEBUG)
#   if defined(SPLINE_ROT_DEBUG)
#       error "rot xor trans"
#   endif
    r.setConfig(&trans);
#else

    r.setConfig(&rot);
#endif
    r.setFixedSize(1024, 600);
    d.show();
    d.exec();
#endif
    }
}

void FilterControls::doOK()
{
    save();
    close();
}

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

void FilterControls::save()
{
    s.b->save();
}

#define FIELD(x, a) ((a).arg(((x).cur()), 0, 'g', 4))
#define LIT(x) QStringLiteral(x)

void FilterControls::update_rot_display(const slider_value& val)
{
    static const QString str(QString::fromUtf8("%1°"));
    ui.rot_gain->setText(FIELD(val, str));
}

void FilterControls::update_trans_display(const slider_value& val)
{
    ui.trans_gain->setText(FIELD(val, LIT("%1mm")));
}

void FilterControls::update_ewma_display(const slider_value& val)
{
    ui.ewma_label->setText(FIELD(val, LIT("%1ms")));
}

void FilterControls::update_rot_dz_display(const slider_value& val)
{
    static const QString str(QString::fromUtf8("%1°"));
    ui.rot_dz->setText(FIELD(val, str));
}

void FilterControls::update_trans_dz_display(const slider_value& val)
{
    ui.trans_dz->setText(FIELD(val, LIT("%1mm")));
}

void FilterControls::update_rot_nl_slider(const slider_value& val)
{
    ui.rot_nl->setText(FIELD(val, LIT(
                        "<html><head/><body>"
                        "<p>x<span style='vertical-align:super;'>"
                        "%1"
                        "</span></p>"
                        "</body></html>")));
}