[libcamera-devel] [PATCH v2 02/11] qcam: ControlFrame: Display defualt value of controls

Kieran Bingham kieran.bingham at ideasonboard.com
Tue Aug 23 01:40:14 CEST 2022


Quoting Utkarsh Tiwari via libcamera-devel (2022-08-12 13:46:42)
> Display a QLabel below the Control Name showing the default value for
> the controls.
> 
> This adds support to Display defualt value for the
> control types :
>     ControlTypeBool
>     ControlTypeInteger32
>     ControlTypeInteger64
>     ControlTypeFloat
> 
> Signed-off-by: Utkarsh Tiwari <utkarsh02t at gmail.com>
> ---
> Difference from v1: 
>         1. Fix comment styling
>         2. Now parameters can drop libcamera:: as effect from  1/11
>  src/qcam/settings/control_frame.cpp | 48 +++++++++++++++++++++++++++--
>  src/qcam/settings/control_frame.h   |  9 ++++++
>  src/qcam/settings/controls_tab.cpp  |  2 +-
>  3 files changed, 56 insertions(+), 3 deletions(-)
> 
> diff --git a/src/qcam/settings/control_frame.cpp b/src/qcam/settings/control_frame.cpp
> index 8b1162db..79cf67eb 100644
> --- a/src/qcam/settings/control_frame.cpp
> +++ b/src/qcam/settings/control_frame.cpp
> @@ -16,13 +16,57 @@
>  
>  using namespace libcamera;
>  
> -ControlFrame::ControlFrame(const ControlId *control, QWidget *parent)
> -       : QFrame(parent), control_(control)
> +ControlFrame::ControlFrame(const ControlId *control,
> +                          const ControlInfo &controlInfo, QWidget *parent)
> +       : QFrame(parent), control_(control), controlInfo_(controlInfo)
>  {
>         /* Main layout for the frame */
>         QVBoxLayout *frameVLayout = new QVBoxLayout(this);
>  
>         frameVLayout->addWidget(new QLabel(QString::fromStdString(control_->name())));
>  
> +       /*
> +        * No need to pass parents to widgets, as QVBoxLayout transfers
> +        * ownership to its parent widget.
> +        */
> +       frameVLayout->addWidget(defaultValueLabel());
> +
>         setFrameStyle(QFrame::StyledPanel);
>  }
> +
> +/* -----------------------------------------------------------------------------
> + * Widgets
> + */
> +
> +QLabel *ControlFrame::defaultValueLabel(QWidget *parent)
> +{
> +       QLabel *defaultValLabel = new QLabel(parent);
> +
> +       defaultValLabel->setText("Default Value: " + getDefaultValueQStr());
> +
> +       return defaultValLabel;
> +}
> +
> +/* -----------------------------------------------------------------------------
> + * Helpers
> + */
> +
> +QString ControlFrame::getDefaultValueQStr()
> +{
> +       switch (control_->type()) {
> +       case ControlTypeBool:
> +               if (controlInfo_.def().get<bool>()) {
> +                       return QString("True");
> +               } else {
> +                       return QString("False");
> +               }
> +       case ControlTypeInteger32:
> +               return QString::number(controlInfo_.def().get<int32_t>());
> +       case ControlTypeInteger64:
> +               return QString::number(controlInfo_.def().get<int64_t>());
> +       case ControlTypeFloat:
> +               return QString::number(controlInfo_.def().get<float>());
> +       default:
> +               return QString("Unavailable");
> +       }
> +}
> diff --git a/src/qcam/settings/control_frame.h b/src/qcam/settings/control_frame.h
> index 10690674..280f07e0 100644
> --- a/src/qcam/settings/control_frame.h
> +++ b/src/qcam/settings/control_frame.h
> @@ -10,6 +10,7 @@
>  #include <libcamera/controls.h>
>  
>  #include <QFrame>
> +#include <QLabel>
>  #include <QWidget>
>  
>  class ControlFrame : public QFrame
> @@ -18,9 +19,17 @@ class ControlFrame : public QFrame
>  
>  public:
>         ControlFrame(const libcamera::ControlId *control,
> +                    const libcamera::ControlInfo &controlInfo,
>                      QWidget *parent);
>         ~ControlFrame() = default;
>  
>  private:
>         const libcamera::ControlId *control_;
> +       const libcamera::ControlInfo &controlInfo_;
> +
> +       /* Widgets */
> +       QLabel *defaultValueLabel(QWidget *parent = nullptr);
> +
> +       /* Helper Hunctions */
> +       QString getDefaultValueQStr();
>  };
> diff --git a/src/qcam/settings/controls_tab.cpp b/src/qcam/settings/controls_tab.cpp
> index 33ed9332..adc24326 100644
> --- a/src/qcam/settings/controls_tab.cpp
> +++ b/src/qcam/settings/controls_tab.cpp
> @@ -26,7 +26,7 @@ ControlsTab::ControlsTab(std::shared_ptr<libcamera::Camera> camera_,
>  
>         int controlCount = 0;
>         for (auto &[control, info] : camera_->controls()) {
> -               ControlFrame *controlFrame = new ControlFrame(control, this);
> +               ControlFrame *controlFrame = new ControlFrame(control, info, this);
>  
>                 controlGLayout->addWidget(controlFrame, controlCount / 2,
>                                           controlCount % 2);
> -- 
> 2.25.1
>


More information about the libcamera-devel mailing list