• 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_checkbox.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_checkbox.h"
29 #include "ksane_opt_checkbox.moc"
30 
31 #include "labeled_checkbox.h"
32 
33 // Qt includes
34 #include <QtCore/QVarLengthArray>
35 
36 // KDE includes
37 #include <KDebug>
38 #include <KLocale>
39 
40 namespace KSaneIface
41 {
42 
43 KSaneOptCheckBox::KSaneOptCheckBox(const SANE_Handle handle, const int index)
44 : KSaneOption(handle, index), m_checkbox(0), m_checked(false)
45 {
46 }
47 
48 void KSaneOptCheckBox::createWidget(QWidget *parent)
49 {
50  if (m_widget) return;
51 
52  readOption();
53 
54  if (!m_optDesc) {
55  kDebug() << "This is a bug";
56  m_widget = new KSaneOptionWidget(parent, "");
57  return;
58  }
59 
60  m_widget = m_checkbox = new LabeledCheckbox(parent, i18n(m_optDesc->title));
61  m_widget->setToolTip(i18n(m_optDesc->desc));
62 
63  connect(m_checkbox, SIGNAL(toggled(bool)), this, SLOT(checkboxChanged(bool)));
64 
65  updateVisibility();
66  readValue();
67 }
68 
69 void KSaneOptCheckBox::checkboxChanged(bool toggled)
70 {
71  unsigned char data[4];
72 
73  m_checked = toggled;
74  fromSANE_Word(data, (toggled) ? 1:0);
75  writeData(data);
76 }
77 
78 void KSaneOptCheckBox::readValue()
79 {
80  if (state() == STATE_HIDDEN) return;
81 
82  // read the current value
83  QVarLengthArray<unsigned char> data(m_optDesc->size);
84  SANE_Status status;
85  SANE_Int res;
86  status = sane_control_option (m_handle, m_index, SANE_ACTION_GET_VALUE, data.data(), &res);
87  if (status != SANE_STATUS_GOOD) {
88  return;
89  }
90  bool old = m_checked;
91  m_checked = (toSANE_Word(data.data()) != 0) ? true:false;
92  if (m_checkbox) {
93  m_checkbox->setChecked(m_checked);
94  }
95  if ((old != m_checked) && ((m_optDesc->cap & SANE_CAP_SOFT_SELECT) == 0)) {
96  emit buttonPressed(name(), i18n(m_optDesc->title), m_checked);
97  }
98 }
99 
100 bool KSaneOptCheckBox::getValue(float &val)
101 {
102  if (state() == STATE_HIDDEN) return false;
103  val = m_checked ? 1.0 : 0.0;
104  return true;
105 }
106 
107 bool KSaneOptCheckBox::setValue(float val)
108 {
109  if (state() == STATE_HIDDEN) return false;
110  checkboxChanged(val == 0);
111  readValue();
112  return true;
113 }
114 
115 bool KSaneOptCheckBox::getValue(QString &val)
116 {
117  if (state() == STATE_HIDDEN) return false;
118  val = m_checked ? "true" : "false";
119  return true;
120 }
121 
122 bool KSaneOptCheckBox::setValue(const QString &val)
123 {
124  if (state() == STATE_HIDDEN) return false;
125  if ((val.compare("true", Qt::CaseInsensitive) == 0) ||
126  (val.compare("1") == 0))
127  {
128  checkboxChanged(true);
129  }
130  else {
131  checkboxChanged(false);
132  }
133  readValue();
134  return true;
135 }
136 
137 
138 } // NameSpace KSaneIface
QWidget
KSaneIface::LabeledCheckbox::setChecked
void setChecked(bool)
Definition: labeled_checkbox.cpp:52
KSaneIface::KSaneOption::m_index
int m_index
Definition: ksane_option.h:114
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
labeled_checkbox.h
KSaneIface::KSaneOption::state
KSaneOptWState state()
Definition: ksane_option.cpp:92
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::KSaneOptionWidget
A wrapper for a checkbox.
Definition: ksane_option_widget.h:45
KSaneIface::KSaneOptCheckBox::createWidget
void createWidget(QWidget *parent)
Definition: ksane_opt_checkbox.cpp:48
QString
KSaneIface::KSaneOptCheckBox::readValue
void readValue()
Definition: ksane_opt_checkbox.cpp:78
KSaneIface::KSaneOption
Definition: ksane_option.h:49
KSaneIface::KSaneOptCheckBox::KSaneOptCheckBox
KSaneOptCheckBox(const SANE_Handle handle, const int index)
Definition: ksane_opt_checkbox.cpp:43
KSaneIface::LabeledCheckbox
A wrapper for a checkbox.
Definition: labeled_checkbox.h:47
KSaneIface::KSaneOption::STATE_HIDDEN
Definition: ksane_option.h:69
KSaneIface::KSaneOptCheckBox::buttonPressed
void buttonPressed(const QString &optionName, const QString &optionLabel, bool pressed)
KSaneIface::KSaneOption::writeData
bool writeData(void *data)
Definition: ksane_option.cpp:126
KSaneIface::KSaneOption::readOption
virtual void readOption()
Definition: ksane_option.cpp:73
KSaneIface::KSaneOption::updateVisibility
void updateVisibility()
Definition: ksane_option.cpp:79
KSaneIface::KSaneOptCheckBox::setValue
bool setValue(float val)
Definition: ksane_opt_checkbox.cpp:107
QVarLengthArray::data
T * data()
KSaneIface::KSaneOption::m_widget
KSaneOptionWidget * m_widget
Definition: ksane_option.h:117
ksane_opt_checkbox.h
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)
QString::compare
int compare(const QString &other) const
KSaneIface::KSaneOption::name
QString name()
Definition: ksane_option.cpp:120
KSaneIface::KSaneOptCheckBox::getValue
bool getValue(float &val)
Definition: ksane_opt_checkbox.cpp:100
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