# -*- coding: utf-8 -*-

"""implementation of color models. The module provides the following
public attribute:

COLOR_MODEL_FACTORIES = list containing all color model factories
"""

from PyQt4 import QtCore, QtGui
from chartables_model_factory import ModelFactoryBase, ModelBase, ModelColumn
from chartables_model_options import Options

COLOR_MODEL_FACTORIES = []
#*******************************************************************
# helpers
#*******************************************************************

BROWSER_SAVE = [0x00, 0x33, 0x66, 0xcc, 0xff]

def html_color_to_rgb(html_color):
    """converts a Html color to a rgb tuple"""

    if len(html_color) == 7 and html_color[0] == '#':
        try:
            return (
                    int(html_color[1:3], 16),
                    int(html_color[3:5], 16),
                    int(html_color[5:7], 16)
                    )
        except:
            pass
    raise ValueError('invalid html color: %s' % html_color)


# thanks to Steven Bethard
# in http://groups.google.com/group/comp.lang.python/browse_thread/thread/a505ba2e70d00250/dd7a20b42c62e48e?lnk=gst&q=permutations&rnum=1#dd7a20b42c62e48e
def permute(Xs, N):
    """generator to calculate all permutations of a sequence

    @param Xs sequence to permute
    @param N desired length of the single permutations
    @return (list) the next permutation in turn
    """
    if N <= 0:
        yield []
    else:
        for x in Xs:
            for sub in permute(Xs, N-1):
                yield [x]+sub

#*********************************************************************************
# bit of owner drawing here to show some nice rows in the first column
#*********************************************************************************
class _Delegate(QtGui.QItemDelegate):
    """QItemDelegate implementation to handle owner drawing"""


    def __init__(self, parent, columns, rows):
        QtGui.QItemDelegate.__init__(self, parent)
        self.rows = rows
        self.columns = columns
        self.feedbackIndex = None


    def _hasIndex(self, row, column):
        """protected method to check if a table index is valid"""
        return -1 < row < len(self.rows)


    def paint(self, painter, option, index):
        """QItemDelegate.paint() implementation"""

        if index.column() == 0:
            if self._hasIndex(index.row(), index.column()):
                func = self.columns[0].callback
                return func(painter, option, index)

        return QtGui.QItemDelegate.paint(self, painter, option, index)

#*******************************************************************
# Table model for rows
#*******************************************************************
class _ColorModelBase(ModelBase):
    """
    QAbstractTableModel implementation. Base class for all color models


    All models derrived from this class should provide a 'name' class attribute
    set to the display name of the model.
    """

    name = ""

    def __init__(self, table, header=None, rows=None, options=None):
        """
        constructor

        @param parent parent window of the model
        @param columns tuple of table columns the model supports

        The tuple should contain any number of two tuples(headerText, callback, whats this?)
        'headerText' is the text to display for the column header of the table,
        callback is a method to be called with one arument: the color in 'rows'
        currently required by the table for display and "whats this?" the whats this
        text of th ciolumn.

        Return a stringable representation according to the demands of the
        column in response.


        @paran rows iterable of rows the model supports
        """
        ModelBase.__init__(self, table, header=header, rows=rows, options=options)
        self.delegate = _Delegate(self, header, rows)


    def getDelegate(self):
        """
        public method to query the model for its QItemDelegate

        @return QItemDelegate instance or None
        """
        return self.delegate
    
    
    def data(self, index, role):
        """QAbstractTableModel.data() implementation"""

        if index.column() == 0:
            return QtCore.QVariant()
        return ModelBase.data(self, index, role)


