Harmony
Scripting Interface Documentation
Palette Class Reference

The JavaScript class providing informations about a specific palette. More...

Public Slots

String getPath ()
 Returns the folder in which this palette is located. More...
 
String getName ()
 Returns the name of this palette. The extension (".plt") is not included. More...
 
bool isValid ()
 Returns whether the palette object is valid. More...
 
bool isLoaded ()
 Was the palette successfully loaded from disk (true or false)? More...
 
bool isNotFound ()
 Was the palette found at the location specified by the path and name (true or false)? More...
 
BaseColorgetColorByIndex (int index)
 Iterate over the colours. Return an invalid colour if the index is out of bound or otherwise invalid. More...
 
BaseColorgetColorById (String &uniqueId)
 Retrieve a colour by id. If the colour is not found, the isValid property will be false. More...
 
bool getLock ()
 Try to obtain the database lock. Return true on success, and false on failure. The lock will be held until it is released in script or the ui. Safe to call multiple time to get the lock state. More...
 
bool releaseLock ()
 Release access to the palette. Other users will be able to obtain the access rights to the palette. More...
 
bool isColorPalette ()
 The following methods test the type of the wrapped palette. More...
 
bool isTexturePalette ()
 Returns whether the palette is a texture palette. More...
 
void setToColorPalette ()
 sets the type of the palette to be a color palette More...
 
void setToTexturePalette ()
 sets the type of the palette to be a texture palette More...
 
ColorcreateNewColor (int colorType, String &name, QVariant colorData)
 Create a new colour of a given type. More...
 
ColorcreateNewSolidColor (String &name, QVariant colorData)
 Create a new solid colour. More...
 
ColorcreateNewLinearGradientColor (String &name, QVariant colorData)
 Create a new linear gradient colour. More...
 
ColorcreateNewRadialGradientColor (String &name, QVariant colorData)
 Create a new radial gradient colour. More...
 
TexturecreateNewTexture (String &name, String &filename, bool tiled)
 Create a new texture colour object. More...
 
TexturecreateNewTexture (String &name, QImage &bitmap, bool tiled)
 Create a new texture from a QImage object (may not be done from the script). More...
 
BaseColorduplicateColor (BaseColor *source)
 Create a duplicate of a colour object - this colourID is unique. More...
 
BaseColorcloneColor (BaseColor *source)
 Create a clone of a colour object - this colourID is identical to original colour. More...
 
BaseColorcloneColor (BaseColor *source, bool replaceOnIDConflict)
 Create a clone of a colour object - resolve the potential ID conflict by either cloning or duplicating the colour. More...
 
bool removeColor (String &uniqueId)
 Delete a colour from the palette. More...
 
bool moveColor (int index, int beforeIndex)
 Move a colour at the specified index. More...
 
bool acquire (BaseColor *color)
 Move a colour to this palette. More...
 

Properties

int nColors
 Number of colours in this palette. More...
 
String id
 The palette ID of this palette. More...
 
int location
 Returns one of the PaletteLocation constants or -1 if the palette is invalid. More...
 
int elementId
 Returns the element id in which the palette is stored if location is PaletteLocation ELEMENT. Returns -1 if the palette is not stored in an element. More...
 

Detailed Description

The JavaScript class providing informations about a specific palette.

A Palette object can be obtained from PaletteList methods like getPaletteByIndex, getPaletteById or createPalette or from the PaletteObjectManager method getPalette. The Palette class defines a palette of colours. It provides access to functionalities of palettes like:

  • Creating or modifying the colour types.
  • Reordering, cloning or duplicating the colours of a Palette.
  • Moving a colour pot from a palette to another.
Note
Functions that modify the state of the palette will try to obtain the database access lock. If the lock cannot be obtained, a JavaScript exception will be thrown.
for ( var j = 0; j < paletteList.numPalettes; ++ j )
{
var myPalette = paletteList.getPaletteByIndex( j );
var path = myPalette.getPath() + "/" + myPalette.getName();
}

Member Function Documentation

◆ acquire

bool Palette::acquire ( BaseColor color)
slot

Move a colour to this palette.

Will remove the colour from its original palette and move it to this one.

Returns false if the colour is invalid or if this is the same palette as the current colour palette.

If this palette has a colour with the same colour ID as the source colour, it will return false also.

◆ cloneColor [1/2]

BaseColor* Palette::cloneColor ( BaseColor source)
slot

Create a clone of a colour object - this colourID is identical to original colour.

Will create a copy of the colour with all the same values including the colorID. The source must be from another palette otherwise it will return an invalid color.

◆ cloneColor [2/2]

BaseColor* Palette::cloneColor ( BaseColor source,
bool  replaceOnIDConflict 
)
slot

Create a clone of a colour object - resolve the potential ID conflict by either cloning or duplicating the colour.

This version allow you to specify whether to replace an already existing color when cloning the palette

◆ createNewColor

Color* Palette::createNewColor ( int  colorType,
String &  name,
QVariant  colorData 
)
slot

Create a new colour of a given type.

Create a new colour of given type colorType can be:

Depending on the value of colorType argument, colorData has to be either an array of object or an object. If the colorType argument is SOLID_COLOR, the colorData must be an object defined like this:

{ r : 255, g: 0, b: 0, a : 255 }

to represent a solid red color. If the colorType argument is one of the gradients, there must be an array of objects, one for each gradient tack. For example:

[ { r : 255, g: 0, b: 0, a : 255, t: 0 }, { r : 0, g: 0, b: 255, a : 255, t: 1 } ]

would define a gradient going from red to blue. The t parameter in each object represents the tack position and is a double value going from 0 to 1.

◆ createNewLinearGradientColor

Color* Palette::createNewLinearGradientColor ( String &  name,
QVariant  colorData 
)
slot

Create a new linear gradient colour.

Same as createNewColor(ColorType.LINEAR_GRADIENT, name, colorData);

◆ createNewRadialGradientColor

Color* Palette::createNewRadialGradientColor ( String &  name,
QVariant  colorData 
)
slot

Create a new radial gradient colour.

Same as createNewColor(ColorType.RADIAL_GRADIENT, name, colorData);

◆ createNewSolidColor

Color* Palette::createNewSolidColor ( String &  name,
QVariant  colorData 
)
slot

Create a new solid colour.

Same as createNewColor(ColorType.SOLID_COLOR, name, colorData);

◆ createNewTexture [1/2]

Texture* Palette::createNewTexture ( String &  name,
String &  filename,
bool  tiled 
)
slot

Create a new texture colour object.

Creates a texture pot. Will copy the bitmap file internally to the palette

◆ createNewTexture [2/2]

Texture* Palette::createNewTexture ( String &  name,
QImage &  bitmap,
bool  tiled 
)
slot

Create a new texture from a QImage object (may not be done from the script).

Creates a texture pot. Will copy the bitmap data internally to the palette

◆ duplicateColor

BaseColor* Palette::duplicateColor ( BaseColor source)
slot

Create a duplicate of a colour object - this colourID is unique.

Will create a copy of the colour with all the same values as source except for the colorID which will be a new uniqueID.

◆ getColorById

BaseColor* Palette::getColorById ( String &  uniqueId)
slot

Retrieve a colour by id. If the colour is not found, the isValid property will be false.

Parameters
uniqueId- The id of the colour

◆ getColorByIndex

BaseColor* Palette::getColorByIndex ( int  index)
slot

Iterate over the colours. Return an invalid colour if the index is out of bound or otherwise invalid.

Parameters
index- The zero based index of the colour.

◆ getLock

bool Palette::getLock ( )
slot

Try to obtain the database lock. Return true on success, and false on failure. The lock will be held until it is released in script or the ui. Safe to call multiple time to get the lock state.

◆ getName

String Palette::getName ( )
slot

Returns the name of this palette. The extension (".plt") is not included.

◆ getPath

String Palette::getPath ( )
slot

Returns the folder in which this palette is located.

◆ isColorPalette

bool Palette::isColorPalette ( )
slot

The following methods test the type of the wrapped palette.

Returns whether the palette is a color palette

◆ isLoaded

bool Palette::isLoaded ( )
slot

Was the palette successfully loaded from disk (true or false)?

◆ isNotFound

bool Palette::isNotFound ( )
slot

Was the palette found at the location specified by the path and name (true or false)?

◆ isTexturePalette

bool Palette::isTexturePalette ( )
slot

Returns whether the palette is a texture palette.

◆ isValid

bool Palette::isValid ( )
slot

Returns whether the palette object is valid.

◆ moveColor

bool Palette::moveColor ( int  index,
int  beforeIndex 
)
slot

Move a colour at the specified index.

Will move the colour at given index just before the colour at beforeIndex in the list.

Will move the colour at the end if beforeIndex is -1.

Returns true if successful.

◆ releaseLock

bool Palette::releaseLock ( )
slot

Release access to the palette. Other users will be able to obtain the access rights to the palette.

◆ removeColor

bool Palette::removeColor ( String &  uniqueId)
slot

Delete a colour from the palette.

Permanently delete a colour. Returns whether a colour was removed

◆ setToColorPalette

void Palette::setToColorPalette ( )
slot

sets the type of the palette to be a color palette

◆ setToTexturePalette

void Palette::setToTexturePalette ( )
slot

sets the type of the palette to be a texture palette

Property Documentation

◆ elementId

int Palette::elementId
read

Returns the element id in which the palette is stored if location is PaletteLocation ELEMENT. Returns -1 if the palette is not stored in an element.

◆ id

String Palette::id
read

The palette ID of this palette.

◆ location

int Palette::location
read

Returns one of the PaletteLocation constants or -1 if the palette is invalid.

◆ nColors

int Palette::nColors
read

Number of colours in this palette.