1 /***************************************************************************
2 * Copyright (C) 2006 by David Cuadrado *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "palettedocument.h"
23 namespace Components
{
25 PaletteDocument::PaletteDocument(const QString
&name
, bool isEditable
) : QDomDocument()
27 QDomProcessingInstruction header
= this->createProcessingInstruction("xml","version=\"1.0\" encoding=\"UTF-8\"");
28 this->appendChild(header
);
30 QDomElement root
= createElement( "Palette" );
31 root
.setAttribute("name", name
);
35 root
.setAttribute("editable", "true" );
39 root
.setAttribute("editable", "false" );
45 PaletteDocument::~PaletteDocument()
49 void PaletteDocument::addColor(const QColor
&color
)
51 QDomElement element
= createElement("Color");
53 element
.setAttribute("colorName", color
.name());
54 element
.setAttribute("alpha", QString::number(color
.alpha()) );
56 documentElement().appendChild(element
);
60 void PaletteDocument::addGradient(const QGradient
&gradient
)
62 QDomElement element
= createElement("Gradient");
64 element
.setAttribute("type", gradient
.type() );
65 element
.setAttribute("spread", gradient
.spread() );
66 const QGradient
*gr
= &gradient
;
67 switch( gradient
.type() )
69 case QGradient::LinearGradient
:
71 element
.setAttribute("startX", static_cast<const QLinearGradient
*>(gr
)->start().x() );
72 element
.setAttribute("startY", static_cast<const QLinearGradient
*>(gr
)->start().y() );
74 element
.setAttribute("finalX", static_cast<const QLinearGradient
*>(gr
)->finalStop().x() );
75 element
.setAttribute("finalY", static_cast<const QLinearGradient
*>(gr
)->finalStop().y() );
78 case QGradient::RadialGradient
:
80 element
.setAttribute("centerX", static_cast<const QRadialGradient
*>(gr
)->center().x() );
81 element
.setAttribute("centerY", static_cast<const QRadialGradient
*>(gr
)->center().y() );
83 element
.setAttribute("focalX", static_cast<const QRadialGradient
*>(gr
)->focalPoint().x() );
84 element
.setAttribute("focalY", static_cast<const QRadialGradient
*>(gr
)->focalPoint().y() );
86 element
.setAttribute("radius", static_cast<const QRadialGradient
*>(gr
)->radius() );
89 case QGradient::ConicalGradient
:
91 element
.setAttribute("centerX", static_cast<const QRadialGradient
*>(gr
)->center().x() );
92 element
.setAttribute("centerY", static_cast<const QRadialGradient
*>(gr
)->center().y() );
94 element
.setAttribute("angle", static_cast<const QConicalGradient
*>(gr
)->angle() );
97 case QGradient::NoGradient
:
104 QGradientStops stops
= gradient
.stops();
106 foreach(QGradientStop stop
, stops
)
108 QDomElement stopElement
= createElement("Stop");
109 stopElement
.setAttribute("value", stop
.first
);
110 stopElement
.setAttribute("colorName", stop
.second
.name());
111 stopElement
.setAttribute("alpha", stop
.second
.alpha());
113 element
.appendChild(stopElement
);
116 documentElement().appendChild(element
);
119 void PaletteDocument::setElements(const QList
<QBrush
> &brushes
)
121 foreach( QBrush brush
, brushes
)
123 if ( brush
.gradient() )
125 addGradient( *brush
.gradient() );
129 addColor(brush
.color());