2016-05-27 10:57:11 +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.
|
2016-05-27 10:57:11 +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
|
2016-05-27 10:57:11 +00:00
|
|
|
*/
|
|
|
|
#include "profile/profile_cover_drop_area.h"
|
|
|
|
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "ui/ui_utility.h"
|
2016-05-27 10:57:11 +00:00
|
|
|
#include "styles/style_profile.h"
|
|
|
|
|
|
|
|
namespace Profile {
|
|
|
|
|
|
|
|
CoverDropArea::CoverDropArea(QWidget *parent, const QString &title, const QString &subtitle) : TWidget(parent)
|
|
|
|
, _title(title)
|
|
|
|
, _subtitle(subtitle)
|
|
|
|
, _titleWidth(st::profileDropAreaTitleFont->width(_title))
|
|
|
|
, _subtitleWidth(st::profileDropAreaSubtitleFont->width(_subtitle)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoverDropArea::showAnimated() {
|
|
|
|
show();
|
|
|
|
_hiding = false;
|
|
|
|
setupAnimation();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoverDropArea::hideAnimated(HideFinishCallback &&callback) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_hideFinishCallback = std::move(callback);
|
2016-05-27 10:57:11 +00:00
|
|
|
_hiding = true;
|
|
|
|
setupAnimation();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoverDropArea::paintEvent(QPaintEvent *e) {
|
2022-09-16 20:23:27 +00:00
|
|
|
auto p = QPainter(this);
|
2016-05-27 10:57:11 +00:00
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
if (_a_appearance.animating()) {
|
|
|
|
p.setOpacity(_a_appearance.value(_hiding ? 0. : 1.));
|
2016-05-27 10:57:11 +00:00
|
|
|
p.drawPixmap(0, 0, _cache);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_cache.isNull()) {
|
|
|
|
_cache = QPixmap();
|
|
|
|
if (_hiding) {
|
|
|
|
hide();
|
2016-09-26 12:09:59 +00:00
|
|
|
if (_hideFinishCallback) {
|
|
|
|
_hideFinishCallback(this);
|
|
|
|
}
|
2016-05-27 10:57:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p.fillRect(e->rect(), st::profileDropAreaBg);
|
|
|
|
|
|
|
|
if (width() < st::profileDropAreaPadding.left() + st::profileDropAreaPadding.right()) return;
|
|
|
|
if (height() < st::profileDropAreaPadding.top() + st::profileDropAreaPadding.bottom()) return;
|
|
|
|
|
|
|
|
auto border = st::profileDropAreaBorderWidth;
|
|
|
|
auto &borderFg = st::profileDropAreaBorderFg;
|
|
|
|
auto inner = rect().marginsRemoved(st::profileDropAreaPadding);
|
|
|
|
p.fillRect(inner.x(), inner.y(), inner.width(), border, borderFg);
|
|
|
|
p.fillRect(inner.x(), inner.y() + inner.height() - border, inner.width(), border, borderFg);
|
|
|
|
p.fillRect(inner.x(), inner.y() + border, border, inner.height() - 2 * border, borderFg);
|
|
|
|
p.fillRect(inner.x() + inner.width() - border, inner.y() + border, border, inner.height() - 2 * border, borderFg);
|
|
|
|
|
|
|
|
int titleLeft = inner.x() + (inner.width() - _titleWidth) / 2;
|
|
|
|
int titleTop = inner.y() + st::profileDropAreaTitleTop + st::profileDropAreaTitleFont->ascent;
|
|
|
|
p.setFont(st::profileDropAreaTitleFont);
|
|
|
|
p.setPen(st::profileDropAreaFg);
|
|
|
|
p.drawText(titleLeft, titleTop, _title);
|
|
|
|
|
|
|
|
int subtitleLeft = inner.x() + (inner.width() - _subtitleWidth) / 2;
|
|
|
|
int subtitleTop = inner.y() + st::profileDropAreaSubtitleTop + st::profileDropAreaSubtitleFont->ascent;
|
|
|
|
p.setFont(st::profileDropAreaSubtitleFont);
|
|
|
|
p.setPen(st::profileDropAreaFg);
|
|
|
|
p.drawText(subtitleLeft, subtitleTop, _subtitle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoverDropArea::setupAnimation() {
|
|
|
|
if (_cache.isNull()) {
|
2017-12-26 12:41:48 +00:00
|
|
|
_cache = Ui::GrabWidget(this);
|
2016-05-27 10:57:11 +00:00
|
|
|
}
|
|
|
|
auto from = _hiding ? 1. : 0., to = _hiding ? 0. : 1.;
|
2017-12-26 12:41:48 +00:00
|
|
|
_a_appearance.start(
|
2019-04-02 09:13:30 +00:00
|
|
|
[=] { update(); },
|
2017-12-26 12:41:48 +00:00
|
|
|
from,
|
|
|
|
to,
|
|
|
|
st::profileDropAreaDuration);
|
2016-05-27 10:57:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Profile
|