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
3777d843
Commit
3777d843
authored
Mar 23, 2021
by
Alexander Stippich
Browse files
reimplement the invert option as a KSaneOption
parent
085eb929
Changes
8
Hide whitespace changes
Inline
Side-by-side
src/CMakeLists.txt
View file @
3777d843
...
...
@@ -40,6 +40,7 @@ set(ksane_SRCS
options/ksaneoptslider.cpp
options/ksaneoptfslider.cpp
options/ksaneoptcombo.cpp
options/ksaneinvertoption.cpp
)
ecm_qt_declare_logging_category
(
ksane_SRCS
...
...
src/ksanewidget.cpp
View file @
3777d843
...
...
@@ -44,6 +44,7 @@
#include "ksaneoptslider.h"
#include "ksanedevicedialog.h"
#include "labeledgamma.h"
#include "ksaneinvertoption.h"
#include <ksane_debug.h>
...
...
@@ -52,8 +53,6 @@ namespace KSaneIface
static
int
s_objectCount
=
0
;
Q_GLOBAL_STATIC
(
QMutex
,
s_objectMutex
)
static
const
QLatin1String
InvetColorsOption
(
"KSane::InvertColors"
);
KSaneWidget
::
KSaneWidget
(
QWidget
*
parent
)
:
QWidget
(
parent
),
d
(
new
KSaneWidgetPrivate
(
this
))
{
...
...
@@ -462,6 +461,9 @@ bool KSaneWidget::openDevice(const QString &deviceName)
break
;
}
}
// add extra option for inverting image colors
d
->
m_optList
.
append
(
new
KSaneInvertOption
());
// do the connections of the option parameters
for
(
const
auto
&
option
:
qAsConst
(
d
->
m_optList
))
{
...
...
@@ -700,8 +702,6 @@ void KSaneWidget::getOptVals(QMap <QString, QString> &opts)
opts
[
option
->
name
()]
=
tmp
;
}
}
// Special handling for non sane option
opts
[
InvetColorsOption
]
=
d
->
m_invertColors
->
isChecked
()
?
QStringLiteral
(
"true"
)
:
QStringLiteral
(
"false"
);
}
bool
KSaneWidget
::
getOptVal
(
const
QString
&
optname
,
QString
&
value
)
...
...
@@ -712,11 +712,6 @@ bool KSaneWidget::getOptVal(const QString &optname, QString &value)
value
=
option
->
getValueAsString
();
return
!
value
.
isEmpty
();
}
// Special handling for non sane option
if
(
optname
==
InvetColorsOption
)
{
value
=
d
->
m_invertColors
->
isChecked
()
?
QStringLiteral
(
"true"
)
:
QStringLiteral
(
"false"
);
return
true
;
}
return
false
;
}
...
...
@@ -785,17 +780,6 @@ int KSaneWidget::setOptVals(const QMap <QString, QString> &opts)
d
->
m_splitGamChB
->
setChecked
(
true
);
}
}
// special handling for non-sane option
if
(
optionMapCopy
.
contains
(
InvetColorsOption
))
{
tmp
=
optionMapCopy
[
InvetColorsOption
];
if
((
tmp
.
compare
(
QStringLiteral
(
"true"
),
Qt
::
CaseInsensitive
)
==
0
)
||
(
tmp
.
compare
(
QStringLiteral
(
"1"
))
==
0
))
{
d
->
m_invertColors
->
setChecked
(
true
);
}
else
{
d
->
m_invertColors
->
setChecked
(
false
);
}
}
return
ret
;
}
...
...
@@ -834,17 +818,6 @@ bool KSaneWidget::setOptVal(const QString &option, const QString &value)
}
}
// special handling for non-sane option
if
(
option
==
InvetColorsOption
)
{
if
((
value
.
compare
(
QStringLiteral
(
"true"
),
Qt
::
CaseInsensitive
)
==
0
)
||
(
value
.
compare
(
QStringLiteral
(
"1"
))
==
0
))
{
d
->
m_invertColors
->
setChecked
(
true
);
}
else
{
d
->
m_invertColors
->
setChecked
(
false
);
}
return
true
;
}
return
false
;
}
...
...
src/ksanewidget_p.cpp
View file @
3777d843
...
...
@@ -66,7 +66,6 @@ KSaneWidgetPrivate::KSaneWidgetPrivate(KSaneWidget *parent):
m_splitGamChB
=
nullptr
;
m_commonGamma
=
nullptr
;
m_previewDPI
=
0
;
m_invertColors
=
nullptr
;
m_previewWidth
=
0
;
m_previewHeight
=
0
;
...
...
@@ -570,11 +569,13 @@ void KSaneWidgetPrivate::createOptInterface()
KSaneOptionWidget
*
blackLevel
=
createOptionWidget
(
m_colorOpts
,
option
);
color_lay
->
addWidget
(
blackLevel
);
}
m_invertColors
=
new
LabeledCheckbox
(
m_colorOpts
,
i18n
(
"Invert colors"
));
color_lay
->
addWidget
(
m_invertColors
);
m_invertColors
->
setChecked
(
false
);
connect
(
m_invertColors
,
&
LabeledCheckbox
::
toggled
,
this
,
&
KSaneWidgetPrivate
::
invertPreview
);
if
((
option
=
getOption
(
InvertColorsOptionName
))
!=
nullptr
)
{
m_optInvert
=
option
;
KSaneOptionWidget
*
invertColor
=
createOptionWidget
(
m_colorOpts
,
option
);
color_lay
->
addWidget
(
invertColor
);
connect
(
m_optInvert
,
&
KSaneOption
::
valueChanged
,
this
,
&
KSaneWidgetPrivate
::
invertPreview
);
}
// Add our own size options
m_scanareaPapersize
=
new
LabeledCombo
(
m_basicOptsTab
,
i18n
(
"Scan Area Size"
));
...
...
@@ -1057,7 +1058,7 @@ void KSaneWidgetPrivate::startPreviewScan()
m_progressBar
->
setValue
(
0
);
m_isPreview
=
true
;
m_previewThread
->
setPreviewInverted
(
m_
i
nvert
Colors
->
isChecked
());
m_previewThread
->
setPreviewInverted
(
m_
optI
nvert
->
getValue
().
toBool
());
m_previewThread
->
start
();
m_updProgressTmr
.
start
();
}
...
...
@@ -1146,7 +1147,7 @@ void KSaneWidgetPrivate::startFinalScan()
setBusy
(
true
);
m_updProgressTmr
.
start
();
m_scanThread
->
setImageInverted
(
m_
i
nvert
Colors
->
isChecked
());
m_scanThread
->
setImageInverted
(
m_
optI
nvert
->
getValue
().
toBool
());
m_scanThread
->
start
();
}
...
...
@@ -1330,9 +1331,9 @@ void KSaneWidgetPrivate::checkInvert()
"Transparency"
),
Qt
::
CaseInsensitive
))
&&
(
filmtype
.
contains
(
i18nc
(
"This is compared to the option string returned by sane"
,
"Negative"
),
Qt
::
CaseInsensitive
)))
{
m_
i
nvert
Colors
->
setChecked
(
true
);
m_
optI
nvert
->
setValue
(
true
);
}
else
{
m_
i
nvert
Colors
->
setChecked
(
false
);
m_
optI
nvert
->
setValue
(
false
);
}
}
...
...
src/ksanewidget_p.h
View file @
3777d843
...
...
@@ -36,6 +36,7 @@ extern "C"
#include "ksanewidget.h"
#include "ksaneoption.h"
#include "ksaneinvertoption.h"
#include "ksaneoptionwidget.h"
#include "ksaneviewer.h"
#include "labeledcombo.h"
...
...
@@ -122,7 +123,6 @@ public:
QWidget
*
m_colorOpts
;
QScrollArea
*
m_otherScrollA
;
QWidget
*
m_otherOptsTab
;
LabeledCheckbox
*
m_invertColors
;
QVector
<
int
>
m_sizeCodes
;
LabeledCombo
*
m_scanareaPapersize
;
...
...
@@ -177,6 +177,7 @@ public:
KSaneOption
*
m_optGamR
;
KSaneOption
*
m_optGamG
;
KSaneOption
*
m_optGamB
;
KSaneOption
*
m_optInvert
;
LabeledCheckbox
*
m_splitGamChB
;
LabeledGamma
*
m_commonGamma
;
KSaneOption
*
m_optWaitForBtn
;
...
...
src/options/ksaneinvertoption.cpp
0 → 100644
View file @
3777d843
/* ============================================================
*
* Date : 2021-03-21
* Description : Sane interface for KDE
*
* 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
*
* ============================================================ */
#include "ksaneinvertoption.h"
#include <ksane_debug.h>
namespace
KSaneIface
{
KSaneInvertOption
::
KSaneInvertOption
()
{
m_optionType
=
KSaneOption
::
TypeBool
;
}
bool
KSaneInvertOption
::
setValue
(
const
QVariant
&
value
)
{
if
(
value
.
canConvert
<
bool
>
())
{
if
(
m_checked
!=
value
.
toBool
())
{
m_checked
=
value
.
toBool
();
Q_EMIT
valueChanged
(
m_checked
);
}
return
true
;
}
else
{
return
false
;
}
}
QVariant
KSaneInvertOption
::
getValue
()
const
{
return
m_checked
;
}
QString
KSaneInvertOption
::
getValueAsString
()
const
{
if
(
m_checked
)
{
return
QStringLiteral
(
"true"
);
}
else
{
return
QStringLiteral
(
"false"
);
}
}
KSaneOption
::
KSaneOptionState
KSaneInvertOption
::
state
()
const
{
return
StateActive
;
}
QString
KSaneInvertOption
::
name
()
const
{
return
InvertColorsOptionName
;
}
QString
KSaneInvertOption
::
title
()
const
{
return
i18n
(
"Invert colors"
);
}
QString
KSaneInvertOption
::
description
()
const
{
return
i18n
(
"Invert the colors of the scanned image."
);
}
}
// NameSpace KSaneIface
src/options/ksaneinvertoption.h
0 → 100644
View file @
3777d843
/* ============================================================
*
* Date : 2021-03-21
* Description : Sane interface for KDE
*
* 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_INVERT_OPTION_H
#define KSANE_INVERT_OPTION_H
#include "ksaneoption.h"
namespace
KSaneIface
{
static
const
QString
InvertColorsOptionName
=
QStringLiteral
(
"KSane::InvertColors"
);
class
KSaneInvertOption
:
public
KSaneOption
{
Q_OBJECT
public:
KSaneInvertOption
();
QVariant
getValue
()
const
override
;
QString
getValueAsString
()
const
override
;
KSaneOptionState
state
()
const
override
;
QString
name
()
const
override
;
QString
title
()
const
override
;
QString
description
()
const
override
;
public
Q_SLOTS
:
bool
setValue
(
const
QVariant
&
value
)
override
;
private:
bool
m_checked
=
false
;
};
}
// NameSpace KSaneIface
#endif // KSANE_INVERT_OPTION_H
src/options/ksaneoption.cpp
View file @
3777d843
...
...
@@ -19,10 +19,13 @@
namespace
KSaneIface
{
KSaneOption
::
KSaneOption
()
:
QObject
()
{
}
KSaneOption
::
KSaneOption
(
const
SANE_Handle
handle
,
const
int
index
)
:
QObject
(),
m_handle
(
handle
),
m_index
(
index
)
{
m_data
=
nullptr
;
readOption
();
readValue
();
}
...
...
@@ -37,13 +40,15 @@ KSaneOption::~KSaneOption()
void
KSaneOption
::
readOption
()
{
m_optDesc
=
sane_get_option_descriptor
(
m_handle
,
m_index
);
Q_EMIT
optionReloaded
();
if
(
m_handle
!=
nullptr
)
{
m_optDesc
=
sane_get_option_descriptor
(
m_handle
,
m_index
);
Q_EMIT
optionReloaded
();
}
}
KSaneOption
::
KSaneOptionState
KSaneOption
::
state
()
const
{
if
(
!
m_optDesc
)
{
if
(
m_optDesc
==
nullptr
)
{
return
StateHidden
;
}
...
...
@@ -200,14 +205,18 @@ QString KSaneOption::getValueAsString() const
KSaneOption
::
KSaneOptionUnit
KSaneOption
::
getUnit
()
const
{
switch
(
m_optDesc
->
unit
)
{
case
SANE_UNIT_PIXEL
:
return
UnitPixel
;
case
SANE_UNIT_BIT
:
return
UnitBit
;
case
SANE_UNIT_MM
:
return
UnitMilliMeter
;
case
SANE_UNIT_DPI
:
return
UnitDPI
;
case
SANE_UNIT_PERCENT
:
return
UnitPercent
;
case
SANE_UNIT_MICROSECOND
:
return
UnitMicroSecond
;
default:
return
UnitNone
;
if
(
m_optDesc
!=
nullptr
)
{
switch
(
m_optDesc
->
unit
)
{
case
SANE_UNIT_PIXEL
:
return
UnitPixel
;
case
SANE_UNIT_BIT
:
return
UnitBit
;
case
SANE_UNIT_MM
:
return
UnitMilliMeter
;
case
SANE_UNIT_DPI
:
return
UnitDPI
;
case
SANE_UNIT_PERCENT
:
return
UnitPercent
;
case
SANE_UNIT_MICROSECOND
:
return
UnitMicroSecond
;
default:
return
UnitNone
;
}
}
else
{
return
UnitNone
;
}
}
...
...
src/options/ksaneoption.h
View file @
3777d843
...
...
@@ -75,15 +75,16 @@ public:
StateActive
}
KSaneOptionState
;
KSaneOption
();
KSaneOption
(
const
SANE_Handle
handle
,
const
int
index
);
~
KSaneOption
();
static
KSaneOptionType
optionType
(
const
SANE_Option_Descriptor
*
optDesc
);
bool
needsPolling
()
const
;
KSaneOptionState
state
()
const
;
QString
name
()
const
;
QString
title
()
const
;
QString
description
()
const
;
virtual
KSaneOptionState
state
()
const
;
virtual
QString
name
()
const
;
virtual
QString
title
()
const
;
virtual
QString
description
()
const
;
KSaneOptionType
type
()
const
;
virtual
void
readOption
();
...
...
@@ -116,10 +117,10 @@ protected:
static
void
fromSANE_Word
(
unsigned
char
*
data
,
SANE_Word
from
);
bool
writeData
(
void
*
data
);
SANE_Handle
m_handle
;
int
m_index
;
const
SANE_Option_Descriptor
*
m_optDesc
;
///< This pointer is provided by sane
unsigned
char
*
m_data
;
SANE_Handle
m_handle
=
nullptr
;
int
m_index
=
-
1
;
const
SANE_Option_Descriptor
*
m_optDesc
=
nullptr
;
///< This pointer is provided by sane
unsigned
char
*
m_data
=
nullptr
;
KSaneOptionType
m_optionType
=
TypeDetectFail
;
};
...
...
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