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

A QStackedWidget subclass that provides animated transitions between widgets. More...

#include <animated_stacked_widget.h>

Inheritance diagram for AnimatedStackedWidget:
Collaboration diagram for AnimatedStackedWidget:

Public Types

enum  AnimationType { Fade , Slide , SlideAndFade , Push }
 Enum defining the available types of transition animations. More...
 

Public Slots

void SlideToIndex (int index)
 Initiates an animated transition to the widget at the specified index. Plays a sound effect and starts the configured animation type. Does nothing if an animation is already running, or the index is invalid/current.
 
void SlideToNextIndex ()
 Initiates an animated transition to the next widget in the stack (wraps around). Useful for creating carousel-like behavior.
 
void SlideToWidget (QWidget *widget)
 Initiates an animated transition to the specified widget. Convenience slot that finds the index of the widget and calls SlideToIndex().
 

Public Member Functions

 AnimatedStackedWidget (QWidget *parent=nullptr)
 Constructs an AnimatedStackedWidget. Initializes the animation group, sound effect, and the optional OpenGL transition widget. Connects animation signals.
 
AnimationType GetAnimationType () const
 Gets the currently configured animation type.
 
int GetDuration () const
 Gets the current duration of the transition animation.
 
bool IsAnimating () const
 Checks if a transition animation is currently running.
 
void SetAnimationType (const AnimationType type)
 Sets the type of animation to use for transitions.
 
void SetDuration (const int duration)
 Sets the duration of the transition animation.
 
 ~AnimatedStackedWidget () override
 Destructor. Cleans up the animation group and the OpenGL transition widget.
 

Protected Member Functions

void AnimateFade (int next_index) const
 Configures and adds animations to the animation_group_ for a fade transition.
 
void AnimatePush (int next_index) const
 Configures and adds animations to the animation_group_ for a push transition.
 
void AnimateSlide (int next_index) const
 Configures and adds animations to the animation_group_ for a slide transition (CPU fallback).
 
void AnimateSlideAndFade (int next_index) const
 Configures and adds animations to the animation_group_ for a combined slide and fade transition.
 

Properties

int duration
 Property controlling the duration of the transition animation in milliseconds.
 

Private Slots

void OnGLTransitionFinished ()
 Slot called when the OpenGL transition animation finishes. Hides the OpenGL widget, updates the current index, shows the target widget, resets animation flags, and emits currentChanged().
 

Private Member Functions

void CleanupAfterAnimation () const
 Cleans up graphics effects and resets widget geometries after an animation finishes. Ensures widgets are in their correct final state and removes temporary effects.
 
void PrepareAnimation (int next_index) const
 Prepares the appropriate animation based on animation_type_. Calls the corresponding Animate* method or set up the OpenGL transition. Starts the animation_group_ if not using OpenGL.
 

Private Attributes

QParallelAnimationGroup * animation_group_
 Parallel animation group managing the individual property animations.
 
bool animation_running_
 Flag indicating if a transition animation is currently running.
 
AnimationType animation_type_
 The type of animation currently configured.
 
int duration_
 Duration of the transition animation in milliseconds.
 
GLTransitionWidgetgl_transition_widget_ = nullptr
 Optional widget for handling OpenGL-accelerated slide transitions.
 
QSoundEffect * swoosh_sound_
 Sound effect played during transitions.
 
int target_index_
 Stores the index of the target widget during an animation.
 

Detailed Description

A QStackedWidget subclass that provides animated transitions between widgets.

This widget enhances the standard QStackedWidget by adding visual animations (like fade, slide, push) when switching between child widgets. It supports different animation types and durations, and can optionally use OpenGL for smoother slide transitions via GLTransitionWidget. It also plays a sound effect during transitions.

Member Enumeration Documentation

◆ AnimationType

Enum defining the available types of transition animations.

Enumerator
Fade 

Cross-fade between the current and next widget.

Slide 

Slide the current widget out and the next widget in (can use OpenGL).

SlideAndFade 

Combine sliding and fading effects.

Push 

Push the current widget partially out while the next slides in.

Constructor & Destructor Documentation

◆ AnimatedStackedWidget()

AnimatedStackedWidget::AnimatedStackedWidget ( QWidget * parent = nullptr)
explicit

Constructs an AnimatedStackedWidget. Initializes the animation group, sound effect, and the optional OpenGL transition widget. Connects animation signals.

Parameters
parentOptional parent widget.
Here is the call graph for this function:

◆ ~AnimatedStackedWidget()

AnimatedStackedWidget::~AnimatedStackedWidget ( )
override

Destructor. Cleans up the animation group and the OpenGL transition widget.

Member Function Documentation

◆ AnimateFade()

void AnimatedStackedWidget::AnimateFade ( int next_index) const
protected