#*******************************************************************
# consts
#*******************************************************************
class CT_HeaderColors(QtCore.QObject):

    def __init__(self, parent, cbPaint, cbHtml, cbRgb, cbCmy, cbHls, cbName=None):
        QtCore.QObject.__init__(self)
        
        self.columns = [
            ModelColumn(
                    title=self.trUtf8("#            "),
                    doc=self.trUtf8("Displays the color"),
                    flags=Options.CTF_NONE,
                    callback=cbPaint,
                    ),
            ModelColumn(
                    title=self.trUtf8("Html"),
                    doc=self.trUtf8("Displays the html color representation"),
                    flags=Options.CTF_SHOWHTMLCOLORS,
                    callback=cbHtml,
                    ),
                
            ModelColumn(
                    title=self.trUtf8("Rgb"),
                    doc=self.trUtf8("Displays the (red, green, blue) portions"),
                    flags=Options.CTF_SHOWRGBCOLORS,
                    callback=cbRgb,
                    ),
            ModelColumn(
                    title=self.trUtf8("Cmyk"),
                    doc=self.trUtf8("Displays the (cyan, magenta, yellow, black) portions"),
                    flags=Options.CTF_SHOWCMYCOLORS,
                    callback=cbCmy,
                    ),
            ModelColumn(
                    title=self.trUtf8("Hsv"),
                    doc=self.trUtf8("Displays the (hue, saturation, value) portions"),
                    flags=Options.CTF_SHOWHLSCOLORS,
                    callback=cbHls,
                    ),
            ]
        if cbName:
            self.columns.insert(
                1,
                ModelColumn(
                        title=self.trUtf8("Name"),
                        doc=self.trUtf8("Displays the color name"),
                        flags=Options.CTF_SHOWCOLORNAMES,
                        callback=cbName,
                        ),
                )
        

    def __getitem__(self, i):
        return self.columns[i]
    
        def __len__(self):
            return len(self.columns)


#*******************************************************************
#
#*******************************************************************
class _VGA(_ColorModelBase):
    """VGA color model implementation"""

    def __init__(self, parent, options=None):
        """
        constructor

        @param parent parent of the model
        @param options Options instance
        """

        self.rows = (
            ("white", '#ffffff'),
            ("yellow", '#ffff00'),
            ("orange", '#ffA500'),
            ("red", '#ff0000'),
            ("fuchsia", '#ff00ff'),
            ("silver", '#c0c0c0'),
            ("gray", '#808080'),
            ("olive", '#808000'),
            ("purple", '#800080'),
            ("maroon", '#800000'),
            ("aqua", '#00ffff'),
            ("lime", '#00ff00'),
            ("teal", '#008080'),
            ("green", '#008000'),
            ("blue", '#0000ff'),
            ("navy", '#000080'),
            ("black", '#000000'),
            )
        
        header = CT_HeaderColors(parent, 
                self._doPaint, self._toHtml, self._toRgb,
                self._toCmyk, self._toHsv, cbName=self._toName)
        _ColorModelBase.__init__(self,
                parent,
                header=header,
                rows=self.rows,
                options=options,
                )

    def _doPaint(self, painter, option, index):
        """protected method to paint a color into a cell"""
        color = self.rows[index.row()][1]
        color = html_color_to_rgb(color)
        brush = QtGui.QBrush(QtGui.QColor(*color))
        painter.fillRect(option.rect, brush)
        return None


    def _toName(self, color):
        """returns the name of a color

        @param color tuple of color data
        """
        return color[0]


    def _toHtml(self, color):
        """returns the name of a color

        @param color tuple of color data
        @return (string) name
        """
        return color[1]


    def _toRgb(self, color):
        """returns the rgb value of a color

        @param color tuple of color data
        @return (string) (r, g, b)
        """
        return "(%s, %s, %s)" % html_color_to_rgb(color[1])

    def _toCmyk(self, color):
        """returns the cmy value of a coloror

        @param color tuple of color data
        @return (string) (c, m, y)
        """
        rgb = QtGui.QColor(*html_color_to_rgb(color[1]))
        cmyk = rgb.toCmyk()
        return "(%s, %s, %s, %s)" % (cmyk.cyan(), cmyk.magenta(), cmyk.yellow(), cmyk.black())

    def _toHsv(self, color):
        """returns the hls value of a color

        @param color tuple of color data
        @return (string) (h, l, s)
        """
        rgb = QtGui.QColor(*html_color_to_rgb(color[1]))
        hsv = rgb.toHsv()
        return "(%s, %s, %s)" % (hsv.hue(), hsv.saturation(), hsv.value())


