Skip to content

Commit

Permalink
Save and restore the background picture/text
Browse files Browse the repository at this point in the history
  • Loading branch information
arntanguy committed Jul 9, 2009
1 parent ebb306e commit da3aef1
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 97 deletions.
126 changes: 126 additions & 0 deletions Desk.cpp
Expand Up @@ -330,6 +330,132 @@ void Desk::setProjectMode(Mode mode)
}
}

void Desk::toXml(QDomElement & de) const
{
QDomDocument doc = de.ownerDocument();
// Save Title
QDomElement titleElement = doc.createElement("title");
de.appendChild(titleElement);
QDomText titleText = doc.createTextNode(m_titleText);
titleElement.appendChild(titleText);

// Save background colors
QColor color;
QString r, g, b;
QDomElement domElement, topColor, bottomColor,
redElement = doc.createElement("red"),
greenElement = doc.createElement("green"),
blueElement = doc.createElement("blue"),
redElement2 = doc.createElement("red"),
greenElement2 = doc.createElement("green"),
blueElement2 = doc.createElement("blue"),
rElement = doc.createElement("red"),
gElement = doc.createElement("green"),
bElement = doc.createElement("blue"),
rElement2 = doc.createElement("red"),
gElement2 = doc.createElement("green"),
bElement2 = doc.createElement("blue");
domElement = doc.createElement("background-color");

topColor = doc.createElement("top");
color = m_grad1ColorPicker->color();
r.setNum(color.red()); g.setNum(color.green()); b.setNum(color.blue());
redElement.appendChild(doc.createTextNode(r));
greenElement.appendChild(doc.createTextNode(g));
blueElement.appendChild(doc.createTextNode(b));
topColor.appendChild(redElement); topColor.appendChild(greenElement); topColor.appendChild(blueElement);
domElement.appendChild(topColor);

bottomColor = doc.createElement("bottom");
color = m_grad2ColorPicker->color();
r.setNum(color.red()); g.setNum(color.green()); b.setNum(color.blue());
redElement2.appendChild(doc.createTextNode(r));
greenElement2.appendChild(doc.createTextNode(g));
blueElement2.appendChild(doc.createTextNode(b));
bottomColor.appendChild(redElement2); bottomColor.appendChild(greenElement2); bottomColor.appendChild(blueElement2);
domElement.appendChild(bottomColor);

de.appendChild(domElement);

QDomElement titleColor = doc.createElement("title-color");
color = m_titleColorPicker->color();
r.setNum(color.red()); g.setNum(color.green()); b.setNum(color.blue());
rElement.appendChild(doc.createTextNode(r));
gElement.appendChild(doc.createTextNode(g));
bElement.appendChild(doc.createTextNode(b));
titleColor.appendChild(rElement); titleColor.appendChild(gElement); titleColor.appendChild(bElement);
de.appendChild(titleColor);

QDomElement foreColor = doc.createElement("foreground-color");
color = m_foreColorPicker->color();
r.setNum(color.red()); g.setNum(color.green()); b.setNum(color.blue());
rElement2.appendChild(doc.createTextNode(r));
gElement2.appendChild(doc.createTextNode(g));
bElement2.appendChild(doc.createTextNode(b));
foreColor.appendChild(rElement2); foreColor.appendChild(gElement2); foreColor.appendChild(bElement2);
de.appendChild(foreColor);

// Save the background image
if(m_backContent) {
QDomElement element = doc.createElement("background-content");
de.appendChild(element);
m_backContent->toXml(element);
}
}


