From patchwork Wed Aug 3 17:55:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Utkarsh Tiwari X-Patchwork-Id: 16959 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 7978DC3272 for ; Wed, 3 Aug 2022 17:55:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 317BE63321; Wed, 3 Aug 2022 19:55:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1659549335; bh=xdyTipN04m4FOCC8IhJVcDGM5cq7LQ8at0Jd+ICqVrg=; 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=gm+PtUJ7aHD5lTw9qW17XTV01Y1dsWRGWSCSXxa4vIhWHhFZHnxNkDMiMRQ6mjish XD34LcJ9d1gxW7fSD9+h3f6fzqjk/zTjgJ0WVvvZ4InRrB8dtjNdmhMPzVHrK+Ol9B 3PMvUeIni6wVKUK5ixud5j/4onHvaWNbcGK9aMaDr7pEUfTBJXeggtiH3wQ5cf0hCE GVxEfjc+6P1y/t1/WtIaOmhpY5edcN7mhilIrgcjww1alWzKEksw43pE/1qn+qIPcb 3lGFejQORPh5tCIsjVHEEB2btiBf7J8UDYZ1iA1CTu9BhM/FQ2KB6Ne4YqDNsq10QA k+2SGmvRFZpCA== Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E06586331E for ; Wed, 3 Aug 2022 19:55:32 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="aL0D0F39"; dkim-atps=neutral Received: by mail-pg1-x533.google.com with SMTP id 13so1333932pgc.8 for ; Wed, 03 Aug 2022 10:55:32 -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=zTPzlmBu9WrbT3szxYMLbFPUmXMs8/t6CORexb8HThk=; b=aL0D0F39Gk4HZnCAbvq6I+WIPj37ffbOKxoVJCC6du8J8ua+lmKP3sngF5a5saqSLh nCMFRT9hD4hwToakL62+hHgLjkIPH9gpMk3mWNeGNop/PbzzTAt7m1DMeNLDMqDNW5Qu IMvKjYUjp1JS+xOJuDP+BzlY+7Q+XjM6u5A3zILiI0mV+JTZj7FT3iiPOe0BsaDInxac 2Y66yRrX5JCnnwe2MBcWnufCtTpjFdRi0bY1mkHa3EF+mku3GmM7In4Sg22yX0e6mY0Y f1leiMCFutgQeEBL2IcVpodS6oYIYBNgHvjTafPeW6g9L9yQIYJsXIeF92ZFN7lhGT5d Mx5g== 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=zTPzlmBu9WrbT3szxYMLbFPUmXMs8/t6CORexb8HThk=; b=nKtCxDrir/NXri9YCqiD1uh4q+o2OBFo2wWafKvA7PhbyL6fLUS6++D6bFKJpCK3Cv Uvwe6Mx8ZFDumaqED3xDlOjrddY2XoJunrlITwhW7mR3IyOFVdVKDJw8C3ZqWaenTMjP AtZVNXbXqJzzMleUFnqOkMb6tgvI8bk1Bl7pj0OERk3Umn2O8d6CBni/3xfUVunNLTom VLC/8xN7nDQuSARAdlzpQWx2S3kS4iyewWkwMjctR8cQD99H4XhsKaIYB8nw0z4EJpRI M58iBwjE47BFoVTkzNAE1Ed0C4nsD6tTJroQCy57zoSTOtrUtwBsgbT2zzOyI9DYtfYT 5AZg== X-Gm-Message-State: AJIora9T09LtYG34Fk/QTFjwtBoNeTvse2QygMQNmFDm3IwjtCgrUmJ7 TeJaAcvZmaWEi0Iv76qwQzDLHSZxYzY= X-Google-Smtp-Source: AGRyM1vRZsqdPS4tLIaAmb+MvvK0trf5ARIpltTzohntCcU6U/lgmhxjrFXAvyLqlNzXGdcAYfSdBQ== X-Received: by 2002:a63:4c4d:0:b0:41a:a125:60c9 with SMTP id m13-20020a634c4d000000b0041aa12560c9mr21780249pgl.329.1659549331193; Wed, 03 Aug 2022 10:55:31 -0700 (PDT) Received: from localhost.localdomain ([2404:bd00:3:d5b8:ad21:c99c:170f:1ae]) by smtp.gmail.com with ESMTPSA id f3-20020a170902860300b0016357fd0fd1sm2193343plo.69.2022.08.03.10.55.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Aug 2022 10:55:30 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 3 Aug 2022 23:25:17 +0530 Message-Id: <20220803175517.175332-5-utkarsh02t@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220803175517.175332-1-utkarsh02t@gmail.com> References: <20220803175517.175332-1-utkarsh02t@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/4] qcam: MainWindow: Replace cameraCombo_ with cameraSelectDialog 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 cameraSelectDialog. 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: Umang Jain --- src/qcam/main_window.cpp | 47 ++++++++++++++++++++++------------------ src/qcam/main_window.h | 5 +++-- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 81fa3e60..2a9dcc1e 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -198,14 +198,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(); @@ -265,14 +262,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 cameraId = chooseCamera(); + if (cameraId.empty()) return; - const std::shared_ptr &cam = cameras[index]; + /* Don't try the current camera. */ + if (cameraId == camera_->id()) + return; + + const std::shared_ptr &cam = cm_->get(cameraId); if (cam->acquire()) { qInfo() << "Failed to acquire camera" << cam->id().c_str(); @@ -290,6 +291,9 @@ void MainWindow::switchCamera(int index) camera_->release(); camera_ = cam; + /* Set the QPushButton text with current camera. */ + cameraSelectButton_->setText(QString::fromStdString(camera_->id())); + startStopAction_->setChecked(true); } @@ -356,10 +360,16 @@ std::string MainWindow::chooseCamera() * When the Qdialog starts, the QComboBox would have the first * camera's Id as its currentText. */ - if (cm_->cameras().size()) - currentCamera = cm_->cameras()[0]; - else - currentCamera = nullptr; + if (!isCapturing_) { + if (cm_->cameras().size()) + currentCamera = cm_->cameras()[0]; + else + currentCamera = nullptr; + } else { + int cameraIndex = cameraIdComboBox_->findText(QString::fromStdString(camera_->id())); + cameraIdComboBox_->setCurrentIndex(cameraIndex); + currentCamera = camera_; + } if (currentCamera) updateCameraInfo(currentCamera); @@ -428,8 +438,8 @@ int MainWindow::openCamera() return -EBUSY; } - /* Set the combo-box entry with the currently selected Camera. */ - cameraCombo_->setCurrentText(QString::fromStdString(cameraName)); + /* Set the QPushButton text with the currently selected Camera. */ + cameraSelectButton_->setText(QString::fromStdString(cameraName)); return 0; } @@ -695,7 +705,6 @@ void MainWindow::processHotplug(HotplugEvent *e) if (event == HotplugEvent::HotPlug) { QString cameraId = QString::fromStdString(camera->id()); - cameraCombo_->addItem(cameraId); /* Update cameraIdCombox_ to include the new camera. */ if (cameraIdComboBox_) @@ -706,16 +715,12 @@ void MainWindow::processHotplug(HotplugEvent *e) toggleCapture(false); camera_->release(); camera_.reset(); - cameraCombo_->setCurrentIndex(0); } if (cameraIdComboBox_) { int cameraIdIndex = cameraIdComboBox_->findText(QString::fromStdString(camera_->id())); cameraIdComboBox_->removeItem(cameraIdIndex); } - - int camIndex = cameraCombo_->findText(QString::fromStdString(camera->id())); - cameraCombo_->removeItem(camIndex); } } diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h index 3a1c6156..b15f9409 100644 --- a/src/qcam/main_window.h +++ b/src/qcam/main_window.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -62,7 +63,7 @@ private Q_SLOTS: void quit(); void updateTitle(); - void switchCamera(int index); + void switchCamera(); void toggleCapture(bool start); void saveImageAs(); @@ -96,7 +97,7 @@ private: /* UI elements */ QToolBar *toolbar_; QAction *startStopAction_; - QComboBox *cameraCombo_; + QPushButton *cameraSelectButton_; QAction *saveRaw_; ViewFinder *viewfinder_;