| 897 | } |
| 898 | |
| 899 | void MainWidget::createPlayer() { |
| 900 | if (!_player) { |
| 901 | _player.create( |
| 902 | this, |
| 903 | object_ptr<Media::Player::Widget>(this, this, _controller), |
| 904 | _controller->adaptive().oneColumnValue()); |
| 905 | rpl::merge( |
| 906 | _player->heightValue() | rpl::map_to(true), |
| 907 | _player->shownValue() |
| 908 | ) | rpl::on_next( |
| 909 | [this] { playerHeightUpdated(); }, |
| 910 | _player->lifetime()); |
| 911 | _player->entity()->setCloseCallback([=] { |
| 912 | Media::Player::instance()->stopAndClose(); |
| 913 | }); |
| 914 | _player->entity()->setShowItemCallback([=]( |
| 915 | not_null<const HistoryItem*> item) { |
| 916 | const auto peer = item->history()->peer; |
| 917 | if (const auto window = Core::App().windowFor(peer)) { |
| 918 | if (const auto controller = window->sessionController()) { |
| 919 | controller->showMessage(item); |
| 920 | return; |
| 921 | } |
| 922 | } |
| 923 | _controller->showMessage(item); |
| 924 | }); |
| 925 | |
| 926 | _player->entity()->togglePlaylistRequests( |
| 927 | ) | rpl::on_next([=](bool shown) { |
| 928 | if (!shown) { |
| 929 | _playerPlaylist->hideFromOther(); |
| 930 | return; |
| 931 | } else if (_playerPlaylist->isHidden()) { |
| 932 | auto position = mapFromGlobal(QCursor::pos()).x(); |
| 933 | auto bestPosition = _playerPlaylist->bestPositionFor(position); |
| 934 | if (rtl()) bestPosition = position + 2 * (position - bestPosition) - _playerPlaylist->width(); |
| 935 | updateMediaPlaylistPosition(bestPosition); |
| 936 | } |
| 937 | _playerPlaylist->showFromOther(); |
| 938 | }, _player->lifetime()); |
| 939 | |
| 940 | orderWidgets(); |
| 941 | if (_showAnimation) { |
| 942 | _player->show(anim::type::instant); |
| 943 | _player->setVisible(false); |
| 944 | Shortcuts::ToggleMediaShortcuts(true); |
| 945 | } else { |
| 946 | _player->hide(anim::type::instant); |
| 947 | } |
| 948 | } |
| 949 | if (_player && !_player->toggled()) { |
| 950 | if (!_showAnimation) { |
| 951 | _player->show(anim::type::normal); |
| 952 | _playerHeight = _contentScrollAddToY = _player->contentHeight(); |
| 953 | updateControlsGeometry(); |
| 954 | Shortcuts::ToggleMediaShortcuts(true); |
| 955 | } |
| 956 | } |
nothing calls this directly
no test coverage detected