From patchwork Sat Aug 6 19:04:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Utkarsh Tiwari X-Patchwork-Id: 16994 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 919E9C3275 for ; Sat, 6 Aug 2022 19:04:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4BE5763313; Sat, 6 Aug 2022 21:04:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1659812694; bh=7d4DgRBK36XXC05mClFv2k3rijGpz/Zg/AJ+NsNoglI=; 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=oo7V1vXaXSOygJ6lWfPmqBGIf7S2YN/hkxkvdWqFNFkdn5vtqTWVFnZ0n63esffVM Z8KoUxiccg6QPU93QcRUw4UC1qzFBKVd7qWV3mYXORjE3PJv46d+IG/oHy5ovyvM0g VVjY/F6PCStOgM1PlvMRhD1N4Vz4GuSY8v6cxuBdXIDpgyzRTXePxBPd+q8llumkug P3xlku6wwVX6tetsuW/DpB04lpWVZvL2WzP6UQYgFHlKKGEjVTA1EOWvcCVAXZDBLl lCmG+qFzH3c85LJbo7QGWWyBtj3AlA2ZDqDMVeyA/mRKg2P6RA1rJjjWI9eJuOoy50 ikNyZ9JL47ODQ== Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2AE516332B for ; Sat, 6 Aug 2022 21:04:52 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Q2RmZ1MG"; dkim-atps=neutral Received: by mail-pl1-x631.google.com with SMTP id t2so5331249ply.2 for ; Sat, 06 Aug 2022 12:04:52 -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=dpfpf09IEIUwxuA/C+IBy9n5tZOTeXXc4N1nwXYN5jg=; b=Q2RmZ1MG3gBHxsvA/RbsAQfDfHq5ij7vdID9W42Rp3T0i/qWOXQclFxDRJG9v00Ozz YlcmgEIclR+fvE8WTrSdw5uZORKD7Qf8S8135rv9/bGemggVYihhyE0hBnFbJdD8Fcsn /Y7j9f/Obg+FsemIRugIpTqFKjHuhu3Bcip9b1cQV/gx16LrN7bih0t+laWm9J/VI9Bm jmbsHrhyYuuDfhMTAlm6E7bRe8Q05IIjjvQOUmsyX/xYE94xAerRlf7CXZtn81ZN3TMu r3rpkccO8P2r92myHuuLmzk6e4NJ9pLKNV7LzqMAvWk9wtA3eau+7279+T/UW0JX+2GA T0NA== 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=dpfpf09IEIUwxuA/C+IBy9n5tZOTeXXc4N1nwXYN5jg=; b=7Z2nFoU4L87nA+Vgdur3vlBirMESH9OQMdoTtU5/fBaf6Rvg/hwYSGXFLgqESXzdNm 2GAlL0LBhR4cP7PQSaiJ2CXmRxum19OQSSgYLhBjJWiC9AXEFFDAgJVCZe36enyGY7eS bztqAG/ROfhqhhc4b+PlvlsQWw3L3eHkG4yq44jITf592046bOb/S0Y6KfXp+udByqoc gnGK60KL66Kxyjok08NoB7ecFTiL7exsxQLgNDe6OahCz+xdMWEkT0fJQ8h/tdS74Yh6 9tBxpPYWhTpcKxmjPBaOq2RmxwUh5aJjVJCS1zZsQuGEpgY7V4PYjhbiZwRwrqHhuwmP bpyg== X-Gm-Message-State: ACgBeo1Dy2daVEVvldy63r439fF0PmjY8JV6jcv+3Ete7i8BiG3Qx1YG nyGp+QR28YA3+KQMV61UO0vhcb/Y+dY= X-Google-Smtp-Source: AA6agR4gs+zwEsdxxWaNrp2ihus4LHrf1UYX/2/VzAgqNSUR+TtA0n6Hv9cFNvfFqJkkfYUnFvBkgw== X-Received: by 2002:a17:90a:fc2:b0:1f3:20d0:2e47 with SMTP id 60-20020a17090a0fc200b001f320d02e47mr13368102pjz.117.1659812690296; Sat, 06 Aug 2022 12:04:50 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Aug 2022 12:04:49 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Sun, 7 Aug 2022 00:34:30 +0530 Message-Id: <20220806190433.59128-2-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 1/4] 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 --- Difference from V1: The biggest change here is the introduction of class, inside of the class the layout remains same. src/qcam/cam_select_dialog.h | 64 ++++++++++++++++++++++++++++++++++++ src/qcam/main_window.cpp | 22 +++---------- src/qcam/main_window.h | 4 +++ src/qcam/meson.build | 1 + 4 files changed, 74 insertions(+), 17 deletions(-) create mode 100644 src/qcam/cam_select_dialog.h diff --git a/src/qcam/cam_select_dialog.h b/src/qcam/cam_select_dialog.h new file mode 100644 index 00000000..c23bad59 --- /dev/null +++ b/src/qcam/cam_select_dialog.h @@ -0,0 +1,64 @@ + +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * cam_select_dialog.h - qcam - Camera Selection dialog + */ + +#pragma once + +#include + +#include +#include + +#include +#include +#include +#include +#include + +class CamSelectDialog : public QDialog +{ + Q_OBJECT +public: + CamSelectDialog(libcamera::CameraManager *cameraManager, QWidget *parent) + : QDialog(parent), cm_(cameraManager) + { + /* Use a QFormLayout for the dialog. */ + QFormLayout *camSelectDialogLayout = 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 *dialogButtonBox = + new QDialogButtonBox(QDialogButtonBox::Ok | + QDialogButtonBox::Cancel); + + connect(dialogButtonBox, &QDialogButtonBox::accepted, + this, &QDialog::accept); + connect(dialogButtonBox, &QDialogButtonBox::rejected, + this, &QDialog::reject); + + /* Set the layout. */ + camSelectDialogLayout->addRow("Camera: ", cameraIdComboBox_); + camSelectDialogLayout->addWidget(dialogButtonBox); + } + + ~CamSelectDialog() = default; + + std::string getCameraId() + { + return cameraIdComboBox_->currentText().toStdString(); + } + +private: + libcamera::CameraManager *cm_; + + /* UI elements. */ + QComboBox *cameraIdComboBox_; +}; diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 7433d647..758e2c94 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,24 +290,12 @@ void MainWindow::switchCamera(int index) std::string MainWindow::chooseCamera() { - QStringList cameras; - bool result; + camSelectDialog_ = new CamSelectDialog(cm_, this); - /* 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) + if (camSelectDialog_->exec() == QDialog::Accepted) + return camSelectDialog_->getCameraId(); + else return std::string(); - - return id.toStdString(); } int MainWindow::openCamera() diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h index fc70920f..6d80b5be 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_; + QPointer camSelectDialog_; + /* Options */ const OptionsParser::Options &options_; diff --git a/src/qcam/meson.build b/src/qcam/meson.build index c46f4631..70615e92 100644 --- a/src/qcam/meson.build +++ b/src/qcam/meson.build @@ -26,6 +26,7 @@ qcam_sources = files([ ]) qcam_moc_headers = files([ + 'cam_select_dialog.h', 'main_window.h', 'viewfinder_qt.h', ])