Commit 8bc2f9d9 authored by Frédéric Larue's avatar Frédéric Larue
Browse files

gradientModified() signal emitted by GradientWidget every time the gradient value changes.

parent dc2c26c6
......@@ -26,8 +26,8 @@ GradientWidget::GradientWidget( QWidget *parent ) : QWidget(parent)
GradientWidget::GradientWidget( const QColor& start, const QColor& end, QWidget *parent ) : GradientWidget(parent)
{
m_Stops.push_back( Stop(start, 0.0f) );
m_Stops.push_back( Stop(end , 1.0f) );
addStop( start, 0.0f );
addStop( end , 1.0f );
}
......@@ -214,6 +214,7 @@ void GradientWidget::addStop( const QColor& color, float value )
m_Stops.insert( getInterval(value), stop );
emit gradientModified();
update();
}
......@@ -237,7 +238,7 @@ void GradientWidget::setStops( const QList<QColor>& colors, const QList<float>&
}
QString GradientWidget::getShaderFunctionBodyGLSL( int beg, int end, const QString& indent )
QString GradientWidget::getShaderFunctionBodyGLSL( int beg, int end, const QString& indent ) const
{
QString res;
if( end != beg )
......@@ -280,7 +281,7 @@ QString GradientWidget::getShaderFunctionBodyGLSL( int beg, int end, const QStri
}
QString GradientWidget::getShaderFunctionGLSL( const QString& funcName )
QString GradientWidget::getShaderFunctionGLSL( const QString& funcName ) const
{
QString func =
"vec3 " + funcName + "( float value )\n"
......@@ -298,9 +299,10 @@ void GradientWidget::mouseDoubleClickEvent( QMouseEvent *evt )
{
Stop &stop = m_Stops[m_SelectedStop];
QColor color = QColorDialog::getColor( stop.color(), this, "Select gradient stop color" );
if( color.isValid() )
if( color.isValid() && color != stop.color() )
{
stop.setColor( color );
emit gradientModified();
update();
}
}
......@@ -313,6 +315,7 @@ void GradientWidget::mouseDoubleClickEvent( QMouseEvent *evt )
stop.updateX( width()-1 );
m_Stops.insert( interval, stop );
emit gradientModified();
update();
}
}
......@@ -330,11 +333,13 @@ void GradientWidget::mouseMoveEvent( QMouseEvent *evt )
if( (evt->buttons() & Qt::LeftButton) && m_SelectedStop >= 0 )
{
float value = clampValueToStopInterval( m_SelectedStop, float(evt->x()) / (width()-1) );
m_Stops[m_SelectedStop].setValue( value );
m_Stops[m_SelectedStop].updateX( width()-1 );
update();
if( value != m_Stops[m_SelectedStop].value() )
{
m_Stops[m_SelectedStop].setValue( value );
m_Stops[m_SelectedStop].updateX( width()-1 );
emit gradientModified();
update();
}
}
else
{
......@@ -403,6 +408,7 @@ void GradientWidget::keyPressEvent( QKeyEvent *evt )
m_Stops.remove( m_SelectedStop );
m_SelectedStop = -1;
m_KeyboardInputValue = QString();
emit gradientModified();
update();
}
break;
......@@ -413,11 +419,15 @@ void GradientWidget::keyPressEvent( QKeyEvent *evt )
if( m_KeyboardInputValue.isEmpty() )
break;
float value = m_KeyboardInputValue.toFloat();
float value = clampValueToStopInterval( m_SelectedStop, m_KeyboardInputValue.toFloat() );
m_KeyboardInputValue = QString();
m_Stops[m_SelectedStop].setValue( clampValueToStopInterval( m_SelectedStop, value ) );
m_Stops[m_SelectedStop].updateX( width()-1 );
if( value != m_Stops[m_SelectedStop].value() )
{
m_Stops[m_SelectedStop].setValue( value );
m_Stops[m_SelectedStop].updateX( width()-1 );
emit gradientModified();
}
update();
break;
......
......@@ -47,7 +47,7 @@ private:
int getInterval( float value ) const;
QColor getColor( int interval, float value ) const;
float clampValueToStopInterval( int n, float value ) const;
QString getShaderFunctionBodyGLSL( int beg, int end, const QString& indent );
QString getShaderFunctionBodyGLSL( int beg, int end, const QString& indent ) const;
protected:
void resizeEvent( QResizeEvent *evt );
......@@ -70,7 +70,10 @@ public:
void setStops( const QList<QColor>& colors, const QList<float>& values );
inline QColor getColor( float v ) const { return getColor( getInterval(v), v ); }
QString getShaderFunctionGLSL( const QString& funcName );
QString getShaderFunctionGLSL( const QString& funcName ) const;
signals:
void gradientModified();
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment