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();
|
||||
auto ref = text.midRef(0);
|
||||
while (!ref.isEmpty() && ref.at(0) == '0') {
|
||||
while (ref.size() > 1 && ref.at(0) == '0') {
|
||||
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) {
|
||||
|
|
@ -118,7 +120,11 @@ void TimePart::keyPressEvent(QKeyEvent *e) {
|
|||
|
||||
void TimePart::wheelEvent(QWheelEvent *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;
|
||||
if (time < 0) {
|
||||
time += max;
|
||||
|
|
@ -248,13 +254,13 @@ TimeInput::TimeInput(
|
|||
}, lifetime());
|
||||
|
||||
const auto submitHour = [=] {
|
||||
if (hour()) {
|
||||
if (hour().has_value()) {
|
||||
_minute->setFocus();
|
||||
}
|
||||
};
|
||||
const auto submitMinute = [=] {
|
||||
if (minute()) {
|
||||
if (hour()) {
|
||||
if (minute().has_value()) {
|
||||
if (hour().has_value()) {
|
||||
_submitRequests.fire({});
|
||||
} else {
|
||||
_hour->setFocus();
|
||||
|
|
@ -290,7 +296,7 @@ void TimeInput::erasePrevious(const object_ptr<TimePart> &field) {
|
|||
}
|
||||
|
||||
bool TimeInput::setFocusFast() {
|
||||
if (hour()) {
|
||||
if (hour().has_value()) {
|
||||
_minute->setFocusFast();
|
||||
} else {
|
||||
_hour->setFocusFast();
|
||||
|
|
@ -298,18 +304,18 @@ bool TimeInput::setFocusFast() {
|
|||
return true;
|
||||
}
|
||||
|
||||
int TimeInput::hour() const {
|
||||
std::optional<int> TimeInput::hour() const {
|
||||
return Number(_hour);
|
||||
}
|
||||
|
||||
int TimeInput::minute() const {
|
||||
std::optional<int> TimeInput::minute() const {
|
||||
return Number(_minute);
|
||||
}
|
||||
|
||||
QString TimeInput::valueCurrent() const {
|
||||
const auto result = QString("%1:%2"
|
||||
).arg(hour()
|
||||
).arg(minute(), 2, 10, QChar('0'));
|
||||
).arg(hour().value_or(0)
|
||||
).arg(minute().value_or(0), 2, 10, QChar('0'));
|
||||
return ValidateTime(result).isValid() ? result : QString();
|
||||
}
|
||||
|
||||
|
|
@ -422,7 +428,7 @@ void TimeInput::showError() {
|
|||
}
|
||||
|
||||
void TimeInput::setInnerFocus() {
|
||||
if (hour()) {
|
||||
if (hour().has_value()) {
|
||||
_minute->setFocus();
|
||||
} else {
|
||||
_hour->setFocus();
|
||||
|
|
|
|||
|
|
@ -26,10 +26,10 @@ public:
|
|||
const style::margins &stSeparatorPadding);
|
||||
|
||||
bool setFocusFast();
|
||||
rpl::producer<QString> value() const;
|
||||
rpl::producer<> submitRequests() const;
|
||||
rpl::producer<> focuses() const;
|
||||
QString valueCurrent() const;
|
||||
[[nodiscard]] rpl::producer<QString> value() const;
|
||||
[[nodiscard]] rpl::producer<> submitRequests() const;
|
||||
[[nodiscard]] rpl::producer<> focuses() const;
|
||||
[[nodiscard]] QString valueCurrent() const;
|
||||
void showError();
|
||||
|
||||
int resizeGetHeight(int width) override;
|
||||
|
|
@ -49,8 +49,8 @@ private:
|
|||
template <typename Widget>
|
||||
bool insideSeparator(QPoint position, const Widget &widget) const;
|
||||
|
||||
int hour() const;
|
||||
int minute() const;
|
||||
[[nodiscard]] std::optional<int> hour() const;
|
||||
[[nodiscard]] std::optional<int> minute() const;
|
||||
|
||||
const style::InputField &_stField;
|
||||
const style::InputField &_stDateField;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue