From patchwork Mon Jun 14 11:11:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 12592 X-Patchwork-Delegate: kieran.bingham@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 7518FC3218 for ; Mon, 14 Jun 2021 11:11:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EA8906892E; Mon, 14 Jun 2021 13:11:15 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="B8lOSLiM"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2C2266029D for ; Mon, 14 Jun 2021 13:11:15 +0200 (CEST) Received: from Q.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3FD62A59; Mon, 14 Jun 2021 13:11:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1623669074; bh=LHTzgC3SGcknbUsDYCtumc2BVJYbpYf0T7SnajkaIG4=; h=From:To:Cc:Subject:Date:From; b=B8lOSLiMpvJZnxx3zj75avcmqj4Bt6Ip9FBw0HGg0EcMkIeUCq83CPbwNgPxy1sRg InAt/TzACKXPnnAbQkJPD6M74nb2dkUiPVdUJTmssTqjdTF9m/t96gN6Ixw0UmFUfK OC1aesHTAxzMDLvNenkHbiJFMCk1r0UlgrDmVlKM= From: Kieran Bingham To: libcamera devel Date: Mon, 14 Jun 2021 12:11:10 +0100 Message-Id: <20210614111110.33324-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] qcam: viewfinder: Maintain aspect ratio X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 viewpoint. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- v2: (fixed up from Laurent's review comments) - No longer accept event on an invalid size. - centering simplifed src/qcam/viewfinder_qt.cpp | 16 ++++++++++++++-- src/qcam/viewfinder_qt.h | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/qcam/viewfinder_qt.cpp b/src/qcam/viewfinder_qt.cpp index e436714c6bdb..08ac29e9fa99 100644 --- a/src/qcam/viewfinder_qt.cpp +++ b/src/qcam/viewfinder_qt.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -34,7 +35,7 @@ static const QMap nativeFormats }; ViewFinderQt::ViewFinderQt(QWidget *parent) - : QWidget(parent), buffer_(nullptr) + : QWidget(parent), place_(rect()), buffer_(nullptr) { icon_ = QIcon(":camera-off.svg"); } @@ -146,7 +147,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; } @@ -179,3 +180,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()); + + event->accept(); +} diff --git a/src/qcam/viewfinder_qt.h b/src/qcam/viewfinder_qt.h index d755428887c0..bf31b81b3437 100644 --- a/src/qcam/viewfinder_qt.h +++ b/src/qcam/viewfinder_qt.h @@ -42,6 +42,7 @@ Q_SIGNALS: protected: void paintEvent(QPaintEvent *) override; + void resizeEvent(QResizeEvent *) override; QSize sizeHint() const override; private: @@ -49,6 +50,7 @@ private: libcamera::PixelFormat format_; QSize size_; + QRect place_; /* Camera stopped icon */ QSize vfSize_;