| 1 | // For license of this file, see <project-root-folder>/LICENSE.md.cxx . . $ `<file>/src/librssguard/gui/reusable/timespinbox.cpp`/ |
| 2 | |
| 3 | #include "gui/reusable/timespinbox.h"cxx . . $ `<file>/src/librssguard/gui/reusable/timespinbox.h`/ |
| 4 | |
| 5 | #include "definitions/definitions.h"cxx . . $ `<file>/src/librssguard/definitions/definitions.h`/ |
| 6 | |
| 7 | #include <QStringList> |
| 8 | |
| 9 | TimeSpinBoxcxx . . $ TimeSpinBox#::TimeSpinBoxcxx . . $ TimeSpinBox#TimeSpinBox(108f35f7aa7f3cf9).(QWidgetcxx . . $ QWidget#* parent) : QDoubleSpinBoxcxx . . $ QDoubleSpinBox#(parent) { |
| 10 | setAcceleratedcxx . . $ QAbstractSpinBox#setAccelerated(b45ddcbc8423892c).(true); |
| 11 | setMinimumcxx . . $ QDoubleSpinBox#setMinimum(ba8836b59fb42830).(1.0); |
| 12 | setMaximumcxx . . $ QDoubleSpinBox#setMaximum(ba8836b59fb42830).(10000000.0); |
| 13 | setModecxx . . $ TimeSpinBox#setMode(392a4df3fd7b235e).(TimeSpinBoxcxx . . $ TimeSpinBox#::Modecxx . . $ TimeSpinBox#Mode#::HoursMinutescxx . . $ TimeSpinBox#Mode#HoursMinutes.); |
| 14 | } |
| 15 | |
| 16 | double TimeSpinBoxcxx . . $ TimeSpinBox#::valueFromTextcxx . . $ TimeSpinBox#valueFromText(512e058d2fe20f7f).(const QStringcxx . . $ QString#& text) const { |
| 17 | bool ok; |
| 18 | double value = text.toDoublecxx . . $ QString#toDouble(1bd8e57dd4a29c14).(&ok); |
| 19 | |
| 20 | if (ok) { |
| 21 | return value; |
| 22 | } |
| 23 | else { |
| 24 | static QRegularExpressioncxx . . $ QRegularExpression# rxcxx . . $ QRegularExpression#QRegularExpression(4279d2539df7cd4a).(QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("\\b[0-9]{1,}\\b")); |
| 25 | QStringListcxx . . $ QStringList# numberscxx . . $ QList#QList(ced63f7c635d850d).; |
| 26 | QRegularExpressionMatchIteratorcxx . . $ QRegularExpressionMatchIterator# i = rx.globalMatchcxx . . $ QRegularExpression#globalMatch(27b5aa3d61ae1b2f).(text); |
| 27 | |
| 28 | while (i.hasNextcxx . . $ QRegularExpressionMatchIterator#hasNext(50ce9a9e25b4a850).()) { |
| 29 | numbers.appendcxx . . $ QList#append(1262c8661f7a27a7).(i.nextcxx . . $ QRegularExpressionMatchIterator#next(5870644aafa115db).().capturedcxx . . $ QRegularExpressionMatch#captured(3f3c3d0e9c0eb37f).()); |
| 30 | } |
| 31 | |
| 32 | if (numbers.sizecxx . . $ QList#size(6b0412d51016192f).() == 2) { |
| 33 | switch (m_modecxx . . $ TimeSpinBox#m_mode.) { |
| 34 | case TimeSpinBoxcxx . . $ TimeSpinBox#::Modecxx . . $ TimeSpinBox#Mode#::DaysHourscxx . . $ TimeSpinBox#Mode#DaysHours.: |
| 35 | return (numbers.atcxx . . $ QList#at(c7965f769b39929).(0).toDoublecxx . . $ QString#toDouble(1bd8e57dd4a29c14).() * 24.0) + numbers.atcxx . . $ QList#at(c7965f769b39929).(1).toDoublecxx . . $ QString#toDouble(1bd8e57dd4a29c14).(); |
| 36 | |
| 37 | default: |
| 38 | case TimeSpinBoxcxx . . $ TimeSpinBox#::Modecxx . . $ TimeSpinBox#Mode#::HoursMinutescxx . . $ TimeSpinBox#Mode#HoursMinutes.: |
| 39 | case TimeSpinBoxcxx . . $ TimeSpinBox#::Modecxx . . $ TimeSpinBox#Mode#::MinutesSecondscxx . . $ TimeSpinBox#Mode#MinutesSeconds.: |
| 40 | return (numbers.atcxx . . $ QList#at(c7965f769b39929).(0).toDoublecxx . . $ QString#toDouble(1bd8e57dd4a29c14).() * 60.0) + numbers.atcxx . . $ QList#at(c7965f769b39929).(1).toDoublecxx . . $ QString#toDouble(1bd8e57dd4a29c14).(); |
| 41 | } |
| 42 | } |
| 43 | else { |
| 44 | return -1.0; |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | QStringcxx . . $ QString# TimeSpinBoxcxx . . $ TimeSpinBox#::textFromValuecxx . . $ TimeSpinBox#textFromValue(7e2283acc48daae0).(double val) const { |
| 50 | switch (m_modecxx . . $ TimeSpinBox#m_mode.) { |
| 51 | case TimeSpinBoxcxx . . $ TimeSpinBox#::Modecxx . . $ TimeSpinBox#Mode#::MinutesSecondscxx . . $ TimeSpinBox#Mode#MinutesSeconds.: { |
| 52 | // "val" is number of seconds. |
| 53 | int seconds_val = int(val); |
| 54 | int minutes_total = seconds_val / 60; |
| 55 | int seconds_total = seconds_val - (minutes_total * 60); |
| 56 | QStringcxx . . $ QString# seconds = trcxx . . $ TimeSpinBox#tr(75d9f1c324b4579d).("%n second(s)", nullptr, seconds_total); |
| 57 | QStringcxx . . $ QString# minutes = trcxx . . $ TimeSpinBox#tr(75d9f1c324b4579d).("%n minute(s)", nullptr, minutes_total); |
| 58 | |
| 59 | return minutes +cxx . . $ operator+(adfbdceb504720ce). trcxx . . $ TimeSpinBox#tr(75d9f1c324b4579d).(" and ") +cxx . . $ operator+(adfbdceb504720ce). seconds; |
| 60 | } |
| 61 | |
| 62 | case TimeSpinBoxcxx . . $ TimeSpinBox#::Modecxx . . $ TimeSpinBox#Mode#::DaysHourscxx . . $ TimeSpinBox#Mode#DaysHours.: { |
| 63 | // "val" is number of hours. |
| 64 | int hours_val = int(val); |
| 65 | int days_total = hours_val / 24; |
| 66 | int hours_total = hours_val - (days_total * 24); |
| 67 | QStringcxx . . $ QString# hours = trcxx . . $ TimeSpinBox#tr(75d9f1c324b4579d).("%n hour(s)", nullptr, hours_total); |
| 68 | QStringcxx . . $ QString# days = trcxx . . $ TimeSpinBox#tr(75d9f1c324b4579d).("%n day(s)", nullptr, days_total); |
| 69 | |
| 70 | return days +cxx . . $ operator+(adfbdceb504720ce). trcxx . . $ TimeSpinBox#tr(75d9f1c324b4579d).(" and ") +cxx . . $ operator+(adfbdceb504720ce). hours; |
| 71 | } |
| 72 | |
| 73 | default: |
| 74 | case TimeSpinBoxcxx . . $ TimeSpinBox#::Modecxx . . $ TimeSpinBox#Mode#::HoursMinutescxx . . $ TimeSpinBox#Mode#HoursMinutes.: { |
| 75 | // "val" is number of minutes. |
| 76 | int minutes_total = int(val); |
| 77 | int minutes_val = minutes_total % 60; |
| 78 | int hours_val = (minutes_total - minutes_val) / 60; |
| 79 | QStringcxx . . $ QString# hours = trcxx . . $ TimeSpinBox#tr(75d9f1c324b4579d).("%n hour(s)", nullptr, hours_val); |
| 80 | QStringcxx . . $ QString# minutes = trcxx . . $ TimeSpinBox#tr(75d9f1c324b4579d).("%n minute(s)", nullptr, minutes_val); |
| 81 | |
| 82 | return hours +cxx . . $ operator+(adfbdceb504720ce). trcxx . . $ TimeSpinBox#tr(75d9f1c324b4579d).(" and ") +cxx . . $ operator+(adfbdceb504720ce). minutes; |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | void TimeSpinBoxcxx . . $ TimeSpinBox#::fixupcxx . . $ TimeSpinBox#fixup(e91a184ddc958453).(QStringcxx . . $ QString#& input) const { |
| 88 | bool ok; |
| 89 | double value = input.toDoublecxx . . $ QString#toDouble(1bd8e57dd4a29c14).(&ok); |
| 90 | |
| 91 | if (ok) { |
| 92 | input =cxx . . $ QString#`operator=`(4f35bf974e7f8568). textFromValuecxx . . $ TimeSpinBox#textFromValue(7e2283acc48daae0).(value); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | QValidatorcxx . . $ QValidator#::Statecxx . . $ QValidator#State# TimeSpinBoxcxx . . $ TimeSpinBox#::validatecxx . . $ TimeSpinBox#validate(c53298829ad8eccd).(QStringcxx . . $ QString#& input, int& pos) const { |
| 97 | Q_UNUSEDcxx . . $ `<external>/17563275351362271547/qtpreprocessorsupport.h:20:9`!(pos) |
| 98 | return (valueFromTextcxx . . $ TimeSpinBox#valueFromText(512e058d2fe20f7f).(input) != -1.0) ? QValidatorcxx . . $ QValidator#::Statecxx . . $ QValidator#State#::Acceptablecxx . . $ QValidator#Acceptable. : QValidatorcxx . . $ QValidator#::Statecxx . . $ QValidator#State#::Intermediatecxx . . $ QValidator#Intermediate.; |
| 99 | } |
| 100 | |
| 101 | TimeSpinBoxcxx . . $ TimeSpinBox#::Modecxx . . $ TimeSpinBox#Mode# TimeSpinBoxcxx . . $ TimeSpinBox#::modecxx . . $ TimeSpinBox#mode(d5dc406756ad5091).() const { |
| 102 | return m_modecxx . . $ TimeSpinBox#m_mode.; |
| 103 | } |
| 104 | |
| 105 | void TimeSpinBoxcxx . . $ TimeSpinBox#::setModecxx . . $ TimeSpinBox#setMode(392a4df3fd7b235e).(TimeSpinBoxcxx . . $ TimeSpinBox#::Modecxx . . $ TimeSpinBox#Mode# mode) { |
| 106 | m_modecxx . . $ TimeSpinBox#m_mode. = mode; |
| 107 | |
| 108 | setValuecxx . . $ QDoubleSpinBox#setValue(ba8836b59fb42830).(valuecxx . . $ QDoubleSpinBox#value(21b6c25e127938e2).()); |
| 109 | } |