2017-11-14 17:22:44 +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.
|
2017-11-14 17:22:44 +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
|
2017-11-14 17:22:44 +00:00
|
|
|
*/
|
|
|
|
#include "info/media/info_media_empty_widget.h"
|
|
|
|
|
|
|
|
#include "ui/widgets/labels.h"
|
|
|
|
#include "styles/style_info.h"
|
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
|
|
|
|
namespace Info {
|
|
|
|
namespace Media {
|
|
|
|
|
|
|
|
EmptyWidget::EmptyWidget(QWidget *parent)
|
|
|
|
: RpWidget(parent)
|
|
|
|
, _text(this, st::infoEmptyLabel) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmptyWidget::setFullHeight(rpl::producer<int> fullHeightValue) {
|
2017-12-22 07:05:20 +00:00
|
|
|
std::move(
|
|
|
|
fullHeightValue
|
|
|
|
) | rpl::start_with_next([this](int fullHeight) {
|
|
|
|
// Make icon center be on 1/3 height.
|
|
|
|
auto iconCenter = fullHeight / 3;
|
|
|
|
auto iconHeight = st::infoEmptyFile.height();
|
|
|
|
auto iconTop = iconCenter - iconHeight / 2;
|
|
|
|
_height = iconTop + st::infoEmptyIconTop;
|
|
|
|
resizeToWidth(width());
|
|
|
|
}, lifetime());
|
2017-11-14 17:22:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EmptyWidget::setType(Type type) {
|
|
|
|
_type = type;
|
|
|
|
_icon = [&] {
|
|
|
|
switch (_type) {
|
2020-08-23 19:42:28 +00:00
|
|
|
case Type::Photo:
|
|
|
|
case Type::GIF: return &st::infoEmptyPhoto;
|
2017-11-14 17:22:44 +00:00
|
|
|
case Type::Video: return &st::infoEmptyVideo;
|
|
|
|
case Type::MusicFile: return &st::infoEmptyAudio;
|
|
|
|
case Type::File: return &st::infoEmptyFile;
|
|
|
|
case Type::Link: return &st::infoEmptyLink;
|
2018-11-05 08:22:05 +00:00
|
|
|
case Type::RoundVoiceFile: return &st::infoEmptyVoice;
|
2017-11-14 17:22:44 +00:00
|
|
|
}
|
|
|
|
Unexpected("Bad type in EmptyWidget::setType()");
|
|
|
|
}();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmptyWidget::setSearchQuery(const QString &query) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_text->setText([&] {
|
2017-11-14 17:22:44 +00:00
|
|
|
switch (_type) {
|
|
|
|
case Type::Photo:
|
2019-06-19 15:09:03 +00:00
|
|
|
return tr::lng_media_photo_empty(tr::now);
|
2020-08-23 19:42:28 +00:00
|
|
|
case Type::GIF:
|
|
|
|
return tr::lng_media_gif_empty(tr::now);
|
2017-11-14 17:22:44 +00:00
|
|
|
case Type::Video:
|
2019-06-19 15:09:03 +00:00
|
|
|
return tr::lng_media_video_empty(tr::now);
|
2017-11-14 17:22:44 +00:00
|
|
|
case Type::MusicFile:
|
|
|
|
return query.isEmpty()
|
2019-06-19 15:09:03 +00:00
|
|
|
? tr::lng_media_song_empty(tr::now)
|
|
|
|
: tr::lng_media_song_empty_search(tr::now);
|
2017-11-14 17:22:44 +00:00
|
|
|
case Type::File:
|
|
|
|
return query.isEmpty()
|
2019-06-19 15:09:03 +00:00
|
|
|
? tr::lng_media_file_empty(tr::now)
|
|
|
|
: tr::lng_media_file_empty_search(tr::now);
|
2017-11-14 17:22:44 +00:00
|
|
|
case Type::Link:
|
|
|
|
return query.isEmpty()
|
2019-06-19 15:09:03 +00:00
|
|
|
? tr::lng_media_link_empty(tr::now)
|
|
|
|
: tr::lng_media_link_empty_search(tr::now);
|
2018-11-05 08:22:05 +00:00
|
|
|
case Type::RoundVoiceFile:
|
2019-06-19 15:09:03 +00:00
|
|
|
return tr::lng_media_audio_empty(tr::now);
|
2017-11-14 17:22:44 +00:00
|
|
|
}
|
|
|
|
Unexpected("Bad type in EmptyWidget::setSearchQuery()");
|
2019-06-19 15:09:03 +00:00
|
|
|
}());
|
2017-11-14 17:22:44 +00:00
|
|
|
resizeToWidth(width());
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmptyWidget::paintEvent(QPaintEvent *e) {
|
|
|
|
if (!_icon) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-16 20:23:27 +00:00
|
|
|
auto p = QPainter(this);
|
2017-11-14 17:22:44 +00:00
|
|
|
|
|
|
|
auto iconLeft = (width() - _icon->width()) / 2;
|
|
|
|
auto iconTop = height() - st::infoEmptyIconTop;
|
|
|
|
_icon->paint(p, iconLeft, iconTop, width());
|
|
|
|
}
|
|
|
|
|
|
|
|
int EmptyWidget::resizeGetHeight(int newWidth) {
|
|
|
|
auto labelTop = _height - st::infoEmptyLabelTop;
|
|
|
|
auto labelWidth = newWidth - 2 * st::infoEmptyLabelSkip;
|
|
|
|
_text->resizeToNaturalWidth(labelWidth);
|
|
|
|
|
|
|
|
auto labelLeft = (newWidth - _text->width()) / 2;
|
|
|
|
_text->moveToLeft(labelLeft, labelTop, newWidth);
|
|
|
|
|
|
|
|
update();
|
|
|
|
return _height;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Media
|
|
|
|
} // namespace Info
|