Added small preview to story statistics.
This commit is contained in:
parent
dc04a1afdb
commit
c1d20d16fd
|
@ -626,6 +626,15 @@ void InnerWidget::fill() {
|
||||||
Ui::AddSkip(inner);
|
Ui::AddSkip(inner);
|
||||||
Ui::AddDivider(inner);
|
Ui::AddDivider(inner);
|
||||||
}
|
}
|
||||||
|
} else if (_state.stats.story) {
|
||||||
|
if (const auto story = _peer->owner().stories().lookup(_storyId)) {
|
||||||
|
Ui::AddSkip(inner);
|
||||||
|
const auto preview = inner->add(
|
||||||
|
object_ptr<MessagePreview>(this, *story, QImage()));
|
||||||
|
preview->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
|
Ui::AddSkip(inner);
|
||||||
|
Ui::AddDivider(inner);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
FillOverview(inner, _state.stats);
|
FillOverview(inner, _state.stats);
|
||||||
FillStatistic(inner, descriptor, _state.stats);
|
FillStatistic(inner, descriptor, _state.stats);
|
||||||
|
|
|
@ -43,13 +43,14 @@ namespace {
|
||||||
[[nodiscard]] QImage PreparePreviewImage(
|
[[nodiscard]] QImage PreparePreviewImage(
|
||||||
QImage original,
|
QImage original,
|
||||||
ImageRoundRadius radius,
|
ImageRoundRadius radius,
|
||||||
|
int size,
|
||||||
bool spoiler) {
|
bool spoiler) {
|
||||||
if (original.width() * 10 < original.height()
|
if (original.width() * 10 < original.height()
|
||||||
|| original.height() * 10 < original.width()) {
|
|| original.height() * 10 < original.width()) {
|
||||||
return QImage();
|
return QImage();
|
||||||
}
|
}
|
||||||
const auto factor = style::DevicePixelRatio();
|
const auto factor = style::DevicePixelRatio();
|
||||||
const auto size = st::peerListBoxItem.photoSize * factor;
|
size *= factor;
|
||||||
const auto scaled = original.scaled(
|
const auto scaled = original.scaled(
|
||||||
QSize(size, size),
|
QSize(size, size),
|
||||||
Qt::KeepAspectRatioByExpanding,
|
Qt::KeepAspectRatioByExpanding,
|
||||||
|
@ -156,10 +157,10 @@ void MessagePreview::setInfo(int views, int shares, int reactions) {
|
||||||
: QString());
|
: QString());
|
||||||
_shares = Ui::Text::String(
|
_shares = Ui::Text::String(
|
||||||
st::statisticsHeaderTitleTextStyle,
|
st::statisticsHeaderTitleTextStyle,
|
||||||
(shares >= 0) ? Lang::FormatCountDecimal(shares) : QString());
|
(shares > 0) ? Lang::FormatCountDecimal(shares) : QString());
|
||||||
_reactions = Ui::Text::String(
|
_reactions = Ui::Text::String(
|
||||||
st::statisticsHeaderTitleTextStyle,
|
st::statisticsHeaderTitleTextStyle,
|
||||||
(reactions >= 0) ? Lang::FormatCountDecimal(reactions) : QString());
|
(reactions > 0) ? Lang::FormatCountDecimal(reactions) : QString());
|
||||||
_viewsWidth = (_views.maxWidth());
|
_viewsWidth = (_views.maxWidth());
|
||||||
_sharesWidth = (_shares.maxWidth());
|
_sharesWidth = (_shares.maxWidth());
|
||||||
_reactionsWidth = (_reactions.maxWidth());
|
_reactionsWidth = (_reactions.maxWidth());
|
||||||
|
@ -208,10 +209,40 @@ void MessagePreview::processPreview() {
|
||||||
} else if (computed.loaded) {
|
} else if (computed.loaded) {
|
||||||
_lifetimeDownload.destroy();
|
_lifetimeDownload.destroy();
|
||||||
}
|
}
|
||||||
_preview = PreparePreviewImage(
|
if (_storyId) {
|
||||||
computed.image->original(),
|
const auto line = st::dialogsStoriesFull.lineTwice;
|
||||||
_messageId ? ImageRoundRadius::Large : ImageRoundRadius::Ellipse,
|
const auto rect = Rect(Size(st::peerListBoxItem.photoSize));
|
||||||
!!_spoiler);
|
const auto penWidth = line / 2.;
|
||||||
|
const auto offset = 1.5 * penWidth * 2;
|
||||||
|
const auto preview = PreparePreviewImage(
|
||||||
|
computed.image->original(),
|
||||||
|
ImageRoundRadius::Ellipse,
|
||||||
|
st::peerListBoxItem.photoSize - offset * 2,
|
||||||
|
!!_spoiler);
|
||||||
|
auto image = QImage(
|
||||||
|
rect.size() * style::DevicePixelRatio(),
|
||||||
|
QImage::Format_ARGB32_Premultiplied);
|
||||||
|
image.fill(Qt::transparent);
|
||||||
|
{
|
||||||
|
auto p = QPainter(&image);
|
||||||
|
p.drawImage(offset, offset, preview);
|
||||||
|
auto hq = PainterHighQualityEnabler(p);
|
||||||
|
auto gradient = Ui::UnreadStoryOutlineGradient();
|
||||||
|
gradient.setStart(rect.topRight());
|
||||||
|
gradient.setFinalStop(rect.bottomLeft());
|
||||||
|
|
||||||
|
p.setPen(QPen(gradient, penWidth));
|
||||||
|
p.setBrush(Qt::NoBrush);
|
||||||
|
p.drawEllipse(rect - Margins(penWidth));
|
||||||
|
}
|
||||||
|
_preview = std::move(image);
|
||||||
|
} else {
|
||||||
|
_preview = PreparePreviewImage(
|
||||||
|
computed.image->original(),
|
||||||
|
ImageRoundRadius::Large,
|
||||||
|
st::peerListBoxItem.photoSize,
|
||||||
|
!!_spoiler);
|
||||||
|
}
|
||||||
}, _lifetimeDownload);
|
}, _lifetimeDownload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,17 +284,6 @@ void MessagePreview::paintEvent(QPaintEvent *e) {
|
||||||
_spoiler->index(crl::now(), paused)),
|
_spoiler->index(crl::now(), paused)),
|
||||||
_cornerCache);
|
_cornerCache);
|
||||||
}
|
}
|
||||||
if (_storyId) {
|
|
||||||
auto hq = PainterHighQualityEnabler(p);
|
|
||||||
const auto line = st::dialogsStoriesFull.lineTwice / 2.;
|
|
||||||
auto gradient = Ui::UnreadStoryOutlineGradient();
|
|
||||||
gradient.setStart(rect.topRight());
|
|
||||||
gradient.setFinalStop(rect.bottomLeft());
|
|
||||||
|
|
||||||
p.setPen(QPen(gradient, line));
|
|
||||||
p.setBrush(Qt::NoBrush);
|
|
||||||
p.drawEllipse(rect + Margins(1.5 * line));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const auto topTextTop = st::peerListBoxItem.namePosition.y();
|
const auto topTextTop = st::peerListBoxItem.namePosition.y();
|
||||||
const auto bottomTextTop = st::peerListBoxItem.statusPosition.y();
|
const auto bottomTextTop = st::peerListBoxItem.statusPosition.y();
|
||||||
|
|
Loading…
Reference in New Issue