Many-day selection by two clicks in the calendar.

This commit is contained in:
John Preston 2021-11-19 18:53:18 +04:00
parent ecb4d1d9ba
commit 969b27cb75

View file

@ -367,6 +367,7 @@ private:
const style::CalendarSizes &_st; const style::CalendarSizes &_st;
const not_null<Context*> _context; const not_null<Context*> _context;
bool _twoPressSelectionStarted = false;
std::map<int, std::unique_ptr<RippleAnimation>> _ripples; std::map<int, std::unique_ptr<RippleAnimation>> _ripples;
@ -464,7 +465,7 @@ void CalendarBox::Inner::paintRows(Painter &p, QRect clip) {
if (selectedInRow > 0) { if (selectedInRow > 0) {
auto hq = PainterHighQualityEnabler(p); auto hq = PainterHighQualityEnabler(p);
p.setPen(Qt::NoPen); p.setPen(Qt::NoPen);
p.setBrush(st::lightButtonBgOver); p.setBrush(st::dialogsRippleBgActive);
p.drawRoundedRect( p.drawRoundedRect(
(x (x
+ (selectedFrom - index) * _st.cellSize.width() + (selectedFrom - index) * _st.cellSize.width()
@ -495,27 +496,24 @@ void CalendarBox::Inner::paintRows(Painter &p, QRect clip) {
p.setBrush(Qt::NoBrush); p.setBrush(Qt::NoBrush);
} }
const auto it = _ripples.find(index); const auto it = _ripples.find(index);
if (it != _ripples.cend()) { if (it != _ripples.cend() && !selectionMode) {
const auto colorOverride = [&] { const auto colorOverride = (!highlighted
if (selectionMode) { ? st::windowBgOver
return st::lightButtonBgOver; : grayedOut
} else if (highlighted) { ? st::windowBgRipple
return grayedOut ? st::windowBgRipple : st::dialogsRippleBgActive; : st::dialogsRippleBgActive)->c;
}
return st::windowBgOver;
}()->c;
it->second->paint(p, innerLeft, innerTop, width(), &colorOverride); it->second->paint(p, innerLeft, innerTop, width(), &colorOverride);
if (it->second->empty()) { if (it->second->empty()) {
_ripples.erase(it); _ripples.erase(it);
} }
} }
if (highlighted) { p.setPen(selected
p.setPen(grayedOut ? st::windowSubTextFg : st::dialogsNameFgActive); ? st::dialogsNameFgActive
} else if (enabled) { : highlighted
p.setPen(grayedOut ? st::windowSubTextFg : st::boxTextFg); ? (grayedOut ? st::windowSubTextFg : st::dialogsNameFgActive)
} else { : enabled
p.setPen(st::windowSubTextFg); ? (grayedOut ? st::windowSubTextFg : st::boxTextFg)
} : st::windowSubTextFg);
p.drawText(rect, _context->labelFromIndex(index), style::al_center); p.drawText(rect, _context->labelFromIndex(index), style::al_center);
} }
} }
@ -598,10 +596,15 @@ void CalendarBox::Inner::mousePressEvent(QMouseEvent *e) {
if (_context->selectionMode()) { if (_context->selectionMode()) {
if (_context->selectedMin().has_value() if (_context->selectedMin().has_value()
&& (e->modifiers() & Qt::ShiftModifier)) { && ((e->modifiers() & Qt::ShiftModifier)
|| (_twoPressSelectionStarted
&& (_context->selectedMin()
== _context->selectedMax())))) {
_context->updateSelection(_selected); _context->updateSelection(_selected);
_twoPressSelectionStarted = false;
} else { } else {
_context->startSelection(_selected); _context->startSelection(_selected);
_twoPressSelectionStarted = true;
} }
} }
} }