#*******************************************************************
#
#*******************************************************************
class _X11(_VGA):
    """X11 color model implementation"""

    
    def __init__(self, parent, options=None):
        """
        constructor

        @param parent parent of the model
        @param options Options instance
        """
        self.rows = [
            ("indigo", "#4B0082"),
            ("gold", "#FFD700"),
            ("firebrick", "#B22222"),
            ("indianred", "#CD5C5C"),
            ("yellow", "#FFFF00"),
            ("darkolivegreen", "#556B2F"),
            ("darkseagreen", "#8FBC8F"),
            ("mediumvioletred", "#C71585"),
            ("mediumorchid", "#BA55D3"),
            ("chartreuse", "#7FFF00"),
            ("mediumslateblue", "#7B68EE"),
            ("black", "#000000"),
            ("springgreen", "#00FF7F"),
            ("crimson", "#DC143C"),
            ("lightsalmon", "#FFA07A"),
            ("brown", "#A52A2A"),
            ("turquoise", "#40E0D0"),
            ("olivedrab", "#6B8E23"),
            ("silver", "#C0C0C0"),
            ("skyblue", "#87CEEB"),
            ("gray", "#808080"),
            ("darkturquoise", "#00CED1"),
            ("goldenrod", "#DAA520"),
            ("darkgreen", "#006400"),
            ("darkviolet", "#9400D3"),
            ("darkgray", "#A9A9A9"),
            ("lime", "#00FF00"),
            ("lightpink", "#FFB6C1"),
            ("teal", "#008080"),
            ("darkmagenta", "#8B008B"),
            ("lightgoldenrodyellow", "#FAFAD2"),
            ("lavender", "#E6E6FA"),
            ("yellowgreen", "#9ACD32"),
            ("thistle", "#D8BFD8"),
            ("violet", "#EE82EE"),
            ("navy", "#000080"),
            ("orchid", "#DA70D6"),
            ("blue", "#0000FF"),
            ("ghostwhite", "#F8F8FF"),
            ("honeydew", "#F0FFF0"),
            ("cornflowerblue", "#6495ED"),
            ("darkblue", "#00008B"),
            ("darkkhaki", "#BDB76B"),
            ("mediumpurple", "#9370DB"),
            ("cornsilk", "#FFF8DC"),
            ("red", "#FF0000"),
            ("bisque", "#FFE4C4"),
            ("darkcyan", "#008B8B"),
            ("khaki", "#F0E68C"),
            ("wheat", "#F5DEB3"),
            ("deepskyblue", "#00BFFF"),
            ("darkred", "#8B0000"),
            ("steelblue", "#4682B4"),
            ("aliceblue", "#F0F8FF"),
            ("gainsboro", "#DCDCDC"),
            ("mediumturquoise", "#48D1CC"),
            ("floralwhite", "#FFFAF0"),
            ("plum", "#DDA0DD"),
            ("aqua", "#00FFFF"),
            ("burlywood", "#DEB887"),
            ("darksalmon", "#E9967A"),
            ("beige", "#F5F5DC"),
            ("azure", "#F0FFFF"),
            ("lightsteelblue", "#B0C4DE"),
            ("oldlace", "#FDF5E6"),
            ("greenyellow", "#ADFF2F"),
            ("royalblue", "#4169E1"),
            ("lightseagreen", "#20B2AA"),
            ("mistyrose", "#FFE4E1"),
            ("sienna", "#A0522D"),
            ("lightcoral", "#F08080"),
            ("orangered", "#FF4500"),
            ("navajowhite", "#FFDEAD"),
            ("slategray", "#708090"),
            ("palegreen", "#98FB98"),
            ("lightcyan", "#E0FFFF"),
            ("seashell", "#FFF5EE"),
            ("mediumspringgreen", "#00FA9A"),
            ("fuchsia", "#FF00FF"),
            ("papayawhip", "#FFEFD5"),
            ("blanchedalmond", "#FFEBCD"),
            ("peru", "#CD853F"),
            ("aquamarine", "#7FFFD4"),
            ("white", "#FFFFFF"),
            ("darkslategray", "#2F4F4F"),
            ("ivory", "#FFFFF0"),
            ("darkgoldenrod", "#B8860B"),
            ("lawngreen", "#7CFC00"),
            ("lightgreen", "#90EE90"),
            ("orange", "#FFA500"),
            ("forestgreen", "#228B22"),
            ("maroon", "#800000"),
            ("olive", "#808000"),
            ("mintcream", "#F5FFFA"),
            ("antiquewhite", "#FAEBD7"),
            ("dimgray", "#696969"),
            ("hotpink", "#FF69B4"),
            ("moccasin", "#FFE4B5"),
            ("limegreen", "#32CD32"),
            ("saddlebrown", "#8B4513"),
            ("darkslateblue", "#483D8B"),
            ("lightskyblue", "#87CEFA"),
            ("deeppink", "#FF1493"),
            ("coral", "#FF7F50"),
            ("lightgrey", "#D3D3D3"),
            ("dodgerblue", "#1E90FF"),
            ("slateblue", "#6A5ACD"),
            ("sandybrown", "#F4A460"),
            ("tan", "#D2B48C"),
            ("rosybrown", "#BC8F8F"),
            ("pink", "#FFC0CB"),
            ("lightblue", "#ADD8E6"),
            ("palevioletred", "#DB7093"),
            ("mediumseagreen", "#3CB371"),
            ("linen", "#FAF0E6"),
            ("darkorange", "#FF8C00"),
            ("powderblue", "#B0E0E6"),
            ("seagreen", "#2E8B57"),
            ("snow", "#FFFAFA"),
            ("mediumblue", "#0000CD"),
            ("midnightblue", "#191970"),
            ("paleturquoise", "#AFEEEE"),
            ("palegoldenrod", "#EEE8AA"),
            ("whitesmoke", "#F5F5F5"),
            ("darkorchid", "#9932CC"),
            ("salmon", "#FA8072"),
            ("lightslategray", "#778899"),
            ("lemonchiffon", "#FFFACD"),
            ("chocolate", "#D2691E"),
            ("tomato", "#FF6347"),
            ("cadetblue", "#5F9EA0"),
            ("lightyellow", "#FFFFE0"),
            ("lavenderblush", "#FFF0F5"),
            ("purple", "#800080"),
            ("mediumaquamarine", "#66CDAA"),
            ("green", "#008000"),
            ("blueviolet", "#8A2BE2"),
            ("peachpuff", "#FFDAB9"),
            ]
        header = CT_HeaderColors(parent, 
                self._doPaint, self._toHtml, self._toRgb,
                self._toCmyk, self._toHsv, cbName=self._toName)
        _ColorModelBase.__init__(self,
                parent,
                header=header,
                rows=self.rows,
                options=options,
                )

