Changeset View
Standalone View
src/ksanewidget.cpp
Show First 20 Lines • Show All 97 Lines • ▼ Show 20 Line(s) | 71 | { | |||
---|---|---|---|---|---|
98 | 98 | | |||
99 | d->m_updProgressTmr.setSingleShot(false); | 99 | d->m_updProgressTmr.setSingleShot(false); | ||
100 | d->m_updProgressTmr.setInterval(300); | 100 | d->m_updProgressTmr.setInterval(300); | ||
101 | connect(&d->m_updProgressTmr, SIGNAL(timeout()), d, SLOT(updateProgress())); | 101 | connect(&d->m_updProgressTmr, SIGNAL(timeout()), d, SLOT(updateProgress())); | ||
102 | 102 | | |||
103 | // Create the static UI | 103 | // Create the static UI | ||
104 | // create the preview | 104 | // create the preview | ||
105 | d->m_previewViewer = new KSaneViewer(&(d->m_previewImg), this); | 105 | d->m_previewViewer = new KSaneViewer(&(d->m_previewImg), this); | ||
106 | connect(d->m_previewViewer, SIGNAL(newSelection(float,float,float,float)), | 106 | connect(d->m_previewViewer, SIGNAL(newSelection(float,float,float,float)), | ||
sars: no spaces in the signal/slot signatures | |||||
107 | d, SLOT(handleSelection(float,float,float,float))); | 107 | d, SLOT(handleSelection(float,float,float,float))); | ||
108 | 108 | | |||
109 | d->m_warmingUp = new QLabel; | 109 | d->m_warmingUp = new QLabel; | ||
110 | d->m_warmingUp->setText(i18n("Waiting for the scan to start.")); | 110 | d->m_warmingUp->setText(i18n("Waiting for the scan to start.")); | ||
111 | d->m_warmingUp->setAlignment(Qt::AlignCenter); | 111 | d->m_warmingUp->setAlignment(Qt::AlignCenter); | ||
112 | d->m_warmingUp->setAutoFillBackground(true); | 112 | d->m_warmingUp->setAutoFillBackground(true); | ||
113 | d->m_warmingUp->setBackgroundRole(QPalette::Highlight); | 113 | d->m_warmingUp->setBackgroundRole(QPalette::Highlight); | ||
114 | //d->m_warmingUp->setForegroundRole(QPalette::HighlightedText); | 114 | //d->m_warmingUp->setForegroundRole(QPalette::HighlightedText); | ||
▲ Show 20 Lines • Show All 309 Lines • ▼ Show 20 Line(s) | 394 | #endif | |||
424 | status = sane_control_option(d->m_saneHandle, 0, SANE_ACTION_GET_VALUE, data.data(), &res); | 424 | status = sane_control_option(d->m_saneHandle, 0, SANE_ACTION_GET_VALUE, data.data(), &res); | ||
425 | if (status != SANE_STATUS_GOOD) { | 425 | if (status != SANE_STATUS_GOOD) { | ||
426 | d->m_auth->clearDeviceAuth(d->m_devName); | 426 | d->m_auth->clearDeviceAuth(d->m_devName); | ||
427 | d->m_devName.clear(); | 427 | d->m_devName.clear(); | ||
428 | return false; | 428 | return false; | ||
429 | } | 429 | } | ||
430 | numSaneOptions = *reinterpret_cast<SANE_Word *>(data.data()); | 430 | numSaneOptions = *reinterpret_cast<SANE_Word *>(data.data()); | ||
431 | 431 | | |||
432 | // read the rest of the options | 432 | // read the rest of the options | ||
Why do we need to rearrange the m_optList? Isn't it enough that we restore the options in the right order? sars: Why do we need to rearrange the m_optList? Isn't it enough that we restore the options in the… | |||||
433 | for (i = 1; i < numSaneOptions; ++i) { | 433 | for (i = 1; i < numSaneOptions; ++i) { | ||
434 | switch (KSaneOption::optionType(sane_get_option_descriptor(d->m_saneHandle, i))) { | 434 | switch (KSaneOption::optionType(sane_get_option_descriptor(d->m_saneHandle, i))) { | ||
435 | case KSaneOption::TYPE_DETECT_FAIL: | 435 | case KSaneOption::TYPE_DETECT_FAIL: | ||
436 | d->m_optList.append(new KSaneOption(d->m_saneHandle, i)); | 436 | d->m_optList.append(new KSaneOption(d->m_saneHandle, i)); | ||
437 | break; | 437 | break; | ||
438 | case KSaneOption::TYPE_CHECKBOX: | 438 | case KSaneOption::TYPE_CHECKBOX: | ||
439 | d->m_optList.append(new KSaneOptCheckBox(d->m_saneHandle, i)); | 439 | d->m_optList.append(new KSaneOptCheckBox(d->m_saneHandle, i)); | ||
440 | break; | 440 | break; | ||
Show All 14 Lines | 453 | case KSaneOption::TYPE_GAMMA: | |||
455 | break; | 455 | break; | ||
456 | case KSaneOption::TYPE_BUTTON: | 456 | case KSaneOption::TYPE_BUTTON: | ||
457 | d->m_optList.append(new KSaneOptButton(d->m_saneHandle, i)); | 457 | d->m_optList.append(new KSaneOptButton(d->m_saneHandle, i)); | ||
458 | break; | 458 | break; | ||
459 | } | 459 | } | ||
460 | } | 460 | } | ||
461 | 461 | | |||
462 | // do the connections of the option parameters | 462 | // do the connections of the option parameters | ||
463 | for (i = 1; i < d->m_optList.size(); ++i) { | 463 | for (i = 0; i < d->m_optList.size(); ++i) { | ||
464 | //qDebug() << d->m_optList.at(i)->name(); | 464 | //qDebug() << d->m_optList.at(i)->name(); | ||
465 | connect(d->m_optList.at(i), SIGNAL(optsNeedReload()), d, SLOT(optReload())); | 465 | connect(d->m_optList.at(i), SIGNAL(optsNeedReload()), d, SLOT(optReload())); | ||
466 | connect(d->m_optList.at(i), SIGNAL(valsNeedReload()), d, SLOT(scheduleValReload())); | 466 | connect(d->m_optList.at(i), SIGNAL(valsNeedReload()), d, SLOT(scheduleValReload())); | ||
467 | 467 | | |||
468 | if (d->m_optList.at(i)->needsPolling()) { | 468 | if (d->m_optList.at(i)->needsPolling()) { | ||
469 | //qDebug() << d->m_optList.at(i)->name() << " needs polling"; | 469 | //qDebug() << d->m_optList.at(i)->name() << " needs polling"; | ||
470 | d->m_pollList.append(d->m_optList.at(i)); | 470 | d->m_pollList.append(d->m_optList.at(i)); | ||
471 | KSaneOptCheckBox *buttonOption = qobject_cast<KSaneOptCheckBox *>(d->m_optList.at(i)); | 471 | KSaneOptCheckBox *buttonOption = qobject_cast<KSaneOptCheckBox *>(d->m_optList.at(i)); | ||
sars: Is this a bug-fix or a mistake? | |||||
antonarnold: this is part of the bugfix that options become inconsistent | |||||
472 | if (buttonOption) { | 472 | if (buttonOption) { | ||
473 | connect(buttonOption, SIGNAL(buttonPressed(QString,QString,bool)), | 473 | connect(buttonOption, SIGNAL(buttonPressed(QString,QString,bool)), | ||
474 | this, SIGNAL(buttonPressed(QString,QString,bool))); | 474 | this, SIGNAL(buttonPressed(QString,QString,bool))); | ||
475 | } | 475 | } | ||
476 | } | 476 | } | ||
477 | } | 477 | } | ||
478 | 478 | | |||
479 | // start polling the poll options | 479 | // start polling the poll options | ||
▲ Show 20 Lines • Show All 206 Lines • ▼ Show 20 Line(s) | |||||
686 | } | 686 | } | ||
687 | 687 | | |||
688 | void KSaneWidget::getOptVals(QMap <QString, QString> &opts) | 688 | void KSaneWidget::getOptVals(QMap <QString, QString> &opts) | ||
689 | { | 689 | { | ||
690 | KSaneOption *option; | 690 | KSaneOption *option; | ||
691 | opts.clear(); | 691 | opts.clear(); | ||
692 | QString tmp; | 692 | QString tmp; | ||
693 | 693 | | |||
694 | for (int i = 1; i < d->m_optList.size(); i++) { | 694 | for (int i = 0; i < d->m_optList.size(); i++) { | ||
695 | option = d->m_optList.at(i); | 695 | option = d->m_optList.at(i); | ||
696 | if (option->getValue(tmp)) { | 696 | if (option->getValue(tmp)) { | ||
697 | opts[option->name()] = tmp; | 697 | opts[option->name()] = tmp; | ||
698 | } | 698 | } | ||
699 | } | 699 | } | ||
700 | // Special handling for non sane option | 700 | // Special handling for non sane option | ||
701 | opts[InvetColorsOption] = d->m_invertColors->isChecked() ? QStringLiteral("true") : QStringLiteral("false"); | 701 | opts[InvetColorsOption] = d->m_invertColors->isChecked() ? QStringLiteral("true") : QStringLiteral("false"); | ||
702 | } | 702 | } | ||
Show All 15 Lines | |||||
718 | 718 | | |||
719 | int KSaneWidget::setOptVals(const QMap <QString, QString> &opts) | 719 | int KSaneWidget::setOptVals(const QMap <QString, QString> &opts) | ||
720 | { | 720 | { | ||
721 | if (d->m_scanThread->isRunning() || | 721 | if (d->m_scanThread->isRunning() || | ||
722 | d->m_previewThread->isRunning()) { | 722 | d->m_previewThread->isRunning()) { | ||
723 | return -1; | 723 | return -1; | ||
724 | } | 724 | } | ||
725 | 725 | | |||
726 | QMap <QString, QString> optionMapCopy = opts; | ||||
727 | | ||||
726 | QString tmp; | 728 | QString tmp; | ||
727 | int i; | 729 | int i; | ||
728 | int ret = 0; | 730 | int ret = 0; | ||
729 | 731 | | |||
732 | const QString sourceOptionSaneName = QStringLiteral(SANE_NAME_SCAN_SOURCE); | ||||
733 | const QString modeOptionSaneName = QStringLiteral(SANE_NAME_SCAN_MODE); | ||||
734 | | ||||
735 | KSaneOption *opt; | ||||
736 | | ||||
737 | // Priorize source option | ||||
738 | if (optionMapCopy.contains(sourceOptionSaneName)) { | ||||
739 | if ((opt = d->getOption(sourceOptionSaneName)) != nullptr) { | ||||
740 | if (opt->setValue(optionMapCopy[sourceOptionSaneName])) { | ||||
741 | ret++; | ||||
742 | } | ||||
743 | } | ||||
744 | optionMapCopy.remove(sourceOptionSaneName); | ||||
745 | } | ||||
746 | | ||||
747 | // Priorize mode option | ||||
This could be simplified: if (map.contains(foo)) { if (setValue(foo, map[foo])) { ret++; } map.remove(foo); } sars: This could be simplified:
if (map.contains(foo)) {
if (setValue(foo, map[foo])) {… | |||||
I assume you mean setOptValue? I'd rather avoid calling it since it does some additional stuff besides setting the option. antonarnold: I assume you mean setOptValue? I'd rather avoid calling it since it does some additional stuff… | |||||
748 | if (optionMapCopy.contains(modeOptionSaneName)) { | ||||
I try to avoid assignments in the if() statement as it is harder to read and the risk of mistakes is higher. But this is a bit of taste issue ;) sars: I try to avoid assignments in the if() statement as it is harder to read and the risk of… | |||||
I'm not a fan of this, too. But it's the same style as in setOptValue so I wouldn't start to change it here. antonarnold: I'm not a fan of this, too. But it's the same style as in setOptValue so I wouldn't start to… | |||||
749 | if ((opt = d->getOption(modeOptionSaneName)) != nullptr) { | ||||
750 | if (opt->setValue(optionMapCopy[modeOptionSaneName])) { | ||||
751 | ret++; | ||||
752 | } | ||||
753 | } | ||||
754 | optionMapCopy.remove(modeOptionSaneName); | ||||
755 | } | ||||
756 | | ||||
757 | // Update remaining options | ||||
730 | for (i = 0; i < d->m_optList.size(); i++) { | 758 | for (i = 0; i < d->m_optList.size(); i++) { | ||
731 | if (opts.contains(d->m_optList.at(i)->name())) { | 759 | if (optionMapCopy.contains(d->m_optList.at(i)->name())) { | ||
732 | tmp = opts[d->m_optList.at(i)->name()]; | 760 | tmp = optionMapCopy[d->m_optList.at(i)->name()]; | ||
733 | if (d->m_optList.at(i)->setValue(tmp) == false) { | 761 | if (d->m_optList.at(i)->setValue(tmp)) { | ||
I was about to click "Accept Revision" when this hit my eye... The logic is reversed... But then again this seems to be a fix to a bug :) sars: I was about to click "Accept Revision" when this hit my eye... The logic is reversed...
But… | |||||
Yes this fixes the return value to actually represent the number of written options. antonarnold: Yes this fixes the return value to actually represent the number of written options. | |||||
734 | ret++; | 762 | ret++; | ||
735 | } | 763 | } | ||
736 | } | 764 | } | ||
737 | } | 765 | } | ||
738 | if ((d->m_splitGamChB) && | 766 | if ((d->m_splitGamChB) && | ||
739 | (d->m_optGamR) && | 767 | (d->m_optGamR) && | ||
740 | (d->m_optGamG) && | 768 | (d->m_optGamG) && | ||
741 | (d->m_optGamB)) { | 769 | (d->m_optGamB)) { | ||
Show All 10 Lines | 778 | if ((redGamma == greenGamma) && (greenGamma == blueGamma)) { | |||
752 | // set the values to the common gamma widget | 780 | // set the values to the common gamma widget | ||
753 | d->m_commonGamma->setValues(redGamma); | 781 | d->m_commonGamma->setValues(redGamma); | ||
754 | } else { | 782 | } else { | ||
755 | d->m_splitGamChB->setChecked(true); | 783 | d->m_splitGamChB->setChecked(true); | ||
756 | } | 784 | } | ||
757 | } | 785 | } | ||
758 | 786 | | |||
759 | // special handling for non-sane option | 787 | // special handling for non-sane option | ||
760 | if (opts.contains(InvetColorsOption)) { | 788 | if (optionMapCopy.contains(InvetColorsOption)) { | ||
761 | tmp = opts[InvetColorsOption]; | 789 | tmp = optionMapCopy[InvetColorsOption]; | ||
762 | if ((tmp.compare(QStringLiteral("true"), Qt::CaseInsensitive) == 0) || | 790 | if ((tmp.compare(QStringLiteral("true"), Qt::CaseInsensitive) == 0) || | ||
763 | (tmp.compare(QStringLiteral("1")) == 0)) { | 791 | (tmp.compare(QStringLiteral("1")) == 0)) { | ||
764 | d->m_invertColors->setChecked(true); | 792 | d->m_invertColors->setChecked(true); | ||
765 | } else { | 793 | } else { | ||
766 | d->m_invertColors->setChecked(false); | 794 | d->m_invertColors->setChecked(false); | ||
767 | } | 795 | } | ||
768 | } | 796 | } | ||
769 | return ret; | 797 | return ret; | ||
▲ Show 20 Lines • Show All 130 Lines • ▼ Show 20 Line(s) | 915 | { | |||
900 | float tlyRatio = topLeft.y()/ymax; | 928 | float tlyRatio = topLeft.y()/ymax; | ||
901 | float brxRatio = bottomRight.x()/xmax; | 929 | float brxRatio = bottomRight.x()/xmax; | ||
902 | float bryRatio = bottomRight.y()/ymax; | 930 | float bryRatio = bottomRight.y()/ymax; | ||
903 | 931 | | |||
904 | d->m_previewViewer->setSelection(tlxRatio, tlyRatio, brxRatio, bryRatio); | 932 | d->m_previewViewer->setSelection(tlxRatio, tlyRatio, brxRatio, bryRatio); | ||
905 | } | 933 | } | ||
906 | 934 | | |||
907 | void KSaneWidget::setOptionsCollapsed(bool collapse) | 935 | void KSaneWidget::setOptionsCollapsed(bool collapse) | ||
908 | { | 936 | { | ||
looks like these are the same white-space changes as in the other review. This will lead to merge conflicts. sars: looks like these are the same white-space changes as in the other review. This will lead to… | |||||
909 | if (collapse) { | 937 | if (collapse) { | ||
910 | QTimer::singleShot(0, d->m_optionsCollapser, SLOT(slotCollapse())); | 938 | QTimer::singleShot(0, d->m_optionsCollapser, SLOT(slotCollapse())); | ||
911 | } else { | 939 | } else { | ||
912 | QTimer::singleShot(0, d->m_optionsCollapser, SLOT(slotRestore())); | 940 | QTimer::singleShot(0, d->m_optionsCollapser, SLOT(slotRestore())); | ||
913 | } | 941 | } | ||
914 | } | 942 | } | ||
915 | 943 | | |||
916 | void KSaneWidget::setScanButtonHidden(bool hidden) | 944 | void KSaneWidget::setScanButtonHidden(bool hidden) | ||
917 | { | 945 | { | ||
918 | d->m_scanBtn->setHidden(hidden); | 946 | d->m_scanBtn->setHidden(hidden); | ||
919 | } | 947 | } | ||
920 | 948 | | |||
921 | } // NameSpace KSaneIface | 949 | } // NameSpace KSaneIface |
no spaces in the signal/slot signatures