UIParamFunction.h 3.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
/*
 *	(c) LSIIT, UMR CNRS/UdS
 *	Authors: O. Gnevaux, F. Larue.
 *
 *	See licence.txt for additional information.
 */


#ifndef UIPARAMFUNCTION_H
#define UIPARAMFUNCTION_H


13 14


15 16 17 18 19 20
#include "UIParam.h"
#include "FunctionGraphWidget.h"


class UIParamFunction : public UIParam
{
21
    FunctionGraphWidget*    m_FuncWidget;
22 23

public:
24 25 26 27 28 29 30 31
    inline                  UIParamFunction( const QString& id,
                                             const QString& name,
                                             const QString& description );

    inline void             Value( QVector<float> &funcSamples ) const  { m_FuncWidget->getFunction(funcSamples); }

    inline const QWidget*   Widget() const                              { return m_Widget; }
    inline QWidget*         Widget()                                    { return m_Widget; }
32

33 34
    inline void             ArrangeInLayout( QGridLayout *l, int line );
    inline void             ConnectModificationSignal();
35 36 37

    inline virtual QString  ValueString() const { return QString(); }
    inline virtual bool     SetValueString( const QString &valueString ) { return true; }
38 39 40 41 42 43 44 45 46 47 48
};


inline UIParamFunction::UIParamFunction( const QString& id,
                        const QString& name,
                        const QString& description ) : UIParam(id,name,description)
{
    const int BUTTON_COUNT = 6;

    QGridLayout *l = new QGridLayout();
    l->setSpacing( 2 );
49

50 51 52 53
    m_Widget = new QWidget();
    m_Widget->setLayout( l );
    if( !m_Description.isNull() && !m_Description.isEmpty() )
        m_Widget->setToolTip( m_Description );
54
        
55 56 57 58 59 60
    m_FuncWidget = new FunctionGraphWidget( name );
    l->addWidget( m_FuncWidget, 0,0, 1,BUTTON_COUNT+1 );

    const char *buttonLabels[BUTTON_COUNT] = { "Lin", "Box", "Gauss", "Sigmo", "Pow", "V" };
    QPushButton *buttons[BUTTON_COUNT];
    for( int i=0; i<BUTTON_COUNT; ++i )
61
    {
62
        buttons[i] = new QPushButton( buttonLabels[i] );
63
#if QT_VERSION < QT_VERSION_CHECK(5,11,0)
64
        int w = QFontMetrics(m_Widget->font()).width(buttons[i]->text()) + 8;
65 66 67
#else
        int w = QFontMetrics(m_Widget->font()).horizontalAdvance(buttons[i]->text()) + 8;
#endif
68 69 70
        buttons[i]->setMinimumWidth( w );
        buttons[i]->setMaximumWidth( w );
        l->addWidget( buttons[i], 1,i );
71
    }
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91

    QObject::connect( buttons[0], SIGNAL(clicked()), m_FuncWidget, SLOT(setLinear     ()) );
    QObject::connect( buttons[1], SIGNAL(clicked()), m_FuncWidget, SLOT(setBox        ()) );
    QObject::connect( buttons[2], SIGNAL(clicked()), m_FuncWidget, SLOT(setGaussian   ()) );
    QObject::connect( buttons[3], SIGNAL(clicked()), m_FuncWidget, SLOT(setSigmoid    ()) );
    QObject::connect( buttons[4], SIGNAL(clicked()), m_FuncWidget, SLOT(setPower      ()) );
    QObject::connect( buttons[5], SIGNAL(clicked()), m_FuncWidget, SLOT(setGemanMcLure()) );
}

inline void UIParamFunction::ArrangeInLayout( QGridLayout *l, int line )
{
    l->addWidget( m_Widget, line,0, 1,2 );
}

inline void UIParamFunction::ConnectModificationSignal()
{
    QObject::connect( m_FuncWidget, SIGNAL(functionModified()), this, SLOT(triggerParameterUpdate()) );
}


92 93 94


#endif // UIPARAMFUNCTION_H