Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Graphics
libksane
Commits
67fc90e4
Commit
67fc90e4
authored
Apr 06, 2021
by
Alexander Stippich
Browse files
rework the float option to a double option
parent
32ff8dd8
Changes
9
Hide whitespace changes
Inline
Side-by-side
src/CMakeLists.txt
View file @
67fc90e4
...
...
@@ -38,7 +38,7 @@ set(ksane_SRCS
options/ksanestringoption.cpp
options/ksanegammaoption.cpp
options/ksaneintegeroption.cpp
options/ksane
float
option.cpp
options/ksane
double
option.cpp
options/ksanelistoption.cpp
options/ksaneinvertoption.cpp
)
...
...
src/ksanewidget.cpp
View file @
67fc90e4
...
...
@@ -39,7 +39,7 @@
#include "ksanebooloption.h"
#include "ksanelistoption.h"
#include "ksanestringoption.h"
#include "ksane
float
option.h"
#include "ksane
double
option.h"
#include "ksanegammaoption.h"
#include "ksaneintegeroption.h"
#include "ksanedevicedialog.h"
...
...
@@ -444,8 +444,8 @@ bool KSaneWidget::openDevice(const QString &deviceName)
case
KSaneOption
::
TypeInteger
:
d
->
m_optList
.
append
(
new
KSaneIntegerOption
(
d
->
m_saneHandle
,
i
));
break
;
case
KSaneOption
::
Type
Float
:
d
->
m_optList
.
append
(
new
KSane
Float
Option
(
d
->
m_saneHandle
,
i
));
case
KSaneOption
::
Type
Double
:
d
->
m_optList
.
append
(
new
KSane
Double
Option
(
d
->
m_saneHandle
,
i
));
break
;
case
KSaneOption
::
TypeValueList
:
d
->
m_optList
.
append
(
new
KSaneListOption
(
d
->
m_saneHandle
,
i
));
...
...
src/ksanewidget_p.cpp
View file @
67fc90e4
...
...
@@ -378,7 +378,7 @@ KSaneOptionWidget *KSaneWidgetPrivate::createOptionWidget(QWidget *parent, KSane
case
KSaneOption
::
TypeInteger
:
widget
=
new
LabeledSlider
(
parent
,
option
);
break
;
case
KSaneOption
::
Type
Float
:
case
KSaneOption
::
Type
Double
:
widget
=
new
LabeledFSlider
(
parent
,
option
);
break
;
case
KSaneOption
::
TypeValueList
:
...
...
src/options/ksane
float
option.cpp
→
src/options/ksane
double
option.cpp
View file @
67fc90e4
...
...
@@ -7,12 +7,13 @@
*
* SPDX-FileCopyrightText: 2009 Kare Sars <kare dot sars at iki dot fi>
* SPDX-FileCopyrightText: 2014 Gregor Mitsch : port to KDE5 frameworks
* SPDX-FileCopyrightText: 2021 Alexander Stippich <a.stippich@gmx.net>
*
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*
* ============================================================ */
// Local includes
#include "ksane
float
option.h"
#include "ksane
double
option.h"
#include <QVarLengthArray>
...
...
@@ -24,17 +25,17 @@ static const float MIN_FIXED_STEP = 0.0001;
namespace
KSaneIface
{
KSane
Float
Option
::
KSane
Float
Option
(
const
SANE_Handle
handle
,
const
int
index
)
:
KSaneOption
(
handle
,
index
)
,
m_fVal
(
0
),
m_minChange
(
MIN_FIXED_STEP
)
KSane
Double
Option
::
KSane
Double
Option
(
const
SANE_Handle
handle
,
const
int
index
)
:
KSaneOption
(
handle
,
index
)
{
m_optionType
=
KSaneOption
::
Type
Float
;
m_optionType
=
KSaneOption
::
Type
Double
;
}
void
KSane
Float
Option
::
readOption
()
void
KSane
Double
Option
::
readOption
()
{
KSaneOption
::
readOption
();
float
step
=
MIN_FIXED_STEP
;
double
step
=
MIN_FIXED_STEP
;
if
(
m_optDesc
->
constraint_type
==
SANE_CONSTRAINT_RANGE
)
{
step
=
SANE_UNFIX
(
m_optDesc
->
constraint
.
range
->
quant
);
if
(
step
<
MIN_FIXED_STEP
)
{
...
...
@@ -44,7 +45,7 @@ void KSaneFloatOption::readOption()
m_minChange
=
step
;
}
void
KSane
Float
Option
::
readValue
()
void
KSane
Double
Option
::
readValue
()
{
if
(
state
()
==
StateHidden
)
{
return
;
...
...
@@ -59,32 +60,32 @@ void KSaneFloatOption::readValue()
return
;
}
m_
fVal
=
SANE_UNFIX
(
toSANE_Word
(
data
.
data
()));
m_
value
=
SANE_UNFIX
(
toSANE_Word
(
data
.
data
()));
Q_EMIT
valueChanged
(
m_
fVal
);
Q_EMIT
valueChanged
(
m_
value
);
}
bool
KSane
Float
Option
::
setValue
(
const
QVariant
&
value
)
bool
KSane
Double
Option
::
setValue
(
const
QVariant
&
value
)
{
if
(
state
()
==
StateHidden
)
{
return
false
;
}
bool
ok
;
float
newValue
=
value
.
to
Float
(
&
ok
);
if
(
ok
&&
(((
newValue
-
m_
fVal
)
>=
m_minChange
)
||
((
m_
fVal
-
newValue
)
>=
m_minChange
))
)
{
double
newValue
=
value
.
to
Double
(
&
ok
);
if
(
ok
&&
(((
newValue
-
m_
value
)
>=
m_minChange
)
||
((
m_
value
-
newValue
)
>=
m_minChange
))
)
{
unsigned
char
data
[
4
];
SANE_Word
fixed
;
//qCDebug(KSANE_LOG) <<m_optDesc->name << fVal << "!=" << val;
m_
fVal
=
newValue
;
m_
value
=
newValue
;
fixed
=
SANE_FIX
(
newValue
);
fromSANE_Word
(
data
,
fixed
);
writeData
(
data
);
Q_EMIT
valueChanged
(
m_
fVal
);
Q_EMIT
valueChanged
(
m_
value
);
}
return
ok
;
}
QVariant
KSane
Float
Option
::
getMinValue
()
const
QVariant
KSane
Double
Option
::
getMinValue
()
const
{
QVariant
value
;
if
(
m_optDesc
->
constraint_type
==
SANE_CONSTRAINT_RANGE
)
{
...
...
@@ -95,7 +96,7 @@ QVariant KSaneFloatOption::getMinValue() const
return
value
;
}
QVariant
KSane
Float
Option
::
getMaxValue
()
const
QVariant
KSane
Double
Option
::
getMaxValue
()
const
{
QVariant
value
;
if
(
m_optDesc
->
constraint_type
==
SANE_CONSTRAINT_RANGE
)
{
...
...
@@ -106,7 +107,7 @@ QVariant KSaneFloatOption::getMaxValue() const
return
value
;
}
QVariant
KSane
Float
Option
::
getStepValue
()
const
QVariant
KSane
Double
Option
::
getStepValue
()
const
{
QVariant
value
;
if
(
m_optDesc
->
constraint_type
==
SANE_CONSTRAINT_RANGE
)
{
...
...
@@ -117,20 +118,20 @@ QVariant KSaneFloatOption::getStepValue() const
return
value
;
}
QVariant
KSane
Float
Option
::
getValue
()
const
QVariant
KSane
Double
Option
::
getValue
()
const
{
if
(
state
()
==
StateHidden
)
{
return
QVariant
();
}
return
QVariant
(
m_
fVal
);
return
QVariant
(
m_
value
);
}
QString
KSane
Float
Option
::
getValueAsString
()
const
QString
KSane
Double
Option
::
getValueAsString
()
const
{
if
(
state
()
==
StateHidden
)
{
return
QString
();
}
return
QString
::
number
(
m_
fVal
,
'F'
,
6
);
return
QString
::
number
(
m_
value
,
'F'
,
6
);
}
}
// NameSpace KSaneIface
src/options/ksane
float
option.h
→
src/options/ksane
double
option.h
View file @
67fc90e4
...
...
@@ -2,29 +2,30 @@
*
* This file is part of the KDE project
*
* Date : 20
09-01-21
* Date : 20
21-04-6
* Description : Sane interface for KDE
*
* SPDX-FileCopyrightText: 2009 Kare Sars <kare dot sars at iki dot fi>
* SPDX-FileCopyrightText: 2021 Alexander Stippich <a.stippich@gmx.net>
*
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*
* ============================================================ */
#ifndef KSANE_
FLOAT
_OPTION_H
#define KSANE_
FLOAT
_OPTION_H
#ifndef KSANE_
DOUBLE
_OPTION_H
#define KSANE_
DOUBLE
_OPTION_H
#include "ksaneoption.h"
namespace
KSaneIface
{
class
KSane
Float
Option
:
public
KSaneOption
class
KSane
Double
Option
:
public
KSaneOption
{
Q_OBJECT
public:
KSane
Float
Option
(
const
SANE_Handle
handle
,
const
int
index
);
KSane
Double
Option
(
const
SANE_Handle
handle
,
const
int
index
);
void
readValue
()
override
;
void
readOption
()
override
;
...
...
@@ -39,8 +40,8 @@ public Q_SLOTS:
bool
setValue
(
const
QVariant
&
value
)
override
;
private:
float
m_fVal
;
float
m_minChange
;
double
m_value
=
0
;
double
m_minChange
=
0.0001
;
};
}
// NameSpace KSaneIface
...
...
src/options/ksaneoption.cpp
View file @
67fc90e4
...
...
@@ -289,7 +289,7 @@ KSaneOption::KSaneOptionType KSaneOption::optionType(const SANE_Option_Descripto
break
;
case
SANE_TYPE_FIXED
:
if
(
optDesc
->
size
==
sizeof
(
SANE_Word
))
{
return
Type
Float
;
return
Type
Double
;
}
qCDebug
(
KSANE_LOG
)
<<
"Can not handle:"
<<
optDesc
->
title
;
qCDebug
(
KSANE_LOG
)
<<
"SANE_CONSTRAINT_NONE && SANE_TYPE_FIXED"
;
...
...
@@ -324,7 +324,7 @@ KSaneOption::KSaneOptionType KSaneOption::optionType(const SANE_Option_Descripto
break
;
case
SANE_TYPE_FIXED
:
if
(
optDesc
->
size
==
sizeof
(
SANE_Word
))
{
return
Type
Float
;
return
Type
Double
;
}
qCDebug
(
KSANE_LOG
)
<<
"Can not handle:"
<<
optDesc
->
title
;
qCDebug
(
KSANE_LOG
)
<<
"SANE_CONSTRAINT_RANGE && SANE_TYPE_FIXED"
;
...
...
src/options/ksaneoption.h
View file @
67fc90e4
...
...
@@ -48,7 +48,7 @@ public:
TypeDetectFail
,
TypeBool
,
TypeInteger
,
Type
Float
,
Type
Double
,
TypeValueList
,
TypeString
,
TypeGamma
,
...
...
src/widgets/labeledfslider.cpp
View file @
67fc90e4
...
...
@@ -15,14 +15,14 @@
#include "labeledfslider.h"
#define FLOAT_MULTIP 32768.0
#define TO_
FLOAT(v) ((float)v
/ FLOAT_MULTIP)
#define TO_FIX(v) (
(
int
)
(v * FLOAT_MULTIP))
#define TO_
DOUBLE(v) (static_cast<double>(v)
/ FLOAT_MULTIP)
#define TO_FIX(v) (
static_cast<
int
>
(v * FLOAT_MULTIP))
namespace
KSaneIface
{
LabeledFSlider
::
LabeledFSlider
(
QWidget
*
parent
,
const
QString
&
ltext
,
float
min
,
float
max
,
float
step
)
double
min
,
double
max
,
double
step
)
:
KSaneOptionWidget
(
parent
,
ltext
)
{
initFSlider
(
min
,
max
,
step
);
...
...
@@ -31,10 +31,10 @@ LabeledFSlider::LabeledFSlider(QWidget *parent, const QString <ext,
LabeledFSlider
::
LabeledFSlider
(
QWidget
*
parent
,
KSaneOption
*
option
)
:
KSaneOptionWidget
(
parent
,
option
)
{
float
maxValue
F
=
option
->
getMaxValue
().
to
Float
();
float
minValue
F
=
option
->
getMinValue
().
to
Float
();
float
stepValue
F
=
option
->
getStepValue
().
to
Float
();
initFSlider
(
minValue
F
,
maxValue
F
,
stepValue
F
);
double
maxValue
=
option
->
getMaxValue
().
to
Double
();
double
minValue
=
option
->
getMinValue
().
to
Double
();
double
stepValue
=
option
->
getStepValue
().
to
Double
();
initFSlider
(
minValue
,
maxValue
,
stepValue
);
QString
unitSuffix
;
KSaneOption
::
KSaneOptionUnit
unit
=
option
->
getUnit
();
...
...
@@ -67,19 +67,19 @@ LabeledFSlider::LabeledFSlider(QWidget *parent, KSaneOption *option)
setToolTip
(
option
->
description
());
connect
(
this
,
&
LabeledFSlider
::
valueChanged
,
option
,
&
KSaneOption
::
setValue
);
connect
(
option
,
&
KSaneOption
::
valueChanged
,
this
,
&
LabeledFSlider
::
setValue
);
float
value
F
=
option
->
getValue
().
to
Float
();
setValue
(
value
F
);
double
value
=
option
->
getValue
().
to
Double
();
setValue
(
value
);
}
void
LabeledFSlider
::
initFSlider
(
float
minValue
F
,
float
maxValue
F
,
float
stepValue
F
)
void
LabeledFSlider
::
initFSlider
(
double
minValue
,
double
maxValue
,
double
stepValue
)
{
int
imin
=
TO_FIX
(
minValue
F
);
int
imax
=
TO_FIX
(
maxValue
F
);
m_istep
=
TO_FIX
(
stepValue
F
);
m_fstep
=
stepValue
F
;
int
imin
=
TO_FIX
(
minValue
);
int
imax
=
TO_FIX
(
maxValue
);
m_istep
=
TO_FIX
(
stepValue
);
m_fstep
=
stepValue
;
if
(
m_istep
==
0
)
{
m_istep
=
1
;
m_fstep
=
TO_
FLOAT
(
m_istep
);
m_fstep
=
TO_
DOUBLE
(
m_istep
);
}
//std::cout << "min=" << min << ", max=" << max << ", m_fstep="<<m_fstep<<std::endl;
...
...
@@ -92,11 +92,11 @@ void LabeledFSlider::initFSlider(float minValueF, float maxValueF, float stepVal
m_slider
->
setValue
(
imin
);
m_spinb
=
new
QDoubleSpinBox
(
this
);
m_spinb
->
setMinimum
(
minValue
F
);
m_spinb
->
setMaximum
(
maxValue
F
);
m_spinb
->
setMinimum
(
minValue
);
m_spinb
->
setMaximum
(
maxValue
);
m_spinb
->
setSingleStep
(
m_fstep
);
int
decimals
=
0
;
float
tmp_step
=
m_fstep
;
double
tmp_step
=
m_fstep
;
while
(
tmp_step
<
1
)
{
tmp_step
*=
10
;
decimals
++
;
...
...
@@ -105,11 +105,11 @@ void LabeledFSlider::initFSlider(float minValueF, float maxValueF, float stepVal
}
}
m_spinb
->
setDecimals
(
decimals
);
m_spinb
->
setValue
(
maxValue
F
);
m_spinb
->
setValue
(
maxValue
);
//m_spinb->setMinimumWidth(m_spinb->sizeHint().width()+35);
m_spinb
->
setMinimumWidth
(
m_spinb
->
sizeHint
().
width
());
m_spinb
->
setAlignment
(
Qt
::
AlignRight
);
m_spinb
->
setValue
(
minValue
F
);
m_spinb
->
setValue
(
minValue
);
m_label
->
setBuddy
(
m_spinb
);
...
...
@@ -128,12 +128,12 @@ LabeledFSlider::~LabeledFSlider()
{
}
float
LabeledFSlider
::
value
()
const
double
LabeledFSlider
::
value
()
const
{
return
(
float
)
m_spinb
->
value
();
return
m_spinb
->
value
();
}
float
LabeledFSlider
::
step
()
const
double
LabeledFSlider
::
step
()
const
{
return
m_fstep
;
}
...
...
@@ -143,7 +143,7 @@ void LabeledFSlider::setSuffix(const QString &text)
m_spinb
->
setSuffix
(
text
);
}
void
LabeledFSlider
::
setRange
(
float
min
,
float
max
)
void
LabeledFSlider
::
setRange
(
double
min
,
double
max
)
{
//qCDebug(KSANE_LOG) << "min,max(" << m_spinb->minimum() << " - " << m_spinb->maximum();
//qCDebug(KSANE_LOG) << ") -> (" << min << " - " << max << ")" << std::endl;
...
...
@@ -155,19 +155,19 @@ void LabeledFSlider::setRange(float min, float max)
m_spinb
->
setRange
(
min
,
max
);
}
void
LabeledFSlider
::
setStep
(
float
step
)
void
LabeledFSlider
::
setStep
(
double
step
)
{
m_istep
=
TO_FIX
(
step
);
m_fstep
=
step
;
if
(
m_istep
==
0
)
{
m_istep
=
1
;
m_fstep
=
TO_
FLOAT
(
m_istep
);
m_fstep
=
TO_
DOUBLE
(
m_istep
);
}
m_slider
->
setSingleStep
(
m_istep
);
m_spinb
->
setSingleStep
(
m_fstep
);
int
decimals
=
0
;
float
tmp_step
=
m_fstep
;
double
tmp_step
=
m_fstep
;
while
(
tmp_step
<
1
)
{
tmp_step
*=
10
;
decimals
++
;
...
...
@@ -181,7 +181,7 @@ void LabeledFSlider::setStep(float step)
void
LabeledFSlider
::
setValue
(
const
QVariant
&
value
)
{
bool
ok
;
float
newValue
=
value
.
to
Float
(
&
ok
);
double
newValue
=
value
.
to
Double
(
&
ok
);
if
(
!
ok
)
{
return
;
}
...
...
@@ -196,7 +196,7 @@ void LabeledFSlider::setValue(const QVariant &value)
void
LabeledFSlider
::
syncValues
(
int
ivalue
)
{
double
value
=
TO_
FLOAT
(
ivalue
);
double
value
=
TO_
DOUBLE
(
ivalue
);
if
(((
value
-
m_spinb
->
value
())
>
m_fstep
)
||
((
m_spinb
->
value
()
-
value
)
>
m_fstep
))
{
m_spinb
->
setValue
(
value
);
}
else
if
(
ivalue
!=
m_slider
->
value
())
{
...
...
@@ -229,7 +229,7 @@ void LabeledFSlider::fixValue()
}
else
{
m_slider
->
setValue
(
m_slider
->
value
()
-
rest
);
}
m_spinb
->
setValue
(
TO_
FLOAT
(
m_slider
->
value
()));
m_spinb
->
setValue
(
TO_
DOUBLE
(
m_slider
->
value
()));
}
}
...
...
src/widgets/labeledfslider.h
View file @
67fc90e4
...
...
@@ -45,10 +45,10 @@ public:
* contains a '&', a buddy for the slider will be created.
* \param min minimum slider value
* \param max maximum slider value
* \param st is the step between values.
* \param st
ep
is the step between values.
*/
LabeledFSlider
(
QWidget
*
parent
,
const
QString
&
text
,
float
min
,
float
max
,
float
step
);
double
min
,
double
max
,
double
step
);
LabeledFSlider
(
QWidget
*
parent
,
KSaneOption
*
option
);
~
LabeledFSlider
();
...
...
@@ -56,15 +56,15 @@ public:
/**
* \return the slider value.
*/
float
value
()
const
;
float
step
()
const
;
double
value
()
const
;
double
step
()
const
;
public
Q_SLOTS
:
/** Set the slider/spinbox value */
void
setValue
(
const
QVariant
&
value
);
void
setRange
(
float
min
,
float
max
);
void
setStep
(
float
step
);
void
setRange
(
double
min
,
double
max
);
void
setStep
(
double
step
);
/** Set the unit */
void
setSuffix
(
const
QString
&
text
);
...
...
@@ -86,11 +86,11 @@ Q_SIGNALS:
void
valueChanged
(
const
QVariant
&
val
);
private:
void
initFSlider
(
float
minValue
F
,
float
maxValue
F
,
float
stepValue
F
);
void
initFSlider
(
double
minValue
,
double
maxValue
,
double
stepValue
);
QSlider
*
m_slider
;
QDoubleSpinBox
*
m_spinb
;
float
m_fstep
;
double
m_fstep
;
int
m_istep
;
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment