#ifndef TDE_WIDGETS_PUSHBUTTON_H
#define TDE_WIDGETS_PUSHBUTTON_H

#include <QWidget>
#include <QPushButton>
#include <QTimer>

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

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

namespace TDE {

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

namespace Widgets {

/*!
 * \class PushButton
 * \brief Widget for changing a boolean DataStore variable through a push button.
 *
 * \see DataStore
 * \see WidgetInfo
 */
class PushButton : public QPushButton
{
    Q_OBJECT
	Q_PROPERTY(QString variableName READ variableName WRITE setVariableName NOTIFY variableChanged)
    Q_PROPERTY(int emitInterval READ emitInterval WRITE setEmitInterval NOTIFY emitIntervalChanged)
    Q_PROPERTY(bool trace READ trace WRITE setTrace NOTIFY traceChanged)
    Q_PROPERTY(int refresh READ refresh WRITE setRefresh NOTIFY refreshChanged)

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

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

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

    // properties getters/setters

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

    int     emitInterval() const;
    void    setEmitInterval(int);

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

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

signals:
    void variableChanged(QString);
    void emitIntervalChanged(int);

    void emitTimerExpired();

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

public slots:
    void buttonPressed();
    void buttonReleased();

    void emitValue();

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

private:
	SHARED_PTR<WidgetInfo> m_winfo;
    int m_emit_interval;
    bool m_pressed_timer_set;
    QTimer *m_pressed_timer;
    bool m_pressed;
    bool m_current_value;
};

} /* end of namespace Widgets */

} /* end of namespace TDE */

#endif /* TDE_WIDGETS_PUSHBUTTON_H */
