Color

Since: BlackBerry 10.0.0

#include <bb/cascades/Color>

An implementation of Paint that represents a color with alpha channel.

At this point the Color objects are immutable.

Creating a color in C++:
 Color c1 = Color::fromRGBA(0.5f, 1.0f, 0.2f, 0.8f);
 Color c2 = Color::fromARGB(0xff996633);

Predefined color constants

The predefined constants are helpful when you quickly need to specify a color that stands out (for example, if you are debugging and wondering how a specific Container is laid out).

These are the 18 predefined colors.
Using predefined color constants in C++:
 Container container = Container::create()
              .background(Color::DarkGreen)
              .preferredSize(100.0f, 100.0f);
This is the result of the example above.

Using Color in QML

Operating Color in QML using the exposed functions in QML only:

 Container {
     // specify r, g, b components using hex string
     background: Color.create("#ff808080")
     preferredWidth: 100
     preferredHeight: 50
 }
 Container {
     // specify r, g, b components using floats
     background: Color.create(0.2, 0.4, 0.5)
     preferredWidth: 100
     preferredHeight: 50
 }
 Container {
     // specify the color using one of predefined constants
     background: Color.Green
     preferredWidth: 100
     preferredHeight: 50
 }
This is the result of the example above (assuming an outer container and layout).
 Button {
     id: button
     text : "Change Color"
     color: Color.Red
     onClicked : {
         if (Color.areEqual(button.color, "#ffff0000")) {
             button.color = Color.Black;
         } else if (Color.areEqual(button.color, Color.Black)) {
             button.resetColor();
         } else {
             button.color = Color.Red;
         }
     }
     onColorChanged: textArea.text = "onColorChanged - " + Color.toHexString(color) + "\n" + textArea.text
 }


Overview

Inheritance

Public Functions Index

Color ()
Color (const Color &orig)
virtual ~Color ()
floatalpha () const
floatblue () const
floatgreen () const
virtual booloperator!= (const Paint &other) const
Color &operator= (const Color &other)
virtual booloperator== (const Paint &other) const
floatred () const
ColorPaint ()Inherited
ColorPaint (const ColorPaint &orig)Inherited
boolisNull () const Inherited
virtual ColorPaint &operator= (const ColorPaint &other)Inherited
Paint &operator= (const Paint &other)Inherited
Paint (const Paint &orig)Inherited

Static Public Functions Index

ColorfromARGB (unsigned int argb)
ColorfromRGBA (float red, float green, float blue, float alpha=1.0f)

Public Static Attributes

const Color Black ()

Predefined opaque black color.

Since:

BlackBerry 10.0.0

const Color Blue ()

Predefined opaque blue color.

Since:

BlackBerry 10.0.0

const Color Cyan ()

Predefined opaque cyan color.

Since:

BlackBerry 10.0.0

const Color DarkBlue ()

Predefined opaque dark blue color.

Since:

BlackBerry 10.0.0

const Color DarkCyan ()

Predefined opaque dark cyan color.

Since:

BlackBerry 10.0.0

const Color DarkGray ()

Predefined opaque dark gray color.

Since:

BlackBerry 10.0.0

const Color DarkGreen ()

Predefined opaque dark green color.

Since:

BlackBerry 10.0.0

const Color DarkMagenta ()

Predefined opaque dark magenta color.

Since:

BlackBerry 10.0.0

const Color DarkRed ()

Predefined opaque dark red color.

Since:

BlackBerry 10.0.0

const Color DarkYellow ()

Predefined opaque dark yellow color.

Since:

BlackBerry 10.0.0

const Color Gray ()

Predefined opaque gray color.

Since:

BlackBerry 10.0.0

const Color Green ()

Predefined opaque green color.

Since:

BlackBerry 10.0.0

const Color LightGray ()

Predefined opaque light gray color.

Since:

BlackBerry 10.0.0

const Color Magenta ()

Predefined opaque magenta color.

Since:

BlackBerry 10.0.0

const Color Red ()

Predefined opaque red color.

Since:

BlackBerry 10.0.0

