Пример #1
0
int GradientStopEditor::moveStop( int stop, int newStopValue, qreal newStopPosition )
{
	if( ( stop < 0 ) || ( stop >= values.size() ) )
		return -1;

	if( newStopValue < 0 )
		newStopValue = 0;

	if( newStopValue > 255 )
		newStopValue = 255;

	if( stop != 0 && stop != ( values.size() - 1 ) )
	{
		if( newStopPosition < 0 )
			newStopPosition = 0;

		if( newStopPosition > 1.0 )
			newStopPosition = 1.0;
	}
	else
		newStopPosition = positions[ stop ];

	if( ( stop == 0 ) || ( stop == ( values.size() - 1 ) ) )
	{
		values[ stop ] = newStopValue;
		if( stopChannel == composite )
			generateBackground( true );
		update();
		emit stopMoved( stop, newStopValue, newStopPosition, stop );
		return stop;
	}

	values.remove( stop );
	positions.remove( stop );

	int newIndex = addStop( newStopValue, newStopPosition, false );
	if( currentMovedStop == stop )
		currentMovedStop = newIndex;

	emit stopMoved( stop, newStopValue, newStopPosition, newIndex );
	if( stopChannel == composite )
		generateBackground( true );
	update();

	return newIndex;
}
Пример #2
0
void QtGradientStopsModel::moveStop(QtGradientStop *stop, qreal newPos)
{
    if (!d_ptr->m_stopToPos.contains(stop))
        return;
    if (d_ptr->m_posToStop.contains(newPos))
        return;

    if (newPos > 1.0)
        newPos = 1.0;
    else if (newPos < 0.0)
        newPos = 0.0;

    emit stopMoved(stop, newPos);

    const qreal oldPos = stop->position();
    stop->setPosition(newPos);
    d_ptr->m_stopToPos[stop] = newPos;
    d_ptr->m_posToStop.remove(oldPos);
    d_ptr->m_posToStop[newPos] = stop;
}