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

A custom QPushButton styled as a tab button with an animated underline effect. More...

#include <tab_button.h>

Inheritance diagram for TabButton:
Collaboration diagram for TabButton:

Public Member Functions

void SetActive (bool active)
 Sets the active state of the tab button. An active button displays a full, static underline. An inactive button shows the animated underline on hover. This also affects the underline color. Triggers a repaint.
 
void SetUnderlineOffset (double offset)
 Sets the value of the underline animation offset. Triggers a repaint of the button. Used by the QPropertyAnimation.
 
 TabButton (const QString &text, QWidget *parent=nullptr)
 Constructs a TabButton. Initializes the button as flat, checkable, sets the cursor, and applies the specific stylesheet for tab button appearance (colors, font, padding, etc.).
 
double UnderlineOffset () const
 Gets the current value of the underline animation offset.
 

Protected Member Functions

void enterEvent (QEvent *event) override
 Overridden enter event handler. Starts the animation to show the underline if the button is inactive.
 
void leaveEvent (QEvent *event) override
 Overridden leave event handler. Starts the animation to hide the underline if the button is inactive.
 
void paintEvent (QPaintEvent *event) override
 Overridden paint event handler. Draws the custom underline effect. Calls the base class paintEvent first. Then, draws either a full static underline (if active) or an animated, partial underline (if inactive and underline_offset_ > 0) below the button text. The underline color also depends on the active state.
 

Properties

double underlineOffset
 Property controlling the animation state of the underline effect on hover (0.0 to 5.0). When the button is inactive, this property animates from 0.0 to 5.0 on enter, and back to 0.0 on leave. The paintEvent uses this value (and its sine) to draw the partial, moving underline.
 

Private Attributes

bool is_active_
 Flag indicating if the tab button is currently considered active (displays full underline).
 
double underline_offset_
 Current animation offset for the underline effect (0.0 to 5.0).
 

Detailed Description

A custom QPushButton styled as a tab button with an animated underline effect.

This button is designed for use in tab bars. It features a flat appearance, specific cyberpunk-themed styling (colors, font) via stylesheet, and is checkable. An underline effect is drawn below the button text. The underline is fully visible when the button is active (SetActive(true) or checked) and animates smoothly on mouse hover (enter/leave events) when inactive, controlled by the underlineOffset property.

Constructor & Destructor Documentation

◆ TabButton()

TabButton::TabButton ( const QString & text,
QWidget * parent = nullptr )
explicit

Constructs a TabButton. Initializes the button as flat, checkable, sets the cursor, and applies the specific stylesheet for tab button appearance (colors, font, padding, etc.).

Parameters
textThe text to display on the tab button.
parentOptional parent widget.

Member Function Documentation

◆ enterEvent()

void TabButton::enterEvent ( QEvent * event)
overrideprotected

Overridden enter event handler. Starts the animation to show the underline if the button is inactive.

Parameters
eventThe enter event.

◆ leaveEvent()

void TabButton::leaveEvent ( QEvent * event)
overrideprotected

Overridden leave event handler. Starts the animation to hide the underline if the button is inactive.

Parameters
eventThe leave event.

◆ paintEvent()

void TabButton::paintEvent ( QPaintEvent * event)
overrideprotected

Overridden paint event handler. Draws the custom underline effect. Calls the base class paintEvent first. Then, draws either a full static underline (if active) or an animated, partial underline (if inactive and underline_offset_ > 0) below the button text. The underline color also depends on the active state.

Parameters
eventThe paint event.

◆ SetActive()

void TabButton::SetActive ( bool active)

Sets the active state of the tab button. An active button displays a full, static underline. An inactive button shows the animated underline on hover. This also affects the underline color. Triggers a repaint.

Parameters
activeTrue to set the button as active, false otherwise.

◆ SetUnderlineOffset()

void TabButton::SetUnderlineOffset ( double offset)

Sets the value of the underline animation offset. Triggers a repaint of the button. Used by the QPropertyAnimation.

Parameters
offsetThe desired underline offset value.

◆ UnderlineOffset()

double TabButton::UnderlineOffset ( ) const
inline

Gets the current value of the underline animation offset.

Returns
The underline offset value (typically 0.0 to 5.0).

Member Data Documentation

◆ is_active_

bool TabButton::is_active_
private

Flag indicating if the tab button is currently considered active (displays full underline).

◆ underline_offset_

double TabButton::underline_offset_
private

Current animation offset for the underline effect (0.0 to 5.0).

Property Documentation

◆ underlineOffset

double TabButton::underlineOffset
readwrite

Property controlling the animation state of the underline effect on hover (0.0 to 5.0). When the button is inactive, this property animates from 0.0 to 5.0 on enter, and back to 0.0 on leave. The paintEvent uses this value (and its sine) to draw the partial, moving underline.


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