| 510 | }; |
| 511 | |
| 512 | MultiSelect::MultiSelect( |
| 513 | QWidget *parent, |
| 514 | const style::MultiSelect &st, |
| 515 | rpl::producer<QString> placeholder, |
| 516 | const QString &query) |
| 517 | : RpWidget(parent) |
| 518 | , _st(st) |
| 519 | , _scroll(this, _st.scroll) { |
| 520 | const auto scrollCallback = [=](int activeTop, int activeBottom) { |
| 521 | scrollTo(activeTop, activeBottom); |
| 522 | }; |
| 523 | _inner = _scroll->setOwnedWidget(object_ptr<Inner>( |
| 524 | this, |
| 525 | st, |
| 526 | std::move(placeholder), |
| 527 | query, |
| 528 | scrollCallback)); |
| 529 | _scroll->installEventFilter(this); |
| 530 | _inner->setResizedCallback([this](int innerHeightDelta) { |
| 531 | auto newHeight = resizeGetHeight(width()); |
| 532 | if (innerHeightDelta > 0) { |
| 533 | _scroll->scrollToY(_scroll->scrollTop() + innerHeightDelta); |
| 534 | } |
| 535 | if (newHeight != height()) { |
| 536 | resize(width(), newHeight); |
| 537 | if (_resizedCallback) { |
| 538 | _resizedCallback(); |
| 539 | } |
| 540 | } |
| 541 | }); |
| 542 | _inner->setQueryChangedCallback([this](const QString &query) { |
| 543 | _scroll->scrollToY(_scroll->scrollTopMax()); |
| 544 | if (_queryChangedCallback) { |
| 545 | _queryChangedCallback(query); |
| 546 | } |
| 547 | }); |
| 548 | |
| 549 | setAttribute(Qt::WA_OpaquePaintEvent); |
| 550 | auto defaultWidth = _st.item.maxWidth + _st.fieldMinWidth + _st.fieldCancelSkip; |
| 551 | resizeToWidth(_st.padding.left() + defaultWidth + _st.padding.right()); |
| 552 | } |
| 553 | |
| 554 | bool MultiSelect::eventFilter(QObject *o, QEvent *e) { |
| 555 | if (o == _scroll && e->type() == QEvent::KeyPress) { |
nothing calls this directly
no test coverage detected