Configures and adds animations to the animation_group_ for a fade transition.

Parameters
next_indexThe index of the target widget.
Here is the caller graph for this function:

◆ AnimatePush()

void AnimatedStackedWidget::AnimatePush ( int next_index) const
protected

Configures and adds animations to the animation_group_ for a push transition.

Parameters
next_indexThe index of the target widget.
Here is the caller graph for this function:

◆ AnimateSlide()

void AnimatedStackedWidget::AnimateSlide ( int next_index) const
protected

Configures and adds animations to the animation_group_ for a slide transition (CPU fallback).

Parameters
next_indexThe index of the target widget.
Here is the caller graph for this function:

◆ AnimateSlideAndFade()

void AnimatedStackedWidget::AnimateSlideAndFade ( int next_index) const
protected

Configures and adds animations to the animation_group_ for a combined slide and fade transition.

Parameters
next_indexThe index of the target widget.
Here is the caller graph for this function:

◆ CleanupAfterAnimation()

void AnimatedStackedWidget::CleanupAfterAnimation ( ) const
private

Cleans up graphics effects and resets widget geometries after an animation finishes. Ensures widgets are in their correct final state and removes temporary effects.

Here is the caller graph for this function:

◆ GetAnimationType()

AnimationType AnimatedStackedWidget::GetAnimationType ( ) const
inline

Gets the currently configured animation type.

Returns
The current AnimationType.

◆ GetDuration()

int AnimatedStackedWidget::GetDuration ( ) const
inline

Gets the current duration of the transition animation.

Returns
The animation duration in milliseconds.

◆ IsAnimating()

bool AnimatedStackedWidget::IsAnimating ( ) const
inline

Checks if a transition animation is currently running.

Returns
True if an animation is in progress, false otherwise.

◆ OnGLTransitionFinished

void AnimatedStackedWidget::OnGLTransitionFinished ( )
privateslot

Slot called when the OpenGL transition animation finishes. Hides the OpenGL widget, updates the current index, shows the target widget, resets animation flags, and emits currentChanged().

Here is the caller graph for this function:

◆ PrepareAnimation()

void AnimatedStackedWidget::PrepareAnimation ( int next_index) const
private

Prepares the appropriate animation based on animation_type_. Calls the corresponding Animate* method or set up the OpenGL transition. Starts the animation_group_ if not using OpenGL.

Parameters
next_indexThe index of the target widget.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetAnimationType()

void AnimatedStackedWidget::SetAnimationType ( const AnimationType type)
inline

Sets the type of animation to use for transitions.

Parameters
typeThe desired AnimationType.

◆ SetDuration()

void AnimatedStackedWidget::SetDuration ( const int duration)
inline

Sets the duration of the transition animation.

Parameters
durationThe animation duration in milliseconds.

◆ SlideToIndex

void AnimatedStackedWidget::SlideToIndex ( int index)
slot

Initiates an animated transition to the widget at the specified index. Plays a sound effect and starts the configured animation type. Does nothing if an animation is already running, or the index is invalid/current.

Parameters
indexThe index of the target widget.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SlideToNextIndex

void AnimatedStackedWidget::SlideToNextIndex ( )
slot

Initiates an animated transition to the next widget in the stack (wraps around). Useful for creating carousel-like behavior.

Here is the call graph for this function:

◆ SlideToWidget

void AnimatedStackedWidget::SlideToWidget ( QWidget * widget)
slot

Initiates an animated transition to the specified widget. Convenience slot that finds the index of the widget and calls SlideToIndex().

Parameters
widgetPointer to the target widget.
Here is the call graph for this function:

Member Data Documentation

◆ animation_group_

QParallelAnimationGroup* AnimatedStackedWidget::animation_group_
private

Parallel animation group managing the individual property animations.

◆ animation_running_

bool AnimatedStackedWidget::animation_running_
private

Flag indicating if a transition animation is currently running.

◆ animation_type_

AnimationType AnimatedStackedWidget::animation_type_
private

The type of animation currently configured.

◆ duration_

int AnimatedStackedWidget::duration_
private

Duration of the transition animation in milliseconds.

◆ gl_transition_widget_

GLTransitionWidget* AnimatedStackedWidget::gl_transition_widget_ = nullptr
private

Optional widget for handling OpenGL-accelerated slide transitions.

◆ swoosh_sound_

QSoundEffect* AnimatedStackedWidget::swoosh_sound_
private

Sound effect played during transitions.

◆ target_index_

int AnimatedStackedWidget::target_index_
private

Stores the index of the target widget during an animation.

Property Documentation

◆ duration

int AnimatedStackedWidget::duration
readwrite

Property controlling the duration of the transition animation in milliseconds.


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