Пример #1
0
void TupGradientSelector::setStops(const QGradientStops &stops)
{
    m_gradient.setStops(stops);
    m_arrows.clear();

    for (int i = 0; i < stops.count(); i++)
         addArrow(calcArrowPos((int) (100 - (stops[i].first * 100)) ), stops[i].second);

    update();
}
Пример #2
0
QGradientStops QQuickPathGradient::sortedGradientStops() const
{
    QGradientStops result;
    for (int i = 0; i < m_stops.count(); ++i) {
        QQuickPathGradientStop *s = static_cast<QQuickPathGradientStop *>(m_stops[i]);
        int j = 0;
        while (j < result.count() && result[j].first < s->position())
            ++j;
        result.insert(j, QGradientStop(s->position(), s->color()));
    }
    return result;
}
Пример #3
0
void SvgStyleParser::parseColorStops(QGradient *gradient, const KoXmlElement &e)
{
    QGradientStops stops;
    QColor c;

    for (KoXmlNode n = e.firstChild(); !n.isNull(); n = n.nextSibling()) {
        KoXmlElement stop = n.toElement();
        if (stop.tagName() == "stop") {
            float offset;
            QString temp = stop.attribute("offset");
            if (temp.contains('%')) {
                temp = temp.left(temp.length() - 1);
                offset = temp.toFloat() / 100.0;
            } else
                offset = temp.toFloat();

            QString stopColorStr = stop.attribute("stop-color");
            if (!stopColorStr.isEmpty()) {
                if (stopColorStr == "inherit") {
                    stopColorStr = inheritedAttribute("stop-color", stop);
                }
                parseColor(c, stopColorStr);
            }
            else {
                // try style attr
                QString style = stop.attribute("style").simplified();
                QStringList substyles = style.split(';', QString::SkipEmptyParts);
                for (QStringList::Iterator it = substyles.begin(); it != substyles.end(); ++it) {
                    QStringList substyle = it->split(':');
                    QString command = substyle[0].trimmed();
                    QString params  = substyle[1].trimmed();
                    if (command == "stop-color")
                        parseColor(c, params);
                    if (command == "stop-opacity")
                        c.setAlphaF(params.toDouble());
                }

            }
            QString opacityStr = stop.attribute("stop-opacity");
            if (!opacityStr.isEmpty()) {
                if (opacityStr == "inherit") {
                    opacityStr = inheritedAttribute("stop-opacity", stop);
                }
                c.setAlphaF(opacityStr.toDouble());
            }
            stops.append(QPair<qreal, QColor>(offset, c));
        }
    }
    if (stops.count())
        gradient->setStops(stops);
}
QColor KarbonGradientHelper::colorAt(qreal position, const QGradientStops &stops)
{
    if (! stops.count())
        return QColor();

    if (stops.count() == 1)
        return stops.first().second;

    QGradientStop prevStop(-1.0, QColor());
    QGradientStop nextStop(2.0, QColor());
    // find framing gradient stops
    foreach(const QGradientStop & stop, stops) {
        if (stop.first > prevStop.first && stop.first < position)
            prevStop = stop;
        if (stop.first < nextStop.first && stop.first > position)
            nextStop = stop;
    }

    QColor theColor;

    if (prevStop.first < 0.0) {
        // new stop is before the first stop
        theColor = nextStop.second;
    } else if (nextStop.first > 1.0) {
        // new stop is after the last stop
        theColor = prevStop.second;
    } else {
        // linear interpolate colors between framing stops
        QColor prevColor = prevStop.second, nextColor = nextStop.second;
        qreal colorScale = (position - prevStop.first) / (nextStop.first - prevStop.first);
        theColor.setRedF(prevColor.redF() + colorScale *(nextColor.redF() - prevColor.redF()));
        theColor.setGreenF(prevColor.greenF() + colorScale *(nextColor.greenF() - prevColor.greenF()));
        theColor.setBlueF(prevColor.blueF() + colorScale *(nextColor.blueF() - prevColor.blueF()));
        theColor.setAlphaF(prevColor.alphaF() + colorScale *(nextColor.alphaF() - prevColor.alphaF()));
    }
    return theColor;
}
Пример #5
0
void Project::MatchColors(QAction *action)
{
	if (action)
	{
		QString selectedDomainName = action->text();
		Domain* selectedDomain = DetermineDomain(selectedDomainName);
		if (selectedDomain && visibleDomain)
		{
			// Get the active shader types
			ShaderType outlineType = selectedDomain->GetTerrainOutlineType();
			ShaderType fillType = selectedDomain->GetTerrainFillType();

			if (outlineType == SolidShaderType)
			{
				// Copy the solid outline color from the selected domain
				QColor solidOutline = selectedDomain->GetTerrainSolidOutline();
				visibleDomain->SetTerrainSolidOutline(solidOutline);
			}
			else if (outlineType == GradientShaderType)
			{
				// Copy the outline gradient from the selected domain
				// Convert percentages in gradient stops to elevation values
				// Convert these elevation values back into percentages in the range of the selected domain
				float selectedRange[2] = {selectedDomain->GetTerrainMinZ(), selectedDomain->GetTerrainMaxZ()};
				float currentRange[2] = {visibleDomain->GetTerrainMinZ(), visibleDomain->GetTerrainMaxZ()};
				QGradientStops selectedGradientOutline = selectedDomain->GetTerrainGradientOutline();
				QGradientStops newStopsOutline;
				for (int i=0; i<selectedGradientOutline.count(); ++i)
				{
					QGradientStop currentStop = selectedGradientOutline[i];
					float percentage = currentStop.first;
					QColor color = currentStop.second;

					float selectedValue = selectedRange[1] - percentage*(selectedRange[1] - selectedRange[0]);
					if (selectedValue >= currentRange[0] && selectedValue <= currentRange[1])
					{
						QGradientStop newStop;
						newStop.first = (currentRange[1] - selectedValue) / (currentRange[1] - currentRange[0]);
						newStop.second = color;
						newStopsOutline.append(newStop);
					}
				}
				visibleDomain->SetTerrainGradientOutline(newStopsOutline);
			}

			if (fillType == SolidShaderType)
			{
				// Copy the solid fill color from the selected domain
				QColor solidFill = selectedDomain->GetTerrainSolidFill();
				visibleDomain->SetTerrainSolidFill(solidFill);
			}
			else if (fillType == GradientShaderType)
			{
				// Copy the fill gradient from the selected domain
				// Convert percentages in gradient stops to elevation values
				// Convert these elevation values back into percentages in the range of the selected domain
				float selectedRange[2] = {selectedDomain->GetTerrainMinZ(), selectedDomain->GetTerrainMaxZ()};
				float currentRange[2] = {visibleDomain->GetTerrainMinZ(), visibleDomain->GetTerrainMaxZ()};
				QGradientStops selectedGradientFill = selectedDomain->GetTerrainGradientFill();
				QGradientStops newStopsFill;
				for (int i=0; i<selectedGradientFill.count(); ++i)
				{
					QGradientStop currentStop = selectedGradientFill[i];
					float percentage = currentStop.first;
					QColor color = currentStop.second;

					float selectedValue = selectedRange[1] - percentage*(selectedRange[1] - selectedRange[0]);
					if (selectedValue >= currentRange[0] && selectedValue <= currentRange[1])
					{
						QGradientStop newStop;
						newStop.first = (currentRange[1] - selectedValue) / (currentRange[1] - currentRange[0]);
						newStop.second = color;
						newStopsFill.append(newStop);
					}
				}
				visibleDomain->SetTerrainGradientFill(newStopsFill);
			}
		}
	}
}