doubleadjusterwidget.cpp 2.86 KB
Newer Older
1
2
3
4
// ================================================================================================
// 
// This file is part of the CAMPVis Software Framework.
// 
5
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
6
7
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
//      Chair for Computer Aided Medical Procedures
8
9
//      Technische Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
10
// 
11
12
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
// 
13
14
15
16
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 
// except in compliance with the License. You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
17
// 
18
19
20
21
// Unless required by applicable law or agreed to in writing, software distributed under the 
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
// either express or implied. See the License for the specific language governing permissions 
// and limitations under the License.
22
23
24
25
26
27
28
29
30
// 
// ================================================================================================

#include "doubleadjusterwidget.h"

#include <cmath>

namespace campvis {
    DoubleAdjusterWidget::DoubleAdjusterWidget(QWidget* parent /*= 0*/)
31
        : AbstractAdjusterWidget<double>(parent)
32
    {
33
        setSliderProperties(_spinBox->singleStep(), _spinBox->minimum(), _spinBox->maximum());
34
35
36
37
38
39
40

        connect(_spinBox, SIGNAL(valueChanged(double)), this, SLOT(onSpinBoxValueChanged(double)));
        connect(_slider, SIGNAL(valueChanged(int)), this, SLOT(onSliderValueChanged(int)));
    }

    void DoubleAdjusterWidget::setValue(double value)
    {
41
        setValueImpl(value);
42
43
44
45
46
    }

    void DoubleAdjusterWidget::setDecimals(int prec)
    {
        _spinBox->setDecimals(prec);
47
        setSliderProperties(_spinBox->singleStep(), _spinBox->minimum(), _spinBox->maximum());
48
49
50
    }

    void DoubleAdjusterWidget::onSpinBoxValueChanged(double value) {
51
        onSpinBoxValueChangedImpl(value);
52
53
54
55
56
        emit valueChanged(value);
    }

    void DoubleAdjusterWidget::onSliderValueChanged(int value) {
        const double newValue = _spinBox->minimum() + value * _spinBox->singleStep();
57
        onSliderValueChangedImpl(newValue);
58
59
60
        emit valueChanged(newValue);
    }

61
62
    void DoubleAdjusterWidget::setSliderValue(double value) {
        AbstractAdjusterWidget<double>::setSliderValue(std::ceil((value - minimum()) / singleStep()));
63
64
    }

65
    void DoubleAdjusterWidget::setSliderProperties(double stepValue, double minValue, double maxValue) {
66
        // by default minimum and single step are 0 and 1, respectively, so we don't have to change them
67
68
        AbstractAdjusterWidget<double>::setSliderProperties(1, 0, std::ceil((maxValue - minValue) / stepValue));
        setSliderValue(value());
69
70
    }
}