summaryrefslogtreecommitdiff
path: root/src/qcam/viewfinder.cpp
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-03-23 03:50:53 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-03-24 10:34:12 +0200
commitcb6395599e843241710f1d7224ce94fd28fbae80 (patch)
treeabc486c238e71eb7653203e3e7716c23cfb32149 /src/qcam/viewfinder.cpp
parent5816c0c38e2a7dce1bcbf88f9fdcc330358eea8d (diff)
qcam: viewfinder: Display icon when stopping capture
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 <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src/qcam/viewfinder.cpp')
-rw-r--r--src/qcam/viewfinder.cpp32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/qcam/viewfinder.cpp b/src/qcam/viewfinder.cpp
index 3f984efb..45e226b5 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