void Desk::fromXml(QDomElement & de)
{
setTitleText(de.firstChildElement("title").text());

QDomElement domElement;
int r, g, b;
// Load image size saved in the rect node
domElement = de.firstChildElement("background-color").firstChildElement("top");
r = domElement.firstChildElement("red").text().toInt();
g = domElement.firstChildElement("green").text().toInt();
b = domElement.firstChildElement("blue").text().toInt();
m_grad1ColorPicker->setColor(QColor(r, g, b));

domElement = de.firstChildElement("background-color").firstChildElement("bottom");
r = domElement.firstChildElement("red").text().toInt();
g = domElement.firstChildElement("green").text().toInt();
b = domElement.firstChildElement("blue").text().toInt();
m_grad2ColorPicker->setColor(QColor(r, g, b));

domElement = de.firstChildElement("title-color");
r = domElement.firstChildElement("red").text().toInt();
g = domElement.firstChildElement("green").text().toInt();
b = domElement.firstChildElement("blue").text().toInt();
m_titleColorPicker->setColor(QColor(r, g, b));

domElement = de.firstChildElement("foreground-color");
r = domElement.firstChildElement("red").text().toInt();
g = domElement.firstChildElement("green").text().toInt();
b = domElement.firstChildElement("blue").text().toInt();
m_foreColorPicker->setColor(QColor(r, g, b));

AbstractContent *backContent = 0;
// Load the background picture, if it exists
domElement = de.firstChildElement("picture");
if(!domElement.isNull()) {
backContent = createPicture(QPoint());
} else { // load the text background, if it exists
domElement = de.firstChildElement("text");
if(!domElement.isNull()) {
backContent = createText(QPoint());
}
}
if (backContent->fromXml(domElement)) {
m_backContent = backContent;
m_backCache = QPixmap();
} else {
m_content.removeAll(backContent);
delete backContent;
}
update();
}

