2015-02-03 15:02:46 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2015-02-03 15:02:46 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2015-02-03 15:02:46 +00:00
|
|
|
*/
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/background_box.h"
|
2015-02-03 15:02:46 +00:00
|
|
|
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2016-11-21 17:46:29 +00:00
|
|
|
#include "ui/effects/round_checkbox.h"
|
2018-10-23 09:44:42 +00:00
|
|
|
#include "ui/image/image.h"
|
2023-04-19 06:42:01 +00:00
|
|
|
#include "ui/chat/attach/attach_extensions.h"
|
2021-08-27 11:32:18 +00:00
|
|
|
#include "ui/chat/chat_theme.h"
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "ui/ui_utility.h"
|
2023-11-14 19:12:53 +00:00
|
|
|
#include "ui/vertical_list.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2019-02-09 13:36:07 +00:00
|
|
|
#include "apiwrap.h"
|
2019-02-07 16:36:30 +00:00
|
|
|
#include "mtproto/sender.h"
|
2023-04-19 06:42:01 +00:00
|
|
|
#include "core/file_utilities.h"
|
2023-04-18 12:47:31 +00:00
|
|
|
#include "data/data_peer.h"
|
2019-01-03 12:36:01 +00:00
|
|
|
#include "data/data_session.h"
|
2019-09-16 11:14:06 +00:00
|
|
|
#include "data/data_file_origin.h"
|
2020-04-15 14:06:34 +00:00
|
|
|
#include "data/data_document.h"
|
|
|
|
#include "data/data_document_media.h"
|
2019-02-07 16:36:30 +00:00
|
|
|
#include "boxes/background_preview_box.h"
|
2023-04-18 18:07:12 +00:00
|
|
|
#include "info/profile/info_profile_icon.h"
|
2021-10-18 21:36:55 +00:00
|
|
|
#include "ui/boxes/confirm_box.h"
|
2023-04-18 18:07:12 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2020-06-10 18:08:17 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2021-07-15 11:12:38 +00:00
|
|
|
#include "window/themes/window_theme.h"
|
2018-10-23 09:44:42 +00:00
|
|
|
#include "styles/style_overview.h"
|
2019-09-18 11:19:05 +00:00
|
|
|
#include "styles/style_layers.h"
|
2018-10-23 09:44:42 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2019-02-09 13:36:07 +00:00
|
|
|
#include "styles/style_chat_helpers.h"
|
2023-04-18 18:07:12 +00:00
|
|
|
#include "styles/style_info.h"
|
2015-02-03 15:02:46 +00:00
|
|
|
|
2019-01-16 12:25:29 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr auto kBackgroundsInRow = 3;
|
|
|
|
|
2019-02-05 09:32:54 +00:00
|
|
|
QImage TakeMiddleSample(QImage original, QSize size) {
|
|
|
|
size *= cIntRetinaFactor();
|
|
|
|
const auto from = original.size();
|
|
|
|
if (from.isEmpty()) {
|
|
|
|
auto result = original.scaled(size);
|
|
|
|
result.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto take = (from.width() * size.height()
|
|
|
|
> from.height() * size.width())
|
|
|
|
? QSize(size.width() * from.height() / size.height(), from.height())
|
|
|
|
: QSize(from.width(), size.height() * from.width() / size.width());
|
|
|
|
auto result = original.copy(
|
|
|
|
(from.width() - take.width()) / 2,
|
|
|
|
(from.height() - take.height()) / 2,
|
|
|
|
take.width(),
|
|
|
|
take.height()
|
|
|
|
).scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
|
|
|
result.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-01-16 12:25:29 +00:00
|
|
|
} // namespace
|
|
|
|
|
2021-07-15 11:12:38 +00:00
|
|
|
class BackgroundBox::Inner final : public Ui::RpWidget {
|
2017-03-07 14:03:07 +00:00
|
|
|
public:
|
2019-07-24 14:00:30 +00:00
|
|
|
Inner(
|
|
|
|
QWidget *parent,
|
2023-04-18 12:47:31 +00:00
|
|
|
not_null<Main::Session*> session,
|
|
|
|
PeerData *forPeer);
|
2020-05-21 10:32:10 +00:00
|
|
|
~Inner();
|
2017-03-07 14:03:07 +00:00
|
|
|
|
2023-04-18 12:47:31 +00:00
|
|
|
[[nodiscard]] rpl::producer<Data::WallPaper> chooseEvents() const;
|
|
|
|
[[nodiscard]] rpl::producer<Data::WallPaper> removeRequests() const;
|
|
|
|
|
|
|
|
[[nodiscard]] auto resolveResetCustomPaper() const
|
|
|
|
->std::optional<Data::WallPaper>;
|
2019-02-09 13:36:07 +00:00
|
|
|
|
|
|
|
void removePaper(const Data::WallPaper &data);
|
2017-03-07 14:03:07 +00:00
|
|
|
|
2020-05-21 10:32:10 +00:00
|
|
|
private:
|
2017-03-07 14:03:07 +00:00
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
|
|
|
|
2020-05-21 10:32:10 +00:00
|
|
|
void visibleTopBottomUpdated(
|
|
|
|
int visibleTop,
|
|
|
|
int visibleBottom) override;
|
|
|
|
|
2019-02-05 09:32:54 +00:00
|
|
|
struct Paper {
|
|
|
|
Data::WallPaper data;
|
2020-04-15 14:06:34 +00:00
|
|
|
mutable std::shared_ptr<Data::DocumentMedia> dataMedia;
|
2019-02-05 09:32:54 +00:00
|
|
|
mutable QPixmap thumbnail;
|
|
|
|
};
|
2019-02-09 13:36:07 +00:00
|
|
|
struct Selected {
|
|
|
|
int index = 0;
|
|
|
|
inline bool operator==(const Selected &other) const {
|
|
|
|
return index == other.index;
|
|
|
|
}
|
|
|
|
inline bool operator!=(const Selected &other) const {
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
struct DeleteSelected {
|
|
|
|
int index = 0;
|
|
|
|
inline bool operator==(const DeleteSelected &other) const {
|
|
|
|
return index == other.index;
|
|
|
|
}
|
|
|
|
inline bool operator!=(const DeleteSelected &other) const {
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
|
|
|
};
|
2020-08-31 09:04:17 +00:00
|
|
|
using Selection = std::variant<v::null_t, Selected, DeleteSelected>;
|
2019-02-09 13:36:07 +00:00
|
|
|
|
|
|
|
int getSelectionIndex(const Selection &selection) const;
|
|
|
|
void repaintPaper(int index);
|
|
|
|
void resizeToContentAndPreload();
|
2019-02-04 18:37:40 +00:00
|
|
|
void updatePapers();
|
2019-02-09 13:36:07 +00:00
|
|
|
void requestPapers();
|
2023-04-19 07:08:44 +00:00
|
|
|
void pushCustomPapers();
|
2019-02-04 18:37:40 +00:00
|
|
|
void sortPapers();
|
2019-01-28 13:59:49 +00:00
|
|
|
void paintPaper(
|
2022-09-16 20:23:27 +00:00
|
|
|
QPainter &p,
|
2019-02-05 09:32:54 +00:00
|
|
|
const Paper &paper,
|
2019-01-28 13:59:49 +00:00
|
|
|
int column,
|
|
|
|
int row) const;
|
2019-02-05 09:32:54 +00:00
|
|
|
void validatePaperThumbnail(const Paper &paper) const;
|
2017-03-07 14:03:07 +00:00
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
const not_null<Main::Session*> _session;
|
2023-04-18 12:47:31 +00:00
|
|
|
PeerData * const _forPeer = nullptr;
|
|
|
|
|
2019-11-27 08:02:56 +00:00
|
|
|
MTP::Sender _api;
|
2019-07-24 14:00:30 +00:00
|
|
|
|
2019-02-05 09:32:54 +00:00
|
|
|
std::vector<Paper> _papers;
|
2023-04-18 12:47:31 +00:00
|
|
|
uint64 _currentId = 0;
|
|
|
|
uint64 _insertedResetId = 0;
|
2017-03-07 14:03:07 +00:00
|
|
|
|
2019-02-09 13:36:07 +00:00
|
|
|
Selection _over;
|
|
|
|
Selection _overDown;
|
2019-01-16 12:25:29 +00:00
|
|
|
|
2017-03-07 14:03:07 +00:00
|
|
|
std::unique_ptr<Ui::RoundCheckbox> _check; // this is not a widget
|
2019-02-09 13:36:07 +00:00
|
|
|
rpl::event_stream<Data::WallPaper> _backgroundChosen;
|
|
|
|
rpl::event_stream<Data::WallPaper> _backgroundRemove;
|
2017-03-07 14:03:07 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-06-10 18:08:17 +00:00
|
|
|
BackgroundBox::BackgroundBox(
|
|
|
|
QWidget*,
|
2023-04-18 12:47:31 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
PeerData *forPeer)
|
|
|
|
: _controller(controller)
|
|
|
|
, _forPeer(forPeer) {
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundBox::prepare() {
|
2019-06-18 15:00:55 +00:00
|
|
|
setTitle(tr::lng_backgrounds_header());
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2019-06-18 16:53:27 +00:00
|
|
|
addButton(tr::lng_close(), [=] { closeBox(); });
|
2016-10-20 16:32:15 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
setDimensions(st::boxWideWidth, st::boxMaxListHeight);
|
|
|
|
|
2023-04-18 18:07:12 +00:00
|
|
|
auto wrap = object_ptr<Ui::VerticalLayout>(this);
|
|
|
|
const auto container = wrap.data();
|
|
|
|
|
2023-11-14 19:12:53 +00:00
|
|
|
Ui::AddSkip(container);
|
2023-04-18 18:07:12 +00:00
|
|
|
|
2023-11-14 20:59:21 +00:00
|
|
|
const auto button = container->add(object_ptr<Ui::SettingsButton>(
|
2023-04-18 18:07:12 +00:00
|
|
|
container,
|
|
|
|
tr::lng_settings_bg_from_file(),
|
|
|
|
st::infoProfileButton));
|
|
|
|
object_ptr<Info::Profile::FloatingIcon>(
|
|
|
|
button,
|
|
|
|
st::infoIconMediaPhoto,
|
|
|
|
st::infoSharedMediaButtonIconPosition);
|
|
|
|
|
2023-04-19 06:42:01 +00:00
|
|
|
button->setClickedCallback([=] {
|
|
|
|
chooseFromFile();
|
|
|
|
});
|
|
|
|
|
2023-11-14 19:12:53 +00:00
|
|
|
Ui::AddSkip(container);
|
|
|
|
Ui::AddDivider(container);
|
2023-04-18 18:07:12 +00:00
|
|
|
|
|
|
|
_inner = container->add(
|
|
|
|
object_ptr<Inner>(this, &_controller->session(), _forPeer));
|
|
|
|
|
|
|
|
container->resizeToWidth(st::boxWideWidth);
|
|
|
|
|
|
|
|
setInnerWidget(std::move(wrap), st::backgroundScroll);
|
|
|
|
setInnerTopSkip(st::lineWidth);
|
2019-02-09 13:36:07 +00:00
|
|
|
|
|
|
|
_inner->chooseEvents(
|
2019-07-24 14:00:30 +00:00
|
|
|
) | rpl::start_with_next([=](const Data::WallPaper &paper) {
|
2023-04-18 12:47:31 +00:00
|
|
|
chosen(paper);
|
2019-02-09 13:36:07 +00:00
|
|
|
}, _inner->lifetime());
|
|
|
|
|
|
|
|
_inner->removeRequests(
|
|
|
|
) | rpl::start_with_next([=](const Data::WallPaper &paper) {
|
|
|
|
removePaper(paper);
|
|
|
|
}, _inner->lifetime());
|
|
|
|
}
|
|
|
|
|
2023-04-19 06:42:01 +00:00
|
|
|
void BackgroundBox::chooseFromFile() {
|
|
|
|
const auto filterStart = _forPeer
|
|
|
|
? u"Image files (*"_q
|
|
|
|
: u"Theme files (*.tdesktop-theme *.tdesktop-palette *"_q;
|
|
|
|
auto filters = QStringList(
|
|
|
|
filterStart
|
|
|
|
+ Ui::ImageExtensions().join(u" *"_q)
|
|
|
|
+ u")"_q);
|
|
|
|
filters.push_back(FileDialog::AllFilesFilter());
|
|
|
|
const auto callback = [=](const FileDialog::OpenResult &result) {
|
|
|
|
if (result.paths.isEmpty() && result.remoteContent.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_forPeer && !result.paths.isEmpty()) {
|
|
|
|
const auto filePath = result.paths.front();
|
|
|
|
const auto hasExtension = [&](QLatin1String extension) {
|
|
|
|
return filePath.endsWith(extension, Qt::CaseInsensitive);
|
|
|
|
};
|
|
|
|
if (hasExtension(qstr(".tdesktop-theme"))
|
|
|
|
|| hasExtension(qstr(".tdesktop-palette"))) {
|
|
|
|
Window::Theme::Apply(filePath);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto image = Images::Read({
|
|
|
|
.path = result.paths.isEmpty() ? QString() : result.paths.front(),
|
|
|
|
.content = result.remoteContent,
|
|
|
|
.forceOpaque = true,
|
|
|
|
}).image;
|
|
|
|
if (image.isNull() || image.width() <= 0 || image.height() <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto local = Data::CustomWallPaper();
|
|
|
|
local.setLocalImageAsThumbnail(std::make_shared<Image>(
|
|
|
|
std::move(image)));
|
|
|
|
_controller->show(Box<BackgroundPreviewBox>(
|
|
|
|
_controller,
|
|
|
|
local,
|
|
|
|
BackgroundPreviewArgs{ _forPeer }));
|
|
|
|
};
|
|
|
|
FileDialog::GetOpenPath(
|
|
|
|
this,
|
|
|
|
tr::lng_choose_image(tr::now),
|
|
|
|
filters.join(u";;"_q),
|
|
|
|
crl::guard(this, callback));
|
|
|
|
}
|
|
|
|
|
2023-04-18 12:47:31 +00:00
|
|
|
bool BackgroundBox::hasDefaultForPeer() const {
|
|
|
|
Expects(_forPeer != nullptr);
|
|
|
|
|
|
|
|
const auto paper = _forPeer->wallPaper();
|
|
|
|
if (!paper) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
const auto reset = _inner->resolveResetCustomPaper();
|
|
|
|
Assert(reset.has_value());
|
|
|
|
return (paper->id() == reset->id());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BackgroundBox::chosenDefaultForPeer(
|
|
|
|
const Data::WallPaper &paper) const {
|
|
|
|
if (!_forPeer) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto reset = _inner->resolveResetCustomPaper();
|
|
|
|
Assert(reset.has_value());
|
|
|
|
return (paper.id() == reset->id());
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundBox::chosen(const Data::WallPaper &paper) {
|
|
|
|
if (chosenDefaultForPeer(paper)) {
|
|
|
|
if (!hasDefaultForPeer()) {
|
|
|
|
const auto reset = crl::guard(this, [=](Fn<void()> close) {
|
|
|
|
resetForPeer();
|
|
|
|
close();
|
|
|
|
});
|
|
|
|
_controller->show(Ui::MakeConfirmBox({
|
2023-06-22 15:29:11 +00:00
|
|
|
.text = tr::lng_background_sure_reset_default(),
|
2023-04-18 12:47:31 +00:00
|
|
|
.confirmed = reset,
|
2023-06-22 15:29:11 +00:00
|
|
|
.confirmText = tr::lng_background_reset_default(),
|
2023-04-18 12:47:31 +00:00
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
closeBox();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2023-05-02 09:33:19 +00:00
|
|
|
_controller->show(Box<BackgroundPreviewBox>(
|
|
|
|
_controller,
|
|
|
|
paper,
|
|
|
|
BackgroundPreviewArgs{ _forPeer }));
|
2023-04-18 12:47:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundBox::resetForPeer() {
|
|
|
|
const auto api = &_controller->session().api();
|
|
|
|
api->request(MTPmessages_SetChatWallPaper(
|
|
|
|
MTP_flags(0),
|
|
|
|
_forPeer->input,
|
|
|
|
MTPInputWallPaper(),
|
|
|
|
MTPWallPaperSettings(),
|
|
|
|
MTPint()
|
|
|
|
)).done([=](const MTPUpdates &result) {
|
|
|
|
api->applyUpdates(result);
|
|
|
|
}).send();
|
|
|
|
|
|
|
|
const auto weak = Ui::MakeWeak(this);
|
|
|
|
_forPeer->setWallPaper(std::nullopt);
|
|
|
|
if (weak) {
|
|
|
|
_controller->finishChatThemeEdit(_forPeer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-09 13:36:07 +00:00
|
|
|
void BackgroundBox::removePaper(const Data::WallPaper &paper) {
|
2020-06-10 18:08:17 +00:00
|
|
|
const auto session = &_controller->session();
|
2020-09-24 12:48:02 +00:00
|
|
|
const auto remove = [=, weak = Ui::MakeWeak(this)](Fn<void()> &&close) {
|
|
|
|
close();
|
2019-02-09 13:36:07 +00:00
|
|
|
if (weak) {
|
|
|
|
weak->_inner->removePaper(paper);
|
|
|
|
}
|
2019-07-24 14:00:30 +00:00
|
|
|
session->data().removeWallpaper(paper);
|
|
|
|
session->api().request(MTPaccount_SaveWallPaper(
|
2020-06-19 15:14:55 +00:00
|
|
|
paper.mtpInput(session),
|
2019-02-09 13:36:07 +00:00
|
|
|
MTP_bool(true),
|
|
|
|
paper.mtpSettings()
|
|
|
|
)).send();
|
|
|
|
};
|
2023-05-02 09:33:19 +00:00
|
|
|
_controller->show(Ui::MakeConfirmBox({
|
|
|
|
.text = tr::lng_background_sure_delete(),
|
|
|
|
.confirmed = remove,
|
|
|
|
.confirmText = tr::lng_selected_delete(),
|
|
|
|
}));
|
2016-10-20 16:32:15 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
BackgroundBox::Inner::Inner(
|
|
|
|
QWidget *parent,
|
2023-04-18 12:47:31 +00:00
|
|
|
not_null<Main::Session*> session,
|
|
|
|
PeerData *forPeer)
|
2019-07-24 14:00:30 +00:00
|
|
|
: RpWidget(parent)
|
|
|
|
, _session(session)
|
2023-04-18 12:47:31 +00:00
|
|
|
, _forPeer(forPeer)
|
2020-06-17 09:36:25 +00:00
|
|
|
, _api(&_session->mtp())
|
2019-01-03 14:39:19 +00:00
|
|
|
, _check(std::make_unique<Ui::RoundCheckbox>(st::overviewCheck, [=] { update(); })) {
|
2020-03-13 13:05:21 +00:00
|
|
|
_check->setChecked(true, anim::type::instant);
|
2023-04-18 12:47:31 +00:00
|
|
|
resize(st::boxWideWidth, 2 * (st::backgroundSize.height() + st::backgroundPadding) + st::backgroundPadding);
|
|
|
|
Window::Theme::IsNightModeValue(
|
|
|
|
) | rpl::start_with_next([=] {
|
2019-02-04 18:37:40 +00:00
|
|
|
updatePapers();
|
2023-04-18 12:47:31 +00:00
|
|
|
}, lifetime());
|
2019-02-09 13:36:07 +00:00
|
|
|
requestPapers();
|
2016-09-26 13:57:08 +00:00
|
|
|
|
2020-07-01 08:03:34 +00:00
|
|
|
_session->downloaderTaskFinished(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
update();
|
|
|
|
}, lifetime());
|
2021-07-15 11:12:38 +00:00
|
|
|
|
|
|
|
style::PaletteChanged(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
_check->invalidateCache();
|
|
|
|
}, lifetime());
|
|
|
|
|
2019-02-04 18:37:40 +00:00
|
|
|
using Update = Window::Theme::BackgroundUpdate;
|
2021-07-15 11:12:38 +00:00
|
|
|
Window::Theme::Background()->updates(
|
|
|
|
) | rpl::start_with_next([=](const Update &update) {
|
|
|
|
if (update.type == Update::Type::New) {
|
2019-02-04 18:37:40 +00:00
|
|
|
sortPapers();
|
2019-02-09 13:36:07 +00:00
|
|
|
requestPapers();
|
2019-02-04 18:37:40 +00:00
|
|
|
this->update();
|
2016-12-20 13:03:51 +00:00
|
|
|
}
|
2021-07-15 11:12:38 +00:00
|
|
|
}, lifetime());
|
|
|
|
|
2023-04-18 12:47:31 +00:00
|
|
|
|
2015-02-03 15:02:46 +00:00
|
|
|
setMouseTracking(true);
|
|
|
|
}
|
|
|
|
|
2019-02-09 13:36:07 +00:00
|
|
|
void BackgroundBox::Inner::requestPapers() {
|
2019-11-27 08:02:56 +00:00
|
|
|
_api.request(MTPaccount_GetWallPapers(
|
2021-08-25 08:15:05 +00:00
|
|
|
MTP_long(_session->data().wallpapersHash())
|
2019-02-09 13:36:07 +00:00
|
|
|
)).done([=](const MTPaccount_WallPapers &result) {
|
2019-07-24 14:00:30 +00:00
|
|
|
if (_session->data().updateWallpapers(result)) {
|
2019-02-09 13:36:07 +00:00
|
|
|
updatePapers();
|
|
|
|
}
|
|
|
|
}).send();
|
2019-02-04 18:37:40 +00:00
|
|
|
}
|
|
|
|
|
2023-04-18 12:47:31 +00:00
|
|
|
auto BackgroundBox::Inner::resolveResetCustomPaper() const
|
|
|
|
-> std::optional<Data::WallPaper> {
|
|
|
|
if (!_forPeer) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
const auto nonCustom = Window::Theme::Background()->paper();
|
|
|
|
const auto themeEmoji = _forPeer->themeEmoji();
|
|
|
|
if (themeEmoji.isEmpty()) {
|
|
|
|
return nonCustom;
|
|
|
|
}
|
|
|
|
const auto &themes = _forPeer->owner().cloudThemes();
|
|
|
|
const auto theme = themes.themeForEmoji(themeEmoji);
|
|
|
|
if (!theme) {
|
|
|
|
return nonCustom;
|
|
|
|
}
|
|
|
|
using Type = Data::CloudTheme::Type;
|
|
|
|
const auto dark = Window::Theme::IsNightMode();
|
|
|
|
const auto i = theme->settings.find(dark ? Type::Dark : Type::Light);
|
|
|
|
if (i != end(theme->settings) && i->second.paper) {
|
|
|
|
return *i->second.paper;
|
|
|
|
}
|
|
|
|
return nonCustom;
|
|
|
|
}
|
|
|
|
|
2023-04-19 07:08:44 +00:00
|
|
|
void BackgroundBox::Inner::pushCustomPapers() {
|
|
|
|
auto customId = uint64();
|
|
|
|
if (const auto custom = _forPeer ? _forPeer->wallPaper() : nullptr) {
|
|
|
|
customId = custom->id();
|
|
|
|
const auto j = ranges::find(
|
|
|
|
_papers,
|
|
|
|
custom->id(),
|
|
|
|
[](const Paper &paper) { return paper.data.id(); });
|
|
|
|
if (j != end(_papers)) {
|
|
|
|
j->data = j->data.withParamsFrom(*custom);
|
|
|
|
} else {
|
|
|
|
_papers.insert(begin(_papers), Paper{ *custom });
|
|
|
|
}
|
|
|
|
}
|
2023-04-18 12:47:31 +00:00
|
|
|
if (const auto reset = resolveResetCustomPaper()) {
|
|
|
|
_insertedResetId = reset->id();
|
|
|
|
const auto j = ranges::find(
|
|
|
|
_papers,
|
|
|
|
_insertedResetId,
|
|
|
|
[](const Paper &paper) { return paper.data.id(); });
|
|
|
|
if (j != end(_papers)) {
|
2023-04-19 07:08:44 +00:00
|
|
|
if (_insertedResetId != customId) {
|
|
|
|
j->data = j->data.withParamsFrom(*reset);
|
|
|
|
}
|
2023-04-18 12:47:31 +00:00
|
|
|
} else {
|
|
|
|
_papers.insert(begin(_papers), Paper{ *reset });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-04 18:37:40 +00:00
|
|
|
void BackgroundBox::Inner::sortPapers() {
|
2023-04-18 12:47:31 +00:00
|
|
|
const auto currentCustom = _forPeer ? _forPeer->wallPaper() : nullptr;
|
|
|
|
_currentId = currentCustom
|
|
|
|
? currentCustom->id()
|
|
|
|
: _insertedResetId
|
|
|
|
? _insertedResetId
|
|
|
|
: Window::Theme::Background()->id();
|
|
|
|
const auto dark = Window::Theme::IsNightMode();
|
2019-02-04 18:37:40 +00:00
|
|
|
ranges::stable_sort(_papers, std::greater<>(), [&](const Paper &paper) {
|
2019-02-05 09:32:54 +00:00
|
|
|
const auto &data = paper.data;
|
2019-02-04 18:37:40 +00:00
|
|
|
return std::make_tuple(
|
2023-04-18 12:47:31 +00:00
|
|
|
_insertedResetId && (_insertedResetId == data.id()),
|
|
|
|
data.id() == _currentId,
|
|
|
|
dark ? data.isDark() : !data.isDark(),
|
2021-07-23 12:16:22 +00:00
|
|
|
Data::IsDefaultWallPaper(data),
|
2021-07-23 09:16:33 +00:00
|
|
|
!data.isDefault() && !Data::IsLegacy1DefaultWallPaper(data),
|
2021-08-31 19:10:39 +00:00
|
|
|
Data::IsLegacy3DefaultWallPaper(data),
|
2021-07-23 09:16:33 +00:00
|
|
|
Data::IsLegacy2DefaultWallPaper(data),
|
|
|
|
Data::IsLegacy1DefaultWallPaper(data));
|
2019-02-04 18:37:40 +00:00
|
|
|
});
|
2023-04-18 12:47:31 +00:00
|
|
|
if (!_papers.empty()
|
|
|
|
&& _papers.front().data.id() == _currentId
|
|
|
|
&& !currentCustom
|
|
|
|
&& !_insertedResetId) {
|
2019-02-07 16:36:30 +00:00
|
|
|
_papers.front().data = _papers.front().data.withParamsFrom(
|
|
|
|
Window::Theme::Background()->paper());
|
|
|
|
}
|
2019-02-04 18:37:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundBox::Inner::updatePapers() {
|
2023-04-18 12:47:31 +00:00
|
|
|
if (_session->data().wallpapers().empty()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-02-09 13:36:07 +00:00
|
|
|
_over = _overDown = Selection();
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
_papers = _session->data().wallpapers(
|
2023-04-19 07:08:44 +00:00
|
|
|
) | ranges::views::filter([&](const Data::WallPaper &paper) {
|
|
|
|
return (!paper.isPattern() || !paper.backgroundColors().empty())
|
|
|
|
&& (!_forPeer
|
|
|
|
|| (!Data::IsDefaultWallPaper(paper)
|
|
|
|
&& (Data::IsCloudWallPaper(paper)
|
|
|
|
|| Data::IsCustomWallPaper(paper))));
|
2021-03-13 12:12:08 +00:00
|
|
|
}) | ranges::views::transform([](const Data::WallPaper &paper) {
|
2019-02-05 09:32:54 +00:00
|
|
|
return Paper{ paper };
|
|
|
|
}) | ranges::to_vector;
|
2023-04-19 07:08:44 +00:00
|
|
|
pushCustomPapers();
|
2019-02-04 18:37:40 +00:00
|
|
|
sortPapers();
|
2019-02-09 13:36:07 +00:00
|
|
|
resizeToContentAndPreload();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundBox::Inner::resizeToContentAndPreload() {
|
2019-02-04 18:37:40 +00:00
|
|
|
const auto count = _papers.size();
|
2019-01-16 12:25:29 +00:00
|
|
|
const auto rows = (count / kBackgroundsInRow)
|
|
|
|
+ (count % kBackgroundsInRow ? 1 : 0);
|
2015-02-03 15:02:46 +00:00
|
|
|
|
2020-04-15 14:06:34 +00:00
|
|
|
resize(
|
|
|
|
st::boxWideWidth,
|
|
|
|
(rows * (st::backgroundSize.height() + st::backgroundPadding)
|
|
|
|
+ st::backgroundPadding));
|
2015-02-03 15:02:46 +00:00
|
|
|
|
2019-01-16 12:25:29 +00:00
|
|
|
const auto preload = kBackgroundsInRow * 3;
|
2021-03-13 12:12:08 +00:00
|
|
|
for (const auto &paper : _papers | ranges::views::take(preload)) {
|
2020-05-29 14:08:18 +00:00
|
|
|
if (!paper.data.localThumbnail() && !paper.dataMedia) {
|
|
|
|
if (const auto document = paper.data.document()) {
|
2020-04-15 14:06:34 +00:00
|
|
|
paper.dataMedia = document->createMediaView();
|
|
|
|
paper.dataMedia->thumbnailWanted(paper.data.fileOrigin());
|
|
|
|
}
|
|
|
|
}
|
2015-02-03 15:02:46 +00:00
|
|
|
}
|
2019-02-09 13:36:07 +00:00
|
|
|
update();
|
2015-02-03 15:02:46 +00:00
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void BackgroundBox::Inner::paintEvent(QPaintEvent *e) {
|
2015-02-03 15:02:46 +00:00
|
|
|
QRect r(e->rect());
|
2022-09-16 20:23:27 +00:00
|
|
|
auto p = QPainter(this);
|
2015-02-03 15:02:46 +00:00
|
|
|
|
2019-02-04 18:37:40 +00:00
|
|
|
if (_papers.empty()) {
|
2016-12-13 17:07:56 +00:00
|
|
|
p.setFont(st::noContactsFont);
|
|
|
|
p.setPen(st::noContactsColor);
|
2019-06-19 15:09:03 +00:00
|
|
|
p.drawText(QRect(0, 0, width(), st::noContactsHeight), tr::lng_contacts_loading(tr::now), style::al_center);
|
2019-01-16 12:25:29 +00:00
|
|
|
return;
|
2015-02-03 15:02:46 +00:00
|
|
|
}
|
2019-01-16 12:25:29 +00:00
|
|
|
auto row = 0;
|
|
|
|
auto column = 0;
|
2019-02-04 18:37:40 +00:00
|
|
|
for (const auto &paper : _papers) {
|
2019-01-16 12:25:29 +00:00
|
|
|
const auto increment = gsl::finally([&] {
|
|
|
|
++column;
|
|
|
|
if (column == kBackgroundsInRow) {
|
|
|
|
column = 0;
|
|
|
|
++row;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if ((st::backgroundSize.height() + st::backgroundPadding) * (row + 1) <= r.top()) {
|
|
|
|
continue;
|
2019-01-28 13:59:49 +00:00
|
|
|
} else if ((st::backgroundSize.height() + st::backgroundPadding) * row >= r.top() + r.height()) {
|
|
|
|
break;
|
2019-01-16 12:25:29 +00:00
|
|
|
}
|
2019-01-28 13:59:49 +00:00
|
|
|
paintPaper(p, paper, column, row);
|
|
|
|
}
|
|
|
|
}
|
2015-02-03 15:02:46 +00:00
|
|
|
|
2019-02-05 09:32:54 +00:00
|
|
|
void BackgroundBox::Inner::validatePaperThumbnail(
|
|
|
|
const Paper &paper) const {
|
|
|
|
if (!paper.thumbnail.isNull()) {
|
|
|
|
return;
|
2020-04-15 14:06:34 +00:00
|
|
|
}
|
|
|
|
const auto localThumbnail = paper.data.localThumbnail();
|
|
|
|
if (!localThumbnail) {
|
|
|
|
if (const auto document = paper.data.document()) {
|
|
|
|
if (!paper.dataMedia) {
|
|
|
|
paper.dataMedia = document->createMediaView();
|
|
|
|
paper.dataMedia->thumbnailWanted(paper.data.fileOrigin());
|
|
|
|
}
|
2021-08-13 12:58:38 +00:00
|
|
|
if (!paper.dataMedia->thumbnail()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (!paper.data.backgroundColors().empty()) {
|
|
|
|
paper.thumbnail = Ui::PixmapFromImage(
|
2021-08-27 11:32:18 +00:00
|
|
|
Ui::GenerateBackgroundImage(
|
2021-08-13 12:58:38 +00:00
|
|
|
st::backgroundSize * cIntRetinaFactor(),
|
|
|
|
paper.data.backgroundColors(),
|
|
|
|
paper.data.gradientRotation()));
|
|
|
|
paper.thumbnail.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
return;
|
|
|
|
} else {
|
2020-04-15 14:06:34 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-02-05 09:32:54 +00:00
|
|
|
}
|
2020-04-15 14:06:34 +00:00
|
|
|
const auto thumbnail = localThumbnail
|
|
|
|
? localThumbnail
|
|
|
|
: paper.dataMedia->thumbnail();
|
2019-02-05 09:32:54 +00:00
|
|
|
auto original = thumbnail->original();
|
|
|
|
if (paper.data.isPattern()) {
|
2021-08-27 11:32:18 +00:00
|
|
|
original = Ui::PreparePatternImage(
|
2019-02-05 09:32:54 +00:00
|
|
|
std::move(original),
|
2021-08-12 14:51:44 +00:00
|
|
|
paper.data.backgroundColors(),
|
|
|
|
paper.data.gradientRotation(),
|
|
|
|
paper.data.patternOpacity());
|
2019-02-05 09:32:54 +00:00
|
|
|
}
|
2021-05-07 14:33:53 +00:00
|
|
|
paper.thumbnail = Ui::PixmapFromImage(TakeMiddleSample(
|
2019-02-05 09:32:54 +00:00
|
|
|
original,
|
|
|
|
st::backgroundSize));
|
|
|
|
paper.thumbnail.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
}
|
|
|
|
|
2019-01-28 13:59:49 +00:00
|
|
|
void BackgroundBox::Inner::paintPaper(
|
2022-09-16 20:23:27 +00:00
|
|
|
QPainter &p,
|
2019-02-05 09:32:54 +00:00
|
|
|
const Paper &paper,
|
2019-01-28 13:59:49 +00:00
|
|
|
int column,
|
|
|
|
int row) const {
|
|
|
|
const auto x = st::backgroundPadding + column * (st::backgroundSize.width() + st::backgroundPadding);
|
|
|
|
const auto y = st::backgroundPadding + row * (st::backgroundSize.height() + st::backgroundPadding);
|
2019-02-05 09:32:54 +00:00
|
|
|
validatePaperThumbnail(paper);
|
|
|
|
if (!paper.thumbnail.isNull()) {
|
|
|
|
p.drawPixmap(x, y, paper.thumbnail);
|
|
|
|
}
|
2019-01-28 13:59:49 +00:00
|
|
|
|
2020-08-31 09:04:17 +00:00
|
|
|
const auto over = !v::is_null(_overDown) ? _overDown : _over;
|
2023-04-18 12:47:31 +00:00
|
|
|
if (paper.data.id() == _currentId) {
|
2019-01-28 13:59:49 +00:00
|
|
|
const auto checkLeft = x + st::backgroundSize.width() - st::overviewCheckSkip - st::overviewCheck.size;
|
|
|
|
const auto checkTop = y + st::backgroundSize.height() - st::overviewCheckSkip - st::overviewCheck.size;
|
2019-09-02 12:24:51 +00:00
|
|
|
_check->paint(p, checkLeft, checkTop, width());
|
2019-02-09 13:36:07 +00:00
|
|
|
} else if (Data::IsCloudWallPaper(paper.data)
|
|
|
|
&& !Data::IsDefaultWallPaper(paper.data)
|
2021-07-23 09:16:33 +00:00
|
|
|
&& !Data::IsLegacy2DefaultWallPaper(paper.data)
|
2021-08-31 19:10:39 +00:00
|
|
|
&& !Data::IsLegacy3DefaultWallPaper(paper.data)
|
2020-08-31 09:04:17 +00:00
|
|
|
&& !v::is_null(over)
|
2019-02-09 13:36:07 +00:00
|
|
|
&& (&paper == &_papers[getSelectionIndex(over)])) {
|
2020-08-31 09:04:17 +00:00
|
|
|
const auto deleteSelected = v::is<DeleteSelected>(over);
|
2019-02-09 13:36:07 +00:00
|
|
|
const auto deletePos = QPoint(x + st::backgroundSize.width() - st::stickerPanDeleteIconBg.width(), y);
|
|
|
|
p.setOpacity(deleteSelected ? st::stickerPanDeleteOpacityBgOver : st::stickerPanDeleteOpacityBg);
|
|
|
|
st::stickerPanDeleteIconBg.paint(p, deletePos, width());
|
|
|
|
p.setOpacity(deleteSelected ? st::stickerPanDeleteOpacityFgOver : st::stickerPanDeleteOpacityFg);
|
|
|
|
st::stickerPanDeleteIconFg.paint(p, deletePos, width());
|
|
|
|
p.setOpacity(1.);
|
2019-01-16 12:25:29 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-03 15:02:46 +00:00
|
|
|
|
2019-01-16 12:25:29 +00:00
|
|
|
void BackgroundBox::Inner::mouseMoveEvent(QMouseEvent *e) {
|
|
|
|
const auto newOver = [&] {
|
|
|
|
const auto x = e->pos().x();
|
|
|
|
const auto y = e->pos().y();
|
|
|
|
const auto width = st::backgroundSize.width();
|
|
|
|
const auto height = st::backgroundSize.height();
|
|
|
|
const auto skip = st::backgroundPadding;
|
|
|
|
const auto row = int((y - skip) / (height + skip));
|
|
|
|
const auto column = int((x - skip) / (width + skip));
|
2019-02-09 13:36:07 +00:00
|
|
|
const auto result = row * kBackgroundsInRow + column;
|
2019-01-16 12:25:29 +00:00
|
|
|
if (y - row * (height + skip) > skip + height) {
|
2019-02-09 13:36:07 +00:00
|
|
|
return Selection();
|
2019-01-16 12:25:29 +00:00
|
|
|
} else if (x - column * (width + skip) > skip + width) {
|
2019-02-09 13:36:07 +00:00
|
|
|
return Selection();
|
|
|
|
} else if (result >= _papers.size()) {
|
|
|
|
return Selection();
|
2019-01-16 12:25:29 +00:00
|
|
|
}
|
2021-07-23 09:16:33 +00:00
|
|
|
auto &data = _papers[result].data;
|
2019-02-09 13:36:07 +00:00
|
|
|
const auto deleteLeft = (column + 1) * (width + skip)
|
|
|
|
- st::stickerPanDeleteIconBg.width();
|
|
|
|
const auto deleteBottom = row * (height + skip) + skip
|
|
|
|
+ st::stickerPanDeleteIconBg.height();
|
|
|
|
const auto inDelete = (x >= deleteLeft)
|
|
|
|
&& (y < deleteBottom)
|
2021-07-23 09:16:33 +00:00
|
|
|
&& Data::IsCloudWallPaper(data)
|
|
|
|
&& !Data::IsDefaultWallPaper(data)
|
|
|
|
&& !Data::IsLegacy2DefaultWallPaper(data)
|
2021-08-31 19:10:39 +00:00
|
|
|
&& !Data::IsLegacy3DefaultWallPaper(data)
|
2023-04-18 12:47:31 +00:00
|
|
|
&& (_currentId != data.id());
|
2019-02-09 13:36:07 +00:00
|
|
|
return (result >= _papers.size())
|
|
|
|
? Selection()
|
|
|
|
: inDelete
|
|
|
|
? Selection(DeleteSelected{ result })
|
|
|
|
: Selection(Selected{ result });
|
2019-01-16 12:25:29 +00:00
|
|
|
}();
|
|
|
|
if (_over != newOver) {
|
2019-02-09 13:36:07 +00:00
|
|
|
repaintPaper(getSelectionIndex(_over));
|
2015-02-03 15:02:46 +00:00
|
|
|
_over = newOver;
|
2019-02-09 13:36:07 +00:00
|
|
|
repaintPaper(getSelectionIndex(_over));
|
2020-08-31 09:04:17 +00:00
|
|
|
setCursor((!v::is_null(_over) || !v::is_null(_overDown))
|
2019-01-16 12:25:29 +00:00
|
|
|
? style::cur_pointer
|
|
|
|
: style::cur_default);
|
2015-02-03 15:02:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-09 13:36:07 +00:00
|
|
|
void BackgroundBox::Inner::repaintPaper(int index) {
|
|
|
|
if (index < 0 || index >= _papers.size()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto row = (index / kBackgroundsInRow);
|
|
|
|
const auto column = (index % kBackgroundsInRow);
|
|
|
|
const auto width = st::backgroundSize.width();
|
|
|
|
const auto height = st::backgroundSize.height();
|
|
|
|
const auto skip = st::backgroundPadding;
|
|
|
|
update(
|
|
|
|
(width + skip) * column + skip,
|
|
|
|
(height + skip) * row + skip,
|
|
|
|
width,
|
|
|
|
height);
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void BackgroundBox::Inner::mousePressEvent(QMouseEvent *e) {
|
2015-02-03 15:02:46 +00:00
|
|
|
_overDown = _over;
|
|
|
|
}
|
|
|
|
|
2019-02-09 13:36:07 +00:00
|
|
|
int BackgroundBox::Inner::getSelectionIndex(
|
|
|
|
const Selection &selection) const {
|
2020-08-31 09:04:17 +00:00
|
|
|
return v::match(selection, [](const Selected &data) {
|
2019-02-09 13:36:07 +00:00
|
|
|
return data.index;
|
|
|
|
}, [](const DeleteSelected &data) {
|
|
|
|
return data.index;
|
2020-08-31 08:14:53 +00:00
|
|
|
}, [](v::null_t) {
|
2019-02-09 13:36:07 +00:00
|
|
|
return -1;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-10-20 16:32:15 +00:00
|
|
|
void BackgroundBox::Inner::mouseReleaseEvent(QMouseEvent *e) {
|
2020-08-31 09:04:17 +00:00
|
|
|
if (base::take(_overDown) == _over && !v::is_null(_over)) {
|
2019-02-09 13:36:07 +00:00
|
|
|
const auto index = getSelectionIndex(_over);
|
|
|
|
if (index >= 0 && index < _papers.size()) {
|
2020-08-31 09:04:17 +00:00
|
|
|
if (std::get_if<DeleteSelected>(&_over)) {
|
2019-02-09 13:36:07 +00:00
|
|
|
_backgroundRemove.fire_copy(_papers[index].data);
|
2020-08-31 09:04:17 +00:00
|
|
|
} else if (std::get_if<Selected>(&_over)) {
|
2020-05-21 10:32:10 +00:00
|
|
|
auto &paper = _papers[index];
|
|
|
|
if (!paper.dataMedia) {
|
|
|
|
if (const auto document = paper.data.document()) {
|
|
|
|
// Keep it alive while it is on the screen.
|
|
|
|
paper.dataMedia = document->createMediaView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_backgroundChosen.fire_copy(paper.data);
|
2019-02-09 13:36:07 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
2020-08-31 09:04:17 +00:00
|
|
|
} else if (v::is_null(_over)) {
|
2015-02-03 15:02:46 +00:00
|
|
|
setCursor(style::cur_default);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-21 10:32:10 +00:00
|
|
|
void BackgroundBox::Inner::visibleTopBottomUpdated(
|
|
|
|
int visibleTop,
|
|
|
|
int visibleBottom) {
|
|
|
|
for (auto i = 0, count = int(_papers.size()); i != count; ++i) {
|
|
|
|
const auto row = (i / kBackgroundsInRow);
|
|
|
|
const auto height = st::backgroundSize.height();
|
|
|
|
const auto skip = st::backgroundPadding;
|
|
|
|
const auto top = skip + row * (height + skip);
|
|
|
|
const auto bottom = top + height;
|
|
|
|
if ((bottom <= visibleTop || top >= visibleBottom)
|
|
|
|
&& !_papers[i].thumbnail.isNull()) {
|
|
|
|
_papers[i].dataMedia = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-09 13:36:07 +00:00
|
|
|
rpl::producer<Data::WallPaper> BackgroundBox::Inner::chooseEvents() const {
|
|
|
|
return _backgroundChosen.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto BackgroundBox::Inner::removeRequests() const
|
|
|
|
-> rpl::producer<Data::WallPaper> {
|
|
|
|
return _backgroundRemove.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundBox::Inner::removePaper(const Data::WallPaper &data) {
|
|
|
|
const auto i = ranges::find(
|
|
|
|
_papers,
|
|
|
|
data.id(),
|
|
|
|
[](const Paper &paper) { return paper.data.id(); });
|
|
|
|
if (i != end(_papers)) {
|
|
|
|
_papers.erase(i);
|
|
|
|
_over = _overDown = Selection();
|
|
|
|
resizeToContentAndPreload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-21 16:24:23 +00:00
|
|
|
BackgroundBox::Inner::~Inner() = default;
|