Added icon cross line animation.

This commit is contained in:
23rd 2020-11-29 09:34:19 +03:00 committed by John Preston
parent 024f777287
commit 21eb3509bc
4 changed files with 108 additions and 0 deletions

View file

@ -42,6 +42,8 @@ PRIVATE
ui/effects/animations.h ui/effects/animations.h
ui/effects/cross_animation.cpp ui/effects/cross_animation.cpp
ui/effects/cross_animation.h ui/effects/cross_animation.h
ui/effects/cross_line.cpp
ui/effects/cross_line.h
ui/effects/fade_animation.cpp ui/effects/fade_animation.cpp
ui/effects/fade_animation.h ui/effects/fade_animation.h
ui/effects/numbers_animation.cpp ui/effects/numbers_animation.cpp

64
ui/effects/cross_line.cpp Normal file
View file

@ -0,0 +1,64 @@
// This file is part of Desktop App Toolkit,
// a set of libraries for developing nice desktop applications.
//
// For license and copyright information please follow this link:
// https://github.com/desktop-app/legal/blob/master/LEGAL
//
#include "ui/effects/cross_line.h"
#include "ui/painter.h"
namespace Ui {
CrossLineAnimation::CrossLineAnimation(
const style::CrossLineAnimation &st,
float angle)
: _st(st)
, _transparentPen(Qt::transparent, st.stroke, Qt::SolidLine, Qt::RoundCap)
, _strokePen(st.fg, st.stroke, Qt::SolidLine, Qt::RoundCap)
, _line(st.startPosition, st.endPosition)
, _completeCross(image(1.)) {
_line.setAngle(angle);
}
void CrossLineAnimation::paint(
Painter &p,
int left,
int top,
float64 progress) {
if (progress == 0.) {
_st.icon.paint(p, left, top, _st.icon.width());
} else if (progress == 1.) {
p.drawImage(left, top, _completeCross);
} else {
p.drawImage(left, top, image(progress));
}
}
QImage CrossLineAnimation::image(float64 progress) const {
const auto ratio = style::DevicePixelRatio();
auto frame = QImage(
QSize(_st.icon.width() * ratio, _st.icon.height() * ratio),
QImage::Format_ARGB32_Premultiplied);
frame.setDevicePixelRatio(ratio);
frame.fill(Qt::transparent);
auto topLine = _line;
topLine.setLength(topLine.length() * progress);
auto bottomLine = topLine.translated(0, _strokePen.widthF() + 1);
Painter q(&frame);
PainterHighQualityEnabler hq(q);
_st.icon.paint(q, 0, 0, _st.icon.width());
q.setPen(_strokePen);
q.drawLine(bottomLine);
q.setCompositionMode(QPainter::CompositionMode_Source);
q.setPen(_transparentPen);
q.drawLine(topLine);
return frame;
}
} // namespace Ui

34
ui/effects/cross_line.h Normal file
View file

@ -0,0 +1,34 @@
// This file is part of Desktop App Toolkit,
// a set of libraries for developing nice desktop applications.
//
// For license and copyright information please follow this link:
// https://github.com/desktop-app/legal/blob/master/LEGAL
//
#pragma once
#include "styles/style_widgets.h"
class Painter;
namespace Ui {
class CrossLineAnimation {
public:
CrossLineAnimation(
const style::CrossLineAnimation &st,
float angle = 315);
void paint(Painter &p, int left, int top, float64 progress);
private:
QImage image(float64 progress) const;
const style::CrossLineAnimation &_st;
const QPen _transparentPen;
const QPen _strokePen;
QLineF _line;
const QImage _completeCross;
};
} // namespace Ui

View file

@ -400,6 +400,14 @@ CrossButton {
ripple: RippleAnimation; ripple: RippleAnimation;
} }
CrossLineAnimation {
fg: color;
icon: icon;
startPosition: point;
endPosition: point;
stroke: pixels;
}
MultiSelectItem { MultiSelectItem {
padding: margins; padding: margins;
maxWidth: pixels; maxWidth: pixels;