diff options
Diffstat (limited to 'src/apps/qcam/viewfinder_qt.cpp')
-rw-r--r-- | src/apps/qcam/viewfinder_qt.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/apps/qcam/viewfinder_qt.cpp b/src/apps/qcam/viewfinder_qt.cpp index 4821c27d..492648cf 100644 --- a/src/apps/qcam/viewfinder_qt.cpp +++ b/src/apps/qcam/viewfinder_qt.cpp @@ -18,6 +18,7 @@ #include <QMap> #include <QMutexLocker> #include <QPainter> +#include <QResizeEvent> #include <QtDebug> #include "../common/image.h" @@ -40,7 +41,7 @@ static const QMap<libcamera::PixelFormat, QImage::Format> nativeFormats }; ViewFinderQt::ViewFinderQt(QWidget *parent) - : QWidget(parent), buffer_(nullptr) + : QWidget(parent), place_(rect()), buffer_(nullptr) { icon_ = QIcon(":camera-off.svg"); } @@ -148,7 +149,7 @@ void ViewFinderQt::paintEvent(QPaintEvent *) /* If we have an image, draw it. */ if (!image_.isNull()) { - painter.drawImage(rect(), image_, image_.rect()); + painter.drawImage(place_, image_, image_.rect()); return; } @@ -181,3 +182,14 @@ QSize ViewFinderQt::sizeHint() const { return size_.isValid() ? size_ : QSize(640, 480); } + +void ViewFinderQt::resizeEvent(QResizeEvent *event) +{ + if (!size_.isValid()) + return; + + place_.setSize(size_.scaled(event->size(), Qt::KeepAspectRatio)); + place_.moveCenter(rect().center()); + + QWidget::resizeEvent(event); +} |