A wrapper widget that automatically scales its content (e.g., image, GIF) to fit within the maximum allowed size, while preserving an aspect ratio.
More...
#include <auto_scaling_attachment.h>
|
| void | clicked () |
| | Emitted when the user clicks on the attachment container. Typically used to trigger showing the full-size attachment.
|
| |
|
| | AutoScalingAttachment (QWidget *content, QWidget *parent=nullptr) |
| | Constructs an AutoScalingAttachment widget. Sets up the layout, installs event filters, connects signals for content loading, and triggers initial scaling check.
|
| |
| QWidget * | Content () const |
| | Gets a pointer to the original content widget.
|
| |
| QSize | ContentOriginalSize () const |
| | Gets the original, unscaled size of the content widget. Primarily uses the content's sizeHint().
|
| |
| bool | IsScaled () const |
| | Checks if the content is currently scaled down.
|
| |
| void | SetMaxAllowedSize (const QSize &max_size) |
| | Sets the maximum allowed size for the content. If the content's original size exceeds this, it will be scaled down. Triggers a re-evaluation of the scaling.
|
| |
| QSize | sizeHint () const override |
| | Provides a size hint for the AutoScalingAttachment widget. Returns the current (potentially scaled) size of the content container.
|
| |
|
| void | enterEvent (QEvent *event) override |
| | Handles mouse enter events. Shows the "Click to enlarge" label if the content is scaled.
|
| |
| bool | eventFilter (QObject *watched, QEvent *event) override |
| | Filters events for the content container, specifically capturing mouse clicks. Emits the clicked() signal when the content container is left-clicked.
|
| |
| void | leaveEvent (QEvent *event) override |
| | Handles mouse leave events. Hides the "Click to enlarge" label.
|
| |
| void | resizeEvent (QResizeEvent *event) override |
| | Handles resize events for the widget. Updates the position of the "Click to enlarge" label if it's visible.
|
| |
|
| void | CheckAndScaleContent () |
| | Checks the content's original size against the maximum allowed size and applies scaling if necessary. Calculates the target scaled size, sets the fixed size of the content container, updates the is_scaled_ flag, and adjusts the UI accordingly (e.g., info label visibility). Triggers layout updates.
|
| |
|
| void | UpdateInfoLabelPosition () const |
| | Updates the position of the info_label_ ("Click to enlarge") to be centered at the bottom of the content container.
|
| |
|
| QWidget * | content_ |
| | Pointer to the original widget displaying the attachment content.
|
| |
| QWidget * | content_container_ |
| | Container widget that holds the content_ and whose size is adjusted during scaling.
|
| |
| QLabel * | info_label_ |
| | Label displayed over scaled content on hover ("Click to enlarge").
|
| |
| bool | is_scaled_ |
| | Flag indicating whether the content is currently scaled down.
|
| |
| QSize | max_allowed_size_ |
| | The maximum size allowed for the content before scaling is applied.
|
| |
| QSize | scaled_size_ |
| | The current scaled size of the content_container_.
|
| |
A wrapper widget that automatically scales its content (e.g., image, GIF) to fit within the maximum allowed size, while preserving an aspect ratio.
This widget takes another widget (content) and displays it. If the content's original size exceeds the specified maximum size, the content is scaled down proportionally. A label indicating "Click to enlarge" is shown over the scaled content when the mouse hovers over it. Clicking the widget emits the clicked() signal, typically used to show the content in its original size in a separate viewer.
◆ AutoScalingAttachment()
| AutoScalingAttachment::AutoScalingAttachment |
( |
QWidget * | content, |
|
|
QWidget * | parent = nullptr ) |
|
explicit |
Constructs an AutoScalingAttachment widget. Sets up the layout, installs event filters, connects signals for content loading, and triggers initial scaling check.
- Parameters
-
| content | The widget containing the attachment content to be scaled. |
| parent | Optional parent widget. |
◆ CheckAndScaleContent
| void AutoScalingAttachment::CheckAndScaleContent |
( |
| ) |
|
|
privateslot |
Checks the content's original size against the maximum allowed size and applies scaling if necessary. Calculates the target scaled size, sets the fixed size of the content container, updates the is_scaled_ flag, and adjusts the UI accordingly (e.g., info label visibility). Triggers layout updates.
◆ clicked
| void AutoScalingAttachment::clicked |
( |
| ) |
|
|
signal |
Emitted when the user clicks on the attachment container. Typically used to trigger showing the full-size attachment.
◆ Content()
| QWidget * AutoScalingAttachment::Content |
( |
| ) |
const |
|
inline |
Gets a pointer to the original content widget.
- Returns
- Pointer to the content QWidget.
◆ ContentOriginalSize()
| QSize AutoScalingAttachment::ContentOriginalSize |
( |
| ) |
const |
Gets the original, unscaled size of the content widget. Primarily uses the content's sizeHint().
- Returns
- The original QSize of the content, or an invalid QSize if undetermined.
◆ enterEvent()
| void AutoScalingAttachment::enterEvent |
( |
QEvent * | event | ) |
|
|
overrideprotected |
Handles mouse enter events. Shows the "Click to enlarge" label if the content is scaled.
- Parameters
-
◆ eventFilter()
| bool AutoScalingAttachment::eventFilter |
( |
QObject * | watched, |
|
|
QEvent * | event ) |
|
overrideprotected |
Filters events for the content container, specifically capturing mouse clicks. Emits the clicked() signal when the content container is left-clicked.
- Parameters
-
| watched | The object being watched (should be content_container_). |
| event | The event being processed. |
- Returns
- True if the event was a left-click on the container (event handled), false otherwise.
◆ IsScaled()
| bool AutoScalingAttachment::IsScaled |
( |
| ) |
const |
|
inline |
Checks if the content is currently scaled down.
- Returns
- True if the content is scaled, false otherwise.
◆ leaveEvent()
| void AutoScalingAttachment::leaveEvent |
( |
QEvent * | event | ) |
|
|
overrideprotected |
Handles mouse leave events. Hides the "Click to enlarge" label.
- Parameters
-
◆ resizeEvent()
| void AutoScalingAttachment::resizeEvent |
( |
QResizeEvent * | event | ) |
|
|
overrideprotected |
Handles resize events for the widget. Updates the position of the "Click to enlarge" label if it's visible.
- Parameters
-
◆ SetMaxAllowedSize()
| void AutoScalingAttachment::SetMaxAllowedSize |
( |
const QSize & | max_size | ) |
|
Sets the maximum allowed size for the content. If the content's original size exceeds this, it will be scaled down. Triggers a re-evaluation of the scaling.
- Parameters
-
| max_size | The maximum QSize allowed for the content. |
◆ sizeHint()
| QSize AutoScalingAttachment::sizeHint |
( |
| ) |
const |
|
override |
Provides a size hint for the AutoScalingAttachment widget. Returns the current (potentially scaled) size of the content container.
- Returns
- The recommended QSize for the widget.
◆ UpdateInfoLabelPosition()
| void AutoScalingAttachment::UpdateInfoLabelPosition |
( |
| ) |
const |
|
private |
Updates the position of the info_label_ ("Click to enlarge") to be centered at the bottom of the content container.
◆ content_
| QWidget* AutoScalingAttachment::content_ |
|
private |
Pointer to the original widget displaying the attachment content.
◆ content_container_
| QWidget* AutoScalingAttachment::content_container_ |
|
private |
Container widget that holds the content_ and whose size is adjusted during scaling.
◆ info_label_
| QLabel* AutoScalingAttachment::info_label_ |
|
private |
Label displayed over scaled content on hover ("Click to enlarge").
◆ is_scaled_
| bool AutoScalingAttachment::is_scaled_ |
|
private |
Flag indicating whether the content is currently scaled down.
◆ max_allowed_size_
| QSize AutoScalingAttachment::max_allowed_size_ |
|
private |
The maximum size allowed for the content before scaling is applied.
◆ scaled_size_
| QSize AutoScalingAttachment::scaled_size_ |
|
private |
The current scaled size of the content_container_.
The documentation for this class was generated from the following files: