~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to extra/libksane/libksane/options/ksane_opt_fslider.cpp

  • Committer: Package Import Robot
  • Author(s): Felix Geyer, Rohan Garg, Philip Muškovac, Felix Geyer
  • Date: 2011-09-23 18:18:55 UTC
  • mfrom: (1.2.36 upstream)
  • Revision ID: package-import@ubuntu.com-20110923181855-ifs67wxkugshev9k
Tags: 2:2.1.1-0ubuntu1
[ Rohan Garg ]
* New upstream release (LP: #834190)
  - debian/control
    + Build with libqtwebkit-dev
 - debian/kipi-plugins-common
    + Install libkvkontakte required by kipi-plugins
 - debian/digikam
    + Install panoramagui

[ Philip Muškovac ]
* New upstream release
  - debian/control:
    + Add libcv-dev, libcvaux-dev, libhighgui-dev, libboost-graph1.46-dev,
      libksane-dev, libxml2-dev, libxslt-dev, libqt4-opengl-dev, libqjson-dev,
      libgpod-dev and libqca2-dev to build-deps
    + Add packages for kipi-plugins, libmediawiki, libkface, libkgeomap and
      libkvkontakte
  - debian/rules:
    + Don't build with gphoto2 since it doesn't build with it.
  - Add kubuntu_fix_test_linking.diff to fix linking of the dngconverter test
  - update install files
  - update kubuntu_01_mysqld_executable_name.diff for new cmake layout
    and rename to kubuntu_mysqld_executable_name.diff
* Fix typo in digikam-data description (LP: #804894)
* Fix Vcs links

[ Felix Geyer ]
* Move library data files to the new packages libkface-data, libkgeomap-data
  and libkvkontakte-data.
* Override version of the embedded library packages to 1.0~digikam<version>.
* Exclude the library packages from digikam-dbg to prevent file conflicts in
  the future.
* Call dh_install with --list-missing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ============================================================
 
2
 *
 
3
 * This file is part of the KDE project
 
4
 *
 
5
 * Date        : 2009-01-21
 
6
 * Description : Sane interface for KDE
 
7
 *
 
8
 * Copyright (C) 2009 by Kare Sars <kare dot sars at iki dot fi>
 
9
 *
 
10
 * This library is free software; you can redistribute it and/or
 
11
 * modify it under the terms of the GNU Lesser General Public
 
12
 * License as published by the Free Software Foundation; either
 
13
 * version 2.1 of the License, or (at your option) version 3, or any
 
14
 * later version accepted by the membership of KDE e.V. (or its
 
15
 * successor approved by the membership of KDE e.V.), which shall
 
16
 * act as a proxy defined in Section 6 of version 3 of the license.
 
17
 *
 
18
 * This library is distributed in the hope that it will be useful,
 
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
21
 * Lesser General Public License for more details.
 
22
 *
 
23
 * You should have received a copy of the GNU Lesser General Public
 
24
 * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
25
 *
 
26
 * ============================================================ */
 
27
// Local includes.
 
28
#include "ksane_opt_fslider.h"
 
29
#include "ksane_opt_fslider.moc"
 
30
 
 
31
#include "labeled_fslider.h"
 
32
 
 
33
// Qt includes
 
34
#include <QtCore/QVarLengthArray>
 
35
 
 
36
// KDE includes
 
37
#include <KDebug>
 
38
#include <KLocale>
 
39
 
 
40
static const float FIXED_MAX = 32767.0;
 
41
static const float FIXED_MIN =-32768.0;
 
42
static const float MIN_FIXED_STEP = 0.0001;
 
43
namespace KSaneIface
 
44
{
 
45
 
 
46
KSaneOptFSlider::KSaneOptFSlider(const SANE_Handle handle, const int index)
 
47
: KSaneOption(handle, index), m_slider(0), m_fVal(0), m_minChange(MIN_FIXED_STEP)
 
48
{
 
49
}
 
50
 
 
51
void KSaneOptFSlider::createWidget(QWidget *parent)
 
52
{
 
53
    if (m_widget) return;
 
54
 
 
55
    m_widget = m_slider = new LabeledFSlider(parent, "", FIXED_MIN, FIXED_MAX, MIN_FIXED_STEP);
 
56
    readOption();
 
57
    m_widget->setToolTip(i18n(m_optDesc->desc));
 
58
    connect(m_slider, SIGNAL(valueChanged(float)), this, SLOT(sliderChanged(float)));
 
59
    readValue();
 
60
}
 
61
 
 
62
void KSaneOptFSlider::readOption()
 
63
{
 
64
    KSaneOption::readOption();
 
65
 
 
66
    if (!m_slider) return;
 
67
    
 
68
    if (m_optDesc->constraint_type == SANE_CONSTRAINT_RANGE) {
 
69
        m_slider->setRange(SANE_UNFIX(m_optDesc->constraint.range->min),
 
70
                           SANE_UNFIX(m_optDesc->constraint.range->max));
 
71
        
 
72
        float tmpStep = SANE_UNFIX(m_optDesc->constraint.range->quant);
 
73
        if (tmpStep < MIN_FIXED_STEP) tmpStep = MIN_FIXED_STEP;
 
74
        m_slider->setStep(tmpStep);
 
75
    }
 
76
    else {
 
77
        m_slider->setRange(FIXED_MIN, FIXED_MAX);
 
78
        m_slider->setStep(MIN_FIXED_STEP);
 
79
    }
 
80
    m_minChange = m_slider->step()/2;
 
81
    m_slider->setSuffix(unitDoubleString());
 
82
    m_slider->setLabelText(i18n(m_optDesc->title));
 
83
}
 
84
 
 
85
void KSaneOptFSlider::readValue()
 
86
{
 
87
    if (state() == STATE_HIDDEN) return;
 
88
    
 
89
    // read that current value
 
90
    QVarLengthArray<unsigned char> data(m_optDesc->size);
 
91
    SANE_Status status;
 
92
    SANE_Int res;
 
93
    status = sane_control_option (m_handle, m_index, SANE_ACTION_GET_VALUE, data.data(), &res);
 
94
    if (status != SANE_STATUS_GOOD) {
 
95
        return;
 
96
    }
 
97
    
 
98
    m_fVal = SANE_UNFIX(toSANE_Word(data.data()));
 
99
    if (m_slider != 0) {
 
100
        if (((m_slider->value() - m_fVal) >= m_minChange) ||
 
101
            ((m_fVal- m_slider->value()) >= m_minChange))
 
102
        {
 
103
            m_slider->setValue(m_fVal);
 
104
        }
 
105
    }
 
106
    emit fValueRead(m_fVal);
 
107
}
 
108
 
 
109
 
 
110
void KSaneOptFSlider::sliderChanged(float val)
 
111
{
 
112
    if (((val-m_fVal) >= m_minChange) || ((m_fVal-val) >= m_minChange)) {
 
113
        unsigned char data[4];
 
114
        SANE_Word fixed;
 
115
        //kDebug() <<m_optDesc->name << fVal << "!=" << val;
 
116
        m_fVal = val;
 
117
        fixed = SANE_FIX(val);
 
118
        fromSANE_Word(data, fixed);
 
119
        writeData(data);
 
120
    }
 
121
}
 
122
 
 
123
bool KSaneOptFSlider::getMinValue(float &val)
 
124
{
 
125
    if (m_optDesc->constraint_type == SANE_CONSTRAINT_RANGE) {
 
126
        val = SANE_UNFIX(m_optDesc->constraint.range->min);
 
127
    }
 
128
    else {
 
129
        val = FIXED_MIN;
 
130
    }
 
131
    return true;
 
132
}
 
133
 
 
134
bool KSaneOptFSlider::getMaxValue(float &max)
 
135
{
 
136
    if (m_optDesc->constraint_type == SANE_CONSTRAINT_RANGE) {
 
137
        max = SANE_UNFIX(m_optDesc->constraint.range->max);
 
138
    }
 
139
    else {
 
140
        max = FIXED_MAX;
 
141
    }
 
142
    return true;
 
143
}
 
144
 
 
145
bool KSaneOptFSlider::getValue(float &val)
 
146
{
 
147
    if (state() == STATE_HIDDEN) return false;
 
148
    val = m_fVal;
 
149
    return true;
 
150
}
 
151
 
 
152
bool KSaneOptFSlider::setValue(float val)
 
153
{
 
154
    if (state() == STATE_HIDDEN) return false;
 
155
    sliderChanged(val);
 
156
    readValue();
 
157
    return true;
 
158
}
 
159
 
 
160
bool KSaneOptFSlider::getValue(QString &val)
 
161
{
 
162
    if (state() == STATE_HIDDEN) return false;
 
163
    val = QString::number(m_fVal, 'F', 6);
 
164
    return true;
 
165
}
 
166
 
 
167
bool KSaneOptFSlider::setValue(const QString &val)
 
168
{
 
169
    if (state() == STATE_HIDDEN) return false;
 
170
    sliderChanged(val.toFloat());
 
171
    readValue();
 
172
    return true;
 
173
}
 
174
 
 
175
 
 
176
}  // NameSpace KSaneIface