From patchwork Wed Aug 31 05:49:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Utkarsh Tiwari X-Patchwork-Id: 17267 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 DF365C3272 for ; Wed, 31 Aug 2022 05:50:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0ABBB61FBB; Wed, 31 Aug 2022 07:50:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1661925002; bh=hu64cImvTVadUShZEqI/nuzEqRWxOMJ5I3KUx/TRGQ8=; 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=NXtcsREAC/LnlSepGS6bl7bt/YG/y51ZE9dxWhmfNKnytTQdA4nYpKPMLA1XrN8hz CoZAns4Qm+v8NX5Rkb/BxN4r1HNOMY+3wv7aDbz/h1JzqmmkZf34v1xyKCMWrGy+YS jg7tWsPx6N0TlT7mZUur/+dVYqD6yPtVUBhZhvowjCRCBk1L4uRwg6jhqYvGQ42n+4 Q5k0k4NbEd2QFFBDX9t8XcR8E75CsV50Jq6HOKGpZw4o51tfHtVUpMcQYkioOzh0q9 c0EHd61wzK1RDZrVy1ogi5DQdVF0sl3MrX4LgEsSb8TpSEJHPO+MF7UrICKYQkcSPT 6h58EJQTtoEDQ== Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9F9AE61F9B for ; Wed, 31 Aug 2022 07:50:00 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="RRPuQf7X"; dkim-atps=neutral Received: by mail-pl1-x633.google.com with SMTP id u22so13175680plq.12 for ; Tue, 30 Aug 2022 22:50:00 -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=1/DFNJqcQfnMM+yUXqCldUE401lVkLLcP0bJcD0xqfw=; b=RRPuQf7XoQMRIOUTKXwdlmz3xBsN+HTGly5RfJyIA3jmDbqXt9VmUluw/RZmUOecUd JDRWivvtVHQbKw0EBt/IMETd4dwvSkIxNndLEL7z/jeA++R3eWObOY0SK4AxXyuUp9nm +nScfE4dNdANT3dt8oRCfmjH0tIiPY7mogKvcwxtoHyzeWwxFzoEVIwIlK+XL7OkH7rb WXuMDpbFQtgk7pb4C9b1LUrBM3GRTX1uBByP1zwoGK4Tk+gFfMmFr/FZeIyi8ER2eXSB 1xKPCPHUtig6YYYXaCCzxMt8bNAhbzONAduNIy8myTyL7HbbaI9Axb/EPsNGKERNzxrG tOCQ== 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=1/DFNJqcQfnMM+yUXqCldUE401lVkLLcP0bJcD0xqfw=; b=mlwqe18quu/OVrf6swCAKtxxw3WOEfSHoDgGQYIH7Pj6G3Dept84rwf0TFsNVxSyEo dIkjmxZYtmjTnij78fx6qvXthXSDhPGwVz1HAugONUr9eS+9QUP0hOK5pTX6Imzou8aO n2x/fXJsgORvw46iBPd5HL/SKgY+fMbFet+9PmkmUCd5C70g+TJMFborW5wEX7P5zGTK 0M+1VVgtAT7ZJqk+7YXqH8Yc1eETesHp8RH4+IfLTRVjQpHl4qoJxIrmSJiw9FabjR1l AW+9QooweKpA9OqdKupiSzxFT9hbZkVSBY0HEIKK9BWZ2OfnFAcFpwQHOky5qudhZG0c K2DA== X-Gm-Message-State: ACgBeo24Em3tpUoH/4YhUT5oBVsf9MGVoGIYvxaCjdRFDmh3C55drutf C/F8RpcYxSkFvGE1pdbtFxI3FPkKRQ0= X-Google-Smtp-Source: AA6agR4V0AvL7FHCK4u4L+hBoTO/leeFDpOi7wMku0BjA6A/wmguI7uV8WnhnMJ5rPWsu8oR2n01pw== X-Received: by 2002:a17:90b:350b:b0:1fd:fe88:7cdf with SMTP id ls11-20020a17090b350b00b001fdfe887cdfmr1638375pjb.236.1661924999040; Tue, 30 Aug 2022 22:49:59 -0700 (PDT) Received: from devut-HP-Laptop-14q-cs0xxx.. ([103.36.82.122]) by smtp.gmail.com with ESMTPSA id q19-20020aa79833000000b00537eacc8fa6sm8307333pfl.40.2022.08.30.22.49.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Aug 2022 22:49:58 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 31 Aug 2022 11:19:34 +0530 Message-Id: <20220831054938.21617-4-utkarsh02t@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220831054938.21617-1-utkarsh02t@gmail.com> References: <20220831054938.21617-1-utkarsh02t@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v9 3/7] 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 --- Differences from v9: 1. Checking for OptCamera now happens in 1/7 in openCamera dropping the firstCameraSelect_ 2. Improve curly brace structure 3. Drop QComboBox src/qcam/main_window.cpp | 33 ++++++++++++++++----------------- src/qcam/main_window.h | 5 +++-- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index e8e22d49..505bdc56 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -14,7 +14,6 @@ #include #include -#include #include #include #include @@ -195,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(); @@ -262,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(); @@ -288,6 +288,9 @@ void MainWindow::switchCamera(int index) camera_ = cam; startStopAction_->setChecked(true); + + /* Display the current cameraId in the toolbar .*/ + cameraSelectButton_->setText(QString::fromStdString(newCameraId)); } std::string MainWindow::chooseCamera() @@ -324,8 +327,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; } @@ -591,7 +594,6 @@ void MainWindow::processHotplug(HotplugEvent *e) HotplugEvent::PlugEvent event = e->hotplugEvent(); if (event == HotplugEvent::HotPlug) { - cameraCombo_->addItem(cameraId); cameraSelectorDialog_->addCamera(cameraId); } else if (event == HotplugEvent::HotUnplug) { /* Check if the currently-streaming camera is removed. */ @@ -599,11 +601,8 @@ void MainWindow::processHotplug(HotplugEvent *e) toggleCapture(false); camera_->release(); camera_.reset(); - cameraCombo_->setCurrentIndex(0); } - int camIndex = cameraCombo_->findText(cameraId); - cameraCombo_->removeItem(camIndex); cameraSelectorDialog_->removeCamera(cameraId); } } diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h index def44605..79723256 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_;