#*******************************************************************
#
#*******************************************************************
class _NetscapeColors(_VGA):
    """Netscape color model implementation"""

    
    def __init__(self, parent, options=None):
        """
        constructor

        @param parent parent of the model
        @param options Options instance
        """


        self.rows = [
            ("aliceblue", "#F0F8FF"),
            ("antiquewhite", "#FAEBD7"),
            ("aqua", "#00FFFF"),
            ("aquamarine", "#7FFFD4"),
            ("azure", "#F0FFFF"),
            ("beige", "#F5F5DC"),
            ("bisque", "#FFE4C4"),
            ("black", "#000000"),
            ("blanchedalmond", "#FFEBCD"),
            ("blue", "#0000FF"),
            ("blueviolet", "#8A2BE2"),
            ("brown", "#A52A2A"),
            ("burlywood", "#DEB887"),
            ("cadetblue", "#5F9EA0"),
            ("chartreuse", "#7FFF00"),
            ("chocolate", "#D2691E"),
            ("coral", "#FF7F50"),
            ("cornflowerblue", "#6495ED"),
            ("cornsilk", "#FFF8DC"),
            ("crimson", "#DC143C"),
            ("cyan", "#00FFFF"),
            ("darkblue", "#00008B"),
            ("darkcyan", "#008B8B"),
            ("darkgoldenrod", "#B8860B"),
            ("darkgray", "#A9A9A9"),
            ("darkgreen", "#006400"),
            ("darkkhaki", "#BDB76B"),
            ("darkmagenta", "#8B008B"),
            ("darkolivegreen", "#556B2F"),
            ("darkorange", "#FF8C00"),
            ("darkorchid", "#9932CC"),
            ("darkred", "#8B0000"),
            ("darksalmon", "#E9967A"),
            ("darkseagreen", "#8FBC8F"),
            ("darkslateblue", "#483D8B"),
            ("darkslategray", "#2F4F4F"),
            ("darkturquoise", "#00CED1"),
            ("darkviolet", "#9400D3"),
            ("deeppink", "#FF1493"),
            ("deepskyblue", "#00BFFF"),
            ("dimgray", "#696969"),
            ("dodgerblue", "#1E90FF"),
            ("firebrick", "#B22222"),
            ("floralwhite", "#FFFAF0"),
            ("forestgreen", "#228B22"),
            ("fuchsia", "#FF00FF"),
            ("gainsboro", "#DCDCDC"),
            ("ghostwhite", "#F8F8FF"),
            ("gold", "#FFD700"),
            ("goldenrod", "#DAA520"),
            ("gray", "#808080"),
            ("green", "#008000"),
            ("greenyellow", "#ADFF2F"),
            ("honeydew", "#F0FFF0"),
            ("hotpink", "#FF69B4"),
            ("indianred", "#CD5C5C"),
            ("indigo", "#4B0082"),
            ("ivory", "#FFFFF0"),
            ("khaki", "#F0E68C"),
            ("lavender", "#E6E6FA"),
            ("lavenderblush", "#FFF0F5"),
            ("lawngreen", "#7CFC00"),
            ("lemonchiffon", "#FFFACD"),
            ("lightblue", "#ADD8E6"),
            ("lightcoral", "#F08080"),
            ("lightcyan", "#E0FFFF"),
            ("lightgoldenrodyellow", "#FAFAD2"),
            ("lightgreen", "#90EE90"),
            ("lightgrey", "#D3D3D3"),
            ("lightpink", "#FFB6C1"),
            ("lightsalmon", "#FFA07A"),
            ("lightseagreen", "#20B2AA"),
            ("lightskyblue", "#87CEFA"),
            ("lightslategray", "#778899"),
            ("lightsteelblue", "#B0C4DE"),
            ("lightyellow", "#FFFFE0"),
            ("lime", "#00FF00"),
            ("limegreen", "#32CD32"),
            ("linen", "#FAF0E6"),
            ("magenta", "#FF00FF"),
            ("maroon", "#800000"),
            ("mediumaquamarine", "#66CDAA"),
            ("mediumblue", "#0000CD"),
            ("mediumorchid", "#BA55D3"),
            ("mediumpurple", "#9370DB"),
            ("mediumseagreen", "#3CB371"),
            ("mediumslateblue", "#7B68EE"),
            ("mediumspringgreen", "#00FA9A"),
            ("mediumturquoise", "#48D1CC"),
            ("mediumvioletred", "#C71585"),
            ("midnightblue", "#191970"),
            ("mintcream", "#F5FFFA"),
            ("mistyrose", "#FFE4E1"),
            ("moccasin", "#FFE4B5"),
            ("navajowhite", "#FFDEAD"),
            ("navy", "#000080"),
            ("oldlace", "#FDF5E6"),
            ("olive", "#808000"),
            ("olivedrab", "#6B8E23"),
            ("orange", "#FFA500"),
            ("orangered", "#FF4500"),
            ("orchid", "#DA70D6"),
            ("palegoldenrod", "#EEE8AA"),
            ("palegreen", "#98FB98"),
            ("paleturquoise", "#AFEEEE"),
            ("palevioletred", "#DB7093"),
            ("papayawhip", "#FFEFD5"),
            ("peachpuff", "#FFDAB9"),
            ("peru", "#CD853F"),
            ("pink", "#FFC0CB"),
            ("plum", "#DDA0DD"),
            ("powderblue", "#B0E0E6"),
            ("purple", "#800080"),
            ("red", "#FF0000"),
            ("rosybrown", "#BC8F8F"),
            ("royalblue", "#4169E1"),
            ("saddlebrown", "#8B4513"),
            ("salmon", "#FA8072"),
            ("sandybrown", "#F4A460"),
            ("seagreen", "#2E8B57"),
            ("seashell", "#FFF5EE"),
            ("sienna", "#A0522D"),
            ("silver", "#C0C0C0"),
            ("skyblue", "#87CEEB"),
            ("slateblue", "#6A5ACD"),
            ("slategray", "#708090"),
            ("snow", "#FFFAFA"),
            ("springgreen", "#00FF7F"),
            ("steelblue", "#4682B4"),
            ("tan", "#D2B48C"),
            ("teal", "#008080"),
            ("thistle", "#D8BFD8"),
            ("tomato", "#FF6347"),
            ("turquoise", "#40E0D0"),
            ("violet", "#EE82EE"),
            ("wheat", "#F5DEB3"),
            ("white", "#FFFFFF"),
            ("whitesmoke", "#F5F5F5"),
            ("yellow", "#FFFF00"),
            ("yellowgreen", "#9ACD32"),
            ]

        header = CT_HeaderColors(parent, 
                self._doPaint, self._toHtml, self._toRgb,
                self._toCmyk, self._toHsv, cbName=self._toName)
        _ColorModelBase.__init__(self,
                parent,
                header=header,
                rows=self.rows,
                options=options,
                )


