fade_animation.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #pragma once
  8. #include "ui/rp_widget.h"
  9. #include "ui/effects/animations.h"
  10. #include "styles/style_widgets.h"
  11. namespace Ui {
  12. class FadeAnimation {
  13. public:
  14. FadeAnimation(TWidget *widget, float64 scale = 1.);
  15. bool paint(QPainter &p);
  16. void refreshCache();
  17. using FinishedCallback = Fn<void()>;
  18. void setFinishedCallback(FinishedCallback &&callback);
  19. using UpdatedCallback = Fn<void(float64)>;
  20. void setUpdatedCallback(UpdatedCallback &&callback);
  21. void show();
  22. void hide();
  23. void fadeIn(int duration);
  24. void fadeOut(int duration);
  25. void finish() {
  26. stopAnimation();
  27. }
  28. bool animating() const {
  29. return _animation.animating();
  30. }
  31. bool visible() const {
  32. return _visible;
  33. }
  34. private:
  35. void startAnimation(int duration);
  36. void stopAnimation();
  37. void updateCallback();
  38. QPixmap grabContent();
  39. TWidget *_widget = nullptr;
  40. float64 _scale = 1.;
  41. Ui::Animations::Simple _animation;
  42. QSize _size;
  43. QPixmap _cache;
  44. bool _visible = false;
  45. FinishedCallback _finishedCallback;
  46. UpdatedCallback _updatedCallback;
  47. };
  48. } // namespace Ui