Modified palette file format
[dashstudio.git] / src / components / colorpalette / palettedocument.cpp
blob692e42d98bec57d66a2bf530413d8ad1820e7562
1 /***************************************************************************
2 * Copyright (C) 2006 by David Cuadrado *
3 * krawek@gmail.com *
4 * *
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. *
9 * *
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. *
14 * *
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 #include <yamf/item/serializer.h>
25 namespace Component {
27 PaletteDocument::PaletteDocument(const QString &name, bool isEditable) : QDomDocument()
29 QDomProcessingInstruction header = this->createProcessingInstruction("xml","version=\"1.0\" encoding=\"UTF-8\"");
30 this->appendChild(header);
32 QDomElement root = createElement( "palette" );
33 root.setAttribute("name", name);
35 if ( isEditable )
37 root.setAttribute("editable", "true" );
39 else
41 root.setAttribute("editable", "false" );
44 appendChild( root );
47 PaletteDocument::~PaletteDocument()
51 void PaletteDocument::addColor(const QColor &color)
53 QDomElement element = createElement("color");
55 element.setAttribute("name", color.name());
56 element.setAttribute("alpha", QString::number(color.alpha()) );
58 documentElement().appendChild(element);
62 void PaletteDocument::addGradient(const QGradient &gradient)
64 documentElement().appendChild(YAMF::Item::Serializer::gradient(&gradient, *this));
67 void PaletteDocument::setElements(const QList<QBrush > &brushes)
69 foreach( QBrush brush, brushes)
71 if ( brush.gradient() )
73 addGradient( *brush.gradient() );
75 else
77 addColor(brush.color());