void Desk::renderVisible(QPainter * painter, const QRectF & target, const QRectF & source, Qt::AspectRatioMode aspectRatioMode)
{
clearSelection();
Expand Down
5 changes: 5 additions & 0 deletions Desk.h
Expand Up @@ -21,6 +21,8 @@
#include <QPixmap>
#include <QRect>
#include <QTime>
#include <QDomElement>

class AbstractContent;
class AbstractProperties;
struct CEffect;
Expand Down Expand Up @@ -80,6 +82,9 @@ class Desk : public QGraphicsScene
Mode projectMode() const;
void setProjectMode(Mode mode);

void toXml(QDomElement &de) const;
void fromXml(QDomElement &de);

// render the Desk, but not the invisible items
void renderVisible(QPainter * painter, const QRectF & target = QRectF(), const QRectF & source = QRectF(), Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio);
QImage renderedImage(const QSize & size, Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio);
Expand Down
39 changes: 4 additions & 35 deletions XmlRead.cpp
Expand Up @@ -84,46 +84,15 @@ void XmlRead::readProject(FotoWall *fotowall)

void XmlRead::readDesk(Desk * desk)
{
desk->setTitleText(m_deskElement.firstChildElement("title").text());

QDomElement domElement;
int r, g, b;
// Load image size saved in the rect node
domElement = m_deskElement.firstChildElement("background-color").firstChildElement("top");
r = domElement.firstChildElement("red").text().toInt();
g = domElement.firstChildElement("green").text().toInt();
b = domElement.firstChildElement("blue").text().toInt();
desk->m_grad1ColorPicker->setColor(QColor(r, g, b));

domElement = m_deskElement.firstChildElement("background-color").firstChildElement("bottom");
r = domElement.firstChildElement("red").text().toInt();
g = domElement.firstChildElement("green").text().toInt();
b = domElement.firstChildElement("blue").text().toInt();
desk->m_grad2ColorPicker->setColor(QColor(r, g, b));

domElement = m_deskElement.firstChildElement("title-color");
r = domElement.firstChildElement("red").text().toInt();
g = domElement.firstChildElement("green").text().toInt();
b = domElement.firstChildElement("blue").text().toInt();
desk->m_titleColorPicker->setColor(QColor(r, g, b));

domElement = m_deskElement.firstChildElement("foreground-color");
r = domElement.firstChildElement("red").text().toInt();
g = domElement.firstChildElement("green").text().toInt();
b = domElement.firstChildElement("blue").text().toInt();
desk->m_foreColorPicker->setColor(QColor(r, g, b));
// clear Desk
qDeleteAll(desk->m_content);
desk->m_content.clear();

// Show the colors
desk->update();
desk->fromXml(m_deskElement);
}

void XmlRead::readContent(Desk * desk)
{
// clear Desk
qDeleteAll(desk->m_content);
desk->m_content.clear();
desk->m_backContent = 0;

// for each child of 'content'
for (QDomElement element = m_contentElement.firstChildElement(); !element.isNull(); element = element.nextSiblingElement()) {

Expand Down
62 changes: 1 addition & 61 deletions XmlSave.cpp
Expand Up @@ -74,67 +74,7 @@ void XmlSave::saveContent(const Desk * desk)

void XmlSave::saveDesk(const Desk *desk)
{
// Save Title
QDomElement titleElement = doc.createElement("title");
m_deskElement.appendChild(titleElement);
QDomText titleText = doc.createTextNode(desk->titleText());
titleElement.appendChild(titleText);

// Save background colors
QColor color;
QString r, g, b;
QDomElement domElement, topColor, bottomColor,
redElement = doc.createElement("red"),
greenElement = doc.createElement("green"),
blueElement = doc.createElement("blue"),
redElement2 = doc.createElement("red"),
greenElement2 = doc.createElement("green"),
blueElement2 = doc.createElement("blue"),
rElement = doc.createElement("red"),
gElement = doc.createElement("green"),
bElement = doc.createElement("blue"),
rElement2 = doc.createElement("red"),
gElement2 = doc.createElement("green"),
bElement2 = doc.createElement("blue");
domElement = doc.createElement("background-color");

topColor = doc.createElement("top");
color = desk->m_grad1ColorPicker->color();
r.setNum(color.red()); g.setNum(color.green()); b.setNum(color.blue());
redElement.appendChild(doc.createTextNode(r));
greenElement.appendChild(doc.createTextNode(g));
blueElement.appendChild(doc.createTextNode(b));
topColor.appendChild(redElement); topColor.appendChild(greenElement); topColor.appendChild(blueElement);
domElement.appendChild(topColor);

bottomColor = doc.createElement("bottom");
color = desk->m_grad2ColorPicker->color();
r.setNum(color.red()); g.setNum(color.green()); b.setNum(color.blue());
redElement2.appendChild(doc.createTextNode(r));
greenElement2.appendChild(doc.createTextNode(g));
blueElement2.appendChild(doc.createTextNode(b));
bottomColor.appendChild(redElement2); bottomColor.appendChild(greenElement2); bottomColor.appendChild(blueElement2);
domElement.appendChild(bottomColor);

m_deskElement.appendChild(domElement);

QDomElement titleColor = doc.createElement("title-color");
color = desk->m_titleColorPicker->color();
r.setNum(color.red()); g.setNum(color.green()); b.setNum(color.blue());
rElement.appendChild(doc.createTextNode(r));
gElement.appendChild(doc.createTextNode(g));
bElement.appendChild(doc.createTextNode(b));
titleColor.appendChild(rElement); titleColor.appendChild(gElement); titleColor.appendChild(bElement);
m_deskElement.appendChild(titleColor);

QDomElement foreColor = doc.createElement("foreground-color");
color = desk->m_foreColorPicker->color();
r.setNum(color.red()); g.setNum(color.green()); b.setNum(color.blue());
rElement2.appendChild(doc.createTextNode(r));
gElement2.appendChild(doc.createTextNode(g));
bElement2.appendChild(doc.createTextNode(b));
foreColor.appendChild(rElement2); foreColor.appendChild(gElement2); foreColor.appendChild(bElement2);
m_deskElement.appendChild(foreColor);
desk->toXml(m_deskElement);
}

void XmlSave::saveProject(int mode, const ModeInfo& modeInfo)
Expand Down
2 changes: 1 addition & 1 deletion fotowall.pro
Expand Up @@ -64,7 +64,7 @@ unix {
man.files = fotowall.1
man.path = /usr/share/man/man1
scripts.files = 3rdparty/fotowall.sh
scripts.path = ~/.gnome2/nautilus-scripts
scripts.path = ~/.gnome2/nautilus-scripts
INSTALLS += target \
icon \
dfile \
Expand Down

0 comments on commit da3aef1

Please sign in to comment.