From patchwork Tue Aug 9 20:50:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Utkarsh Tiwari X-Patchwork-Id: 17055 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 D1BDCBE173 for ; Tue, 9 Aug 2022 20:51:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 91AC363335; Tue, 9 Aug 2022 22:51:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1660078263; bh=O0zffZEsQGLvkgsJV0VrElWOOtCbYO+RXg5NRXzZw4g=; 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=y8WMx6vPXeefvBkoj3uY4ZH3N7dI3tiEHtU/z7qK2u3mhmsWB3bUoF3FFHMV/n1yS AKZOyzjvs+AMjuuIimx31sFom6FaKs438bLyypbVVJ7eLrvaLw1EYXYVa0G8gh+g1b 5AjjNtYUtHe1I/KX+6aAkuypJiwxpnhmjUQ9Ker77dRIs229bEiKUA8WiW/gxAuMx3 69uo6Qw+wGkBVgkQIF7QI2i5rMZ0Zt76cMkOmN8gSIEpu4BuBvuSooAaW/SWEPmL9O 1BkhRu+3pomP181E7lElM7LuDYl9Z7T8DDZmsO2x4ZWmRpFaYc6hi2Kb/HXJFG/oqc XCMYFPGF4NdfQ== Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7C66763330 for ; Tue, 9 Aug 2022 22:51:02 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ltuJG+do"; dkim-atps=neutral Received: by mail-pj1-x102d.google.com with SMTP id o5-20020a17090a3d4500b001ef76490983so117591pjf.2 for ; Tue, 09 Aug 2022 13:51: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=y/7tBegz/tztP0/ebOqZEEH7T7DW+fI884vXr5casuw=; b=ltuJG+dorHyXkzg2hwnUB4FBJinA7GBfk5JwiJEFnm1WFcIcS5oNW6LGZREDvNS9cj ur1DWvBR6knqGXiGuhMhwfy5xGciLOXsVTslWlHhdEVncsoO8jGwyJ5WGzHGygmrTGON cA4J74bO4VoEsxjgV0ZjXmpZOUZViGI+ZWSnsbov23qNcUAaZ8+LQgyybi4sz8DALkEa gnDEJG1/4fsVffwmGgmhaApxYHhjLYPc24zbRNaZp4wJomKX0V9Lbb26TreKlcdnzNC1 UmcdJsp1nK2tC8y0YqJyHthaQQu7cShbSut72dVmH6qaOLXykT9xNXgxrQWnS5rpRqi6 4Lkw== 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=y/7tBegz/tztP0/ebOqZEEH7T7DW+fI884vXr5casuw=; b=0mfOY6WytnyMuzC7cq+SwA7LzrYmwl9vo6Dk9tsAxTik5r1urnCD2LWYm6VHIypmxo 0C/7y5fG1lt94FSs8NBXKsmADZ2lowwZPIckGvZfKvzPM9y8FuYdHSBPZfaZvoiuapQG Zw8LGVdC1/u3JwVbfAyAJJIEeGvvR0dRnGFO0iIsSPGGdxDjyDFoPI2kRwKfnh4KFwch 2ZKW+UiuEAbgjoGJ1L530kv073BzrTvApNdqn1qRZhHS6Geas8tCFWGVJEzvQqRhM+S6 bK10x+6zHZFRi8KhjG3qwYzXSqaQURTuutT66Pq5MnmJfBR2t5o1hrLWOii+t8tIJLbl gAhQ== X-Gm-Message-State: ACgBeo3OiTuWH8jaDtj2Exabhpcpu7/8lQZpiP0qQGZ2JTiKudshChSq hMUdbyxFs6gsN2oKoNve5UdZdl11rGU= X-Google-Smtp-Source: AA6agR5YgmSRh8l2DuIxZvsrkU2XPvrOQvPIclJocUeKZsdFTOvSAYN0h90iq6yVUfmS/UfCyuVsPw== X-Received: by 2002:a17:902:ea03:b0:16f:2506:bfd5 with SMTP id s3-20020a170902ea0300b0016f2506bfd5mr24597020plg.21.1660078260726; Tue, 09 Aug 2022 13:51:00 -0700 (PDT) Received: from localhost.localdomain ([2404:bd00:3:d2bc:2358:3bcd:fb4f:cbb7]) by smtp.gmail.com with ESMTPSA id d3-20020a623603000000b0052d981e7842sm301936pfa.208.2022.08.09.13.50.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Aug 2022 13:51:00 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 10 Aug 2022 02:20:37 +0530 Message-Id: <20220809205042.344923-4-utkarsh02t@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220809205042.344923-1-utkarsh02t@gmail.com> References: <20220809205042.344923-1-utkarsh02t@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v7 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 --- Difference: 1. cameraSwitchButton_ to cameraSelectButton_ src/qcam/main_window.cpp | 44 +++++++++++++++++++--------------------- src/qcam/main_window.h | 5 +++-- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 377b4650..15b150ec 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), + 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 +257,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; + + if (camera_ && newCameraId == camera_->id()) return; - const std::shared_ptr &cam = cameras[index]; + const std::shared_ptr &cam = cm_->get(newCameraId); if (cam->acquire()) { qInfo() << "Failed to acquire camera" << cam->id().c_str(); @@ -300,9 +301,12 @@ std::string MainWindow::chooseCamera() if (options_.isSet(OptCamera)) 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(); } @@ -326,8 +330,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,22 +595,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 b01d2e59..bbdbb21c 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 *cameraSelectButton_; QAction *saveRaw_; ViewFinder *viewfinder_;