|
Wavelength
Privacy-focused, cross-platform, and open-source communication application
|
A widget displaying network connection status and ping time with cyberpunk aesthetics. More...
#include <network_status_widget.h>
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"). | |
| TranslationManager * | translator_ = nullptr |
| Pointer to the translation manager for handling UI translations. | |
| QTimer * | update_timer_ |
| Timer triggering periodic calls to CheckNetworkStatus(). | |
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.
|
private |
|
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.
| parent | Optional parent widget. |
|
override |
Destructor. Stops the update timer.
|
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.
|
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_.
| quality | The current network quality. |
|
staticprivate |
Static utility function to get the appropriate color for a given network quality level. Used for the border, text, and icon color.
| quality | The network quality level. |
|
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_).
| event | The paint event. |
|
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.
|
private |
The color used for the border, text, and active icon parts, based on current_quality_.
|
private |
The currently determined network quality level.
|
private |
Label displaying the WiFi-style icon.
|
private |
Manages network requests for status checking.
|
private |
Label displaying the measured ping time in milliseconds.
|
private |
The last measured ping time in milliseconds.
|
private |
Label displaying the textual status (e.g., "SYSTEM READY").
|
private |
Pointer to the translation manager for handling UI translations.
|
private |
Timer triggering periodic calls to CheckNetworkStatus().