From patchwork Sat Aug 6 19:04:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Utkarsh Tiwari X-Patchwork-Id: 16996 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 7E58DC3275 for ; Sat, 6 Aug 2022 19:04:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3722B63334; Sat, 6 Aug 2022 21:04:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1659812698; bh=1b7MXtW5af+YTtPbczKoGvLv5lK9dyRdeyIxNcHbMF8=; 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=kPho5X8sdDSqPKLzI/4DuQm/2WSYfCQLEfezJHmOcAi2Bhw1us2YYWHq3PVHXCAQK ZpMADuowG1UJTOEij6JZ1b0NiW1GZktAGSRIbyPLaddenqyagxdiY/M6/H4R1qN27V 8Go5BhKUcvfVwliXRNpVpXSOyy7XAlP83Z8D0kUnX+QU2PzAFIJDVg/m3BXinPd3dR 3Qde28aKziXKuhe8z2uf/AmIgPKZ16jks7PkZ3FmOlfF4zmLpApyXC0kYoGCHmpDXm ezNLwdpVXIOa3WTjaoY8R76P5RajyXZ9PoRDPbguVUA7SuY/skR//HyjCmbYkj3sN5 v2B70ZqZsNfYw== Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 019EC63332 for ; Sat, 6 Aug 2022 21:04:57 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="eRfHG5D9"; dkim-atps=neutral Received: by mail-pf1-x433.google.com with SMTP id g12so4939202pfb.3 for ; Sat, 06 Aug 2022 12:04:56 -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=IorJXIXuqkipodRbivrzwNMOGa86T9Mi2AbdLW61dK4=; b=eRfHG5D99ikmBAeneHBsF8AMeC/BzF9btSdZZMwEPpyH2YoJUVGosp7iXfadk3MXfE XDZAH2MnEN0rwEZQulzYuNPDnFp0wLqnc2OIXIfAyv9iTSeCY5eJuffI97dE0b3d7KBh 827T8A0I21GdEDY4S7nZU4WJobLUzuglBsYfuFHWPXknODaR+5TRxGjpaePHcbtuA6Xs uvVm0umUxLGTl9IINSbhDFRVpiDAfRiw5Y3XccD2jZ/KrrWU8ByT7JDfg64IDbnfQkSl 4paK0paRdFv/EruB5y89TgLpb29JhAYwL9HNNcy/GIiLUf5FPEWqa1ba78G3vjCX07X+ 9nGQ== 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=IorJXIXuqkipodRbivrzwNMOGa86T9Mi2AbdLW61dK4=; b=XJH5NaZPV9cse85QHOAGif8heaURuh/GfCzuiIfN18NzFiEafA8kVyGYPfgqutNGHm AmTi37mu0tJ+tn3UX8hmUXBqfxjEYEcte4c0ldLU0FyBbUQv6y1SOJoe6ysGr7Vje3Nw Xti86z0ekT7fq9OJAbbRMznXdzInDD3k2sF5bJPak0lG+ImTkLcQ+6P2gSJqQtbiJEYK rOMu9M+NfeN1igDHt2honfTKVFRIUZrnxvlTO2ZYmYZBvUR7UdWsc7y4j6UH3FNIRT0v vNMbrlZPQZ/Sz4sFf4hIchS/ksakxOycxmQCm8jnBU5TPN9reX+bJwL4Nekisy/fnzEg aDqg== X-Gm-Message-State: ACgBeo0Gfn3tFmFun7G2VDYiyTfOGCohGmkUb/PN/U5QWegPa6H3rMOC fFyplPL9tjUYbFWVxCt4GtQdRQjTDh4= X-Google-Smtp-Source: AA6agR5unG3EzC8Za68zqSMs1ZotbqwApRBG+VqiMNf6+IbjMLP57q/oI0oYv+K/+jvUpHcXkL930A== X-Received: by 2002:aa7:87d8:0:b0:52e:ba7a:7fc0 with SMTP id i24-20020aa787d8000000b0052eba7a7fc0mr8489716pfo.46.1659812695371; Sat, 06 Aug 2022 12:04:55 -0700 (PDT) Received: from localhost.localdomain ([2404:bd00:3:daa9:adf3:a099:1bff:e55]) by smtp.gmail.com with ESMTPSA id z17-20020aa79911000000b0052f20d70845sm406025pff.150.2022.08.06.12.04.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Aug 2022 12:04:55 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Sun, 7 Aug 2022 00:34:32 +0530 Message-Id: <20220806190433.59128-4-utkarsh02t@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220806190433.59128-1-utkarsh02t@gmail.com> References: <20220806190433.59128-1-utkarsh02t@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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 --- src/qcam/cam_select_dialog.h | 5 +++++ src/qcam/main_window.cpp | 41 ++++++++++++++++++------------------ src/qcam/main_window.h | 5 +++-- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/qcam/cam_select_dialog.h b/src/qcam/cam_select_dialog.h index ee65eb88..a5189ec3 100644 --- a/src/qcam/cam_select_dialog.h +++ b/src/qcam/cam_select_dialog.h @@ -56,6 +56,11 @@ public: return cameraIdComboBox_->currentText().toStdString(); } + std::string getCurrentCamera() + { + return cameraIdComboBox_->currentText().toStdString(); + } + /* Hotplug / Unplug Support. */ void cameraAdded(libcamera::Camera *camera) { 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_;