summaryrefslogtreecommitdiff
path: root/src/qcam
diff options
context:
space:
mode:
Diffstat (limited to 'src/qcam')
-rw-r--r--src/qcam/assets/feathericons/feathericons.qrc1
-rw-r--r--src/qcam/viewfinder.cpp32
-rw-r--r--src/qcam/viewfinder.h7
3 files changed, 39 insertions, 1 deletions
diff --git a/src/qcam/assets/feathericons/feathericons.qrc b/src/qcam/assets/feathericons/feathericons.qrc
index 6ca3a846..c4eb7a0b 100644
--- a/src/qcam/assets/feathericons/feathericons.qrc
+++ b/src/qcam/assets/feathericons/feathericons.qrc
@@ -1,5 +1,6 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
+<file>./camera-off.svg</file>
<file>./play-circle.svg</file>
<file>./save.svg</file>
<file>./stop-circle.svg</file>
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
diff --git a/src/qcam/viewfinder.h b/src/qcam/viewfinder.h
index 4d0622a8..1a27f99e 100644
--- a/src/qcam/viewfinder.h
+++ b/src/qcam/viewfinder.h
@@ -9,6 +9,7 @@
#include <stddef.h>
+#include <QIcon>
#include <QImage>
#include <QMutex>
#include <QSize>
@@ -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_ */