• 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_slider.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_slider.h"
29 #include "ksane_opt_slider.moc"
30 
31 #include "labeled_slider.h"
32 
33 // Qt includes
34 #include <QtCore/QVarLengthArray>
35 
36 // KDE includes
37 #include <KDebug>
38 #include <KLocale>
39 
40 static const int KSW_INT_MAX = 2147483647;
41 static const int KSW_INT_MIN = -2147483647-1; // prevent warning
42 
43 
44 namespace KSaneIface
45 {
46 
47 KSaneOptSlider::KSaneOptSlider(const SANE_Handle handle, const int index)
48 : KSaneOption(handle, index), m_slider(0), m_iVal(0)
49 {
50 }
51 
52 void KSaneOptSlider::createWidget(QWidget *parent)
53 {
54  if (m_widget) return;
55 
56  m_widget = m_slider = new LabeledSlider(parent, "", KSW_INT_MIN, KSW_INT_MAX, 1);
57  readOption();
58  m_widget->setToolTip(i18n(m_optDesc->desc));
59  connect(m_slider, SIGNAL(valueChanged(int)), this, SLOT(sliderChanged(int)));
60  readValue();
61 }
62 
63 
64 void KSaneOptSlider::readValue()
65 {
66  if (state() == STATE_HIDDEN) return;
67 
68  // read that current value
69  QVarLengthArray<unsigned char> data(m_optDesc->size);
70  SANE_Status status;
71  SANE_Int res;
72  status = sane_control_option (m_handle, m_index, SANE_ACTION_GET_VALUE, data.data(), &res);
73  if (status != SANE_STATUS_GOOD) {
74  return;
75  }
76 
77  m_iVal = toSANE_Word(data.data());
78  if ((m_slider != 0) && (m_slider->value() != m_iVal)) {
79  m_slider->setValue(m_iVal);
80  }
81  emit fValueRead((float)m_iVal);
82 }
83 
84 void KSaneOptSlider::readOption()
85 {
86  KSaneOption::readOption();
87 
88  if (!m_slider) return;
89 
90  if (m_optDesc->constraint_type == SANE_CONSTRAINT_RANGE) {
91  m_slider->setRange(m_optDesc->constraint.range->min, m_optDesc->constraint.range->max);
92  m_slider->setStep(m_optDesc->constraint.range->quant);
93  }
94  else {
95  m_slider->setRange(KSW_INT_MIN, KSW_INT_MAX);
96  m_slider->setStep(1);
97  }
98  m_slider->setSuffix(unitString());
99  m_slider->setLabelText(i18n(m_optDesc->title));
100 }
101 
102 void KSaneOptSlider::sliderChanged(int val)
103 {
104  if (val == m_iVal) return;
105  unsigned char data[4];
106  m_iVal = val;
107  fromSANE_Word(data, val);
108  writeData(data);
109 }
110 
111 bool KSaneOptSlider::getMinValue(float &val)
112 {
113  if (m_optDesc->constraint_type == SANE_CONSTRAINT_RANGE) {
114  val = (float)m_optDesc->constraint.range->min;
115  }
116  else {
117  val = (float)KSW_INT_MIN;
118  }
119  return true;
120 }
121 
122 bool KSaneOptSlider::getMaxValue(float &val)
123 {
124  if (m_optDesc->constraint_type == SANE_CONSTRAINT_RANGE) {
125  val = (float)m_optDesc->constraint.range->max;
126  }
127  else {
128  val = (float)KSW_INT_MAX;
129  }
130  return true;
131 }
132 
133 bool KSaneOptSlider::getValue(float &val)
134 {
135  if (state() == STATE_HIDDEN) return false;
136  val = (float)m_iVal;
137  return true;
138 }
139 
140 bool KSaneOptSlider::setValue(float val)
141 {
142  if (state() == STATE_HIDDEN) return false;
143  sliderChanged((int)val);
144  readValue();
145  return true;
146 }
147 
148 bool KSaneOptSlider::getValue(QString &val)
149 {
150  if (state() == STATE_HIDDEN) return false;
151  val = QString::number(m_iVal);
152  return true;
153 }
154 
155 bool KSaneOptSlider::setValue(const QString &val)
156 {
157  if (state() == STATE_HIDDEN) return false;
158  sliderChanged(val.toInt());
159  readValue();
160  return true;
161 }
162 
163 
164 } // NameSpace KSaneIface
KSaneIface::LabeledSlider::setSuffix
void setSuffix(const KLocalizedString &text)
Set the unit.
Definition: labeled_slider.cpp:82
QWidget
KSaneIface::KSaneOptionWidget::setLabelText
void setLabelText(const QString &text)
Definition: ksane_option_widget.cpp:54
KSaneIface::KSaneOptSlider::fValueRead
void fValueRead(float)
KSaneIface::KSaneOptSlider::getMinValue
bool getMinValue(float &max)
Definition: ksane_opt_slider.cpp:111
KSW_INT_MAX
static const int KSW_INT_MAX
Definition: ksane_opt_slider.cpp:40
KSaneIface::LabeledSlider::setStep
void setStep(int)
Definition: labeled_slider.cpp:100
KSaneIface::KSaneOption::m_index
int m_index
Definition: ksane_option.h:114
KSaneIface::LabeledSlider
A combination of a label a slider and a spinbox.
Definition: labeled_slider.h:50
ksane_opt_slider.h
KSaneIface::KSaneOption::fromSANE_Word
void fromSANE_Word(unsigned char *data, SANE_Word from)
Definition: ksane_option.cpp:180
KSaneIface::KSaneOptSlider::setValue
bool setValue(float val)
Definition: ksane_opt_slider.cpp:140
KSaneIface::KSaneOption::toSANE_Word
SANE_Word toSANE_Word(unsigned char *data)
Definition: ksane_option.cpp:162
QVarLengthArray
KSaneIface::LabeledSlider::setValue
void setValue(int)
Set the slider value.
Definition: labeled_slider.cpp:87
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
QString::toInt
int toInt(bool *ok, int base) const
KSW_INT_MIN
static const int KSW_INT_MIN
Definition: ksane_opt_slider.cpp:41
KSaneIface::LabeledSlider::setRange
void setRange(int min, int max)
Definition: labeled_slider.cpp:93
QString
KSaneIface::KSaneOptSlider::getValue
bool getValue(float &val)
Definition: ksane_opt_slider.cpp:133
KSaneIface::KSaneOptSlider::KSaneOptSlider
KSaneOptSlider(const SANE_Handle handle, const int index)
Definition: ksane_opt_slider.cpp:47
KSaneIface::KSaneOption
Definition: ksane_option.h:49
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
QVarLengthArray::data
T * data()
KSaneIface::KSaneOptSlider::readValue
void readValue()
Definition: ksane_opt_slider.cpp:64
KSaneIface::KSaneOption::m_widget
KSaneOptionWidget * m_widget
Definition: ksane_option.h:117
KSaneIface::LabeledSlider::value
int value() const
Definition: labeled_slider.h:70
KSaneIface::KSaneOption::unitString
KLocalizedString unitString()
Definition: ksane_option.cpp:311
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)
KSaneIface::KSaneOptSlider::createWidget
void createWidget(QWidget *parent)
Definition: ksane_opt_slider.cpp:52
KSaneIface::KSaneOptSlider::getMaxValue
bool getMaxValue(float &max)
Definition: ksane_opt_slider.cpp:122
labeled_slider.h
KSaneIface::KSaneOptSlider::readOption
void readOption()
Definition: ksane_opt_slider.cpp:84
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