From patchwork Wed Aug 10 15:03:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Utkarsh Tiwari X-Patchwork-Id: 17069 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 2771BC3272 for ; Wed, 10 Aug 2022 15:04:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B27AB63335; Wed, 10 Aug 2022 17:04:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1660143845; bh=Wch9S/K/rq7sqVEfWKmqaA/Tk9UfQePdXxaS0+8gKDc=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=31X+83DMjEjFBv1euaGEC+GK/KB4WeQuQ8SXZoSNj64onURqMfHkHMzlP9rrqv3qw UNva2JnJl7jHHQTc2ZBgP4X08QsnOf05i3vd3yMcKAw8JtJr5/3FMpOo9ypstEgdBD GoKodLEbIzHIskZbRBAIa6IbP52IDOji1dRjjw78jW4ghd32+0ryuLIsom8m0wm4Km JsYSPvKkIX1ePmmN+sNRO73sbJhmmddZ5N3ZbzMrzlGPUHMTcEg/Kadju/xy4CtkWr w0PNMHgPPoZrzFQwY2A2n4UPzMdnxT5UX6Z9SJKjhl8X7qZ2VXd8Z1wIdesRgxQ1Ig ye4yd8WUHJtTw== Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8124763333 for ; Wed, 10 Aug 2022 17:04:02 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="YHXSJO7A"; dkim-atps=neutral Received: by mail-pg1-x530.google.com with SMTP id l64so14641391pge.0 for ; Wed, 10 Aug 2022 08:04:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=9iwKcpTOSLNqoHIQa8Jl32eZDEficXvu3/ctjnyaBtA=; b=YHXSJO7AjvZ7Qrh3AxnTRk66WXX+hhmOKxOtqtOFrWmC7pu2zXGVR/cNDuhX4pvf0i un1HeiQ6CTAGjHcBU2XebyjklwCiZOMko7uMs0Zsl+YYJervrKB0zMGwby8g9ntaNSRb lQkSoEh5BgIPgo0BegGkj0UCkXufXOtA0Vumf4kPe5eI3kYARTX3vk/678hNNdR+WCHN yrY25M1DczGZQV8S/iVSkMXfo9AfqzKClFYVDeAg+OiLPgFzYbcF+fjXi8rulJ1EvMgt jpwJpJUTbCA3pBNxbCh11oVQyZ7TPqAjAcoz8XLY1KBAtA7Iuf1uamxErduoe+xS92lb eJFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=9iwKcpTOSLNqoHIQa8Jl32eZDEficXvu3/ctjnyaBtA=; b=qRL7d1DCuAJ3JfIaMWGV3GWlClLnDHbIvK+Z3LxwJEAVporyudE4dxTpbjqzUfYwpi oRWD5IqpERpddsCCIsmHWf6MtycrikHlOvv9JI+KxIfzeAt+uyDhggV5xg1X4xR0iJWu 0qJ8yNfbIJWwJ3HG5lAzkYoPbyuJIvN/ULi4JJojKZ9auppVoF6SF7bG9+G7Omq8cFMg 0dNSPg6uyds7A60tuM7G2cn4iR+ty/qL2YLGW7Ec7Wls49/572ieHo/twUxoq8F/q0OO rq+5QXLnsXUOpawRUsUzFJoBCdiEIaTmmG6Xd5n3nOrQDD0QqN6kLfK/Rb9BqIaJ4sT8 z03w== X-Gm-Message-State: ACgBeo0fGdmM4kkWYs6aHk2bZjw5MmWIsSP2VHsXFj8SSmPzilLZ9kS5 nJCREwbiJh74nqfK8AhzQd88Eo5Oveo= X-Google-Smtp-Source: AA6agR4DwaF7NWYxCG2ZcBGiF3W3r65OCTTF/yZnNwyPNNVAWZ/ugeCS5TZZCOOt4sUOh4CH+QmKPg== X-Received: by 2002:a05:6a00:9a7:b0:52d:bbf9:c3d5 with SMTP id u39-20020a056a0009a700b0052dbbf9c3d5mr27987008pfg.9.1660143841722; Wed, 10 Aug 2022 08:04:01 -0700 (PDT) Received: from localhost.localdomain ([2404:bd00:3:d2bc:2a55:4cae:bf8f:f4ed]) by smtp.gmail.com with ESMTPSA id b3-20020a1709027e0300b0016f1319d2a7sm12882624plm.297.2022.08.10.08.03.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 08:04:01 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 10 Aug 2022 20:33:44 +0530 Message-Id: <20220810150349.414043-4-utkarsh02t@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220810150349.414043-1-utkarsh02t@gmail.com> References: <20220810150349.414043-1-utkarsh02t@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v8 3/8] qcam: MainWindow: Replace cameraCombo_ with CameraSelectorDialog 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-Patchwork-Original-From: Utkarsh Tiwari via libcamera-devel From: Utkarsh Tiwari Reply-To: Utkarsh Tiwari Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Replace the cameraCombo_ on the toolbar with a QPushButton which displays the CameraSelectorDialog. This would allow the user to view information about the camera when switching. The QPushButton text is set to the camera Id currently in use. Signed-off-by: Utkarsh Tiwari Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- Difference from v7: 1. Moved firstCameraSelect_ from 8/8 to here because if we were previously supplied camera id on the cmdline we always used that and sdisabled the showing of the dialog src/qcam/main_window.cpp | 51 ++++++++++++++++++++-------------------- src/qcam/main_window.h | 6 +++-- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 9ec94708..d1b8d2dd 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -98,7 +98,8 @@ private: MainWindow::MainWindow(CameraManager *cm, const OptionsParser::Options &options) : saveRaw_(nullptr), cameraSelectorDialog_(nullptr), options_(options), - cm_(cm), allocator_(nullptr), isCapturing_(false), captureRaw_(false) + cm_(cm), allocator_(nullptr), isCapturing_(false), captureRaw_(false), + firstCameraSelect_(true) { int ret; @@ -193,14 +194,11 @@ int MainWindow::createToolbars() connect(action, &QAction::triggered, this, &MainWindow::quit); /* Camera selector. */ - cameraCombo_ = new QComboBox(); - connect(cameraCombo_, QOverload::of(&QComboBox::activated), + cameraSelectButton_ = new QPushButton; + connect(cameraSelectButton_, &QPushButton::clicked, this, &MainWindow::switchCamera); - for (const std::shared_ptr &cam : cm_->cameras()) - cameraCombo_->addItem(QString::fromStdString(cam->id())); - - toolbar_->addWidget(cameraCombo_); + toolbar_->addWidget(cameraSelectButton_); toolbar_->addSeparator(); @@ -260,14 +258,18 @@ void MainWindow::updateTitle() * Camera Selection */ -void MainWindow::switchCamera(int index) +void MainWindow::switchCamera() { /* Get and acquire the new camera. */ - const auto &cameras = cm_->cameras(); - if (static_cast(index) >= cameras.size()) + std::string newCameraId = chooseCamera(); + + if (newCameraId.empty()) return; - const std::shared_ptr &cam = cameras[index]; + if (camera_ && newCameraId == camera_->id()) + return; + + const std::shared_ptr &cam = cm_->get(newCameraId); if (cam->acquire()) { qInfo() << "Failed to acquire camera" << cam->id().c_str(); @@ -298,12 +300,17 @@ std::string MainWindow::chooseCamera() * Use the camera specified on the command line, if any, or display the * camera selection dialog box otherwise. */ - if (options_.isSet(OptCamera)) + if (firstCameraSelect_ && options_.isSet(OptCamera)) { + firstCameraSelect_ = false; return static_cast(options_[OptCamera]); + } - if (cameraSelectorDialog_->exec() == QDialog::Accepted) - return cameraSelectorDialog_->getCameraId(); - else + if (cameraSelectorDialog_->exec() == QDialog::Accepted) { + std::string cameraId = cameraSelectorDialog_->getCameraId(); + cameraSelectButton_->setText(QString::fromStdString(cameraId)); + + return cameraId; + } else return std::string(); } @@ -327,8 +334,8 @@ int MainWindow::openCamera() return -EBUSY; } - /* Set the combo-box entry with the currently selected Camera. */ - cameraCombo_->setCurrentText(QString::fromStdString(cameraName)); + /* Set the camera switch button with the currently selected Camera id. */ + cameraSelectButton_->setText(QString::fromStdString(cameraName)); return 0; } @@ -592,22 +599,16 @@ void MainWindow::processHotplug(HotplugEvent *e) Camera *camera = e->camera(); HotplugEvent::PlugEvent event = e->hotplugEvent(); - if (event == HotplugEvent::HotPlug) { - cameraCombo_->addItem(QString::fromStdString(camera->id())); - + if (event == HotplugEvent::HotPlug) cameraSelectorDialog_->cameraAdded(camera); - } else if (event == HotplugEvent::HotUnplug) { + else if (event == HotplugEvent::HotUnplug) { /* Check if the currently-streaming camera is removed. */ if (camera == camera_.get()) { toggleCapture(false); camera_->release(); camera_.reset(); - cameraCombo_->setCurrentIndex(0); } - int camIndex = cameraCombo_->findText(QString::fromStdString(camera->id())); - cameraCombo_->removeItem(camIndex); - cameraSelectorDialog_->cameraRemoved(camera); } } diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h index 4ad5e6e9..f9ea8bd3 100644 --- a/src/qcam/main_window.h +++ b/src/qcam/main_window.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -60,7 +61,7 @@ private Q_SLOTS: void quit(); void updateTitle(); - void switchCamera(int index); + void switchCamera(); void toggleCapture(bool start); void saveImageAs(); @@ -90,7 +91,7 @@ private: /* UI elements */ QToolBar *toolbar_; QAction *startStopAction_; - QComboBox *cameraCombo_; + QPushButton *cameraSelectButton_; QAction *saveRaw_; ViewFinder *viewfinder_; @@ -116,6 +117,7 @@ private: /* Capture state, buffers queue and statistics */ bool isCapturing_; bool captureRaw_; + bool firstCameraSelect_; libcamera::Stream *vfStream_; libcamera::Stream *rawStream_; std::map> freeBuffers_;