diff --git a/widget/netcamview.cpp b/widget/netcamview.cpp index 4268ea8dd..fc94393d5 100644 --- a/widget/netcamview.cpp +++ b/widget/netcamview.cpp @@ -59,7 +59,7 @@ NetCamView::NetCamView(QWidget* parent) setWindowTitle("Tox video"); setMinimumSize(320,240); - displayLabel->setScaledContents(true); + displayLabel->setAlignment(Qt::AlignCenter); mainLayout->addWidget(displayLabel); } @@ -73,10 +73,10 @@ void NetCamView::updateDisplay(vpx_image* frame) core->increaseVideoBusyness(); - QImage img = convert(*frame); + img = convert(*frame); vpx_img_free(frame); - displayLabel->setPixmap(QPixmap::fromImage(img)); + displayLabel->setPixmap(QPixmap::fromImage(img).scaled(displayLabel->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); core->decreaseVideoBusyness(); } @@ -108,3 +108,9 @@ QImage NetCamView::convert(vpx_image& frame) return img; } + +void NetCamView::resizeEvent(QResizeEvent *e) +{ + Q_UNUSED(e) + displayLabel->setPixmap(QPixmap::fromImage(img).scaled(displayLabel->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); +} diff --git a/widget/netcamview.h b/widget/netcamview.h index 0aba0edd9..a8698eaa3 100644 --- a/widget/netcamview.h +++ b/widget/netcamview.h @@ -24,6 +24,7 @@ class QShowEvent; class QPainter; class QLabel; class QHBoxLayout; +class QImage; class vpx_image; class NetCamView : public QWidget @@ -39,10 +40,14 @@ public slots: private: static QImage convert(vpx_image& frame); +protected: + void resizeEvent(QResizeEvent *e); + private: QLabel *displayLabel; QImage lastFrame; QHBoxLayout* mainLayout; + QImage img; }; #endif // NETCAMVIEW_H diff --git a/widget/selfcamview.cpp b/widget/selfcamview.cpp index 6436e24d9..7e9c3d252 100644 --- a/widget/selfcamview.cpp +++ b/widget/selfcamview.cpp @@ -36,7 +36,7 @@ SelfCamView::SelfCamView(Camera* Cam, QWidget* parent) updateDisplayTimer->setInterval(5); updateDisplayTimer->setSingleShot(false); - displayLabel->setScaledContents(true); + displayLabel->setAlignment(Qt::AlignCenter); mainLayout->addWidget(displayLabel); @@ -59,6 +59,11 @@ void SelfCamView::showEvent(QShowEvent* event) void SelfCamView::updateDisplay() { - displayLabel->setPixmap(QPixmap::fromImage(cam->getLastImage())); + displayLabel->setPixmap(QPixmap::fromImage(cam->getLastImage()).scaled(displayLabel->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); } +void SelfCamView::resizeEvent(QResizeEvent *e) +{ + Q_UNUSED(e) + updateDisplay(); +} diff --git a/widget/selfcamview.h b/widget/selfcamview.h index a8cc29679..26a8b315c 100644 --- a/widget/selfcamview.h +++ b/widget/selfcamview.h @@ -42,6 +42,9 @@ private: void showEvent(QShowEvent*); void paint(QPainter *painter); +protected: + void resizeEvent(QResizeEvent *e); + private: QLabel *displayLabel; QHBoxLayout* mainLayout;