29 #include "ksane_opt_combo.moc"
34 #include <QtCore/QVarLengthArray>
57 connect(m_combo, SIGNAL(activated(
int)),
this, SLOT(comboboxChangedIndex(
int)));
70 if (status != SANE_STATUS_GOOD) {
75 m_currentText = getSaneComboString(data.
data());
92 m_strList = genComboStringList();
96 m_combo->
setIcon(KIcon(
"color"), getSaneComboString((
unsigned char*)SANE_VALUE_SCAN_MODE_COLOR));
97 m_combo->
setIcon(KIcon(
"gray-scale"),
98 getSaneComboString((
unsigned char*)SANE_VALUE_SCAN_MODE_GRAY));
99 m_combo->
setIcon(KIcon(
"black-white"),
100 getSaneComboString((
unsigned char*)SANE_VALUE_SCAN_MODE_LINEART));
117 for (i=1; i<=
m_optDesc->constraint.word_list[0]; ++i) {
118 m_strList += getSaneComboString((
int)
m_optDesc->constraint.word_list[i]);
121 case SANE_TYPE_FIXED:
122 for (i=1; i<=
m_optDesc->constraint.word_list[0]; ++i) {
123 m_strList += getSaneComboString((
float)SANE_UNFIX(
m_optDesc->constraint.word_list[i]));
126 case SANE_TYPE_STRING:
128 while (
m_optDesc->constraint.string_list[i] != 0) {
129 m_strList += getSaneComboString((
unsigned char *)
m_optDesc->constraint.string_list[i]);
134 m_strList +=
"NOT HANDELED";
140 QString KSaneOptCombo::getSaneComboString(
int ival)
144 case SANE_UNIT_NONE:
break;
145 case SANE_UNIT_PIXEL:
return i18np(
"%1 Pixel",
"%1 Pixels", ival);
146 case SANE_UNIT_BIT:
return i18np(
"%1 Bit",
"%1 Bits", ival);
147 case SANE_UNIT_MM:
return i18np(
"%1 mm",
"%1 mm", ival);
148 case SANE_UNIT_DPI:
return i18np(
"%1 DPI",
"%1 DPI", ival);
149 case SANE_UNIT_PERCENT:
return i18np(
"%1 %",
"%1 %", ival);
150 case SANE_UNIT_MICROSECOND:
return i18np(
"%1 µs",
"%1 µs", ival);
155 QString KSaneOptCombo::getSaneComboString(
float fval)
159 case SANE_UNIT_NONE:
break;
160 case SANE_UNIT_PIXEL:
return i18ncp(
"Parameter and Unit",
"%1 Pixel",
"%1 Pixels", fval);
161 case SANE_UNIT_BIT:
return i18ncp(
"Parameter and Unit",
"%1 Bit",
"%1 Bits", fval);
162 case SANE_UNIT_MM:
return i18nc(
"Parameter and Unit (Millimeter)",
"%1 mm", fval);
163 case SANE_UNIT_DPI:
return i18nc(
"Parameter and Unit (Dots Per Inch)",
"%1 DPI", fval);
164 case SANE_UNIT_PERCENT:
return i18nc(
"Parameter and Unit (Percentage)",
"%1 %", fval);
165 case SANE_UNIT_MICROSECOND:
return i18nc(
"Parameter and Unit (Microseconds)",
"%1 µs", fval);
170 QString KSaneOptCombo::getSaneComboString(
unsigned char *data)
173 if (data == 0)
return QString();
179 case SANE_TYPE_FIXED:
180 return getSaneComboString((
float)SANE_UNFIX(
toSANE_Word(data)));
181 case SANE_TYPE_STRING:
182 tmp = i18n(reinterpret_cast<char*>(data));
193 void KSaneOptCombo::comboboxChangedIndex(
int i)
195 if (m_combo && (m_combo->
currentText() == m_currentText)) {
199 unsigned char data[4];
205 case SANE_TYPE_FIXED:
209 case SANE_TYPE_STRING:
210 dataPtr = (
void *)
m_optDesc->constraint.string_list[i];
213 kDebug() <<
"can not handle type:" <<
m_optDesc->type;
227 val = (float)
m_optDesc->constraint.word_list[1];
228 for (
int i=2; i<=
m_optDesc->constraint.word_list[0]; i++) {
229 val = qMin((
float)
m_optDesc->constraint.word_list[i], val);
232 case SANE_TYPE_FIXED:
233 val = (float)SANE_UNFIX(
m_optDesc->constraint.word_list[1]);
234 for (
int i=2; i<=
m_optDesc->constraint.word_list[0]; i++) {
235 val = qMin((
float)SANE_UNFIX(
m_optDesc->constraint.word_list[i]), val);
239 kDebug() <<
"can not handle type:" <<
m_optDesc->type;
253 status = sane_control_option (
m_handle,
m_index, SANE_ACTION_GET_VALUE, data.
data(), &res);
254 if (status != SANE_STATUS_GOOD) {
255 kDebug() <<
m_optDesc->name <<
"sane_control_option returned" << status;
264 case SANE_TYPE_FIXED:
268 kDebug() <<
"Type" <<
m_optDesc->type <<
"not supported!";
276 unsigned char data[4];
285 tmp = (float)
m_optDesc->constraint.word_list[minIndex];
286 minDiff = qAbs(value - tmp);
287 for (i=2; i<=
m_optDesc->constraint.word_list[0]; ++i) {
288 tmp = (float)
m_optDesc->constraint.word_list[i];
289 if (qAbs(value - tmp) < minDiff) {
290 minDiff = qAbs(value - tmp);
297 return (minDiff < 1.0);
298 case SANE_TYPE_FIXED:
299 tmp = (float)SANE_UNFIX(
m_optDesc->constraint.word_list[minIndex]);
300 minDiff = qAbs(value - tmp);
301 for (i=2; i<=
m_optDesc->constraint.word_list[0]; ++i) {
302 tmp = (float)SANE_UNFIX(
m_optDesc->constraint.word_list[i]);
303 if (qAbs(value - tmp) < minDiff) {
304 minDiff = qAbs(value - tmp);
311 return (minDiff < 1.0);
313 kDebug() <<
"can not handle type:" <<
m_optDesc->type;
329 if (val == m_currentText)
return true;
331 unsigned char data[4];
345 if (ok ==
false)
return false;
349 case SANE_TYPE_FIXED:
352 if (ok ==
false)
return false;
357 case SANE_TYPE_STRING:
359 while (
m_optDesc->constraint.string_list[i] != 0) {
360 tmp = getSaneComboString((
unsigned char *)
m_optDesc->constraint.string_list[i]);
362 data_ptr = (
void *)
m_optDesc->constraint.string_list[i];
367 if (
m_optDesc->constraint.string_list[i] == 0)
return false;
370 kDebug() <<
"can only handle SANE_TYPE: INT, FIXED and STRING";
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
KSaneOptCombo(const SANE_Handle handle, const int index)
bool getMinValue(float &max)
void fromSANE_Word(unsigned char *data, SANE_Word from)
void setCurrentText(const QString &)
If the given string can be found in the comobox, activate that entry.
QString simplified() const
SANE_Word toSANE_Word(unsigned char *data)
void addItems(const QStringList &list)
Add string entries to the combobox.
QString number(int n, int base)
const SANE_Option_Descriptor * m_optDesc
This pointer is provided by sane.
bool getValue(float &val)
void createWidget(QWidget *parent)
QString currentText()
This function is used to read the current string of the combobox.
bool setIcon(const QIcon &icon, const QString &str)
add an icon for a string in the combobox
bool writeData(void *data)
virtual void readOption()
float toFloat(bool *ok) const
KSaneOptionWidget * m_widget
QString left(int n) const
static const char tmp_binary[]
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void clear()
Remove all string entries.