mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-07-27 07:52:57 +02:00
Added ability to change date in schedule box with wheel.
This commit is contained in:
parent
425423e113
commit
50ab655af9
1 changed files with 34 additions and 12 deletions
|
@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
#include "data/data_scheduled_messages.h" // kScheduledUntilOnlineTimestamp
|
#include "data/data_scheduled_messages.h" // kScheduledUntilOnlineTimestamp
|
||||||
#include "lang/lang_keys.h"
|
#include "lang/lang_keys.h"
|
||||||
|
#include "base/event_filter.h"
|
||||||
#include "base/unixtime.h"
|
#include "base/unixtime.h"
|
||||||
#include "boxes/calendar_box.h"
|
#include "boxes/calendar_box.h"
|
||||||
#include "ui/widgets/input_fields.h"
|
#include "ui/widgets/input_fields.h"
|
||||||
|
@ -65,6 +66,17 @@ QString TimeString(TimeId time) {
|
||||||
).arg(parsed.minute(), 2, 10, QLatin1Char('0'));
|
).arg(parsed.minute(), 2, 10, QLatin1Char('0'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ProcessWheelEvent(not_null<QWheelEvent*> e) {
|
||||||
|
// Only a mouse wheel is accepted.
|
||||||
|
constexpr auto step = static_cast<int>(QWheelEvent::DefaultDeltasPerStep);
|
||||||
|
const auto delta = e->angleDelta().y();
|
||||||
|
const auto absDelta = std::abs(delta);
|
||||||
|
if (absDelta != step) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return (delta / absDelta);
|
||||||
|
}
|
||||||
|
|
||||||
class TimePart final : public Ui::MaskedInputField {
|
class TimePart final : public Ui::MaskedInputField {
|
||||||
public:
|
public:
|
||||||
using MaskedInputField::MaskedInputField;
|
using MaskedInputField::MaskedInputField;
|
||||||
|
@ -215,15 +227,8 @@ void TimePart::keyPressEvent(QKeyEvent *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimePart::wheelEvent(QWheelEvent *e) {
|
void TimePart::wheelEvent(QWheelEvent *e) {
|
||||||
// Only a mouse wheel is accepted.
|
const auto direction = ProcessWheelEvent(e);
|
||||||
constexpr auto step = static_cast<int>(QWheelEvent::DefaultDeltasPerStep);
|
auto time = Number(this) + (direction * _wheelStep);
|
||||||
const auto delta = e->angleDelta().y();
|
|
||||||
const auto absDelta = std::abs(delta);
|
|
||||||
if (absDelta != step) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto time = Number(this) + ((delta / absDelta) * _wheelStep);
|
|
||||||
const auto max = _maxValue + 1;
|
const auto max = _maxValue + 1;
|
||||||
if (time < 0) {
|
if (time < 0) {
|
||||||
time += max;
|
time += max;
|
||||||
|
@ -628,6 +633,24 @@ void ScheduleBox(
|
||||||
timeInput->setFocusFast();
|
timeInput->setFocusFast();
|
||||||
}, dayInput->lifetime());
|
}, dayInput->lifetime());
|
||||||
|
|
||||||
|
const auto minDate = QDate::currentDate();
|
||||||
|
const auto maxDate = minDate.addYears(1).addDays(-1);
|
||||||
|
|
||||||
|
const auto &dayViewport = dayInput->rawTextEdit()->viewport();
|
||||||
|
base::install_event_filter(dayViewport, [=](not_null<QEvent*> event) {
|
||||||
|
if (event->type() == QEvent::Wheel) {
|
||||||
|
const auto e = static_cast<QWheelEvent*>(event.get());
|
||||||
|
const auto direction = ProcessWheelEvent(e);
|
||||||
|
if (!direction) {
|
||||||
|
return base::EventFilterResult::Continue;
|
||||||
|
}
|
||||||
|
const auto d = date->current().addDays(direction);
|
||||||
|
*date = std::clamp(d, minDate, maxDate);
|
||||||
|
return base::EventFilterResult::Cancel;
|
||||||
|
}
|
||||||
|
return base::EventFilterResult::Continue;
|
||||||
|
});
|
||||||
|
|
||||||
content->widthValue(
|
content->widthValue(
|
||||||
) | rpl::start_with_next([=](int width) {
|
) | rpl::start_with_next([=](int width) {
|
||||||
const auto paddings = width
|
const auto paddings = width
|
||||||
|
@ -656,9 +679,8 @@ void ScheduleBox(
|
||||||
(*calendar)->closeBox();
|
(*calendar)->closeBox();
|
||||||
};
|
};
|
||||||
const auto finalize = [=](not_null<CalendarBox*> box) {
|
const auto finalize = [=](not_null<CalendarBox*> box) {
|
||||||
const auto now = QDate::currentDate();
|
box->setMinDate(minDate);
|
||||||
box->setMinDate(now);
|
box->setMaxDate(maxDate);
|
||||||
box->setMaxDate(now.addYears(1).addDays(-1));
|
|
||||||
};
|
};
|
||||||
*calendar = box->getDelegate()->show(Box<CalendarBox>(
|
*calendar = box->getDelegate()->show(Box<CalendarBox>(
|
||||||
date->current(),
|
date->current(),
|
||||||
|
|
Loading…
Add table
Reference in a new issue