Allow submitting ChooseTimeBox with zeros by Enter.
This commit is contained in:
parent
2d53ef070f
commit
a8a4cc8c1a
2 changed files with 25 additions and 19 deletions
|
|
@ -76,13 +76,15 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int Number(not_null<TimePart*> field) {
|
std::optional<int> Number(not_null<TimePart*> field) {
|
||||||
const auto text = field->getLastText();
|
const auto text = field->getLastText();
|
||||||
auto ref = text.midRef(0);
|
auto ref = text.midRef(0);
|
||||||
while (!ref.isEmpty() && ref.at(0) == '0') {
|
while (ref.size() > 1 && ref.at(0) == '0') {
|
||||||
ref = ref.mid(1);
|
ref = ref.mid(1);
|
||||||
}
|
}
|
||||||
return ref.toInt();
|
return QRegularExpression("^\\d+$").match(ref).hasMatch()
|
||||||
|
? std::make_optional(ref.toInt())
|
||||||
|
: std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimePart::setMaxValue(int value) {
|
void TimePart::setMaxValue(int value) {
|
||||||
|
|
@ -118,7 +120,11 @@ void TimePart::keyPressEvent(QKeyEvent *e) {
|
||||||
|
|
||||||
void TimePart::wheelEvent(QWheelEvent *e) {
|
void TimePart::wheelEvent(QWheelEvent *e) {
|
||||||
const auto direction = WheelDirection(e);
|
const auto direction = WheelDirection(e);
|
||||||
auto time = Number(this) + (direction * _wheelStep);
|
const auto now = Number(this);
|
||||||
|
if (!now.has_value()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto time = *now + (direction * _wheelStep);
|
||||||
const auto max = _maxValue + 1;
|
const auto max = _maxValue + 1;
|
||||||
if (time < 0) {
|
if (time < 0) {
|
||||||
time += max;
|
time += max;
|
||||||
|
|
@ -248,13 +254,13 @@ TimeInput::TimeInput(
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
const auto submitHour = [=] {
|
const auto submitHour = [=] {
|
||||||
if (hour()) {
|
if (hour().has_value()) {
|
||||||
_minute->setFocus();
|
_minute->setFocus();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const auto submitMinute = [=] {
|
const auto submitMinute = [=] {
|
||||||
if (minute()) {
|
if (minute().has_value()) {
|
||||||
if (hour()) {
|
if (hour().has_value()) {
|
||||||
_submitRequests.fire({});
|
_submitRequests.fire({});
|
||||||
} else {
|
} else {
|
||||||
_hour->setFocus();
|
_hour->setFocus();
|
||||||
|
|
@ -290,7 +296,7 @@ void TimeInput::erasePrevious(const object_ptr<TimePart> &field) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TimeInput::setFocusFast() {
|
bool TimeInput::setFocusFast() {
|
||||||
if (hour()) {
|
if (hour().has_value()) {
|
||||||
_minute->setFocusFast();
|
_minute->setFocusFast();
|
||||||
} else {
|
} else {
|
||||||
_hour->setFocusFast();
|
_hour->setFocusFast();
|
||||||
|
|
@ -298,18 +304,18 @@ bool TimeInput::setFocusFast() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int TimeInput::hour() const {
|
std::optional<int> TimeInput::hour() const {
|
||||||
return Number(_hour);
|
return Number(_hour);
|
||||||
}
|
}
|
||||||
|
|
||||||
int TimeInput::minute() const {
|
std::optional<int> TimeInput::minute() const {
|
||||||
return Number(_minute);
|
return Number(_minute);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TimeInput::valueCurrent() const {
|
QString TimeInput::valueCurrent() const {
|
||||||
const auto result = QString("%1:%2"
|
const auto result = QString("%1:%2"
|
||||||
).arg(hour()
|
).arg(hour().value_or(0)
|
||||||
).arg(minute(), 2, 10, QChar('0'));
|
).arg(minute().value_or(0), 2, 10, QChar('0'));
|
||||||
return ValidateTime(result).isValid() ? result : QString();
|
return ValidateTime(result).isValid() ? result : QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -422,7 +428,7 @@ void TimeInput::showError() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimeInput::setInnerFocus() {
|
void TimeInput::setInnerFocus() {
|
||||||
if (hour()) {
|
if (hour().has_value()) {
|
||||||
_minute->setFocus();
|
_minute->setFocus();
|
||||||
} else {
|
} else {
|
||||||
_hour->setFocus();
|
_hour->setFocus();
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,10 @@ public:
|
||||||
const style::margins &stSeparatorPadding);
|
const style::margins &stSeparatorPadding);
|
||||||
|
|
||||||
bool setFocusFast();
|
bool setFocusFast();
|
||||||
rpl::producer<QString> value() const;
|
[[nodiscard]] rpl::producer<QString> value() const;
|
||||||
rpl::producer<> submitRequests() const;
|
[[nodiscard]] rpl::producer<> submitRequests() const;
|
||||||
rpl::producer<> focuses() const;
|
[[nodiscard]] rpl::producer<> focuses() const;
|
||||||
QString valueCurrent() const;
|
[[nodiscard]] QString valueCurrent() const;
|
||||||
void showError();
|
void showError();
|
||||||
|
|
||||||
int resizeGetHeight(int width) override;
|
int resizeGetHeight(int width) override;
|
||||||
|
|
@ -49,8 +49,8 @@ private:
|
||||||
template <typename Widget>
|
template <typename Widget>
|
||||||
bool insideSeparator(QPoint position, const Widget &widget) const;
|
bool insideSeparator(QPoint position, const Widget &widget) const;
|
||||||
|
|
||||||
int hour() const;
|
[[nodiscard]] std::optional<int> hour() const;
|
||||||
int minute() const;
|
[[nodiscard]] std::optional<int> minute() const;
|
||||||
|
|
||||||
const style::InputField &_stField;
|
const style::InputField &_stField;
|
||||||
const style::InputField &_stDateField;
|
const style::InputField &_stDateField;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue