mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-23 16:45:07 +03:00
qcam: viewfinder_qt: Maintain aspect ratio
Keep the image aspect ratio when displaying in the viewfinder. When the window is adjusted to a size that differs in aspect ratio to the image, keep the image centered in the main window. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
parent
d890a7e48e
commit
644986c2b7
2 changed files with 16 additions and 2 deletions
|
@ -18,6 +18,7 @@
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QResizeEvent>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
|
||||||
#include "../common/image.h"
|
#include "../common/image.h"
|
||||||
|
@ -40,7 +41,7 @@ static const QMap<libcamera::PixelFormat, QImage::Format> nativeFormats
|
||||||
};
|
};
|
||||||
|
|
||||||
ViewFinderQt::ViewFinderQt(QWidget *parent)
|
ViewFinderQt::ViewFinderQt(QWidget *parent)
|
||||||
: QWidget(parent), buffer_(nullptr)
|
: QWidget(parent), place_(rect()), buffer_(nullptr)
|
||||||
{
|
{
|
||||||
icon_ = QIcon(":camera-off.svg");
|
icon_ = QIcon(":camera-off.svg");
|
||||||
}
|
}
|
||||||
|
@ -148,7 +149,7 @@ void ViewFinderQt::paintEvent(QPaintEvent *)
|
||||||
|
|
||||||
/* If we have an image, draw it. */
|
/* If we have an image, draw it. */
|
||||||
if (!image_.isNull()) {
|
if (!image_.isNull()) {
|
||||||
painter.drawImage(rect(), image_, image_.rect());
|
painter.drawImage(place_, image_, image_.rect());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,3 +182,14 @@ QSize ViewFinderQt::sizeHint() const
|
||||||
{
|
{
|
||||||
return size_.isValid() ? size_ : QSize(640, 480);
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ Q_SIGNALS:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *) override;
|
void paintEvent(QPaintEvent *) override;
|
||||||
|
void resizeEvent(QResizeEvent *) override;
|
||||||
QSize sizeHint() const override;
|
QSize sizeHint() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -51,6 +52,7 @@ private:
|
||||||
|
|
||||||
libcamera::PixelFormat format_;
|
libcamera::PixelFormat format_;
|
||||||
QSize size_;
|
QSize size_;
|
||||||
|
QRect place_;
|
||||||
|
|
||||||
/* Camera stopped icon */
|
/* Camera stopped icon */
|
||||||
QSize vfSize_;
|
QSize vfSize_;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue