31 int r = ( int )( c1.red() + value * ( c2.red() - c1.red() ) );
32 int g = ( int )( c1.green() + value * ( c2.green() - c1.green() ) );
33 int b = ( int )( c1.blue() + value * ( c2.blue() - c1.blue() ) );
34 int a = ( int )( c1.alpha() + value * ( c2.alpha() - c1.alpha() ) );
36 return QColor::fromRgb( r, g, b, a );
43 : mColor1( color1 ), mColor2( color2 ), mDiscrete( discrete ), mStops( stops )
52 if ( props.contains(
"color1" ) )
54 if ( props.contains(
"color2" ) )
59 if ( props.contains(
"stops" ) )
61 foreach ( QString stop, props[
"stops"].split(
':' ) )
63 int i = stop.indexOf(
';' );
73 bool discrete =
false;
74 if ( props.contains(
"discrete" ) )
76 if ( props[
"discrete"] ==
"1" )
82 for ( QgsStringMap::const_iterator it = props.constBegin();
83 it != props.constEnd(); ++it )
85 if ( it.key().startsWith(
"info_" ) )
86 info[ it.key().mid( 5 )] = it.value();
100 else if ( index >=
mStops.size() + 1 )
106 return mStops[index-1].offset;
120 double lower = 0, upper = 0;
122 for ( QgsGradientStopsList::const_iterator it =
mStops.begin(); it !=
mStops.end(); ++it )
124 if ( it->offset > value )
132 return upper == lower ? c1 :
_interpolate( c1, c2, ( value - lower ) / ( upper - lower ) );
143 return upper == lower ? c1 :
_interpolate( c1, c2, ( value - lower ) / ( upper - lower ) );
163 for ( QgsGradientStopsList::const_iterator it =
mStops.begin(); it !=
mStops.end(); ++it )
167 map[
"stops"] = lst.join(
":" );
172 for ( QgsStringMap::const_iterator it =
mInfo.constBegin();
173 it !=
mInfo.constEnd(); ++it )
175 map[
"info_" + it.key()] = it.value();
191 int numStops =
mStops.count() + 2;
193 for ( QgsGradientStopsList::const_iterator it =
mStops.begin();
194 it !=
mStops.end(); ++it )
196 newStops.append(
QgsGradientStop((
double ) i / numStops, it->color ) );
197 if ( i == numStops - 1 )
207 int numStops =
mStops.count() + 2;
209 for ( QgsGradientStopsList::const_iterator it =
mStops.begin();
210 it !=
mStops.end(); ++it )
212 newStops.append(
QgsGradientStop((
double ) i / ( numStops - 2 ), it->color ) );
213 if ( i == numStops - 3 )
225 gradient->setColorAt( 0,
mColor1 );
226 gradient->setColorAt( 1,
mColor2 );
228 for ( QgsGradientStopsList::const_iterator it =
mStops.begin();
229 it !=
mStops.end(); ++it )
231 gradient->setColorAt( it->offset , it->color );
240 int satMin,
int satMax,
int valMin,
int valMax )
241 : mCount( count ), mHueMin( hueMin ), mHueMax( hueMax ),
242 mSatMin( satMin ), mSatMax( satMax ), mValMin( valMin ), mValMax( valMax )
254 if ( props.contains(
"count" ) ) count = props[
"count"].toInt();
255 if ( props.contains(
"hueMin" ) ) hueMin = props[
"hueMin"].toInt();
256 if ( props.contains(
"hueMax" ) ) hueMax = props[
"hueMax"].toInt();
257 if ( props.contains(
"satMin" ) ) satMin = props[
"satMin"].toInt();
258 if ( props.contains(
"satMax" ) ) satMax = props[
"satMax"].toInt();
259 if ( props.contains(
"valMin" ) ) valMin = props[
"valMin"].toInt();
260 if ( props.contains(
"valMax" ) ) valMax = props[
"valMax"].toInt();
267 if (
mColors.size() < 1 )
return 0;
268 return index /
mColors.size() - 1;
273 int colorCnt =
mColors.count();
274 int colorIdx = ( int )( value * colorCnt );
276 if ( colorIdx >= 0 && colorIdx < colorCnt )
290 map[
"count"] = QString::number(
mCount );
291 map[
"hueMin"] = QString::number(
mHueMin );
292 map[
"hueMax"] = QString::number(
mHueMax );
293 map[
"satMin"] = QString::number(
mSatMin );
294 map[
"satMax"] = QString::number(
mSatMax );
295 map[
"valMin"] = QString::number(
mValMin );
296 map[
"valMax"] = QString::number(
mValMax );
306 double currentHueAngle = 360.0 * ( double )rand() / RAND_MAX;
308 for (
int i = 0; i <
mCount; i++ )
313 currentHueAngle += 137.50776;
318 mColors.append( QColor::fromHsv( h, s, v ) );
326 srand( QTime::currentTime().msec() );
350 int h = 1 + ( int )( 360.0 * rand() / ( RAND_MAX + 1.0 ) );
352 int v = ( rand() % ( maxVal - minVal + 1 ) ) + minVal;
353 return QColor::fromHsv( h, s, v );
358 return "randomcolors";
374 : mSchemeName( schemeName ), mColors( colors )
384 if ( props.contains(
"schemeName" ) )
385 schemeName = props[
"schemeName"];
386 if ( props.contains(
"colors" ) )
387 colors = props[
"colors"].toInt();
409 if (
mPalette.size() < 1 )
return 0;
415 if (
mPalette.isEmpty() || value < 0 || value > 1 )
416 return QColor( 255, 0, 0 );
418 int paletteEntry = ( int )( value *
mPalette.count() );
419 if ( paletteEntry >=
mPalette.count() )
420 paletteEntry =
mPalette.count() - 1;
433 map[
"colors"] = QString::number(
mColors );
444 mSchemeName( schemeName ), mVariantName( variantName ),
445 mVariantList( QStringList() ), mFileLoaded( false ), mMultiStops( false )
449 if ( doLoadFile && ( variantName != QString() ||
mVariantList.isEmpty() ) )
454 QString variantName,
bool doLoadFile )
456 mSchemeName( schemeName ), mVariantName( variantName ),
457 mVariantList( variantList ), mFileLoaded( false ), mMultiStops( false )
463 if ( doLoadFile && ( variantName != QString() ||
mVariantList.isEmpty() ) )
472 if ( props.contains(
"schemeName" ) )
473 schemeName = props[
"schemeName"];
474 if ( props.contains(
"variantName" ) )
475 variantName = props[
"variantName"];
511 info[
"cpt-city-license"] =
"<cpt-city>" + copyingFilename;
563 if ( filename.isNull() )
572 QMap< double, QPair<QColor, QColor> > colorMap =
578 QMap<double, QPair<QColor, QColor> >::const_iterator it, prev;
584 it = prev = colorMap.constBegin();
585 while ( it != colorMap.constEnd() )
588 if ( it != colorMap.constBegin() && ( it.value().first != it.value().second ) )
590 if ( it.value().first == prev.value().second )
606 it = prev = colorMap.constBegin();
607 while ( it != colorMap.constEnd() )
619 ( it.key() != 0.0 && it.key() != 1.0 ) )
629 if ( !
mStops.isEmpty() &&
mStops.first().offset == 0.0 )
631 if ( !
mStops.isEmpty() &&
mStops.last().offset == 1.0 )