[{"id":24735,"web_url":"https://patchwork.libcamera.org/comment/24735/","msgid":"<166120872983.3484129.16251520228309868077@Monstersaurus>","date":"2022-08-22T22:52:09","subject":"Re: [libcamera-devel] [PATCH v2 01/11] qcam: Add settings Dialog\n\twith Control tab","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Utkarsh Tiwari via libcamera-devel (2022-08-12 13:46:41)\n> Implement a Settings QDialog and add its buttonon the toolbar.\n> We only create one instance of the SettingsWindow and its created the\n> first time user clicks on the button. We check its existence with\n> QPointer.\n> \n> This Setting Dialog implements a QTabWidget which resides in a\n> QVBoxLayout so that it spans the whole QDialog.\n> \n> The QTabWidget currently only holds the control tab.\n> This Tab lays out the respective ControlFrames in a QGridLayout listing\n> two controls in each row.\n> \n> ControlFrames handles the UI for each respective controls.\n> It also implements the QVBoxLayout as for future when we want to add\n> more information in each frame.\n> \n> Signed-off-by: Utkarsh Tiwari <utkarsh02t@gmail.com>\n> ---\n> Difference from v1:\n>         1. Settings dialog now primarily uses QIcon::fromTheme(\"preferences-system\")\n>         2. using namespace libcamera; added in ControlFrame\n>  src/qcam/assets/feathericons/feathericons.qrc |  1 +\n>  src/qcam/main_window.cpp                      | 17 ++++++++\n>  src/qcam/main_window.h                        |  5 +++\n>  src/qcam/meson.build                          |  5 +++\n>  src/qcam/settings/control_frame.cpp           | 28 +++++++++++++\n>  src/qcam/settings/control_frame.h             | 26 +++++++++++++\n>  src/qcam/settings/controls_tab.cpp            | 38 ++++++++++++++++++\n>  src/qcam/settings/controls_tab.h              | 24 ++++++++++++\n>  src/qcam/settings/settings_dialog.h           | 39 +++++++++++++++++++\n>  9 files changed, 183 insertions(+)\n>  create mode 100644 src/qcam/settings/control_frame.cpp\n>  create mode 100644 src/qcam/settings/control_frame.h\n>  create mode 100644 src/qcam/settings/controls_tab.cpp\n>  create mode 100644 src/qcam/settings/controls_tab.h\n>  create mode 100644 src/qcam/settings/settings_dialog.h\n> \n> diff --git a/src/qcam/assets/feathericons/feathericons.qrc b/src/qcam/assets/feathericons/feathericons.qrc\n> index c5302040..3078c26f 100644\n> --- a/src/qcam/assets/feathericons/feathericons.qrc\n> +++ b/src/qcam/assets/feathericons/feathericons.qrc\n> @@ -5,6 +5,7 @@\n>         <file>camera-off.svg</file>\n>         <file>play-circle.svg</file>\n>         <file>save.svg</file>\n> +       <file>settings.svg</file>\n>         <file>stop-circle.svg</file>\n>         <file>x-circle.svg</file>\n>  </qresource>\n> diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\n> index ce70cc02..7861c34b 100644\n> --- a/src/qcam/main_window.cpp\n> +++ b/src/qcam/main_window.cpp\n> @@ -239,6 +239,12 @@ int MainWindow::createToolbars()\n>         saveRaw_ = action;\n>  #endif\n>  \n> +       /* Settings Dialog open action */\n> +       action = toolbar_->addAction(QIcon::fromTheme(\"preferences-system\",\n> +                                                     QIcon(\":settings.svg\")),\n> +                                    \"Open Settings Window\");\n> +       connect(action, &QAction::triggered, this, &MainWindow::openSettingsDialog);\n> +\n>         return 0;\n>  }\n>  \n> @@ -262,6 +268,17 @@ void MainWindow::updateTitle()\n>         setWindowTitle(title_ + \" : \" + QString::number(fps, 'f', 2) + \" fps\");\n>  }\n>  \n> +void MainWindow::openSettingsDialog()\n> +{\n> +       if (settingsDialog_) {\n> +               settingsDialog_->show();\n> +               return;\n> +       }\n> +\n> +       settingsDialog_ = new SettingsDialog(camera_, this);\n> +       settingsDialog_->show();\n\nThis could be simplifed with swapping the conditional around:\n\n{\n\tif (!settingsDialog_)\n\t\tsettingsDialog_ = new SettingsDiaglog(camera_, this);\n\n\tsettingsDialog_->show();\n}\n\nBut what happens when the camera_ changes ? (Perhaps that gets updated\non camera change, and I'll see it later?).\n\nCould the dialog always be created during construction of MainWindow and\nthen the settings open button would just call settingsDialog_->show()\ndirectly?\n\nI don't know if application/GUI design is better to construct on demand,\nor pre-construct. I guess there's no point constructing the window if it\nnever gets called ...\n\n\n\n> +}\n> +\n>  /* -----------------------------------------------------------------------------\n>   * Camera Selection\n>   */\n> diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h\n> index c7cba5e9..856a71b1 100644\n> --- a/src/qcam/main_window.h\n> +++ b/src/qcam/main_window.h\n> @@ -23,12 +23,14 @@\n>  #include <QMainWindow>\n>  #include <QMutex>\n>  #include <QObject>\n> +#include <QPointer>\n>  #include <QPushButton>\n>  #include <QQueue>\n>  #include <QTimer>\n>  \n>  #include \"../cam/capture_script.h\"\n>  #include \"../cam/stream_options.h\"\n> +#include \"settings/settings_dialog.h\"\n>  \n>  #include \"cam_select_dialog.h\"\n>  #include \"viewfinder.h\"\n> @@ -94,6 +96,8 @@ private:\n>         void loadCaptureScript();\n>         void stopCaptureScript();\n>  \n> +       void openSettingsDialog();\n> +\n>         /* UI elements */\n>         QToolBar *toolbar_;\n>         QAction *startStopAction_;\n> @@ -108,6 +112,7 @@ private:\n>         QTimer titleTimer_;\n>  \n>         CameraSelectorDialog *cameraSelectorDialog_;\n> +       QPointer<SettingsDialog> settingsDialog_;\n>  \n>         /* Options */\n>         const OptionsParser::Options &options_;\n> diff --git a/src/qcam/meson.build b/src/qcam/meson.build\n> index 70a18d7e..7a785fd0 100644\n> --- a/src/qcam/meson.build\n> +++ b/src/qcam/meson.build\n> @@ -24,12 +24,17 @@ qcam_sources = files([\n>      'main.cpp',\n>      'main_window.cpp',\n>      'message_handler.cpp',\n> +    'settings/control_frame.cpp',\n> +    'settings/controls_tab.cpp',\n>      'viewfinder_qt.cpp',\n>  ])\n>  \n>  qcam_moc_headers = files([\n>      'cam_select_dialog.h',\n>      'main_window.h',\n> +    'settings/control_frame.h',\n> +    'settings/controls_tab.h',\n> +    'settings/settings_dialog.h',\n>      'viewfinder_qt.h',\n>  ])\n>  \n> diff --git a/src/qcam/settings/control_frame.cpp b/src/qcam/settings/control_frame.cpp\n> new file mode 100644\n> index 00000000..8b1162db\n> --- /dev/null\n> +++ b/src/qcam/settings/control_frame.cpp\n> @@ -0,0 +1,28 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * Copyright (C) 2022, Utkarsh Tiwari <utkarsh02t@gmail.com>\n> + *\n> + * control_frame.cpp - qcam - Control frame\n> + */\n> +\n> +#include \"control_frame.h\"\n> +\n> +#include <libcamera/controls.h>\n> +\n> +#include <QFrame>\n> +#include <QLabel>\n> +#include <QString>\n> +#include <QVBoxLayout>\n> +\n> +using namespace libcamera;\n> +\n> +ControlFrame::ControlFrame(const ControlId *control, QWidget *parent)\n> +       : QFrame(parent), control_(control)\n> +{\n> +       /* Main layout for the frame */\n> +       QVBoxLayout *frameVLayout = new QVBoxLayout(this);\n> +\n> +       frameVLayout->addWidget(new QLabel(QString::fromStdString(control_->name())));\n> +\n> +       setFrameStyle(QFrame::StyledPanel);\n> +}\n> diff --git a/src/qcam/settings/control_frame.h b/src/qcam/settings/control_frame.h\n> new file mode 100644\n> index 00000000..10690674\n> --- /dev/null\n> +++ b/src/qcam/settings/control_frame.h\n> @@ -0,0 +1,26 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * Copyright (C) 2022, Utkarsh Tiwari <utkarsh02t@gmail.com>\n> + *\n> + * control_frame.h - qcam - Control frame\n> + */\n> +\n> +#pragma once\n> +\n> +#include <libcamera/controls.h>\n> +\n> +#include <QFrame>\n> +#include <QWidget>\n> +\n> +class ControlFrame : public QFrame\n> +{\n> +       Q_OBJECT\n> +\n> +public:\n> +       ControlFrame(const libcamera::ControlId *control,\n> +                    QWidget *parent);\n> +       ~ControlFrame() = default;\n> +\n> +private:\n> +       const libcamera::ControlId *control_;\n> +};\n> diff --git a/src/qcam/settings/controls_tab.cpp b/src/qcam/settings/controls_tab.cpp\n> new file mode 100644\n> index 00000000..33ed9332\n> --- /dev/null\n> +++ b/src/qcam/settings/controls_tab.cpp\n> @@ -0,0 +1,38 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * Copyright (C) 2022, Utkarsh Tiwari <utkarsh02t@gmail.com>\n> + *\n> + * controls_tab.cpp - qcam - Controls Tab\n> + */\n> +\n> +#include \"controls_tab.h\"\n> +\n> +#include <memory>\n> +\n> +#include <libcamera/camera.h>\n> +\n> +#include <QGridLayout>\n> +#include <QLabel>\n> +#include <QWidget>\n> +\n> +#include \"control_frame.h\"\n> +\n> +ControlsTab::ControlsTab(std::shared_ptr<libcamera::Camera> camera_,\n> +                        QWidget *parent)\n> +       : QWidget(parent)\n> +{\n> +       /* Main Layout for the tab */\n> +       QGridLayout *controlGLayout = new QGridLayout(this);\n> +\n> +       int controlCount = 0;\n> +       for (auto &[control, info] : camera_->controls()) {\n> +               ControlFrame *controlFrame = new ControlFrame(control, this);\n> +\n> +               controlGLayout->addWidget(controlFrame, controlCount / 2,\n> +                                         controlCount % 2);\n> +               controlCount++;\n> +       }\n> +\n> +       if (controlCount == 0)\n\nDo you really need to count them ? Can you get the size from\ncamera_controls().size() ?\n\n\n> +               controlGLayout->addWidget(new QLabel(\"No controls available\"));\n> +}\n> diff --git a/src/qcam/settings/controls_tab.h b/src/qcam/settings/controls_tab.h\n> new file mode 100644\n> index 00000000..6a63f334\n> --- /dev/null\n> +++ b/src/qcam/settings/controls_tab.h\n> @@ -0,0 +1,24 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * Copyright (C) 2022, Utkarsh Tiwari <utkarsh02t@gmail.com>\n> + *\n> + * controls_tab.h - qcam - Controls Tab\n> + */\n> +\n> +#pragma once\n> +\n> +#include <memory>\n> +\n> +#include <libcamera/camera.h>\n> +\n> +#include <QVBoxLayout>\n> +#include <QWidget>\n> +\n> +class ControlsTab : public QWidget\n> +{\n> +       Q_OBJECT\n> +\n> +public:\n> +       ControlsTab(std::shared_ptr<libcamera::Camera> camera_, QWidget *parent);\n> +       ~ControlsTab() = default;\n> +};\n> diff --git a/src/qcam/settings/settings_dialog.h b/src/qcam/settings/settings_dialog.h\n> new file mode 100644\n> index 00000000..c2fa61ea\n> --- /dev/null\n> +++ b/src/qcam/settings/settings_dialog.h\n> @@ -0,0 +1,39 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * Copyright (C) 2022, Utkarsh Tiwari <utkarsh02t@gmail.com>\n> + *\n> + * settings_dialog.h - qcam - Settings Dialog\n> + */\n> +\n> +#pragma once\n> +\n> +#include <memory>\n> +\n> +#include <QDialog>\n> +#include <QTabWidget>\n> +#include <QVBoxLayout>\n> +#include <QWidget>\n> +\n> +#include \"controls_tab.h\"\n> +class SettingsDialog : public QDialog\n> +{\n> +       Q_OBJECT\n> +\n> +public:\n> +       SettingsDialog(std::shared_ptr<libcamera::Camera> camera, QWidget *parent)\n> +               : QDialog(parent)\n> +       {\n> +               /*Main layout for dialog */\n\n\t\t/* Main\n\n\n> +               QVBoxLayout *settingVLayout = new QVBoxLayout(this);\n> +\n> +               /* Main TabWidget which would hold other tabs */\n> +               QTabWidget *settingTabWidget = new QTabWidget;\n> +               settingVLayout->addWidget(settingTabWidget);\n> +\n> +               ControlsTab *controlsTab = new ControlsTab(camera, this);\n> +               settingTabWidget->addTab(controlsTab, \"Controls\");\n> +\n> +               setWindowTitle(\"Settings\");\n> +       }\n> +       ~SettingsDialog() = default;\n> +};\n> -- \n> 2.25.1\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id A25E3C3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 22 Aug 2022 22:52:14 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A5BB961FC0;\n\tTue, 23 Aug 2022 00:52:13 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7D51F60E25\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 23 Aug 2022 00:52:12 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0EE412B3;\n\tTue, 23 Aug 2022 00:52:12 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1661208733;\n\tbh=//sMoq5oNXWIdQAUxLpULMwHFFs6K/OJJxsIoCDzhiM=;\n\th=In-Reply-To:References:To:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=ADrRH9mtUnteb+n9pjmWFJuDC3NTmAARUMXwJDqmHRyRPfiNb3TP+t2arO0vBsiQD\n\tZhhhNEuqDC9zg0iL6UiR3Yf5YW3iT0AKA9eHxJ6MGMh8YhNb7a2WQKra+Uydimrv8M\n\toDw/owJJU80WGqxe15Zkg5wXJMAx95oDwDJzVB5xqlCT8bLkCrLEq+a7yEuPXQrYC9\n\tj3Vc7WgocPC4aUK6t8AXP2bRQPyO0iOH6J/PqEKZuPqZ9YYTmL41KXkeZIIXP4LKA0\n\tQsXBUu+TDd5QVOS7usxgUi+RMhhykvN3/Ti9knsGf0vGHninlc8t1Aj7PvR4wwhX8O\n\tghF//2Swg5OTg==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1661208732;\n\tbh=//sMoq5oNXWIdQAUxLpULMwHFFs6K/OJJxsIoCDzhiM=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=hFFgyQbm8cvWy2CAOKWofcx2HdtoF5BlerOgbbNgUYP4jZo2jQVglZp1IfxCqaZxw\n\tFKdPtwlyWzI0wt+n5ZcVC/Eqlv+X3KQgflqjuui8exdmTTc6B2nijs0hGirxH86akO\n\tRO3cXcDSkVNAEmeu2KAdFFLZ7SXX68tkVdDoX1kM="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"hFFgyQbm\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20220812124651.27496-2-utkarsh02t@gmail.com>","References":"<20220812124651.27496-1-utkarsh02t@gmail.com>\n\t<20220812124651.27496-2-utkarsh02t@gmail.com>","To":"Utkarsh Tiwari <utkarsh02t@gmail.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 22 Aug 2022 23:52:09 +0100","Message-ID":"<166120872983.3484129.16251520228309868077@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH v2 01/11] qcam: Add settings Dialog\n\twith Control tab","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]