2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

'base::optional_variant<' -> 'std::variant<v::null_t,'

This commit is contained in:
John Preston
2020-08-31 13:04:17 +04:00
parent 734d834a20
commit f0e1d2fd02
38 changed files with 189 additions and 169 deletions

View File

@@ -105,7 +105,7 @@ private:
return (index == other.index);
}
};
using Selection = base::optional_variant<RowSelection, MenuSelection>;
using Selection = std::variant<v::null_t, RowSelection, MenuSelection>;
void updateSelected(Selection selected);
void updatePressed(Selection pressed);
@@ -327,7 +327,7 @@ void Rows::mouseMoveEvent(QMouseEvent *e) {
void Rows::mousePressEvent(QMouseEvent *e) {
updatePressed(_selected);
if (_pressed.has_value()
if (!v::is_null(_pressed)
&& !rowBySelection(_pressed).menuToggleForceRippled) {
addRipple(_pressed, e->pos());
}
@@ -348,11 +348,11 @@ QRect Rows::menuToggleArea(not_null<const Row*> row) const {
}
void Rows::addRipple(Selection selected, QPoint position) {
Expects(selected.has_value());
Expects(!v::is_null(selected));
ensureRippleBySelection(selected);
const auto menu = selected.is<MenuSelection>();
const auto menu = v::is<MenuSelection>(selected);
const auto &row = rowBySelection(selected);
const auto menuArea = menuToggleArea(&row);
auto &ripple = rippleBySelection(&row, selected);
@@ -369,7 +369,7 @@ void Rows::ensureRippleBySelection(not_null<Row*> row, Selection selected) {
if (ripple) {
return;
}
const auto menu = selected.is<MenuSelection>();
const auto menu = v::is<MenuSelection>(selected);
const auto menuArea = menuToggleArea(row);
auto mask = menu
? Ui::RippleAnimation::ellipseMask(menuArea.size())
@@ -391,7 +391,7 @@ void Rows::mouseReleaseEvent(QMouseEvent *e) {
const auto pressed = _pressed;
updatePressed({});
if (pressed == _selected) {
pressed.match([&](RowSelection data) {
v::match(pressed, [&](RowSelection data) {
activateByIndex(data.index);
}, [&](MenuSelection data) {
showMenu(data.index);
@@ -597,7 +597,7 @@ int Rows::count() const {
}
int Rows::indexFromSelection(Selection selected) const {
return selected.match([&](RowSelection data) {
return v::match(selected, [&](RowSelection data) {
return data.index;
}, [&](MenuSelection data) {
return data.index;
@@ -648,7 +648,7 @@ rpl::producer<bool> Rows::isEmpty() const {
}
void Rows::repaint(Selection selected) {
selected.match([](v::null_t) {
v::match(selected, [](v::null_t) {
}, [&](const auto &data) {
repaint(data.index);
});
@@ -672,17 +672,17 @@ void Rows::repaintChecked(not_null<const Row*> row) {
}
void Rows::updateSelected(Selection selected) {
const auto changed = (_selected.has_value() != selected.has_value());
const auto changed = (v::is_null(_selected) != v::is_null(selected));
repaint(_selected);
_selected = selected;
repaint(_selected);
if (changed) {
_hasSelection.fire(_selected.has_value());
_hasSelection.fire(!v::is_null(_selected));
}
}
void Rows::updatePressed(Selection pressed) {
if (_pressed.has_value()) {
if (!v::is_null(_pressed)) {
if (!rowBySelection(_pressed).menuToggleForceRippled) {
if (const auto ripple = rippleBySelection(_pressed).get()) {
ripple->lastStop();
@@ -725,7 +725,7 @@ const std::unique_ptr<Ui::RippleAnimation> &Rows::rippleBySelection(
std::unique_ptr<Ui::RippleAnimation> &Rows::rippleBySelection(
not_null<Row*> row,
Selection selected) {
return selected.is<MenuSelection>()
return v::is<MenuSelection>(selected)
? row->menuToggleRipple
: row->ripple;
}
@@ -796,7 +796,7 @@ void Rows::paintEvent(QPaintEvent *e) {
const auto menu = menuToggleArea();
const auto selectedIndex = (_menuShownIndex >= 0)
? _menuShownIndex
: indexFromSelection(_pressed.has_value() ? _pressed : _selected);
: indexFromSelection(!v::is_null(_pressed) ? _pressed : _selected);
for (auto i = 0, till = count(); i != till; ++i) {
const auto &row = rowByIndex(i);
if (row.top + row.height <= clip.y()) {