#ifndef TDE_WIDGETS_UNITLABEL_H
#define TDE_WIDGETS_UNITLABEL_H

#include <QWidget>
#include <QLabel>

#include "EditInteger.h"
#include "Label.h"

#include "common.h"
#include "opaque.h"

// -- TDE NAMESPACE ----------------------------------------------------

namespace TDE {

// -- Widgets NAMESPACE ------------------------------------------------

namespace Widgets {

/*!
 * \class UnitLabel
 * \brief Widget for displaying a DataStore variable value unit of measure in a label.
 *
 * \see DataStore
 * \see WidgetInfo
 */
class UnitLabel : public QLabel
{
    Q_OBJECT
	Q_PROPERTY(QString variableName READ variableName WRITE setVariableName NOTIFY variableChanged)
    Q_PROPERTY(bool trace READ trace WRITE setTrace NOTIFY traceChanged)
    Q_PROPERTY(int refresh READ refresh WRITE setRefresh NOTIFY refreshChanged)
    Q_PROPERTY(bool raw READ raw WRITE setRaw NOTIFY rawChanged)
    Q_PROPERTY(bool descriptionAppend READ descriptionAppend WRITE setDescriptionAppend)
    Q_PROPERTY(bool descriptionPrepend READ descriptionPrepend WRITE setDescriptionPrepend)
    Q_PROPERTY(QString nativeUnit READ nativeUnit)
    Q_PROPERTY(QString displayUnit READ displayUnit WRITE setDisplayUnit NOTIFY displayUnitChanged)
    Q_PROPERTY(bool displayParenthesis READ displayParenthesis WRITE setDisplayParenthesis)

public:
    UnitLabel(QWidget *parent = 0);
    virtual ~UnitLabel();

    SHARED_PTR<TDE::DataStore> dataStore();
    UnitLabel& setDataStore(SHARED_PTR<TDE::DataStore> ds_p);
    UnitLabel& setVariableName(const std::string& name);

    int     variableIndex() const;
    const TDE::VariableDescr& variableDescr() const;

    // properties getters/setters

    QString variableName() const;
    void    setVariableName(const QString&);

    bool trace() const;
    bool setTrace(bool value = true);

    int refresh() const;
    int setRefresh(int value = 0);

    bool raw() const;
    bool setRaw(bool value = true);

    bool setDescriptionAppend(bool value = true);
    bool descriptionAppend() const;
    bool setDescriptionPrepend(bool value = true);
    bool descriptionPrepend() const;
    bool setDisplayParenthesis(bool value = true);
    bool displayParenthesis() const;

    QString nativeUnit() const;
    QString displayUnit() const;
    void    setDisplayUnit(const QString& value);

    TDE::DisplayUnitPtr nativeUnitPtr() const;
    TDE::DisplayUnitPtr displayUnitPtr() const;

    void setReferenceWidget(EditInteger* widget);
    void setReferenceWidget(Label* widget);

signals:
    void variableChanged(QString);

    void traceChanged(bool);                // trace option changed
    void refreshChanged(int);               // refresh value changed
    void rawChanged(bool);                  // raw option changed

    void displayUnitChanged(QString);       // display unit changed

public slots:
    void ui2ds();    // set DataStore variable with value from UI
    void ds2ui();    // set UI with value from DataStore

protected:
    virtual void showEvent(QShowEvent *event);
    SHARED_PTR<WidgetInfo> referenceWInfo() const
    {
        if (m_reference_winfo)
            return m_reference_winfo;
        else
            return m_winfo;
    }

private:
    SHARED_PTR<WidgetInfo> m_reference_winfo;

	SHARED_PTR<WidgetInfo> m_winfo;
    bool m_parenthesis;
};

} /* end of namespace Widgets */

} /* end of namespace TDE */

#endif /* TDE_WIDGETS_UNITLABEL_H */