const Color Transparent ()

Predefined transparent color.

Since:

BlackBerry 10.0.0

const Color White ()

Predefined opaque white color.

Since:

BlackBerry 10.0.0

const Color Yellow ()

Predefined opaque yellow color.

Since:

BlackBerry 10.0.0

Public Functions

Color ()

Default constructor which creates a null color.

See also:

Paint::isNull()

Since:

BlackBerry 10.0.0

Color (

A copy constructor which creates a copy of the passed Color object.

Allows instantiation of a color based on another color object:
 Color c = Color::Green;
        or
 Color c(Color::Green);
Parameters
orig

The color object to create a copy of.

Since:

BlackBerry 10.0.0

virtual~Color ()

Destructor.

Since:

BlackBerry 10.0.0

float alpha ()

Returns the alpha component of this color.

Return:

The alpha component.

Since:

BlackBerry 10.0.0

float blue ()

Returns the blue component of this color.

Return:

The blue component.

Since:

BlackBerry 10.0.0

float green ()

Returns the green component of this color.

Return:

The green component.

Since:

BlackBerry 10.0.0

virtual bool operator!= (

A != operator for Color objects.

This is equivalent to !operator==();

Return:

true if the objects are not equal, false otherwise.

Since:

BlackBerry 10.0.0

Color & operator= (

An assignment operator which sets this instance to have the same color and alpha components as the passed one.

Parameters
other

The color object to create a copy of.

Since:

BlackBerry 10.0.0

virtual bool operator== (

An == operator for Color objects.

The objects are equal if both are of type Color, and have the same color and alpha values.

Return:

true if the objects are both of type Color, and have the same color and alpha values, false otherwise.

Since:

BlackBerry 10.0.0

float red ()

Returns the red component of this color.

Return:

The red component.

Since:

BlackBerry 10.0.0

ColorPaint ()Inherited

Creates a null ColorPaint object.

See also:

Paint::isNull()

Since:

BlackBerry 10.0.0

ColorPaint (Inherited

A copy constructor which creates a copy of the passed ColorPaint object.

Allows instantiation of a ColorPaint based on another ColorPaint object:
 ColorPaint c = SystemDefaults::Paints::defaultText();
        or
 ColorPaint c(SystemDefaults::Paints::defaultText());
Parameters
orig

The ColorPaint object to create a copy of.

Since:

BlackBerry 10.0.0

bool isNull ()Inherited

Checks whether this Paint object is a null paint.

Return:

true if this Paint object is a null paint, false otherwise.

Since:

BlackBerry 10.0.0

virtualColorPaint & operator= (Inherited

Assignment operator that makes this color a copy of the passed color.

Parameters
other

The ColorPaint object to make a copy of.

Since:

BlackBerry 10.0.0

Paint & operator= (Inherited

A = operator for Paint objects.

Since:

BlackBerry 10.0.0

Paint (Inherited

Copy constructor for Paint objects.

Since:

BlackBerry 10.0.0

Static Public Functions

Color fromARGB (
  • unsigned intargb)

Creates a Color from the 32 bit value specified.

The format is ARGB8888.

 //Creates a nice purple color.
 Color c = Color::fromARGB(0xff993399);
Parameters
argb

The color in ARGB888 format as an integer.

Return:

The created color object.

Since:

BlackBerry 10.0.0

Color fromRGBA (
  • floatred,
  • floatgreen,
  • floatblue,
  • floatalpha )

Creates a Color with specified red, green, blue and alpha components.

Values must be in the [0.0 - 1.0] range. If alpha is not specified it is assumed to be 1.0f. If components are not in the [0.0 - 1.0] range they are clamped to it.

 // Creates a nice yellow color. Alpha is left out and
 // thus gets the default value 1.0f.
 Color c = Color::fromRGBA(1.0f, 0.8f, 0.2f);
Parameters
red

The red component.

green

The green component.

blue

The blue component.

alpha

The alpha component (optional, defaults to 1.0f).

Return:

The created color object.

Since:

BlackBerry 10.0.0

Last modified: 2014-09-30



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus