mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 13:47:05 +02:00
Removed QGraphicsOpacityEffect usage from media view overlay widget.
This commit is contained in:
parent
b20e2c37c1
commit
a60385fc3d
2 changed files with 75 additions and 16 deletions
|
@ -34,6 +34,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/text/format_values.h"
|
||||
#include "ui/item_text_options.h"
|
||||
#include "ui/painter.h"
|
||||
#include "ui/rect.h"
|
||||
#include "ui/power_saving.h"
|
||||
#include "ui/cached_round_corners.h"
|
||||
#include "ui/gl/gl_window.h"
|
||||
|
@ -100,7 +101,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include <QtGui/QGuiApplication>
|
||||
#include <QtGui/QWindow>
|
||||
#include <QtGui/QScreen>
|
||||
#include <QGraphicsOpacityEffect>
|
||||
|
||||
#include <kurlmimedata.h>
|
||||
|
||||
|
@ -228,6 +228,73 @@ QWidget *PipDelegate::pipParentWidget() {
|
|||
|
||||
} // namespace
|
||||
|
||||
class OverlayWidget::SponsoredButton : public Ui::RippleButton {
|
||||
public:
|
||||
SponsoredButton(QWidget *parent)
|
||||
: Ui::RippleButton(parent, st::mediaviewSponsoredButton.ripple) {
|
||||
}
|
||||
|
||||
void setText(QString text) {
|
||||
_text = Ui::Text::String(
|
||||
st::mediaviewSponsoredButton.style,
|
||||
std::move(text),
|
||||
kDefaultTextOptions,
|
||||
width());
|
||||
resize(width(), _text.minHeight() * 2);
|
||||
}
|
||||
void setOpacity(float opacity) {
|
||||
_opacity = opacity;
|
||||
}
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e) override {
|
||||
auto p = QPainter(this);
|
||||
const auto &st = st::mediaviewSponsoredButton;
|
||||
|
||||
p.setOpacity(_opacity);
|
||||
|
||||
const auto over = Ui::AbstractButton::isOver();
|
||||
const auto down = Ui::AbstractButton::isDown();
|
||||
{
|
||||
auto hq = PainterHighQualityEnabler(p);
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setBrush((over || down) ? st.textBgOver : st.textBg);
|
||||
p.drawRoundedRect(
|
||||
rect(),
|
||||
st::mediaviewCaptionRadius,
|
||||
st::mediaviewCaptionRadius);
|
||||
}
|
||||
|
||||
Ui::RippleButton::paintRipple(p, 0, 0);
|
||||
|
||||
p.setPen(st.textFg);
|
||||
p.setBrush(Qt::NoBrush);
|
||||
_text.draw(p, {
|
||||
.position = QPoint(
|
||||
(width() - _text.maxWidth()) / 2,
|
||||
(height() - _text.minHeight()) / 2),
|
||||
.outerWidth = width(),
|
||||
.availableWidth = width(),
|
||||
});
|
||||
}
|
||||
|
||||
QImage prepareRippleMask() const override {
|
||||
return Ui::RippleAnimation::RoundRectMask(
|
||||
size(),
|
||||
st::mediaviewCaptionRadius);
|
||||
}
|
||||
QPoint prepareRippleStartPosition() const override {
|
||||
return mapFromGlobal(QCursor::pos())
|
||||
- rect::m::pos::tl(st::mediaviewSponsoredButton.padding);
|
||||
}
|
||||
|
||||
private:
|
||||
Ui::Text::String _text;
|
||||
float64 _opacity = 1.;
|
||||
|
||||
};
|
||||
|
||||
|
||||
struct OverlayWidget::SharedMedia {
|
||||
SharedMedia(SharedMediaKey key) : key(key) {
|
||||
}
|
||||
|
@ -1812,9 +1879,9 @@ bool OverlayWidget::updateControlsAnimation(crl::time now) {
|
|||
} else {
|
||||
_controlsOpacity.update(dt, anim::linear);
|
||||
}
|
||||
if (_sponsoredButtonOpacity && _sponsoredButton) {
|
||||
if (_sponsoredButton) {
|
||||
const auto value = _controlsOpacity.current();
|
||||
_sponsoredButtonOpacity->setOpacity(value);
|
||||
_sponsoredButton->setOpacity(value);
|
||||
_sponsoredButton->setAttribute(
|
||||
Qt::WA_TransparentForMouseEvents,
|
||||
value < 1);
|
||||
|
@ -3678,19 +3745,14 @@ void OverlayWidget::initSponsoredButton() {
|
|||
}
|
||||
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 = base::make_unique_q<SponsoredButton>(_body);
|
||||
_sponsoredButton->setText(details.buttonText);
|
||||
_sponsoredButton->setOpacity(1.0);
|
||||
|
||||
_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() {
|
||||
|
@ -6299,7 +6361,6 @@ void OverlayWidget::clearBeforeHide() {
|
|||
_helper->setControlsOpacity(1.);
|
||||
_groupThumbs = nullptr;
|
||||
_groupThumbsRect = QRect();
|
||||
_sponsoredButtonOpacity = nullptr;
|
||||
_sponsoredButton = nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,8 +20,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "media/view/media_view_open_common.h"
|
||||
#include "media/stories/media_stories_delegate.h"
|
||||
|
||||
class QGraphicsOpacityEffect;
|
||||
|
||||
class History;
|
||||
|
||||
namespace anim {
|
||||
|
@ -143,6 +141,7 @@ private:
|
|||
class Renderer;
|
||||
class RendererSW;
|
||||
class RendererGL;
|
||||
class SponsoredButton;
|
||||
|
||||
// If changing, see paintControls()!
|
||||
enum class Over {
|
||||
|
@ -700,8 +699,7 @@ private:
|
|||
object_ptr<Ui::DropdownMenu> _dropdown;
|
||||
base::Timer _dropdownShowTimer;
|
||||
|
||||
base::unique_qptr<Ui::RoundButton> _sponsoredButton;
|
||||
base::unique_qptr<QGraphicsOpacityEffect> _sponsoredButtonOpacity;
|
||||
base::unique_qptr<SponsoredButton> _sponsoredButton;
|
||||
|
||||
bool _receiveMouse = true;
|
||||
bool _processingKeyPress = false;
|
||||
|
|
Loading…
Add table
Reference in a new issue