Changeset View
Changeset View
Standalone View
Standalone View
src/ksanewidget.cpp
Show First 20 Lines • Show All 874 Lines • ▼ Show 20 Line(s) | |||||
875 | float KSaneWidget::currentDPI() | 875 | float KSaneWidget::currentDPI() | ||
876 | { | 876 | { | ||
877 | if (d->m_optRes) { | 877 | if (d->m_optRes) { | ||
878 | float value; | 878 | float value; | ||
879 | if (d->m_optRes->getValue(value)) { | 879 | if (d->m_optRes->getValue(value)) { | ||
880 | return value; | 880 | return value; | ||
881 | } | 881 | } | ||
882 | } | 882 | } | ||
883 | return 0.0; | 883 | return 0.0; // Failure to read DPI | ||
884 | } | 884 | } | ||
885 | 885 | | |||
886 | float KSaneWidget::scanAreaWidth() | 886 | float KSaneWidget::scanAreaWidth() | ||
887 | { | 887 | { | ||
888 | float result = 0.0; | 888 | float result = 0.0; | ||
889 | if (d->m_optBrX) { | 889 | if (d->m_optBrX) { | ||
890 | if (d->m_optBrX->getUnit() == SANE_UNIT_PIXEL) { | 890 | if (d->m_optBrX->getUnit() == SANE_UNIT_PIXEL) { | ||
891 | d->m_optBrX->getMaxValue(result); | 891 | d->m_optBrX->getMaxValue(result); | ||
892 | result = result / currentDPI() / 25.4; | 892 | float dpi = currentDPI(); | ||
893 | if (dpi < 1) { | ||||
894 | qDebug() << "Broken DPI value"; | ||||
895 | dpi = 1.0; | ||||
896 | } | ||||
897 | result = result / dpi / 25.4; | ||||
893 | } else if (d->m_optBrX->getUnit() == SANE_UNIT_MM) { | 898 | } else if (d->m_optBrX->getUnit() == SANE_UNIT_MM) { | ||
894 | d->m_optBrX->getMaxValue(result); | 899 | d->m_optBrX->getMaxValue(result); | ||
895 | } | 900 | } | ||
896 | } | 901 | } | ||
897 | return result; | 902 | return result; | ||
898 | } | 903 | } | ||
899 | 904 | | |||
900 | float KSaneWidget::scanAreaHeight() | 905 | float KSaneWidget::scanAreaHeight() | ||
901 | { | 906 | { | ||
902 | float result = 0.0; | 907 | float result = 0.0; | ||
903 | if (d->m_optBrY) { | 908 | if (d->m_optBrY) { | ||
904 | if (d->m_optBrY->getUnit() == SANE_UNIT_PIXEL) { | 909 | if (d->m_optBrY->getUnit() == SANE_UNIT_PIXEL) { | ||
905 | d->m_optBrY->getMaxValue(result); | 910 | d->m_optBrY->getMaxValue(result); | ||
906 | result = result / currentDPI() / 25.4; | 911 | float dpi = currentDPI(); | ||
912 | if (dpi < 1) { | ||||
913 | qDebug() << "Broken DPI value"; | ||||
914 | dpi = 1.0; | ||||
915 | } | ||||
916 | result = result / dpi / 25.4; | ||||
907 | } else if (d->m_optBrY->getUnit() == SANE_UNIT_MM) { | 917 | } else if (d->m_optBrY->getUnit() == SANE_UNIT_MM) { | ||
908 | d->m_optBrY->getMaxValue(result); | 918 | d->m_optBrY->getMaxValue(result); | ||
909 | } | 919 | } | ||
910 | } | 920 | } | ||
911 | return result; | 921 | return result; | ||
912 | } | 922 | } | ||
913 | 923 | | |||
914 | void KSaneWidget::setSelection(QPointF topLeft, QPointF bottomRight) | 924 | void KSaneWidget::setSelection(QPointF topLeft, QPointF bottomRight) | ||
915 | { | 925 | { | ||
916 | if (!d->m_optBrX || !d->m_optBrY || !d->m_optTlX || !d->m_optTlY) { | 926 | if (!d->m_optBrX || !d->m_optBrY || !d->m_optTlX || !d->m_optTlY) { | ||
917 | return; | 927 | return; | ||
918 | } | 928 | } | ||
919 | float xmax, ymax; | | |||
920 | d->m_optBrX->getMaxValue(xmax); | | |||
921 | d->m_optBrY->getMaxValue(ymax); | | |||
922 | if (topLeft.x() < 0.0 || topLeft.y() < 0.0 || bottomRight.x() < 0.0 || bottomRight.y() < 0.0) { | 929 | if (topLeft.x() < 0.0 || topLeft.y() < 0.0 || bottomRight.x() < 0.0 || bottomRight.y() < 0.0) { | ||
923 | d->m_previewViewer->clearActiveSelection(); | 930 | d->m_previewViewer->clearActiveSelection(); | ||
924 | return; | 931 | return; | ||
925 | } | 932 | } | ||
926 | 933 | | |||
927 | float tlxRatio = topLeft.x()/xmax; | 934 | float tlxRatio = d->scanAreaToRatioX(topLeft.x()); | ||
928 | float tlyRatio = topLeft.y()/ymax; | 935 | float tlyRatio = d->scanAreaToRatioY(topLeft.y()); | ||
929 | float brxRatio = bottomRight.x()/xmax; | 936 | float brxRatio = d->scanAreaToRatioX(bottomRight.x()); | ||
930 | float bryRatio = bottomRight.y()/ymax; | 937 | float bryRatio = d->scanAreaToRatioX(bottomRight.y()); | ||
931 | 938 | | |||
932 | d->m_previewViewer->setSelection(tlxRatio, tlyRatio, brxRatio, bryRatio); | 939 | d->m_previewViewer->setSelection(tlxRatio, tlyRatio, brxRatio, bryRatio); | ||
933 | } | 940 | } | ||
934 | 941 | | |||
935 | void KSaneWidget::setOptionsCollapsed(bool collapse) | 942 | void KSaneWidget::setOptionsCollapsed(bool collapse) | ||
936 | { | 943 | { | ||
937 | if (collapse) { | 944 | if (collapse) { | ||
938 | QTimer::singleShot(0, d->m_optionsCollapser, SLOT(slotCollapse())); | 945 | QTimer::singleShot(0, d->m_optionsCollapser, SLOT(slotCollapse())); | ||
Show All 11 Lines |