Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
ElectronicShutdownEffect Class Referencefinal

A QGraphicsEffect that simulates an old CRT monitor or electronic device shutting down. More...

#include <electronic_shutdown_effect.h>

Inheritance diagram for ElectronicShutdownEffect:
Collaboration diagram for ElectronicShutdownEffect:

Public Member Functions

 ElectronicShutdownEffect (QObject *parent=nullptr)
 Constructs an ElectronicShutdownEffect. Initializes the effect, sets up the result cache, and seeds the random generator.
 
qreal GetProgress () const
 Gets the current progress of the shutdown animation.
 
void SetProgress (qreal progress)
 Sets the progress of the shutdown animation. Clamps the value between 0.0 and 1.0 and triggers an update of the effect.
 

Protected Member Functions

void draw (QPainter *painter) override
 Overridden draw method that renders the shutdown effect. Retrieves the source pixmap. If progress is minimal, draws the source directly. If progress is maximal, draws nothing. Otherwise, checks a cache for a pre-rendered result at a similar progress level. If not cached or progress changed significantly, it generates the effect based on the current phase (collapsing or fading line), applying glitches, scanlines, brightness changes, and glow effects. The result is stored in the cache. Finally, the cached (or newly generated) pixmap is drawn.
 

Properties

qreal progress
 Property controlling the progress of the shutdown animation (0.0 to 1.0). Animatable.
 

Private Attributes

qreal last_progress_
 Stores the progress value from the last time the cache was updated, used to optimize cache usage.
 
qreal progress_
 Current progress level of the shutdown animation (0.0 to 1.0).
 
QCache< QString, QPixmap > result_cache_
 Cache storing pre-rendered effect pixmaps keyed by progress level string for performance.
 

Detailed Description

A QGraphicsEffect that simulates an old CRT monitor or electronic device shutting down.

This effect animates in two phases based on the progress property (0.0 to 1.0):

  1. (0.0-0.7): The source image vertically collapses into a thin horizontal line, accompanied by visual glitches (random line shifts) and scanline effects.
  2. (0.7-1.0): The horizontal line fades out, shrinks horizontally, increases in brightness, and exhibits flickering and glow effects before disappearing completely.

The effect uses caching (QCache) to store intermediate results for performance.

Constructor & Destructor Documentation

◆ ElectronicShutdownEffect()

ElectronicShutdownEffect::ElectronicShutdownEffect ( QObject * parent = nullptr)
explicit

Constructs an ElectronicShutdownEffect. Initializes the effect, sets up the result cache, and seeds the random generator.

Parameters
parentOptional parent QObject.

Member Function Documentation

◆ draw()

void ElectronicShutdownEffect::draw ( QPainter * painter)
overrideprotected

Overridden draw method that renders the shutdown effect. Retrieves the source pixmap. If progress is minimal, draws the source directly. If progress is maximal, draws nothing. Otherwise, checks a cache for a pre-rendered result at a similar progress level. If not cached or progress changed significantly, it generates the effect based on the current phase (collapsing or fading line), applying glitches, scanlines, brightness changes, and glow effects. The result is stored in the cache. Finally, the cached (or newly generated) pixmap is drawn.

Parameters
painterThe QPainter to use for drawing.

◆ GetProgress()

qreal ElectronicShutdownEffect::GetProgress ( ) const
inline

Gets the current progress of the shutdown animation.

Returns
The current progress level (0.0 to 1.0).

◆ SetProgress()

void ElectronicShutdownEffect::SetProgress ( qreal progress)

Sets the progress of the shutdown animation. Clamps the value between 0.0 and 1.0 and triggers an update of the effect.

Parameters
progressThe desired progress level (0.0 to 1.0).

Member Data Documentation

◆ last_progress_

qreal ElectronicShutdownEffect::last_progress_
private

Stores the progress value from the last time the cache was updated, used to optimize cache usage.

◆ progress_

qreal ElectronicShutdownEffect::progress_
private

Current progress level of the shutdown animation (0.0 to 1.0).

◆ result_cache_

QCache<QString, QPixmap> ElectronicShutdownEffect::result_cache_
private

Cache storing pre-rendered effect pixmaps keyed by progress level string for performance.

Property Documentation

◆ progress

qreal ElectronicShutdownEffect::progress
readwrite

Property controlling the progress of the shutdown animation (0.0 to 1.0). Animatable.


The documentation for this class was generated from the following files: