예제 #1
0
// Add point to scale
ColourScalePoint* ColourScale::addPoint(double value, QColor colour)
{
    ColourScalePoint* csp = NULL;

    // If supplied value is less than that at the start of the list, add it at the beginning.
    // If larget than the one at the end, then append it to the end of the list.
    // If neither of these, find the first existing value which is larger, and add it before that one
    if (points_.nItems() == 0) csp = points_.add();
    else if (value > points_.last()->value()) csp = points_.add();
    else for (ColourScalePoint* oldPoint = points_.first(); oldPoint != NULL; oldPoint = oldPoint->next) if (oldPoint->value() > value)
            {
                csp = points_.insertBefore(oldPoint);
                break;
            }
    if (csp == NULL) return NULL;

    // Now, set data in new point
    csp->setColour(colour);
    csp->setValue(value);

    // Recalculate colour deltas
    calculateDeltas();

    return csp;
}
예제 #2
0
// Set all alpha values to that specified
void ColourScale::setAllAlpha(double alpha)
{
    QColor color;
    for (ColourScalePoint* csp = points_.first(); csp != NULL; csp = csp->next)
    {
        color = csp->colour();
        int alphai = alpha*255;
        if (alphai < 0) alphai = 0;
        else if (alphai > 255) alphai = 255;
        color.setAlpha(alphai);
        csp->setColour(color);
    }
    calculateDeltas();
}
예제 #3
0
// Add point to scale
ColourScalePoint* ColourScale::addPoint(double value, double r, double g, double b, double a)
{
	Messenger::enter("ColourScale::addPoint");

	// Find position to insert new point at
	ColourScalePoint* newPoint = NULL;
	if (points_.nItems() == 0) newPoint = points_.add();
	else if (value < points_.first()->value()) newPoint = points_.prepend();
	else if (value > points_.last()->value()) newPoint = points_.add();
	else
	{
		for (ColourScalePoint* point = points_.first()->next; point != NULL; point = point->next)
		{
			if (value < point->value())
			{
				newPoint = points_.insertBefore(point);
				break;
			}
		}
	}

	// Double-check we have a new point
	if (!newPoint)
	{
		printf("Internal Error: ColourScale::addPoint() failed to add a point.\n");
		return NULL;
	}

	// Now, set data in new point
	newPoint->setParent(this);
	newPoint->setColour(r, g, b, a);
	newPoint->setValue(value);

	// Recalculate colour deltas
	calculateDeltas();

	// Refresh linked objects
	refreshObjects();

	Messenger::exit("ColourScale::addPoint");
	return newPoint;
}