mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-06 10:00:40 +00:00
Add a toggle to RDLabel to preserve the aspect ratio of its pixmap
This commit is contained in:
@@ -60,3 +60,32 @@ void RDLabel::leaveEvent(QEvent *event)
|
||||
|
||||
QLabel::leaveEvent(event);
|
||||
}
|
||||
|
||||
void RDLabel::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
const QPixmap *p = pixmap();
|
||||
if(m_preserveRatio && p)
|
||||
{
|
||||
QRect r = rect();
|
||||
|
||||
float pratio = float(p->width()) / float(p->height());
|
||||
float rratio = float(r.width()) / float(r.height());
|
||||
|
||||
if(pratio > rratio)
|
||||
{
|
||||
int correctHeight = int(r.width() / pratio);
|
||||
|
||||
int margin = (r.height() - correctHeight) / 2;
|
||||
|
||||
setContentsMargins(0, margin, 0, margin);
|
||||
}
|
||||
else
|
||||
{
|
||||
int correctWidth = int(r.height() * pratio);
|
||||
|
||||
int margin = (r.width() - correctWidth) / 2;
|
||||
|
||||
setContentsMargins(margin, 0, margin, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@ public:
|
||||
explicit RDLabel(QWidget *parent = 0);
|
||||
~RDLabel();
|
||||
|
||||
void setPreserveAspectRatio(bool preserve) { m_preserveRatio = preserve; }
|
||||
bool preserveAspectRatio() { return m_preserveRatio; }
|
||||
signals:
|
||||
void clicked(QMouseEvent *event);
|
||||
void doubleClicked(QMouseEvent *event);
|
||||
@@ -46,4 +48,7 @@ protected:
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
void leaveEvent(QEvent *event) override;
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
|
||||
bool m_preserveRatio = false;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user