#*******************************************************************
#
#*******************************************************************
class _BrowserSaveColors(_ColorModelBase):
    """Browser save color model implementation"""

    
    def __init__(self, parent, options=None):
        """
        constructor

        @param parent parent of the model
        @param options Options instance
        """

        self.rows = [tuple(i) for i in permute(BROWSER_SAVE, 3)]
        self.rows.reverse()
        header = CT_HeaderColors(parent, 
                self._doPaint, self._toHtml, self._toRgb,
                self._toCmyk, self._toHsv, cbName=None)
        _ColorModelBase.__init__(self,
                parent,
                header=header,
                rows=self.rows,
                options=options,
                )


    def _doPaint(self, painter, option, index):
        """protected method to paint a color to a given cell"""
        color = self.rows[index.row()]
        brush = QtGui.QBrush(QtGui.QColor(*color))
        painter.fillRect(option.rect, brush)
        return None


    def _toName(eself, color):
        """returns the name of a color

        @param color tuple of color data
        @return (string) name
        """
        pass

    def _toHtml(self, color):
        """returns the Html color value of a color

        @param color tuple of color data
        @return (string) html color
        """
        return "#%02X%02X%02X" % color

    def _toRgb(self, color):
        """returns the rgb value of a color

        @param color tuple of color data
        @return (string) (r, g, b)
        """
        return repr(color)

    def _toCmyk(self, color):
        """returns the cmy value of a coloror

        @param color tuple of color data
        @return (string) (c, m, y)
        """
        rgb = QtGui.QColor(*color)
        cmyk = rgb.toCmyk()
        return "(%s, %s, %s, %s)" % (cmyk.cyan(), cmyk.magenta(), cmyk.yellow(), cmyk.black())

    def _toHsv(self, color):
        """returns the hls value of a color

        @param color tuple of color data
        @return (string) (h, l, s)
        """
        rgb = QtGui.QColor(*color)
        hsv = rgb.toHsv()
        return "(%s, %s, %s)" % (hsv.hue(), hsv.saturation(), hsv.value())





