/****************************************************************************
** Copyright (c) 2016, Fougue SAS <https://www.fougue.pro>
** SPDX-License-Identifier: BSD-2-Clause
****************************************************************************/

#pragma once

#include "property_item_delegate.h"
#include "../base/property.h"

#include <QtWidgets/QWidget>
#include <gsl/span>

namespace Mayo {

// Provides UI edition of properties
class WidgetPropertiesEditor : public QWidget {
public:
    explicit WidgetPropertiesEditor(QWidget* parent = nullptr);
    ~WidgetPropertiesEditor();

    using GroupId = int;
    GroupId addGroup(const QString& name);
    QString groupName(GroupId grpId) const;
    void setGroupName(GroupId grpId, const QString& name);

    void editProperties(PropertyGroup* propGroup, GroupId grpId = -1);
    void editProperty(Property* prop, GroupId grpId = -1);
    void clear();

    void setPropertyEnabled(const Property* prop, bool on);
    void setPropertySelectable(const Property* prop, bool on);

    void addLineSpacer(int height);
    void addLineWidget(QWidget* widget, int height = -1);
    gsl::span<QWidget* const> lineWidgets() const;

    double rowHeightFactor() const;
    void setRowHeightFactor(double v);

    void fitToContents();

    using UnitTranslation = PropertyItemDelegate::UnitTranslation;
    bool overridePropertyUnitTranslation(const BasePropertyQuantity* prop, UnitTranslation unitTr);

private:
    class Private;
    Private* const d = nullptr;
};

} // namespace Mayo
