Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
auto_scaling_attachment.h
Go to the documentation of this file.
1#ifndef AUTO_SCALING_ATTACHMENT_H
2#define AUTO_SCALING_ATTACHMENT_H
3
4#include <QWidget>
5
6class QLabel;
7
18class AutoScalingAttachment final : public QWidget {
19 Q_OBJECT
20
21public:
29 explicit AutoScalingAttachment(QWidget *content, QWidget *parent = nullptr);
30
37 void SetMaxAllowedSize(const QSize &max_size);
38
44 QSize ContentOriginalSize() const;
45
50 bool IsScaled() const {
51 return is_scaled_;
52 }
53
58 QWidget *Content() const {
59 return content_;
60 }
61
67 QSize sizeHint() const override;
68
69signals:
74 void clicked();
75
76protected:
84 bool eventFilter(QObject *watched, QEvent *event) override;
85
91 void enterEvent(QEvent *event) override;
92
98 void leaveEvent(QEvent *event) override;
99
105 void resizeEvent(QResizeEvent *event) override;
106
107private slots:
115
116private:
120 void UpdateInfoLabelPosition() const;
121
123 QWidget *content_;
127 QLabel *info_label_;
134};
135
136#endif // AUTO_SCALING_ATTACHMENT_H
QWidget * content_
Pointer to the original widget displaying the attachment content.
Definition auto_scaling_attachment.h:123
void resizeEvent(QResizeEvent *event) override
Handles resize events for the widget. Updates the position of the "Click to enlarge" label if it's vi...
Definition auto_scaling_attachment.cpp:120
QSize ContentOriginalSize() const
Gets the original, unscaled size of the content widget. Primarily uses the content's sizeHint().
Definition auto_scaling_attachment.cpp:72
AutoScalingAttachment(QWidget *content, QWidget *parent=nullptr)
Constructs an AutoScalingAttachment widget. Sets up the layout, installs event filters,...
Definition auto_scaling_attachment.cpp:12
QWidget * content_container_
Container widget that holds the content_ and whose size is adjusted during scaling.
Definition auto_scaling_attachment.h:125
bool eventFilter(QObject *watched, QEvent *event) override
Filters events for the content container, specifically capturing mouse clicks. Emits the clicked() si...
Definition auto_scaling_attachment.cpp:95
QSize sizeHint() const override
Provides a size hint for the AutoScalingAttachment widget. Returns the current (potentially scaled) s...
Definition auto_scaling_attachment.cpp:82
QSize scaled_size_
The current scaled size of the content_container_.
Definition auto_scaling_attachment.h:131
void UpdateInfoLabelPosition() const
Updates the position of the info_label_ ("Click to enlarge") to be centered at the bottom of the cont...
Definition auto_scaling_attachment.cpp:182
void CheckAndScaleContent()
Checks the content's original size against the maximum allowed size and applies scaling if necessary....
Definition auto_scaling_attachment.cpp:127
void enterEvent(QEvent *event) override
Handles mouse enter events. Shows the "Click to enlarge" label if the content is scaled.
Definition auto_scaling_attachment.cpp:106
void clicked()
Emitted when the user clicks on the attachment container. Typically used to trigger showing the full-...
void leaveEvent(QEvent *event) override
Handles mouse leave events. Hides the "Click to enlarge" label.
Definition auto_scaling_attachment.cpp:115
QLabel * info_label_
Label displayed over scaled content on hover ("Click to enlarge").
Definition auto_scaling_attachment.h:127
bool is_scaled_
Flag indicating whether the content is currently scaled down.
Definition auto_scaling_attachment.h:129
QSize max_allowed_size_
The maximum size allowed for the content before scaling is applied.
Definition auto_scaling_attachment.h:133
bool IsScaled() const
Checks if the content is currently scaled down.
Definition auto_scaling_attachment.h:50
QWidget * Content() const
Gets a pointer to the original content widget.
Definition auto_scaling_attachment.h:58
void SetMaxAllowedSize(const QSize &max_size)
Sets the maximum allowed size for the content. If the content's original size exceeds this,...
Definition auto_scaling_attachment.cpp:67