class CT_ColorsFactoryHTML(ModelFactoryBase):
    """Html colors model factory"""

    
    def trUtf8(self, what): return what
            
    def __init__(self, parent, options=None):
        ModelFactoryBase.__init__(self, parent, options=options)
        
        self._name = self.trUtf8("Html")
        self._models = (
            (_BrowserSaveColors, self.trUtf8("Browser save colors")),
            (_NetscapeColors, self.trUtf8("Netscape colors")),
            (_VGA, self.trUtf8("VGA colors")),
            )

    def __len__(self):
        return len(self._models)

    def __getitem__(self, i):
        return self._models[i][0]
    
    def name(self):
        return self._name

    def displayName(self):
        return QtCore.QObject.trUtf8(self, self._name)
        
    def modelName(self, i):
        return self._models[i][1]

    def modelDisplayName(self, i):
        return QtCore.QObject.trUtf8(self, self._models[i][1])


COLOR_MODEL_FACTORIES.append(CT_ColorsFactoryHTML)
#*******************************************************************
#
#*******************************************************************
class _LegoColors(_VGA):
    """Lego colors model implementation"""

    name = "Lego Colors"

    def __init__(self, parent, options=None):
        """
        constructor

        @param parent parent of the model
        @param options Options instance
        """

        self.rows = [
            ("White", "#f2f3f2"),
            ("Grey", "#a1a5a2"),
            ("Light yellow", "#f9e999"),
            ("Brick yellow", "#d7c599"),
            ("Light green", "#c2dab8"),
            ("Light reddish violet", "#e8bac7"),
            ("Light orange brown", "#cb8442"),
            ("Nougat", "#cc8e68"),
            ("Bright red", "#c4281b"),
            ("Med. reddish violet", "#c470a0"),
            ("Bright blue", "#0d69ab"),
            ("Bright yellow", "#f5cd2f"),
            ("Earth orange", "#624732"),
            ("Black", "#1b2a34"),
            ("Dark grey", "#6d6e6c"),
            ("Dark green", "#287f46"),
            ("Medium green", "#a1c48b"),
            ("Lig. Yellowich orange", "#f3cf9b"),
            ("Bright green", "#4b974a"),
            ("Dark orange", "#a05f34"),
            ("Light bluish violet", "#c1cade"),
            ("Light blue", "#b4d2e3"),
            ("Light red", "#eec4b6"),
            ("Medium red", "#da8679"),
            ("Medium blue", "#6e99c9"),
            ("Light grey", "#c7c1b7"),
            ("Bright violet", "#6b327b"),
            ("Br. yellowish orange", "#e29b3f"),
            ("Bright orange", "#da8540"),
            ("Bright bluish green", "#008f9b"),
            ("Earth yellow", "#685c43"),
            ("Bright bluish violet", "#435493"),
            ("Medium bluish violet", "#6874ac"),
            ("Med. yellowish green", "#c7d23c"),
            ("Med. bluish green", "#55a5af"),
            ("Light bluish green", "#b7d7d5"),
            ("Br. yellowish green", "#a4bd46"),
            ("Lig. yellowish green", "#d9e4a7"),
            ("Med. yellowish orange", "#e7ac58"),
            ("Br. reddish orange", "#d36f4c"),
            ("Bright reddish violet", "#923978"),
            ("Light orange", "#eab891"),
            ("Gold", "#dcbc81"),
            ("Dark nougat", "#ae7a59"),
            ("Silver", "#9ca3a8"),
            ("Sand blue", "#74869c"),
            ("Sand violet", "#877c90"),
            ("Medium orange", "#e09864"),
            ("Sand yellow", "#958a73"),
            ("Earth blue", "#203a56"),
            ("Earth green", "#27462c"),
            ("Sand blue metallic", "#7988a1"),
            ("Sand violet metallic", "#958ea3"),
            ("Sand yellow metallic", "#938767"),
            ("Dark grey metallic", "#575857"),
            ("Black metallic", "#161d32"),
            ("Light grey metallic", "#abadac"),
            ("Sand green", "#789081"),
            ("Sand red", "#957976"),
            ("Dark red", "#7b2e2f"),
            ("Gun metallic", "#756c62"),
            ("Curry", "#d7a94b"),
            ("Lemon metalic", "#828a5d"),
            ("Fire Yellow", "#f9d62e"),
            ("Flame yellowish orange", "#e8ab2d"),
            ("Reddish brown", "#694027"),
            ("Flame reddish orange", "#cf6024"),
            ("Medium stone grey", "#a3a2a4"),
            ("Royal blue", "#4667a4"),
            ("Dark Royal blue", "#23478b"),
            ("Bright reddish lilac", "#8e4285"),
            ("Dark stone grey", "#635f61"),
            ("Light stone grey", "#e5e4de"),
            ("Dark Curry", "#b08e44"),
            ("Faded green", "#709578"),
            ("Turquoise", "#79b5b5"),
            ("Light Royal blue", "#9fc3e9"),
            ("Medium Royal blue", "#6c81b7"),
            ("Rust", "#8f4c2a"),
            ("Brown", "#7c5c45"),
            ("Reddish lilac", "#96709f"),
            ("Lilac", "#6b629b"),
            ("Light lilac", "#a7a9ce"),
            ("Bright purple", "#cd6298"),
            ("Light purple", "#e4adc8"),
            ("Light pink", "#dc9095"),
            ("Light brick yellow", "#f0d5a0"),
            ("Warm yellowish orange", "#ebb87f"),
            ("Cool yellow", "#fdea8c"),
            ("Dove blue", "#7dbbdd"),
            ("Medium lilac", "#342b75"),
            ("Transparent", "#ececec"),
            ("Tr. Red", "#cd544b"),
            ("Tr. Lg blue", "#c1dff0"),
            ("Tr. Blue", "#7bb6e8"),
            ("Tr. Yellow", "#f7f18d"),
            ("Tr. Flu. Reddish orange", "#d9856c"),
            ("Tr. Green", "#84b68d"),
            ("Tr. Flu. Green", "#f8f184"),
            ("Phosph. White", "#ece8de"),
            ("Tr. Brown", "#bfb7b1"),
            ("Tr. Medi. reddish violet", "#e4adc8"),
            ("Tr. Bright bluish violet", "#a5a5cb"),
            ("Neon orange", "#d5733d"),
            ("Neon green", "#d8dd56"),
            ("Tr. Flu. Blue", "#cfe2f7"),
            ("Tr. Flu. Yellow", "#fff67b"),
            ("Tr. Flu. Red", "#e1a4c2"),
            ("Red flip/flop", "#97695b"),
            ("Yellow flip/flop", "#b48455"),
            ("Silver flip/flop", "#898788"),
            ]

        header = CT_HeaderColors(parent, 
                self._doPaint, self._toHtml, self._toRgb,
                self._toCmyk, self._toHsv, cbName=self._toName)
        _ColorModelBase.__init__(self,
                parent,
                header=header,
                rows=self.rows,
                options=options,
                )


