• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegraphics API Reference
  • KDE Home
  • Contact Us
 

libs/libksane/libksane

  • sources
  • kde-4.14
  • kdegraphics
  • libs
  • libksane
  • libksane
  • options
ksane_opt_fslider.cpp
Go to the documentation of this file.
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
KSaneIface::KSaneOptFSlider::createWidget
void createWidget(QWidget *parent)
Definition: ksane_opt_fslider.cpp:51
QWidget
KSaneIface::KSaneOptionWidget::setLabelText
void setLabelText(const QString &text)
Definition: ksane_option_widget.cpp:54
KSaneIface::KSaneOptFSlider::readOption
void readOption()
Definition: ksane_opt_fslider.cpp:62
KSaneIface::KSaneOptFSlider::setValue
bool setValue(float val)
Definition: ksane_opt_fslider.cpp:152
FIXED_MAX
static const float FIXED_MAX
Definition: ksane_opt_fslider.cpp:40
KSaneIface::KSaneOption::m_index
int m_index
Definition: ksane_option.h:114
KSaneIface::KSaneOptFSlider::getMinValue
bool getMinValue(float &max)
Definition: ksane_opt_fslider.cpp:123
KSaneIface::KSaneOption::fromSANE_Word
void fromSANE_Word(unsigned char *data, SANE_Word from)
Definition: ksane_option.cpp:180
KSaneIface::KSaneOption::toSANE_Word
SANE_Word toSANE_Word(unsigned char *data)
Definition: ksane_option.cpp:162
QVarLengthArray
KSaneIface::KSaneOption::state
KSaneOptWState state()
Definition: ksane_option.cpp:92
QString::number
QString number(int n, int base)
KSaneIface::KSaneOption::m_optDesc
const SANE_Option_Descriptor * m_optDesc
This pointer is provided by sane.
Definition: ksane_option.h:115
KSaneIface::KSaneOption::m_handle
SANE_Handle m_handle
Definition: ksane_option.h:113
KSaneIface::KSaneOptFSlider::readValue
void readValue()
Definition: ksane_opt_fslider.cpp:85
FIXED_MIN
static const float FIXED_MIN
Definition: ksane_opt_fslider.cpp:41
KSaneIface::KSaneOptFSlider::KSaneOptFSlider
KSaneOptFSlider(const SANE_Handle handle, const int index)
Definition: ksane_opt_fslider.cpp:46
KSaneIface::LabeledFSlider::setValue
void setValue(float)
Set the slider/spinbox value.
Definition: labeled_fslider.cpp:134
KSaneIface::LabeledFSlider::setStep
void setStep(float)
Definition: labeled_fslider.cpp:113
KSaneIface::LabeledFSlider::value
float value() const
Definition: labeled_fslider.h:71
KSaneIface::LabeledFSlider::setSuffix
void setSuffix(const QString &text)
Set the unit.
Definition: labeled_fslider.cpp:96
QString
KSaneIface::KSaneOption
Definition: ksane_option.h:49
KSaneIface::LabeledFSlider
A combination of a label a slider and a spinbox.
Definition: labeled_fslider.h:48
KSaneIface::KSaneOptFSlider::getValue
bool getValue(float &val)
Definition: ksane_opt_fslider.cpp:145
MIN_FIXED_STEP
static const float MIN_FIXED_STEP
Definition: ksane_opt_fslider.cpp:42
KSaneIface::LabeledFSlider::setRange
void setRange(float, float)
Definition: labeled_fslider.cpp:101
KSaneIface::KSaneOptFSlider::fValueRead
void fValueRead(float)
KSaneIface::KSaneOption::STATE_HIDDEN
Definition: ksane_option.h:69
KSaneIface::KSaneOption::writeData
bool writeData(void *data)
Definition: ksane_option.cpp:126
KSaneIface::KSaneOption::readOption
virtual void readOption()
Definition: ksane_option.cpp:73
QString::toFloat
float toFloat(bool *ok) const
KSaneIface::LabeledFSlider::step
float step() const
Definition: labeled_fslider.h:72
KSaneIface::KSaneOptFSlider::getMaxValue
bool getMaxValue(float &max)
Definition: ksane_opt_fslider.cpp:134
QVarLengthArray::data
T * data()
KSaneIface::KSaneOption::m_widget
KSaneOptionWidget * m_widget
Definition: ksane_option.h:117
KSaneIface::KSaneOption::unitDoubleString
QString unitDoubleString()
Definition: ksane_option.cpp:326
QWidget::setToolTip
void setToolTip(const QString &)
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
labeled_fslider.h
ksane_opt_fslider.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:19:47 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libs/libksane/libksane

Skip menu "libs/libksane/libksane"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdegraphics API Reference

Skip menu "kdegraphics API Reference"
  •     libkdcraw
  •     libkexiv2
  •     libkipi
  •     libksane
  • okular

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal