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

A widget displaying network connection status and ping time with cyberpunk aesthetics. More...

#include <network_status_widget.h>

Inheritance diagram for NetworkStatusWidget:
Collaboration diagram for NetworkStatusWidget:

Public Slots

void CheckNetworkStatus ()
 Performs a network status check. Sends a network request, measures the response time (ping), determines the NetworkQuality based on the result, and calls UpdateStatusDisplay(). Triggered by the update_timer_ and can be called manually.
 

Public Member Functions

 NetworkStatusWidget (QWidget *parent=nullptr)
 Constructs a NetworkStatusWidget. Initializes UI elements (labels, layout), sets appearance (size, transparency, glow effect), creates the network manager, starts the timer for periodic status checks, and performs an initial check.
 
 ~NetworkStatusWidget () override
 Destructor. Stops the update timer.
 

Protected Member Functions

void paintEvent (QPaintEvent *event) override
 Overridden paint event handler. Draws the custom widget background and border. Renders a rounded rectangle background and a border whose color depends on the current network quality (border_color_).
 

Private Types

enum  NetworkQuality {
  kNone , kPoor , kFair , kGood ,
  kExcellent
}
 Enum representing the perceived quality of the network connection. More...
 

Private Member Functions

void CreateNetworkIcon (NetworkQuality quality) const
 Generates the WiFi-style icon as a QPixmap based on the network quality. Draws a series of arcs, coloring them based on the quality level. Sets the generated pixmap on the icon_label_.
 
void UpdateStatusDisplay ()
 Updates the text of the status and ping labels, the icon, and the border color based on the current_quality_ and ping_value_. Triggers a repaint.
 

Static Private Member Functions

static QColor GetQualityColor (NetworkQuality quality)
 Static utility function to get the appropriate color for a given network quality level. Used for the border, text, and icon color.
 

Private Attributes

QColor border_color_
 The color used for the border, text, and active icon parts, based on current_quality_.
 
NetworkQuality current_quality_
 The currently determined network quality level.
 
QLabel * icon_label_
 Label displaying the WiFi-style icon.
 
QNetworkAccessManager * network_manager_
 Manages network requests for status checking.
 
QLabel * ping_label_
 Label displaying the measured ping time in milliseconds.
 
qint64 ping_value_
 The last measured ping time in milliseconds.
 
QLabel * status_label_
 Label displaying the textual status (e.g., "SYSTEM READY").
 
TranslationManagertranslator_ = nullptr
 Pointer to the translation manager for handling UI translations.
 
QTimer * update_timer_
 Timer triggering periodic calls to CheckNetworkStatus().
 

Detailed Description

A widget displaying network connection status and ping time with cyberpunk aesthetics.

This widget periodically checks network connectivity by sending a request to a target server (currently Google, intended to be a Wavelength server). It displays the status ("SYSTEM READY", "OFFLINE", etc.), the ping time in milliseconds, and a WiFi-style icon whose color and number of active arcs reflect the connection quality (Excellent, Good, Fair, Poor, None). The widget features a custom-drawn background and border with colors changing based on quality.

Member Enumeration Documentation

◆ NetworkQuality

Enum representing the perceived quality of the network connection.

Enumerator
kNone 

No connection detected.

kPoor 

Very high latency or unstable connection.

kFair 

Moderate latency.

kGood 

Good latency.

kExcellent 

Low latency.

Constructor & Destructor Documentation

◆ NetworkStatusWidget()

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

Constructs a NetworkStatusWidget. Initializes UI elements (labels, layout), sets appearance (size, transparency, glow effect), creates the network manager, starts the timer for periodic status checks, and performs an initial check.

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

◆ ~NetworkStatusWidget()

NetworkStatusWidget::~NetworkStatusWidget ( )
override

Destructor. Stops the update timer.

Member Function Documentation

◆ CheckNetworkStatus

void NetworkStatusWidget::CheckNetworkStatus ( )
slot

Performs a network status check. Sends a network request, measures the response time (ping), determines the NetworkQuality based on the result, and calls UpdateStatusDisplay(). Triggered by the update_timer_ and can be called manually.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateNetworkIcon()

void NetworkStatusWidget::CreateNetworkIcon ( NetworkQuality quality) const
private

Generates the WiFi-style icon as a QPixmap based on the network quality. Draws a series of arcs, coloring them based on the quality level. Sets the generated pixmap on the icon_label_.

Parameters
qualityThe current network quality.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetQualityColor()

QColor NetworkStatusWidget::GetQualityColor ( NetworkQuality quality)
staticprivate

Static utility function to get the appropriate color for a given network quality level. Used for the border, text, and icon color.

Parameters
qualityThe network quality level.
Returns
The corresponding QColor.
Here is the caller graph for this function:

◆ paintEvent()

void NetworkStatusWidget::paintEvent ( QPaintEvent * event)
overrideprotected

Overridden paint event handler. Draws the custom widget background and border. Renders a rounded rectangle background and a border whose color depends on the current network quality (border_color_).

Parameters
eventThe paint event.

◆ UpdateStatusDisplay()

void NetworkStatusWidget::UpdateStatusDisplay ( )
private

Updates the text of the status and ping labels, the icon, and the border color based on the current_quality_ and ping_value_. Triggers a repaint.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ border_color_

QColor NetworkStatusWidget::border_color_
private

The color used for the border, text, and active icon parts, based on current_quality_.

◆ current_quality_

NetworkQuality NetworkStatusWidget::current_quality_
private

The currently determined network quality level.

◆ icon_label_

QLabel* NetworkStatusWidget::icon_label_
private

Label displaying the WiFi-style icon.

◆ network_manager_

QNetworkAccessManager* NetworkStatusWidget::network_manager_
private

Manages network requests for status checking.

◆ ping_label_

QLabel* NetworkStatusWidget::ping_label_
private

Label displaying the measured ping time in milliseconds.

◆ ping_value_

qint64 NetworkStatusWidget::ping_value_
private

The last measured ping time in milliseconds.

◆ status_label_

QLabel* NetworkStatusWidget::status_label_
private

Label displaying the textual status (e.g., "SYSTEM READY").

◆ translator_

TranslationManager* NetworkStatusWidget::translator_ = nullptr
private

Pointer to the translation manager for handling UI translations.

◆ update_timer_

QTimer* NetworkStatusWidget::update_timer_
private

Timer triggering periodic calls to CheckNetworkStatus().


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