From patchwork Sun Aug 7 15:40:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Utkarsh Tiwari X-Patchwork-Id: 17012 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 68D3FC3272 for ; Sun, 7 Aug 2022 15:40:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D392963327; Sun, 7 Aug 2022 17:40:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1659886822; bh=K6yTNq9W8bpNVicgBdGQnuNqkSC8a2n+cuPHN4KR0ag=; 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=Vw0RvJUYdBjfNtCcpXSBsO5QyLRzurCEyxsFOoxeu55sphfnzj1OzG1zGJzjMqWKz uSZapSbLMP8yRZ45hiqF6OMQ8boeQJorhiJeXlflE+9JM09dSSBf2dXwsBSjxv8VRJ TpmTWMy5BdKkUAdE+LR4kghKhCqcni//L2qNKC3+sZInLGbJetkF4Yo/PeamX+pVFl PqY1T8ufDKXbWIVJ11jJyasCveregEi3NdehY1RKIIS+npai1/ue9Zt8YTCD9nvoi/ FB+YE2wkGeKINSokrLVTTQqd/jHM/ksGi7bc3ZymbKqz11XS1ndddujrYh2wemeSrk 3AC2Bf6NLRslA== Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8BF9963312 for ; Sun, 7 Aug 2022 17:40:20 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Oa00bzdx"; dkim-atps=neutral Received: by mail-pg1-x535.google.com with SMTP id 73so6566121pgb.9 for ; Sun, 07 Aug 2022 08:40:20 -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=wmaDYH9DIjUXsNGf+aQEiWFKdlIdCjQIpa/XcBfSS9M=; b=Oa00bzdxNuUiHjYkuYBcxnGNodeaYwUOvlutj+2tlDG0pZP0wNsD/z8DP4UAI06ssq GTWd+L4e7FfnN54jKLSK4Rx93WYn2uzKIxeOc3Tnnlig7X7Bt9ugzuub6NfjVNUYMlA1 KA927pa/Zt2D0AicjY29mXTiBndFng1o/zMeItGUNFxZR7Lit1230RlRavII04I5b43N me2cthx1bLpxHgwm09+U6fgCaNIsP+Ptp8CHrirFzpPCiFr4w92v5hVpHyXUR0eftIkD 9zBcO2drCbzOIVwJWPEH/AsUEX5QbKZ4W124+zhqXW5btbw1Q9KJspazuvkY1UJM6LgR B0YQ== 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=wmaDYH9DIjUXsNGf+aQEiWFKdlIdCjQIpa/XcBfSS9M=; b=4AtCoaDxkFsHy5wBJ+ObcljwU+jDYm5Gciet4yp5BeVYTZ7Ugm8Iu4fIyjEEVe34tE k9o8ZKMJPb70oqwLZi243VgcTtnguVFc6edeimxU3x8srJP/PsPND8Veb3h0kmsiQaIv fwXeqDjh+HSr7EU7MKNMp2Ai7whsXjpiI+l6xf2S3URj8Aq4DP3BZ7lYPqsoIOWbJ3Jd 5jM8fxIVNAtXP8eqebkj+C2ft7dsTLm52zqd9mH++SNLjAy+HihGiqb0wmws5HSqTeVj uqc86UqbdB6ASmGhLW1LF/HFV/f5GBG+T46EFpMWUp4Z3ohd5gGACgrp5J+GYgZ8l6X5 khHw== X-Gm-Message-State: ACgBeo2lxy587EkeV+61SLJy9gVfu5i3E0IL2DUB9fNTV8y4i3LeAN2l I5qGoBRrVXTA00vmjyGYmACqhm58QZ4= X-Google-Smtp-Source: AA6agR63ziX0/PwgE2dCTSEfLoaE38TK8egtIlGy0mi58XhyIHhkV9rWqKK62isctnjRP9NiYdJqTQ== X-Received: by 2002:a63:8bc7:0:b0:41c:d1e1:7fb2 with SMTP id j190-20020a638bc7000000b0041cd1e17fb2mr12577364pge.281.1659886818635; Sun, 07 Aug 2022 08:40:18 -0700 (PDT) Received: from localhost.localdomain ([2404:bd00:3:d2bc:d9f0:4d1:f1a2:ade]) by smtp.gmail.com with ESMTPSA id w3-20020a17090a6b8300b001f4e8dbed8csm9055843pjj.7.2022.08.07.08.40.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Aug 2022 08:40:18 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Sun, 7 Aug 2022 21:10:02 +0530 Message-Id: <20220807154002.91607-1-utkarsh02t@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220806190433.59128-4-utkarsh02t@gmail.com> References: <20220806190433.59128-4-utkarsh02t@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2.1 3/4] qcam: MainWindow: Replace cameraCombo_ with camSelectDialog 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 camSelectDialog. 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 --- Difference from v2 : remove redudant function getCurrentCamera, its job can be done by getCameraId() src/qcam/main_window.cpp | 41 ++++++++++++++++++++-------------------- src/qcam/main_window.h | 5 +++-- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index dd30817d..98c22b71 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -193,14 +193,11 @@ int MainWindow::createToolbars() connect(action, &QAction::triggered, this, &MainWindow::quit); /* Camera selector. */ - cameraCombo_ = new QComboBox(); - connect(cameraCombo_, QOverload::of(&QComboBox::activated), + cameraSwitchButton_ = new QPushButton; + connect(cameraSwitchButton_, &QPushButton::clicked, this, &MainWindow::switchCamera); - for (const std::shared_ptr &cam : cm_->cameras()) - cameraCombo_->addItem(QString::fromStdString(cam->id())); - - toolbar_->addWidget(cameraCombo_); + toolbar_->addWidget(cameraSwitchButton_); toolbar_->addSeparator(); @@ -260,14 +257,19 @@ 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_) { + if (newCameraId == camera_->id()) + return; + } + const std::shared_ptr &cam = cm_->get(newCameraId); if (cam->acquire()) { qInfo() << "Failed to acquire camera" << cam->id().c_str(); @@ -292,9 +294,12 @@ std::string MainWindow::chooseCamera() { camSelectDialog_ = new CamSelectDialog(cm_, this); - if (camSelectDialog_->exec() == QDialog::Accepted) - return camSelectDialog_->getCameraId(); - else + if (camSelectDialog_->exec() == QDialog::Accepted) { + std::string cameraId = camSelectDialog_->getCameraId(); + cameraSwitchButton_->setText(QString::fromStdString(cameraId)); + + return cameraId; + } else return std::string(); } @@ -327,8 +332,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. */ + cameraSwitchButton_->setText(QString::fromStdString(cameraName)); return 0; } @@ -593,8 +598,6 @@ void MainWindow::processHotplug(HotplugEvent *e) HotplugEvent::PlugEvent event = e->hotplugEvent(); if (event == HotplugEvent::HotPlug) { - cameraCombo_->addItem(QString::fromStdString(camera->id())); - if (camSelectDialog_) camSelectDialog_->cameraAdded(camera); } else if (event == HotplugEvent::HotUnplug) { @@ -603,12 +606,8 @@ void MainWindow::processHotplug(HotplugEvent *e) toggleCapture(false); camera_->release(); camera_.reset(); - cameraCombo_->setCurrentIndex(0); } - int camIndex = cameraCombo_->findText(QString::fromStdString(camera->id())); - cameraCombo_->removeItem(camIndex); - if (camSelectDialog_) camSelectDialog_->cameraRemoved(camera); } diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h index 6d80b5be..fe0f5938 100644 --- a/src/qcam/main_window.h +++ b/src/qcam/main_window.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -61,7 +62,7 @@ private Q_SLOTS: void quit(); void updateTitle(); - void switchCamera(int index); + void switchCamera(); void toggleCapture(bool start); void saveImageAs(); @@ -91,7 +92,7 @@ private: /* UI elements */ QToolBar *toolbar_; QAction *startStopAction_; - QComboBox *cameraCombo_; + QPushButton *cameraSwitchButton_; QAction *saveRaw_; ViewFinder *viewfinder_;