From patchwork Mon Mar 23 17:35:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3287 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 27FA562C9A for ; Mon, 23 Mar 2020 18:36:23 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C4E4EA31 for ; Mon, 23 Mar 2020 18:36:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1584984982; bh=Bk9RqVAYRV6bSXazONtXWPi5XHAba8loE+9oT3Xlh38=; h=From:To:Subject:Date:In-Reply-To:References:From; b=pHgxDY+EK1jPmK1DhaH3y+G9HqD+U+vCWihJRiU/slv60zxED7ID1UwQ24fObC6M3 imvZfnxVAB/WLqEMNoJmTiEdGrUf5TIuX4pKvlNeXDK+czUHTekclNaRE34Lb0LzV6 FW40HpYlkEPn2d9CqO99/aNwwSXexd+0BlO++NbA= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 23 Mar 2020 19:35:58 +0200 Message-Id: <20200323173559.21109-21-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200323173559.21109-1-laurent.pinchart@ideasonboard.com> References: <20200323173559.21109-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 20/21] qcam: viewfinder: Display icon when stopping capture 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: , X-List-Received-Date: Mon, 23 Mar 2020 17:36:26 -0000 When stopping capture, display an icon instead of the last frame. This is required to be able to release the last buffer when the viewfinder operators in zero-copy mode. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- Changes since v1: - Don't use QSize::shrunkBy() which was introduced in Qt 5.14 - Move stop() function to previous commit --- src/qcam/assets/feathericons/feathericons.qrc | 1 + src/qcam/viewfinder.cpp | 32 ++++++++++++++++++- src/qcam/viewfinder.h | 7 ++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/qcam/assets/feathericons/feathericons.qrc b/src/qcam/assets/feathericons/feathericons.qrc index 6ca3a846803c..c4eb7a0be688 100644 --- a/src/qcam/assets/feathericons/feathericons.qrc +++ b/src/qcam/assets/feathericons/feathericons.qrc @@ -1,5 +1,6 @@ +./camera-off.svg ./play-circle.svg ./save.svg ./stop-circle.svg diff --git a/src/qcam/viewfinder.cpp b/src/qcam/viewfinder.cpp index 3f984efbf434..45e226b58135 100644 --- a/src/qcam/viewfinder.cpp +++ b/src/qcam/viewfinder.cpp @@ -20,6 +20,7 @@ ViewFinder::ViewFinder(QWidget *parent) : QWidget(parent), buffer_(nullptr) { + icon_ = QIcon(":camera-off.svg"); } ViewFinder::~ViewFinder() @@ -114,7 +115,36 @@ QImage ViewFinder::getCurrentImage() void ViewFinder::paintEvent(QPaintEvent *) { QPainter painter(this); - painter.drawImage(rect(), image_, image_.rect()); + + /* If we have an image, draw it. */ + if (!image_.isNull()) { + painter.drawImage(rect(), image_, image_.rect()); + return; + } + + /* + * Otherwise, draw the camera stopped icon. Render it to the pixmap if + * the size has changed. + */ + constexpr int margin = 20; + + if (vfSize_ != size() || pixmap_.isNull()) { + QSize vfSize = size() - QSize{ 2 * margin, 2 * margin }; + QSize pixmapSize{ 1, 1 }; + pixmapSize.scale(vfSize, Qt::KeepAspectRatio); + pixmap_ = icon_.pixmap(pixmapSize); + + vfSize_ = size(); + } + + QPoint point{ margin, margin }; + if (pixmap_.width() < width() - 2 * margin) + point.setX((width() - pixmap_.width()) / 2); + else + point.setY((height() - pixmap_.height()) / 2); + + painter.setBackgroundMode(Qt::OpaqueMode); + painter.drawPixmap(point, pixmap_); } QSize ViewFinder::sizeHint() const diff --git a/src/qcam/viewfinder.h b/src/qcam/viewfinder.h index 4d0622a8e4ea..1a27f99ea202 100644 --- a/src/qcam/viewfinder.h +++ b/src/qcam/viewfinder.h @@ -9,6 +9,7 @@ #include +#include #include #include #include @@ -53,6 +54,12 @@ private: libcamera::PixelFormat format_; QSize size_; + /* Camera stopped icon */ + QSize vfSize_; + QIcon icon_; + QPixmap pixmap_; + + /* Buffer and render image */ libcamera::FrameBuffer *buffer_; QImage image_; QMutex mutex_; /* Prevent concurrent access to image_ */