Commit 99a11a1f authored by Alexander Stippich's avatar Alexander Stippich
Browse files

fix and cleanup gamma options

parent 94015db0
......@@ -768,9 +768,9 @@ int KSaneWidget::setOptVals(const QMap <QString, QString> &opts)
(d->m_optGamB)) {
// check if the current gamma values are identical. if they are identical,
// uncheck the "Separate color intensity tables" checkbox
QString redGamma = d->m_optGamR->getValueAsString();
QString greenGamma = d->m_optGamG->getValueAsString();
QString blueGamma = d->m_optGamB->getValueAsString();
QVariant redGamma = d->m_optGamR->getValue();
QVariant greenGamma = d->m_optGamG->getValue();
QVariant blueGamma = d->m_optGamB->getValue();
if ((redGamma == greenGamma) && (greenGamma == blueGamma)) {
d->m_splitGamChB->setChecked(false);
......@@ -803,9 +803,9 @@ bool KSaneWidget::setOptVal(const QString &option, const QString &value)
(opt == d->m_optGamB))) {
// check if the current gamma values are identical. if they are identical,
// uncheck the "Separate color intensity tables" checkbox
QString redGamma = d->m_optGamR->getValueAsString();
QString greenGamma = d->m_optGamG->getValueAsString();
QString blueGamma = d->m_optGamB->getValueAsString();
QVariant redGamma = d->m_optGamR->getValue();
QVariant greenGamma = d->m_optGamG->getValue();
QVariant blueGamma = d->m_optGamB->getValue();
if ((redGamma == greenGamma) && (greenGamma == blueGamma)) {
d->m_splitGamChB->setChecked(false);
// set the values to the common gamma widget
......
......@@ -548,9 +548,9 @@ void KSaneWidgetPrivate::createOptInterface()
m_commonGamma->setToolTip(i18n(SANE_DESC_GAMMA_VECTOR));
connect(m_commonGamma, &LabeledGamma::gammaChanged, gammaR, QOverload<int,int,int>::of(&LabeledGamma::setValues));
connect(m_commonGamma, &LabeledGamma::gammaChanged, gammaG, QOverload<int,int,int>::of(&LabeledGamma::setValues));
connect(m_commonGamma, &LabeledGamma::gammaChanged, gammaB, QOverload<int,int,int>::of(&LabeledGamma::setValues));
connect(m_commonGamma, &LabeledGamma::valuesChanged, gammaR, &LabeledGamma::setValues);
connect(m_commonGamma, &LabeledGamma::valuesChanged, gammaG, &LabeledGamma::setValues);
connect(m_commonGamma, &LabeledGamma::valuesChanged, gammaB, &LabeledGamma::setValues);
m_splitGamChB = new LabeledCheckbox(m_colorOpts, i18n("Separate color intensity tables"));
color_lay->addWidget(m_splitGamChB);
......
......@@ -63,15 +63,17 @@ bool KSaneGammaOption::setValue(const QVariant &value)
}
return true;
}
if (value.canConvert<QVector<int>>()) {
QVector<int> copy = value.value<QVector<int>>();
if (copy.size() != 3) {
if (static_cast<QMetaType::Type>(value.type()) == QMetaType::QVariantList) {
QVariantList copy = value.toList();
if (copy.size() != 3 || static_cast<QMetaType::Type>(copy.at(0).type()) != QMetaType::Int
|| static_cast<QMetaType::Type>(copy.at(1).type()) != QMetaType::Int
|| static_cast<QMetaType::Type>(copy.at(2).type()) != QMetaType::Int ) {
return false;
}
if (m_brightness != copy.at(0) || m_contrast != copy.at(1) || m_gamma != copy.at(2) ) {
m_brightness = copy.at(0);
m_contrast = copy.at(1);
m_gamma = copy.at(2);
if (m_brightness != copy.at(0).toInt() || m_contrast != copy.at(1).toInt() || m_gamma != copy.at(2).toInt() ) {
m_brightness = copy.at(0).toInt();
m_contrast = copy.at(1).toInt();
m_gamma = copy.at(2).toInt();
calculateGTwriteData();
}
return true;
......@@ -103,7 +105,7 @@ QVariant KSaneGammaOption::getValue() const
if (state() == StateHidden) {
return QVariant();
}
return QVariant::fromValue(QVector<int>{ m_brightness, m_contrast, m_gamma });
return QVariantList{ m_brightness, m_contrast, m_gamma };
}
QVariant KSaneGammaOption::getMaxValue() const
......@@ -156,8 +158,8 @@ void KSaneGammaOption::calculateGTwriteData()
}
writeData(m_gammaTable.data());
QVector<int> values = { m_brightness, m_contrast, m_gamma };
Q_EMIT valueChanged(QVariant::fromValue(values));
QVariantList values = { m_brightness, m_contrast, m_gamma };
Q_EMIT valueChanged(values);
}
} // NameSpace KSaneIface
......@@ -36,6 +36,7 @@ LabeledGamma::LabeledGamma(QWidget *parent, KSaneOption *option)
int max = option->getMaxValue().toInt();
initGamma(option->title(), max);
connect(this, &LabeledGamma::valuesChanged, option, &KSaneOption::setValue);
connect(option, &KSaneOption::valueChanged, this, &LabeledGamma::setValues);
if (option->name() == QString::fromUtf8(SANE_NAME_GAMMA_VECTOR_R)) {
setColor(Qt::red);
}
......@@ -101,62 +102,32 @@ void LabeledGamma::setColor(const QColor &color)
}
}
void LabeledGamma::setValues(int brightness, int contrast, int gamma)
void LabeledGamma::setValues(const QVariant &values)
{
m_brightSlider->blockSignals(true);
m_contrastSlider->blockSignals(true);
m_gammaSlider->blockSignals(true);
m_brightness = brightness;
m_contrast = contrast;
m_gamma = gamma;
m_brightSlider->setValue(brightness);
m_contrastSlider->setValue(contrast);
m_gammaSlider->setValue(gamma);
emitNewValues();
m_brightSlider->blockSignals(false);
m_contrastSlider->blockSignals(false);
m_gammaSlider->blockSignals(false);
}
void LabeledGamma::setValues(const QString &values)
{
m_brightSlider->blockSignals(true);
m_contrastSlider->blockSignals(true);
m_gammaSlider->blockSignals(true);
QStringList gammaValues;
int brightness;
int contrast;
int gamma;
bool ok = true;
gammaValues = values.split(QLatin1Char(':'));
brightness = gammaValues.at(0).toInt(&ok);
if (ok) {
contrast = gammaValues.at(1).toInt(&ok);
}
if (ok) {
gamma = gammaValues.at(2).toInt(&ok);
}
if (ok) {
m_brightness = brightness;
m_contrast = contrast;
m_gamma = gamma;
m_brightSlider->setValue(brightness);
m_contrastSlider->setValue(contrast);
m_gammaSlider->setValue(gamma);
if (static_cast<QMetaType::Type>(values.type()) == QMetaType::QVariantList) {
QVariantList copy = values.toList();
if (copy.size() != 3) {
return;
}
m_brightSlider->blockSignals(true);
m_contrastSlider->blockSignals(true);
m_gammaSlider->blockSignals(true);
m_brightness = copy.at(0).toInt();
m_contrast = copy.at(1).toInt();
m_gamma = copy.at(2).toInt();
m_brightSlider->setValue(m_brightness);
m_contrastSlider->setValue(m_contrast);
m_gammaSlider->setValue(m_gamma);
emitNewValues();
m_brightSlider->blockSignals(false);
m_contrastSlider->blockSignals(false);
m_gammaSlider->blockSignals(false);
}
m_brightSlider->blockSignals(false);
m_contrastSlider->blockSignals(false);
m_gammaSlider->blockSignals(false);
}
void LabeledGamma::emitNewValues()
......@@ -164,10 +135,9 @@ void LabeledGamma::emitNewValues()
m_brightness = m_brightSlider->value();
m_contrast = m_contrastSlider->value();
m_gamma = m_gammaSlider->value();
QVector<int> values = { m_brightness, m_contrast, m_gamma };
QVariantList values = { m_brightness, m_contrast, m_gamma };
m_gammaDisplay->update();
Q_EMIT gammaChanged(m_brightness, m_contrast, m_gamma);
Q_EMIT valuesChanged(QVariant::fromValue(values));
}
......
......@@ -35,11 +35,10 @@ class LabeledGamma : public KSaneOptionWidget
public:
/**
* Create the checkbox.
* Create the labeled gamma widget.
*
* \param parent parent widget
* \param text is the text describing the checkbox.
* \param elements is the number of elements in the gamma table
* \param max is the maximum gamma-table-value
*/
LabeledGamma(QWidget *parent, const QString &text, int max);
......@@ -54,12 +53,9 @@ public:
bool getValues(int &brightness, int &contrast, int &gamma);
public Q_SLOTS:
void setValues(int brightness, int contrast, int gamma);
void setValues(const QString &values);
void setValues(const QVariant &values);
Q_SIGNALS:
void gammaChanged(int brightness, int contrast, int gamma);
void valuesChanged(const QVariant &values);
private Q_SLOTS:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment