2017-09-13 17:01:23 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|
|
|
*/
|
|
|
|
#include "info/info_top_bar.h"
|
|
|
|
|
2017-11-03 18:26:14 +00:00
|
|
|
#include <rpl/never.h>
|
2017-11-26 17:05:52 +00:00
|
|
|
#include <rpl/merge.h>
|
2017-09-15 17:34:41 +00:00
|
|
|
#include "styles/style_info.h"
|
2017-09-30 18:26:45 +00:00
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "info/info_wrap_widget.h"
|
2017-10-31 18:25:22 +00:00
|
|
|
#include "info/info_controller.h"
|
2017-11-17 13:23:36 +00:00
|
|
|
#include "info/profile/info_profile_values.h"
|
2017-09-30 18:26:45 +00:00
|
|
|
#include "storage/storage_shared_media.h"
|
2017-11-26 17:05:52 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
|
|
|
#include "boxes/peer_list_controllers.h"
|
|
|
|
#include "mainwidget.h"
|
2017-09-13 17:01:23 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
|
|
|
#include "ui/widgets/labels.h"
|
2017-11-03 12:03:00 +00:00
|
|
|
#include "ui/widgets/input_fields.h"
|
2017-09-30 18:26:45 +00:00
|
|
|
#include "ui/widgets/shadow.h"
|
2017-11-03 12:03:00 +00:00
|
|
|
#include "ui/wrap/fade_wrap.h"
|
|
|
|
#include "ui/wrap/padding_wrap.h"
|
|
|
|
#include "ui/search_field_controller.h"
|
2017-09-13 17:01:23 +00:00
|
|
|
|
|
|
|
namespace Info {
|
|
|
|
|
2017-11-26 17:05:52 +00:00
|
|
|
TopBar::TopBar(
|
|
|
|
QWidget *parent,
|
|
|
|
const style::InfoTopBar &st,
|
|
|
|
SelectedItems &&selectedItems)
|
2017-09-13 17:01:23 +00:00
|
|
|
: RpWidget(parent)
|
2017-11-26 17:05:52 +00:00
|
|
|
, _st(st)
|
|
|
|
, _selectedItems(Section::MediaType::kCount) {
|
2017-09-13 17:01:23 +00:00
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
2017-11-26 17:05:52 +00:00
|
|
|
setSelectedItems(std::move(selectedItems));
|
2017-11-27 11:43:57 +00:00
|
|
|
updateControlsVisibility(anim::type::instant);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Callback>
|
|
|
|
void TopBar::registerUpdateControlCallback(
|
|
|
|
QObject *guard,
|
|
|
|
Callback &&callback) {
|
|
|
|
_updateControlCallbacks[guard] =[
|
|
|
|
object = weak(guard),
|
|
|
|
callback = std::forward<Callback>(callback)
|
|
|
|
](anim::type animated) {
|
|
|
|
if (!object) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
callback(animated);
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Widget, typename IsVisible>
|
|
|
|
void TopBar::registerToggleControlCallback(
|
|
|
|
Widget *widget,
|
|
|
|
IsVisible &&callback) {
|
|
|
|
registerUpdateControlCallback(widget, [
|
|
|
|
widget,
|
|
|
|
isVisible = std::forward<IsVisible>(callback)
|
|
|
|
](anim::type animated) {
|
|
|
|
widget->toggle(isVisible(), animated);
|
|
|
|
});
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TopBar::setTitle(rpl::producer<QString> &&title) {
|
2017-11-26 17:05:52 +00:00
|
|
|
if (_title) {
|
|
|
|
delete _title;
|
|
|
|
}
|
2017-11-27 11:43:57 +00:00
|
|
|
_title = Ui::CreateChild<Ui::FadeWrap<Ui::FlatLabel>>(
|
2017-11-26 17:05:52 +00:00
|
|
|
this,
|
2017-11-27 11:43:57 +00:00
|
|
|
object_ptr<Ui::FlatLabel>(this, std::move(title), _st.title),
|
|
|
|
st::infoTopBarScale);
|
|
|
|
_title->setDuration(st::infoTopBarDuration);
|
2017-11-26 17:05:52 +00:00
|
|
|
_title->toggle(!selectionMode(), anim::type::instant);
|
2017-11-27 11:43:57 +00:00
|
|
|
registerToggleControlCallback(_title.data(), [=] {
|
|
|
|
return !selectionMode() && !searchMode();
|
|
|
|
});
|
2017-11-26 17:05:52 +00:00
|
|
|
|
2017-09-15 17:34:41 +00:00
|
|
|
if (_back) {
|
|
|
|
_title->setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
}
|
|
|
|
updateControlsGeometry(width());
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2017-11-26 17:05:52 +00:00
|
|
|
void TopBar::enableBackButton() {
|
|
|
|
if (_back) {
|
|
|
|
return;
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
2017-11-27 11:43:57 +00:00
|
|
|
_back = Ui::CreateChild<Ui::FadeWrap<Ui::IconButton>>(
|
2017-11-26 17:05:52 +00:00
|
|
|
this,
|
2017-11-27 11:43:57 +00:00
|
|
|
object_ptr<Ui::IconButton>(this, _st.back),
|
|
|
|
st::infoTopBarScale);
|
|
|
|
_back->setDuration(st::infoTopBarDuration);
|
2017-11-26 17:05:52 +00:00
|
|
|
_back->toggle(!selectionMode(), anim::type::instant);
|
|
|
|
_back->entity()->clicks()
|
|
|
|
| rpl::start_to_stream(_backClicks, _back->lifetime());
|
2017-11-27 11:43:57 +00:00
|
|
|
registerToggleControlCallback(_back.data(), [=] {
|
|
|
|
return !selectionMode();
|
|
|
|
});
|
2017-11-26 17:05:52 +00:00
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
if (_title) {
|
2017-11-26 17:05:52 +00:00
|
|
|
_title->setAttribute(Qt::WA_TransparentForMouseEvents);
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
updateControlsGeometry(width());
|
|
|
|
}
|
|
|
|
|
2017-11-03 12:03:00 +00:00
|
|
|
void TopBar::createSearchView(
|
2017-11-03 18:26:14 +00:00
|
|
|
not_null<Ui::SearchFieldController*> controller,
|
|
|
|
rpl::producer<bool> &&shown) {
|
|
|
|
setSearchField(
|
|
|
|
controller->createField(this, _st.searchRow.field),
|
|
|
|
std::move(shown));
|
2017-11-03 12:03:00 +00:00
|
|
|
}
|
|
|
|
|
2017-11-27 11:43:57 +00:00
|
|
|
Ui::FadeWrap<Ui::RpWidget> *TopBar::pushButton(
|
|
|
|
base::unique_qptr<Ui::RpWidget> button) {
|
|
|
|
auto wrapped = base::make_unique_q<Ui::FadeWrap<Ui::RpWidget>>(
|
|
|
|
this,
|
|
|
|
object_ptr<Ui::RpWidget>::fromRaw(button.release()),
|
|
|
|
st::infoTopBarScale);
|
|
|
|
auto weak = wrapped.get();
|
|
|
|
_buttons.push_back(std::move(wrapped));
|
|
|
|
weak->setDuration(st::infoTopBarDuration);
|
|
|
|
registerToggleControlCallback(weak, [=] {
|
|
|
|
return !selectionMode()
|
|
|
|
&& !_searchModeEnabled;
|
|
|
|
});
|
2017-09-13 17:01:23 +00:00
|
|
|
weak->widthValue()
|
2017-09-27 18:29:13 +00:00
|
|
|
| rpl::start_with_next([this] {
|
2017-11-03 12:03:00 +00:00
|
|
|
updateControlsGeometry(width());
|
2017-09-30 18:26:45 +00:00
|
|
|
}, lifetime());
|
2017-11-27 11:43:57 +00:00
|
|
|
return weak;
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2017-11-03 12:03:00 +00:00
|
|
|
void TopBar::setSearchField(
|
2017-11-03 18:26:14 +00:00
|
|
|
base::unique_qptr<Ui::InputField> field,
|
|
|
|
rpl::producer<bool> &&shown) {
|
2017-11-03 12:03:00 +00:00
|
|
|
if (auto value = field.release()) {
|
2017-11-03 18:26:14 +00:00
|
|
|
createSearchView(value, std::move(shown));
|
2017-11-03 12:03:00 +00:00
|
|
|
} else {
|
|
|
|
_searchView = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-03 18:26:14 +00:00
|
|
|
void TopBar::createSearchView(
|
|
|
|
not_null<Ui::InputField*> field,
|
|
|
|
rpl::producer<bool> &&shown) {
|
2017-11-03 12:03:00 +00:00
|
|
|
_searchView = base::make_unique_q<Ui::FixedHeightWidget>(
|
|
|
|
this,
|
|
|
|
_st.searchRow.height);
|
|
|
|
auto wrap = _searchView.get();
|
2017-11-27 11:43:57 +00:00
|
|
|
registerUpdateControlCallback(wrap, [=](anim::type) {
|
|
|
|
wrap->setVisible(!selectionMode() && _searchModeAvailable);
|
|
|
|
});
|
2017-11-03 12:03:00 +00:00
|
|
|
|
2017-11-27 11:43:57 +00:00
|
|
|
auto fieldWrap = Ui::CreateChild<Ui::FadeWrap<Ui::InputField>>(
|
2017-11-03 12:03:00 +00:00
|
|
|
wrap,
|
2017-11-27 11:43:57 +00:00
|
|
|
object_ptr<Ui::InputField>::fromRaw(field),
|
|
|
|
st::infoTopBarScale);
|
|
|
|
fieldWrap->setDuration(st::infoTopBarDuration);
|
|
|
|
|
|
|
|
auto focusLifetime = field->lifetime().make_state<rpl::lifetime>();
|
|
|
|
registerUpdateControlCallback(fieldWrap, [=](anim::type animated) {
|
|
|
|
auto fieldShown = !selectionMode() && searchMode();
|
|
|
|
if (!fieldShown && field->hasFocus()) {
|
2017-11-17 13:23:36 +00:00
|
|
|
setFocus();
|
|
|
|
}
|
2017-11-27 11:43:57 +00:00
|
|
|
fieldWrap->toggle(fieldShown, animated);
|
|
|
|
if (fieldShown) {
|
|
|
|
*focusLifetime = field->shownValue()
|
|
|
|
| rpl::filter([](bool shown) { return shown; })
|
|
|
|
| rpl::take(1)
|
|
|
|
| rpl::start_with_next([=] {
|
|
|
|
field->setFocus();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
focusLifetime->destroy();
|
2017-11-17 13:23:36 +00:00
|
|
|
}
|
2017-11-27 11:43:57 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
auto button = base::make_unique_q<Ui::IconButton>(this, _st.search);
|
|
|
|
auto search = button.get();
|
|
|
|
search->addClickHandler([=] {
|
|
|
|
_searchModeEnabled = true;
|
|
|
|
updateControlsVisibility(anim::type::normal);
|
|
|
|
});
|
|
|
|
auto searchWrap = pushButton(std::move(button));
|
|
|
|
registerToggleControlCallback(searchWrap, [=] {
|
|
|
|
return !selectionMode()
|
|
|
|
&& _searchModeAvailable
|
|
|
|
&& !_searchModeEnabled;
|
|
|
|
});
|
|
|
|
|
|
|
|
auto cancel = Ui::CreateChild<Ui::CrossButton>(
|
|
|
|
wrap,
|
|
|
|
_st.searchRow.fieldCancel);
|
|
|
|
registerToggleControlCallback(cancel, [=] {
|
|
|
|
return !selectionMode() && searchMode();
|
|
|
|
});
|
2017-11-03 12:03:00 +00:00
|
|
|
|
|
|
|
auto cancelSearch = [=] {
|
|
|
|
if (!field->getLastText().isEmpty()) {
|
|
|
|
field->setText(QString());
|
|
|
|
} else {
|
2017-11-27 11:43:57 +00:00
|
|
|
_searchModeEnabled = false;
|
|
|
|
updateControlsVisibility(anim::type::normal);
|
2017-11-03 12:03:00 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-11-27 11:43:57 +00:00
|
|
|
cancel->addClickHandler(cancelSearch);
|
2017-11-03 12:03:00 +00:00
|
|
|
field->connect(field, &Ui::InputField::cancelled, cancelSearch);
|
|
|
|
|
|
|
|
wrap->widthValue()
|
|
|
|
| rpl::start_with_next([=](int newWidth) {
|
|
|
|
auto availableWidth = newWidth
|
|
|
|
- _st.searchRow.fieldCancelSkip;
|
2017-11-27 11:43:57 +00:00
|
|
|
fieldWrap->resizeToWidth(availableWidth);
|
|
|
|
fieldWrap->moveToLeft(
|
2017-11-03 12:03:00 +00:00
|
|
|
_st.searchRow.padding.left(),
|
2017-11-27 11:43:57 +00:00
|
|
|
_st.searchRow.padding.top());
|
2017-11-03 12:03:00 +00:00
|
|
|
cancel->moveToRight(0, 0);
|
|
|
|
}, wrap->lifetime());
|
|
|
|
|
|
|
|
widthValue()
|
|
|
|
| rpl::start_with_next([=](int newWidth) {
|
|
|
|
auto left = _back
|
|
|
|
? _st.back.width
|
|
|
|
: _st.titlePosition.x();
|
|
|
|
wrap->setGeometryToLeft(
|
|
|
|
left,
|
|
|
|
0,
|
|
|
|
newWidth - left,
|
|
|
|
wrap->height(),
|
|
|
|
newWidth);
|
|
|
|
}, wrap->lifetime());
|
|
|
|
|
|
|
|
field->alive()
|
|
|
|
| rpl::start_with_done([=] {
|
|
|
|
field->setParent(nullptr);
|
|
|
|
removeButton(search);
|
2017-11-03 18:26:14 +00:00
|
|
|
setSearchField(nullptr, rpl::never<bool>());
|
2017-11-03 12:03:00 +00:00
|
|
|
}, _searchView->lifetime());
|
|
|
|
|
2017-11-27 11:43:57 +00:00
|
|
|
_searchModeEnabled = !field->getLastText().isEmpty();
|
|
|
|
updateControlsVisibility(anim::type::instant);
|
2017-11-03 18:26:14 +00:00
|
|
|
|
|
|
|
std::move(shown)
|
|
|
|
| rpl::start_with_next([=](bool visible) {
|
2017-11-27 11:43:57 +00:00
|
|
|
auto alreadyInSearch = !field->getLastText().isEmpty();
|
|
|
|
_searchModeAvailable = visible || alreadyInSearch;
|
|
|
|
updateControlsVisibility(anim::type::instant);
|
2017-11-03 18:26:14 +00:00
|
|
|
}, wrap->lifetime());
|
2017-11-03 12:03:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TopBar::removeButton(not_null<Ui::RpWidget*> button) {
|
|
|
|
_buttons.erase(
|
|
|
|
std::remove(_buttons.begin(), _buttons.end(), button),
|
|
|
|
_buttons.end());
|
|
|
|
}
|
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
int TopBar::resizeGetHeight(int newWidth) {
|
|
|
|
updateControlsGeometry(newWidth);
|
|
|
|
return _st.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TopBar::updateControlsGeometry(int newWidth) {
|
2017-11-26 17:05:52 +00:00
|
|
|
updateDefaultControlsGeometry(newWidth);
|
|
|
|
updateSelectionControlsGeometry(newWidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TopBar::updateDefaultControlsGeometry(int newWidth) {
|
2017-09-13 17:01:23 +00:00
|
|
|
auto right = 0;
|
|
|
|
for (auto &button : _buttons) {
|
2017-11-03 12:03:00 +00:00
|
|
|
if (!button) continue;
|
2017-09-13 17:01:23 +00:00
|
|
|
button->moveToRight(right, 0, newWidth);
|
|
|
|
right += button->width();
|
|
|
|
}
|
|
|
|
if (_back) {
|
2017-09-15 17:34:41 +00:00
|
|
|
_back->setGeometryToLeft(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
newWidth - right,
|
|
|
|
_back->height(),
|
|
|
|
newWidth);
|
|
|
|
}
|
|
|
|
if (_title) {
|
|
|
|
_title->moveToLeft(
|
|
|
|
_back ? _st.back.width : _st.titlePosition.x(),
|
|
|
|
_st.titlePosition.y(),
|
|
|
|
newWidth);
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-26 17:05:52 +00:00
|
|
|
void TopBar::updateSelectionControlsGeometry(int newWidth) {
|
|
|
|
if (!_selectionText) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto right = _st.mediaActionsSkip;
|
|
|
|
if (_canDelete) {
|
|
|
|
_delete->moveToRight(right, 0, newWidth);
|
|
|
|
right += _delete->width();
|
|
|
|
}
|
|
|
|
_forward->moveToRight(right, 0, newWidth);
|
|
|
|
right += _forward->width();
|
|
|
|
|
|
|
|
auto left = 0;
|
|
|
|
_cancelSelection->moveToLeft(left, 0);
|
|
|
|
left += _cancelSelection->width();
|
|
|
|
|
|
|
|
const auto top = 0;
|
|
|
|
const auto availableWidth = newWidth - left - right;
|
2017-11-27 11:43:57 +00:00
|
|
|
_selectionText->resizeToNaturalWidth(availableWidth);
|
2017-11-26 17:05:52 +00:00
|
|
|
_selectionText->moveToLeft(
|
|
|
|
left,
|
|
|
|
top,
|
|
|
|
newWidth);
|
|
|
|
}
|
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
void TopBar::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
2017-11-16 09:13:17 +00:00
|
|
|
|
|
|
|
auto ms = getms();
|
|
|
|
auto highlight = _a_highlight.current(ms, _highlight ? 1. : 0.);
|
|
|
|
if (_highlight && !_a_highlight.animating()) {
|
|
|
|
_highlight = false;
|
|
|
|
startHighlightAnimation();
|
|
|
|
}
|
|
|
|
auto brush = anim::brush(_st.bg, _st.highlightBg, highlight);
|
|
|
|
p.fillRect(e->rect(), brush);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TopBar::highlight() {
|
|
|
|
_highlight = true;
|
|
|
|
startHighlightAnimation();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TopBar::startHighlightAnimation() {
|
|
|
|
_a_highlight.start(
|
|
|
|
[this] { update(); },
|
|
|
|
_highlight ? 0. : 1.,
|
|
|
|
_highlight ? 1. : 0.,
|
|
|
|
_st.highlightDuration);
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2017-11-27 11:43:57 +00:00
|
|
|
void TopBar::updateControlsVisibility(anim::type animated) {
|
|
|
|
for (auto i = _updateControlCallbacks.begin(); i != _updateControlCallbacks.end();) {
|
|
|
|
auto &&[widget, callback] = *i;
|
|
|
|
if (!callback(animated)) {
|
|
|
|
i = _updateControlCallbacks.erase(i);
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-26 17:05:52 +00:00
|
|
|
void TopBar::setSelectedItems(SelectedItems &&items) {
|
2017-11-27 11:43:57 +00:00
|
|
|
auto wasSelectionMode = selectionMode();
|
2017-11-26 17:05:52 +00:00
|
|
|
_selectedItems = std::move(items);
|
|
|
|
if (selectionMode()) {
|
|
|
|
if (_selectionText) {
|
|
|
|
updateSelectionState();
|
2017-11-27 11:43:57 +00:00
|
|
|
if (!wasSelectionMode) {
|
|
|
|
_selectionText->entity()->finishAnimating();
|
|
|
|
}
|
2017-11-26 17:05:52 +00:00
|
|
|
} else {
|
|
|
|
createSelectionControls();
|
|
|
|
}
|
|
|
|
}
|
2017-11-27 11:43:57 +00:00
|
|
|
updateControlsVisibility(anim::type::normal);
|
2017-11-26 17:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SelectedItems TopBar::takeSelectedItems() {
|
|
|
|
_canDelete = false;
|
|
|
|
return std::move(_selectedItems);
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> TopBar::cancelSelectionRequests() const {
|
|
|
|
return _cancelSelectionClicks.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TopBar::updateSelectionState() {
|
|
|
|
Expects(_selectionText && _delete);
|
|
|
|
|
|
|
|
_canDelete = computeCanDelete();
|
|
|
|
_selectionText->entity()->setValue(generateSelectedText());
|
2017-11-28 15:16:28 +00:00
|
|
|
_delete->toggle(_canDelete, anim::type::instant);
|
2017-11-26 17:05:52 +00:00
|
|
|
|
|
|
|
updateSelectionControlsGeometry(width());
|
|
|
|
}
|
|
|
|
|
|
|
|
void TopBar::createSelectionControls() {
|
|
|
|
auto wrap = [&](auto created) {
|
2017-11-27 11:43:57 +00:00
|
|
|
registerToggleControlCallback(
|
|
|
|
created,
|
|
|
|
[this] { return selectionMode(); });
|
2017-11-26 17:05:52 +00:00
|
|
|
created->toggle(false, anim::type::instant);
|
|
|
|
return created;
|
|
|
|
};
|
|
|
|
_canDelete = computeCanDelete();
|
2017-11-27 11:43:57 +00:00
|
|
|
_cancelSelection = wrap(Ui::CreateChild<Ui::FadeWrap<Ui::IconButton>>(
|
2017-11-26 17:05:52 +00:00
|
|
|
this,
|
2017-11-27 11:43:57 +00:00
|
|
|
object_ptr<Ui::IconButton>(this, _st.mediaCancel),
|
|
|
|
st::infoTopBarScale));
|
|
|
|
_cancelSelection->setDuration(st::infoTopBarDuration);
|
2017-11-26 17:05:52 +00:00
|
|
|
_cancelSelection->entity()->clicks()
|
|
|
|
| rpl::start_to_stream(
|
|
|
|
_cancelSelectionClicks,
|
|
|
|
_cancelSelection->lifetime());
|
2017-11-27 11:43:57 +00:00
|
|
|
_selectionText = wrap(Ui::CreateChild<Ui::FadeWrap<Ui::LabelWithNumbers>>(
|
2017-11-26 17:05:52 +00:00
|
|
|
this,
|
|
|
|
object_ptr<Ui::LabelWithNumbers>(
|
|
|
|
this,
|
|
|
|
_st.title,
|
|
|
|
_st.titlePosition.y(),
|
2017-11-27 11:43:57 +00:00
|
|
|
generateSelectedText()),
|
|
|
|
st::infoTopBarScale));
|
|
|
|
_selectionText->setDuration(st::infoTopBarDuration);
|
2017-11-26 17:05:52 +00:00
|
|
|
_selectionText->entity()->resize(0, _st.height);
|
2017-11-27 11:43:57 +00:00
|
|
|
_forward = wrap(Ui::CreateChild<Ui::FadeWrap<Ui::IconButton>>(
|
2017-11-26 17:05:52 +00:00
|
|
|
this,
|
2017-11-27 11:43:57 +00:00
|
|
|
object_ptr<Ui::IconButton>(this, _st.mediaForward),
|
|
|
|
st::infoTopBarScale));
|
|
|
|
_forward->setDuration(st::infoTopBarDuration);
|
2017-11-26 17:05:52 +00:00
|
|
|
_forward->entity()->addClickHandler([this] { performForward(); });
|
2017-11-27 11:43:57 +00:00
|
|
|
_delete = wrap(Ui::CreateChild<Ui::FadeWrap<Ui::IconButton>>(
|
2017-11-26 17:05:52 +00:00
|
|
|
this,
|
2017-11-27 11:43:57 +00:00
|
|
|
object_ptr<Ui::IconButton>(this, _st.mediaDelete),
|
|
|
|
st::infoTopBarScale));
|
2017-11-28 15:16:28 +00:00
|
|
|
registerToggleControlCallback(
|
|
|
|
_delete.data(),
|
|
|
|
[this] { return selectionMode() && _canDelete; });
|
2017-11-27 11:43:57 +00:00
|
|
|
_delete->setDuration(st::infoTopBarDuration);
|
2017-11-26 17:05:52 +00:00
|
|
|
_delete->entity()->addClickHandler([this] { performDelete(); });
|
|
|
|
_delete->entity()->setVisible(_canDelete);
|
|
|
|
|
|
|
|
updateControlsGeometry(width());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TopBar::computeCanDelete() const {
|
|
|
|
return ranges::find_if(
|
|
|
|
_selectedItems.list,
|
|
|
|
[](const SelectedItem &item) { return !item.canDelete; }
|
|
|
|
) == _selectedItems.list.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
Ui::StringWithNumbers TopBar::generateSelectedText() const {
|
|
|
|
using Data = Ui::StringWithNumbers;
|
|
|
|
using Type = Storage::SharedMediaType;
|
|
|
|
auto phrase = [&] {
|
|
|
|
switch (_selectedItems.type) {
|
|
|
|
case Type::Photo: return lng_media_selected_photo__generic<Data>;
|
|
|
|
case Type::Video: return lng_media_selected_video__generic<Data>;
|
|
|
|
case Type::File: return lng_media_selected_file__generic<Data>;
|
|
|
|
case Type::MusicFile: return lng_media_selected_song__generic<Data>;
|
|
|
|
case Type::Link: return lng_media_selected_link__generic<Data>;
|
|
|
|
case Type::VoiceFile: return lng_media_selected_audio__generic<Data>;
|
|
|
|
// case Type::RoundFile: return lng_media_selected_round__generic<Data>;
|
|
|
|
}
|
2017-11-27 11:43:57 +00:00
|
|
|
Unexpected("Type in TopBar::generateSelectedText()");
|
2017-11-26 17:05:52 +00:00
|
|
|
}();
|
|
|
|
return phrase(lt_count, _selectedItems.list.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TopBar::selectionMode() const {
|
|
|
|
return !_selectedItems.list.empty();
|
|
|
|
}
|
|
|
|
|
2017-11-27 11:43:57 +00:00
|
|
|
bool TopBar::searchMode() const {
|
|
|
|
return _searchModeAvailable && _searchModeEnabled;
|
2017-11-26 17:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SelectedItemSet TopBar::collectItems() const {
|
|
|
|
auto result = SelectedItemSet();
|
|
|
|
for (auto value : _selectedItems.list) {
|
|
|
|
if (auto item = App::histItemById(value.msgId)) {
|
|
|
|
result.insert(result.size(), item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TopBar::performForward() {
|
|
|
|
auto items = collectItems();
|
|
|
|
if (items.empty()) {
|
|
|
|
_cancelSelectionClicks.fire({});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto callback = [items = std::move(items), that = weak(this)](
|
|
|
|
not_null<PeerData*> peer) {
|
|
|
|
App::main()->setForwardDraft(peer->id, items);
|
|
|
|
if (that) {
|
|
|
|
that->_cancelSelectionClicks.fire({});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Ui::show(Box<PeerListBox>(
|
|
|
|
std::make_unique<ChooseRecipientBoxController>(std::move(callback)),
|
|
|
|
[](not_null<PeerListBox*> box) {
|
|
|
|
box->addButton(langFactory(lng_cancel), [box] {
|
|
|
|
box->closeBox();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TopBar::performDelete() {
|
|
|
|
auto items = collectItems();
|
|
|
|
if (items.empty()) {
|
|
|
|
_cancelSelectionClicks.fire({});
|
|
|
|
} else {
|
|
|
|
Ui::show(Box<DeleteMessagesBox>(items));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
rpl::producer<QString> TitleValue(
|
|
|
|
const Section §ion,
|
2017-10-31 18:25:22 +00:00
|
|
|
not_null<PeerData*> peer) {
|
2017-09-30 18:26:45 +00:00
|
|
|
return Lang::Viewer([&] {
|
|
|
|
switch (section.type()) {
|
|
|
|
case Section::Type::Profile:
|
2017-10-31 18:25:22 +00:00
|
|
|
if (auto user = peer->asUser()) {
|
|
|
|
return user->botInfo
|
2017-09-30 18:26:45 +00:00
|
|
|
? lng_info_bot_title
|
|
|
|
: lng_info_user_title;
|
2017-10-31 18:25:22 +00:00
|
|
|
} else if (auto channel = peer->asChannel()) {
|
|
|
|
return channel->isMegagroup()
|
2017-09-30 18:26:45 +00:00
|
|
|
? lng_info_group_title
|
|
|
|
: lng_info_channel_title;
|
2017-10-31 18:25:22 +00:00
|
|
|
} else if (peer->isChat()) {
|
2017-09-30 18:26:45 +00:00
|
|
|
return lng_info_group_title;
|
|
|
|
}
|
|
|
|
Unexpected("Bad peer type in Info::TitleValue()");
|
|
|
|
|
|
|
|
case Section::Type::Media:
|
|
|
|
switch (section.mediaType()) {
|
|
|
|
case Section::MediaType::Photo:
|
|
|
|
return lng_media_type_photos;
|
|
|
|
case Section::MediaType::Video:
|
|
|
|
return lng_media_type_videos;
|
|
|
|
case Section::MediaType::MusicFile:
|
|
|
|
return lng_media_type_songs;
|
|
|
|
case Section::MediaType::File:
|
|
|
|
return lng_media_type_files;
|
|
|
|
case Section::MediaType::VoiceFile:
|
|
|
|
return lng_media_type_audios;
|
|
|
|
case Section::MediaType::Link:
|
|
|
|
return lng_media_type_links;
|
|
|
|
case Section::MediaType::RoundFile:
|
|
|
|
return lng_media_type_rounds;
|
|
|
|
}
|
|
|
|
Unexpected("Bad media type in Info::TitleValue()");
|
|
|
|
|
|
|
|
case Section::Type::CommonGroups:
|
|
|
|
return lng_profile_common_groups_section;
|
|
|
|
|
2017-11-17 17:02:49 +00:00
|
|
|
case Section::Type::Members:
|
|
|
|
return lng_profile_participants_section;
|
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
}
|
|
|
|
Unexpected("Bad section type in Info::TitleValue()");
|
|
|
|
}());
|
|
|
|
}
|
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
} // namespace Info
|