From patchwork Tue Aug 9 20:50:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Utkarsh Tiwari X-Patchwork-Id: 17053 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 E02C9BE173 for ; Tue, 9 Aug 2022 20:51:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7E5D563328; Tue, 9 Aug 2022 22:51:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1660078260; bh=u4MTFmMccitsy66efRjXwl3R+v/Nznti/BpmNgO8DPg=; 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=mYZ4G8k4P53TFYUS2AdhoUxaxfdoOo/t2knclnpZbOmNL9xq/Cv3STByuec7tZW3M T3VwM3uJkMLJTuKy/ktJhd1+TJwPVNrq9a0+DIgpS/J9wUlCNpUNdoo9uJqaYbCLJQ jcHSmvr4c5FaDRdw+cJhReostZUa1M57qOP+3Hws3ZKmLvDJWsXHM9oU0out3ONrMm WtJ6Zx5yKF8/pK01kXGuvVVTvRnwgrhRR1xHm4CeWIH8dAddtBrrDI/xIbnfrteoAE x2d8x++B7hTrCJcUdZ33vkIGugznNPizKRbkW6CciXZPA470co4pRY/LVynrQRRcnd exx0QABnOQI6A== Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 144F263326 for ; Tue, 9 Aug 2022 22:50:58 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="PC+88RYD"; dkim-atps=neutral Received: by mail-pg1-x530.google.com with SMTP id r69so5913816pgr.2 for ; Tue, 09 Aug 2022 13:50:58 -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=dfYq8LWQIvsQ5s6c7P+CGWO6qRw4gGkJtVXHJcDVppQ=; b=PC+88RYDCWlkbuI1ZGci2B0lo7jyuSUAonLhW6HKobKX/cw2I2r1OVLbl6B/z4C/Mw 3GicsE2Sd+TzafA+a30JmG+pnq1dkcz8oHh8aYlGLrENF4gWX4cPkUyPx8SF63+kzYG2 n2AW6Z/bV0nU+74vAvpASqCQ2zSu41dYj5S1tJYqHrrww4jzRun5I39Llr/3J1RU5s+E TOt78e7NYujdVWlAp01cSwW9zSu6EKzdIfnUpGqiMLAKnXDdRZJkcxaaQ0xbfAaIsoL8 K9RxEJ5oXH4tLPXzqN4WFcO35aQTJaYfezK9azrhlbqRgajzFA+w7apPEQA1VFFH2GP4 Ayag== 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=dfYq8LWQIvsQ5s6c7P+CGWO6qRw4gGkJtVXHJcDVppQ=; b=4mhOQ8A8azZFDhjBkyNiHBiwevuIO31JQTYwcT2BoKmM6OroNv8GWhKYLM7iq+ofdt Hs0Y/CnRSEioYeDeKCn95lWdTvrWvmYEyJRbvfjzp3xFbg+5wP49+ugXoZLhUFuSSKG8 u0v+0Ntbe2rFPPLSK9Ala89YsEaG7WWOomHsSAzSJgxyW6uyZ61BHJzsCdEgI9iyuCub W+zYTW+I1ptZk1sBAnNykP3ZCkM4hX29DHFGbndqzjD98fpXRU9b6CQwFXp3v8w76pia IHk2qUr9LZmDHy4gKYmRf7sqpcenPfmckZcJ2WSOho7vKQQawOLF/SeBnnWyQ3zRDIdE Slkg== X-Gm-Message-State: ACgBeo3eYTwcUTFW8Y0+JnXaaT7/2RxxAICMG+drwQ+c1BmExc4iYAu/ Rfwghg3GAtjCItTnIm0r+iZPEHzPuUs= X-Google-Smtp-Source: AA6agR4U7mHh6tlaqB5K8XMCugqer/529ygfmo5MYIe7JdXDxygoyrSETYFgpZJlWOa8bk8zh0axLQ== X-Received: by 2002:a65:6398:0:b0:415:7d00:c1de with SMTP id h24-20020a656398000000b004157d00c1demr20996195pgv.610.1660078256368; Tue, 09 Aug 2022 13:50:56 -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.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Aug 2022 13:50:55 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 10 Aug 2022 02:20:35 +0530 Message-Id: <20220809205042.344923-2-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 1/8] qcam: Use QDialog for selection of cameras at startup 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" Currently we use QInputDialog convenience dialogs to allow the user to select a camera. This doesn't allow adding of more information (such as camera location, model etc). Create a QDialog with a QFormLayout that shows a QComboBox with camera Ids. Use a QDialogButtonBox to provide buttons for accepting and cancelling the action. Signed-off-by: Utkarsh Tiwari Reviewed-by: Kieran Bingham Reviewed-by: Kieran Bingham --- Difference 1. Renamed dialogButtonBox to buttonBox 2. Removed spaces 3. Renamed to just layout 4. No longer use the QPointer 5. The dialog is always constructed now src/qcam/cam_select_dialog.cpp | 51 ++++++++++++++++++++++++++++++++++ src/qcam/cam_select_dialog.h | 37 ++++++++++++++++++++++++ src/qcam/main_window.cpp | 39 +++++++++----------------- src/qcam/main_window.h | 4 +++ src/qcam/meson.build | 2 ++ 5 files changed, 107 insertions(+), 26 deletions(-) create mode 100644 src/qcam/cam_select_dialog.cpp create mode 100644 src/qcam/cam_select_dialog.h diff --git a/src/qcam/cam_select_dialog.cpp b/src/qcam/cam_select_dialog.cpp new file mode 100644 index 00000000..dceaa590 --- /dev/null +++ b/src/qcam/cam_select_dialog.cpp @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2022, Utkarsh Tiwari + * + * cam_select_dialog.cpp - qcam - Camera Selection dialog + */ + +#include "cam_select_dialog.h" + +#include + +#include +#include + +#include +#include +#include +#include +#include + +CameraSelectorDialog::CameraSelectorDialog(libcamera::CameraManager *cameraManager, + QWidget *parent) + : QDialog(parent), cm_(cameraManager) +{ + /* Use a QFormLayout for the dialog. */ + QFormLayout *layout = new QFormLayout(this); + + /* Setup the camera id combo-box. */ + cameraIdComboBox_ = new QComboBox; + for (const auto &cam : cm_->cameras()) + cameraIdComboBox_->addItem(QString::fromStdString(cam->id())); + + /* Setup the QDialogButton Box */ + QDialogButtonBox *buttonBox = + new QDialogButtonBox(QDialogButtonBox::Ok | + QDialogButtonBox::Cancel); + + connect(buttonBox, &QDialogButtonBox::accepted, + this, &QDialog::accept); + connect(buttonBox, &QDialogButtonBox::rejected, + this, &QDialog::reject); + + /* Set the layout. */ + layout->addRow("Camera:", cameraIdComboBox_); + layout->addWidget(buttonBox); +} + +std::string CameraSelectorDialog::getCameraId() +{ + return cameraIdComboBox_->currentText().toStdString(); +} diff --git a/src/qcam/cam_select_dialog.h b/src/qcam/cam_select_dialog.h new file mode 100644 index 00000000..8e54f916 --- /dev/null +++ b/src/qcam/cam_select_dialog.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2022, Utkarsh Tiwari + * + * cam_select_dialog.h - qcam - Camera Selection dialog + */ + +#pragma once + +#include + +#include +#include + +#include +#include +#include +#include +#include + +class CameraSelectorDialog : public QDialog +{ + Q_OBJECT +public: + CameraSelectorDialog(libcamera::CameraManager *cameraManager, + QWidget *parent); + + ~CameraSelectorDialog() = default; + + std::string getCameraId(); + +private: + libcamera::CameraManager *cm_; + + /* UI elements. */ + QComboBox *cameraIdComboBox_; +}; diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 7433d647..48479f35 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -30,6 +29,7 @@ #include "../cam/image.h" +#include "cam_select_dialog.h" #include "dng_writer.h" #ifndef QT_NO_OPENGL #include "viewfinder_gl.h" @@ -290,38 +290,25 @@ void MainWindow::switchCamera(int index) std::string MainWindow::chooseCamera() { - QStringList cameras; - bool result; - - /* If only one camera is available, use it automatically. */ - if (cm_->cameras().size() == 1) - return cm_->cameras()[0]->id(); - - /* Present a dialog box to pick a camera. */ - for (const std::shared_ptr &cam : cm_->cameras()) - cameras.append(QString::fromStdString(cam->id())); - - QString id = QInputDialog::getItem(this, "Select Camera", - "Camera:", cameras, 0, - false, &result); - if (!result) - return std::string(); - - return id.toStdString(); -} - -int MainWindow::openCamera() -{ - std::string cameraName; + /* Construct the selection dialog, unconditionally. */ + cameraSelectorDialog_ = new CameraSelectorDialog(cm_, this); /* * Use the camera specified on the command line, if any, or display the * camera selection dialog box otherwise. */ if (options_.isSet(OptCamera)) - cameraName = static_cast(options_[OptCamera]); + return static_cast(options_[OptCamera]); + + if (cameraSelectorDialog_->exec() == QDialog::Accepted) + return cameraSelectorDialog_->getCameraId(); else - cameraName = chooseCamera(); + return std::string(); +} + +int MainWindow::openCamera() +{ + std::string cameraName = chooseCamera(); if (cameraName == "") return -EINVAL; diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h index fc70920f..b01d2e59 100644 --- a/src/qcam/main_window.h +++ b/src/qcam/main_window.h @@ -23,11 +23,13 @@ #include #include #include +#include #include #include #include "../cam/stream_options.h" +#include "cam_select_dialog.h" #include "viewfinder.h" class QAction; @@ -99,6 +101,8 @@ private: QString title_; QTimer titleTimer_; + CameraSelectorDialog *cameraSelectorDialog_; + /* Options */ const OptionsParser::Options &options_; diff --git a/src/qcam/meson.build b/src/qcam/meson.build index c46f4631..61861ea6 100644 --- a/src/qcam/meson.build +++ b/src/qcam/meson.build @@ -18,6 +18,7 @@ qcam_sources = files([ '../cam/image.cpp', '../cam/options.cpp', '../cam/stream_options.cpp', + 'cam_select_dialog.cpp', 'format_converter.cpp', 'main.cpp', 'main_window.cpp', @@ -26,6 +27,7 @@ qcam_sources = files([ ]) qcam_moc_headers = files([ + 'cam_select_dialog.h', 'main_window.h', 'viewfinder_qt.h', ])