Added ability to provide custom top bar mask to Window::SlideAnimation.

This commit is contained in:
23rd 2022-05-19 10:51:03 +03:00
parent ef3e139b85
commit 3fde5b56a1
4 changed files with 47 additions and 0 deletions

View file

@ -157,6 +157,7 @@ void SectionWidget::showAnimated(
_showAnimation->setTopBarShadow(params.withTopBarShadow);
_showAnimation->setWithFade(params.withFade);
_showAnimation->setTopSkip(params.topSkip);
_showAnimation->setTopBarMask(params.topMask);
_showAnimation->start();
show();

View file

@ -72,6 +72,7 @@ class SectionMemento;
struct SectionSlideParams {
QPixmap oldContentCache;
int topSkip = 0;
QPixmap topMask;
bool withTopBarShadow = false;
bool withTabs = false;
bool withFade = false;

View file

@ -39,6 +39,45 @@ void SlideAnimation::paintContents(Painter &p) const {
const auto leftWidth = (leftWidthFull + leftCoord);
const auto rightWidth = rightWidthFull - rightCoord;
if (!_mask.isNull()) {
auto frame = QImage(
_mask.size(),
QImage::Format_ARGB32_Premultiplied);
frame.setDevicePixelRatio(_mask.devicePixelRatio());
frame.fill(Qt::transparent);
QPainter q(&frame);
if (leftWidth > 0) {
q.setOpacity(leftAlpha);
q.drawPixmap(
0,
0,
_cacheUnder,
(_cacheUnder.width() - leftWidth * cIntRetinaFactor()),
0,
leftWidth * cIntRetinaFactor(),
_topSkip * retina);
}
if (rightWidth > 0) {
q.setOpacity(rightAlpha);
q.drawPixmap(
rightCoord,
0,
_cacheOver,
0,
0,
rightWidth * cIntRetinaFactor(),
_topSkip * retina);
}
q.setOpacity(1.);
q.setCompositionMode(QPainter::CompositionMode_DestinationIn);
q.drawPixmap(0, 0, _mask);
p.drawImage(0, 0, frame);
}
if (leftWidth > 0) {
p.setOpacity(leftAlpha);
p.drawPixmap(
@ -133,6 +172,10 @@ void SlideAnimation::setFinishedCallback(FinishedCallback &&callback) {
_finishedCallback = std::move(callback);
}
void SlideAnimation::setTopBarMask(const QPixmap &mask) {
_mask = mask;
}
void SlideAnimation::start() {
const auto fromLeft = (_direction == SlideDirection::FromLeft);
if (fromLeft) {

View file

@ -26,6 +26,7 @@ public:
const QPixmap &newContentCache);
void setTopBarShadow(bool enabled);
void setTopSkip(int skip);
void setTopBarMask(const QPixmap &mask);
void setWithFade(bool withFade);
using RepaintCallback = Fn<void()>;
@ -50,6 +51,7 @@ private:
mutable Ui::Animations::Simple _animation;
QPixmap _cacheUnder, _cacheOver;
QPixmap _mask;
RepaintCallback _repaintCallback;
FinishedCallback _finishedCallback;