class _QtColors(_VGA):
    """Lego colors model implementation"""

    name = "Qt colors"

    def __init__(self, parent, options=None):
        """
        constructor

        @param parent parent of the model
        @param options Options instance
        """

        self.rows = [
            ("white", "#ffffff"),
            ("black", "#000000"),
            ("red", "#ff0000"),
            ("darkRed", "#800000"),
            ("green", "#00ff00"),
            ("darkGreen", "#008000"),
            ("blue", "#0000ff"),
            ("darkBlue", "#000080"),
            ("cyan", "#00ffff"),
            ("darkCyan", "#008080"),
            ("magenta", "#ff00ff"),
            ("darkMagenta", "#800080"),
            ("yellow", "#ffff00"),
            ("darkYellow", "#808000"),
            ("gray", "#a0a0a4"),
            ("darkGray", "#808080"),
            ("lightGray", "#c0c0c0"),
            ]

        header = CT_HeaderColors(parent, 
                self._doPaint, self._toHtml, self._toRgb,
                self._toCmyk, self._toHsv, cbName=self._toName)
        _ColorModelBase.__init__(self,
                parent,
                header=header,
                rows=self.rows,
                options=options,
                )



class CT_ColorsFactoryMisc(ModelFactoryBase):
    """Lego colors model factory"""

    
    def trUtf8(self, what): return what
            
    def __init__(self, parent, options=None):
        ModelFactoryBase.__init__(self, parent, options=options)
        
        self._name = self.trUtf8("Misc.")
        self._models = (
            (_LegoColors, self.trUtf8("Lego Colors")),
            (_QtColors, self.trUtf8("Qt Colors")),
             (_X11, self.trUtf8("X11 colors")),
            )

    def __len__(self):
        return len(self._models)

    def __getitem__(self, i):
        return self._models[i][0]
    
    def name(self):
        return self._name

    def displayName(self):
        return QtCore.QObject.trUtf8(self, self._name)
        
    def modelName(self, i):
        return self._models[i][1]

    def modelDisplayName(self, i):
        return QtCore.QObject.trUtf8(self, self._models[i][1])


COLOR_MODEL_FACTORIES.append(CT_ColorsFactoryMisc)
#*****************************************************************************
#
#*****************************************************************************
