mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added button to media viewer for media from sponsored messages.
This commit is contained in:
parent
73609fe5b2
commit
0477d43fbb
3 changed files with 100 additions and 2 deletions
|
@ -1051,3 +1051,12 @@ storiesRepostSimpleStyle: QuoteStyle(defaultQuoteStyle) {
|
||||||
storiesRepostIcon: icon {{ "mediaview/mini_repost", windowFg }};
|
storiesRepostIcon: icon {{ "mediaview/mini_repost", windowFg }};
|
||||||
storiesRepostIconPadding: margins(0px, 4px, 2px, 0px);
|
storiesRepostIconPadding: margins(0px, 4px, 2px, 0px);
|
||||||
storiesRepostUserpicPadding: margins(0px, 1px, 4px, 0px);
|
storiesRepostUserpicPadding: margins(0px, 1px, 4px, 0px);
|
||||||
|
|
||||||
|
mediaviewSponsoredButton: RoundButton(defaultActiveButton) {
|
||||||
|
textFg: mediaviewPlaybackIconFg;
|
||||||
|
textFgOver: mediaviewPlaybackIconFg;
|
||||||
|
textBg: mediaviewSaveMsgBg;
|
||||||
|
textBgOver: mediaviewSaveMsgBg;
|
||||||
|
|
||||||
|
ripple: universalRippleAnimation;
|
||||||
|
}
|
||||||
|
|
|
@ -99,6 +99,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include <QtGui/QGuiApplication>
|
#include <QtGui/QGuiApplication>
|
||||||
#include <QtGui/QWindow>
|
#include <QtGui/QWindow>
|
||||||
#include <QtGui/QScreen>
|
#include <QtGui/QScreen>
|
||||||
|
#include <QGraphicsOpacityEffect>
|
||||||
|
|
||||||
#include <kurlmimedata.h>
|
#include <kurlmimedata.h>
|
||||||
|
|
||||||
|
@ -750,6 +751,8 @@ void OverlayWidget::setupWindow() {
|
||||||
&& (widgetPoint.y() > st::mediaviewHeaderTop)
|
&& (widgetPoint.y() > st::mediaviewHeaderTop)
|
||||||
&& QRect(_x, _y, _w, _h).contains(widgetPoint)) {
|
&& QRect(_x, _y, _w, _h).contains(widgetPoint)) {
|
||||||
} else if (_stories && _stories->ignoreWindowMove(widgetPoint)) {
|
} else if (_stories && _stories->ignoreWindowMove(widgetPoint)) {
|
||||||
|
} else if (_sponsoredButton
|
||||||
|
&& _sponsoredButton->geometry().contains(widgetPoint)) {
|
||||||
} else if (_windowed) {
|
} else if (_windowed) {
|
||||||
result |= Flag::Move;
|
result |= Flag::Move;
|
||||||
}
|
}
|
||||||
|
@ -1421,7 +1424,9 @@ void OverlayWidget::resizeCenteredControls() {
|
||||||
_groupThumbsTop = _groupThumbs ? (height() - _groupThumbs->height()) : 0;
|
_groupThumbsTop = _groupThumbs ? (height() - _groupThumbs->height()) : 0;
|
||||||
|
|
||||||
refreshClipControllerGeometry();
|
refreshClipControllerGeometry();
|
||||||
|
refreshSponsoredButtonGeometry();
|
||||||
refreshCaptionGeometry();
|
refreshCaptionGeometry();
|
||||||
|
refreshSponsoredButtonWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverlayWidget::refreshCaptionGeometry() {
|
void OverlayWidget::refreshCaptionGeometry() {
|
||||||
|
@ -1443,6 +1448,8 @@ void OverlayWidget::refreshCaptionGeometry() {
|
||||||
}
|
}
|
||||||
const auto captionBottom = _stories
|
const auto captionBottom = _stories
|
||||||
? (_y + _h)
|
? (_y + _h)
|
||||||
|
: _sponsoredButton
|
||||||
|
? (_sponsoredButton->y() - st::mediaviewCaptionMargin.height())
|
||||||
: (_streamed && _streamed->controls)
|
: (_streamed && _streamed->controls)
|
||||||
? (_streamed->controls->y() - st::mediaviewCaptionMargin.height())
|
? (_streamed->controls->y() - st::mediaviewCaptionMargin.height())
|
||||||
: _groupThumbs
|
: _groupThumbs
|
||||||
|
@ -1487,6 +1494,41 @@ void OverlayWidget::refreshCaptionGeometry() {
|
||||||
captionHeight);
|
captionHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OverlayWidget::refreshSponsoredButtonGeometry() {
|
||||||
|
if (!_sponsoredButton) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto controllerBottom = (_groupThumbs && !_fullScreenVideo)
|
||||||
|
? _groupThumbsTop
|
||||||
|
: height();
|
||||||
|
const auto skip = st::mediaviewCaptionPadding.bottom();
|
||||||
|
const auto captionRect = captionGeometry();
|
||||||
|
_sponsoredButton->resize(
|
||||||
|
captionRect.width(),
|
||||||
|
_sponsoredButton->height());
|
||||||
|
_sponsoredButton->move(
|
||||||
|
(width() - captionRect.width()) / 2,
|
||||||
|
(controllerBottom // Duplicated in recountSkipTop().
|
||||||
|
- ((_streamed && _streamed->controls)
|
||||||
|
? (_streamed->controls->height()
|
||||||
|
+ st::mediaviewCaptionMargin.height())
|
||||||
|
: 0)
|
||||||
|
- _sponsoredButton->height()
|
||||||
|
- st::mediaviewCaptionPadding.bottom()));
|
||||||
|
Ui::SendPendingMoveResizeEvents(_sponsoredButton.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
void OverlayWidget::refreshSponsoredButtonWidth() {
|
||||||
|
if (!_sponsoredButton) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto captionWidth = captionGeometry().width();
|
||||||
|
_sponsoredButton->resize(captionWidth, _sponsoredButton->height());
|
||||||
|
_sponsoredButton->move(
|
||||||
|
(width() - captionWidth) / 2,
|
||||||
|
_sponsoredButton->y());
|
||||||
|
}
|
||||||
|
|
||||||
void OverlayWidget::fillContextMenuActions(
|
void OverlayWidget::fillContextMenuActions(
|
||||||
const Ui::Menu::MenuCallback &addAction) {
|
const Ui::Menu::MenuCallback &addAction) {
|
||||||
if (_message && _message->isSponsored()) {
|
if (_message && _message->isSponsored()) {
|
||||||
|
@ -1769,6 +1811,13 @@ bool OverlayWidget::updateControlsAnimation(crl::time now) {
|
||||||
} else {
|
} else {
|
||||||
_controlsOpacity.update(dt, anim::linear);
|
_controlsOpacity.update(dt, anim::linear);
|
||||||
}
|
}
|
||||||
|
if (_sponsoredButtonOpacity && _sponsoredButton) {
|
||||||
|
const auto value = _controlsOpacity.current();
|
||||||
|
_sponsoredButtonOpacity->setOpacity(value);
|
||||||
|
_sponsoredButton->setAttribute(
|
||||||
|
Qt::WA_TransparentForMouseEvents,
|
||||||
|
value < 1);
|
||||||
|
}
|
||||||
_helper->setControlsOpacity(_controlsOpacity.current());
|
_helper->setControlsOpacity(_controlsOpacity.current());
|
||||||
const auto content = finalContentRect();
|
const auto content = finalContentRect();
|
||||||
const auto siblingType = (_over == Over::LeftStories)
|
const auto siblingType = (_over == Over::LeftStories)
|
||||||
|
@ -3508,6 +3557,7 @@ void OverlayWidget::displayDocument(
|
||||||
).toImage());
|
).toImage());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
initSponsoredButton();
|
||||||
if (_documentMedia->canBePlayed(_message)
|
if (_documentMedia->canBePlayed(_message)
|
||||||
&& initStreaming(startStreaming)) {
|
&& initStreaming(startStreaming)) {
|
||||||
} else if (_document->isVideoFile()) {
|
} else if (_document->isVideoFile()) {
|
||||||
|
@ -3613,6 +3663,33 @@ void OverlayWidget::displayDocument(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OverlayWidget::initSponsoredButton() {
|
||||||
|
const auto has = _message && _message->isSponsored() && _session;
|
||||||
|
if (has && _sponsoredButton) {
|
||||||
|
return;
|
||||||
|
} else if (!has && _sponsoredButton) {
|
||||||
|
_sponsoredButton = nullptr;
|
||||||
|
return;
|
||||||
|
} else if (!has && !_sponsoredButton) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto &component = _session->sponsoredMessages();
|
||||||
|
const auto details = component.lookupDetails(_message->fullId());
|
||||||
|
_sponsoredButton = base::make_unique_q<Ui::RoundButton>(
|
||||||
|
_body,
|
||||||
|
rpl::single(details.buttonText),
|
||||||
|
st::mediaviewSponsoredButton);
|
||||||
|
|
||||||
|
_sponsoredButton->setClickedCallback([=, link = details.link] {
|
||||||
|
UrlClickHandler::Open(link);
|
||||||
|
hide();
|
||||||
|
});
|
||||||
|
_sponsoredButtonOpacity = base::make_unique_q<QGraphicsOpacityEffect>(
|
||||||
|
_sponsoredButton.get());
|
||||||
|
_sponsoredButtonOpacity->setOpacity(1.0);
|
||||||
|
_sponsoredButton->setGraphicsEffect(_sponsoredButtonOpacity.get());
|
||||||
|
}
|
||||||
|
|
||||||
void OverlayWidget::updateThemePreviewGeometry() {
|
void OverlayWidget::updateThemePreviewGeometry() {
|
||||||
if (_themePreviewShown) {
|
if (_themePreviewShown) {
|
||||||
auto previewRect = QRect((width() - st::themePreviewSize.width()) / 2, (height() - st::themePreviewSize.height()) / 2, st::themePreviewSize.width(), st::themePreviewSize.height());
|
auto previewRect = QRect((width() - st::themePreviewSize.width()) / 2, (height() - st::themePreviewSize.height()) / 2, st::themePreviewSize.width(), st::themePreviewSize.height());
|
||||||
|
@ -5677,8 +5754,8 @@ void OverlayWidget::updateOverRect(Over state) {
|
||||||
break;
|
break;
|
||||||
case Over::LeftStories:
|
case Over::LeftStories:
|
||||||
update(_stories
|
update(_stories
|
||||||
? _stories->sibling(Type::Left).layout.geometry :
|
? _stories->sibling(Type::Left).layout.geometry
|
||||||
QRect());
|
: QRect());
|
||||||
break;
|
break;
|
||||||
case Over::RightStories:
|
case Over::RightStories:
|
||||||
update(_stories
|
update(_stories
|
||||||
|
@ -6219,6 +6296,8 @@ void OverlayWidget::clearBeforeHide() {
|
||||||
_helper->setControlsOpacity(1.);
|
_helper->setControlsOpacity(1.);
|
||||||
_groupThumbs = nullptr;
|
_groupThumbs = nullptr;
|
||||||
_groupThumbsRect = QRect();
|
_groupThumbsRect = QRect();
|
||||||
|
_sponsoredButtonOpacity = nullptr;
|
||||||
|
_sponsoredButton = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverlayWidget::clearAfterHide() {
|
void OverlayWidget::clearAfterHide() {
|
||||||
|
|
|
@ -20,6 +20,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "media/view/media_view_open_common.h"
|
#include "media/view/media_view_open_common.h"
|
||||||
#include "media/stories/media_stories_delegate.h"
|
#include "media/stories/media_stories_delegate.h"
|
||||||
|
|
||||||
|
class QGraphicsOpacityEffect;
|
||||||
|
|
||||||
class History;
|
class History;
|
||||||
|
|
||||||
namespace anim {
|
namespace anim {
|
||||||
|
@ -149,6 +151,7 @@ private:
|
||||||
Right,
|
Right,
|
||||||
LeftStories,
|
LeftStories,
|
||||||
RightStories,
|
RightStories,
|
||||||
|
SponsoredButton,
|
||||||
Header,
|
Header,
|
||||||
Name,
|
Name,
|
||||||
Date,
|
Date,
|
||||||
|
@ -411,6 +414,10 @@ private:
|
||||||
void destroyThemePreview();
|
void destroyThemePreview();
|
||||||
void updateThemePreviewGeometry();
|
void updateThemePreviewGeometry();
|
||||||
|
|
||||||
|
void initSponsoredButton();
|
||||||
|
void refreshSponsoredButtonGeometry();
|
||||||
|
void refreshSponsoredButtonWidth();
|
||||||
|
|
||||||
void documentUpdated(not_null<DocumentData*> document);
|
void documentUpdated(not_null<DocumentData*> document);
|
||||||
void changingMsgId(FullMsgId newId, MsgId oldId);
|
void changingMsgId(FullMsgId newId, MsgId oldId);
|
||||||
|
|
||||||
|
@ -693,6 +700,9 @@ private:
|
||||||
object_ptr<Ui::DropdownMenu> _dropdown;
|
object_ptr<Ui::DropdownMenu> _dropdown;
|
||||||
base::Timer _dropdownShowTimer;
|
base::Timer _dropdownShowTimer;
|
||||||
|
|
||||||
|
base::unique_qptr<Ui::RoundButton> _sponsoredButton;
|
||||||
|
base::unique_qptr<QGraphicsOpacityEffect> _sponsoredButtonOpacity;
|
||||||
|
|
||||||
bool _receiveMouse = true;
|
bool _receiveMouse = true;
|
||||||
bool _processingKeyPress = false;
|
bool _processingKeyPress = false;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue