Commit f227f44e authored by Alexander Stippich's avatar Alexander Stippich
Browse files

try every possible resolution value for preview

and use the one with the minimum distance to the set preview resolution
BUG: 440932
parent 644e0714
...@@ -904,15 +904,23 @@ void KSaneWidgetPrivate::startPreviewScan() ...@@ -904,15 +904,23 @@ void KSaneWidgetPrivate::startPreviewScan()
} }
if (m_optRes->type() == KSaneOption::TypeValueList) { if (m_optRes->type() == KSaneOption::TypeValueList) {
const auto &values = m_optRes->valueList(); const auto &values = m_optRes->valueList();
/* if there are discrete values, use the value which is equal or just below the specified preview DPI if (values.count() <= 0) {
* assumes an ordered list of DPI values */ qCWarning(KSANE_LOG) << "Resolution option is broken and has no entries";
for (int i = 0; i < values.count(); ++i) { return;
const auto &value = values.at(i); }
if (value.toFloat() > m_previewDPI && i != 0) { /* if there are discrete values, try to find the one which fits best. */
targetPreviewDPI = values.at(i-1).toFloat(); int minIndex = 0;
break; int minDistance = abs(values.at(0).toInt() - m_previewDPI);
for (int i = 1; i < values.count(); ++i) {
int distance = abs(values.at(i).toInt() - m_previewDPI);
if (distance < minDistance) {
minIndex = i;
minDistance = distance;
} }
} }
targetPreviewDPI = values.at(minIndex).toInt();
} }
m_optRes->setValue(targetPreviewDPI); m_optRes->setValue(targetPreviewDPI);
if ((m_optResY != nullptr) && (m_optRes == m_optResX)) { if ((m_optResY != nullptr) && (m_optRes == m_optResX)) {
......
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