⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 customface.cpp

📁 linux下的eva源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
 /*************************************************************************** *   Copyright (C) 2006 by yunfan                                          * *   yunfan_zg@163.com                                                     * *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * *   This program is distributed in the hope that it will be useful,       * *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * *   GNU General Public License for more details.                          * *                                                                         * *   You should have received a copy of the GNU General Public License     * *   along with this program; if not, write to the                         * *   Free Software Foundation, Inc.,                                       * *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             * ***************************************************************************/#include "customface.h"#include <qfile.h>#include <qtextstream.h>#include <qtextcodec.h>#include <klocale.h>#define XML_FACE_FILE                   "face.xml"#define XML_NAME                          "EVA_CUSTOM_FACE_CONFIG"#define XML_ROOT                           "FACESETTING"#define TAG_CUSTOMFACE               "CUSTOMFACE"#define TAG_CUSTOMFACEGROUP    "CUSTOMFACEGROUP"#define TAG_FACE                            "FACE"#define TAG_FILE_ORG                      "FILE_ORG"#define __FILE_ORG                           "FILE ORG"#define TAG_FILE_FIXED                   "FILE_FIXED"#define __FILE_FIXED                        "FILE FIXED"#define TAG_DEFAULTFACE              "DEFAULTFACE"#define TAG_SORT                            "SORT"#define ATTR_version          "version"#define ATTR_name            "name"#define ATTR_count            "count"#define ATTR_showall         "showall"#define ATTR_line               "line"#define ATTR_id                  "id"#define ATTR_shortcut         "shortcut"#define ATTR_tip                 "tip"#define ATTR_multiframe       "multiframe"#define FACE_GROUP_VERSION     "1003"CustomFace::CustomFace()	: m_OrgName(""),	m_Shortcut(""),	m_Tip(""),	m_Frames(0),	m_GroupId(0){}CustomFace::CustomFace(const CustomFace&rhs){		(*this) = rhs;}CustomFace::CustomFace(const QString &name, const int groupId)	: m_OrgName(name), m_Frames(0), m_GroupId(groupId){	m_Shortcut = m_OrgName.left(6);	m_Tip = m_OrgName.left(m_OrgName.findRev('.')); // get rid of the file ext}CustomFace::CustomFace(const QString &name,				const QString &shortcut,				const QString &tip,				const int frames,				const int groupId)	: m_OrgName(name),	m_Shortcut(shortcut),	m_Tip(tip),	m_Frames(frames),	m_GroupId(groupId){}CustomFace & CustomFace::operator =( const CustomFace & rhs ){	m_OrgName = rhs.org(),	m_Shortcut = rhs.shortcut(),	m_Tip = rhs.tip(),	m_Frames = rhs.numFrames(),	m_GroupId = rhs.group();	return *this;}const QString CustomFace::id()  const{	return m_OrgName.left(m_OrgName.findRev('.'));}const QString CustomFace::fixed()  const{	return id() + "fixed.bmp";}/* ================================================================= */CustomFaceConfig::CustomFaceConfig(const QString &dir)	: m_Dir(dir), m_Doc(0){}CustomFaceConfig::~CustomFaceConfig(){	if(m_Doc) delete m_Doc;}void CustomFaceConfig::createConfig(){	if(m_Doc ) delete m_Doc;	m_Doc = new QDomDocument(XML_NAME);	// add a root node	QDomElement root = m_Doc->createElement(XML_ROOT);	m_Doc->appendChild(root);	///NOTE: do we follow Tencent way? Yes, we do.	QDomElement g = m_Doc->createElement(TAG_CUSTOMFACE);	g.setAttribute(ATTR_count, 0);	g.setAttribute(ATTR_version, FACE_GROUP_VERSION);	g.setAttribute(ATTR_name, i18n("Default"));	m_Doc->documentElement().appendChild(g);}bool CustomFaceConfig::addFace(const CustomFace &face){	// if not created, just do it	if(!m_Doc) createConfig();	int gId = face.group();	if(gId <0 || gId >= numGroups())		return false; // out of range	// create a new node & set attributes	QDomElement f = m_Doc->createElement(TAG_FACE);	f.setAttribute(ATTR_id, face.id());	f.setAttribute(ATTR_shortcut, face.shortcut());	f.setAttribute(ATTR_tip, face.tip());	f.setAttribute(ATTR_multiframe, face.numFrames());	// sub item: org	QDomElement org = m_Doc->createElement(TAG_FILE_ORG);	f.appendChild(org);  // append it to face node	// data of org node	QDomText orgData = m_Doc->createTextNode(face.org());	org.appendChild(orgData); // append it to the node	// sub item: fixed	QDomElement fixed = m_Doc->createElement(TAG_FILE_FIXED);	f.appendChild(fixed); // add it the end of face node	// data of fixed node	QDomText fixedData = m_Doc->createTextNode(face.fixed());	fixed.appendChild(fixedData); // add data to fixed node	QDomNode root = m_Doc->documentElement();	QDomNodeList groups = root.childNodes();	QDomNode node = groups.item(gId);	if(node.isNull()) return false;	QDomElement group = node.toElement();	// add the face to group	group.appendChild(f);	//don't forget update group count attribute	group.setAttribute(ATTR_count, group.childNodes().count());	return true;}CustomFace CustomFaceConfig::getFace(const int gId, const int fNo){	CustomFace face;	if(!m_Doc) return face;	if(gId <0 || gId >= numGroups())		return face; // out of range	QDomNode root = m_Doc->documentElement();	QDomNodeList groups = root.childNodes();	QDomNode node = groups.item(gId);	if(node.isNull()) return face;	QDomElement group = node.toElement();		int index = 0;	QDomNode n = group.firstChild();	while(!n.isNull()){		if(index == fNo){			QDomElement e = n.toElement();			if(!e.isNull()){				if( e.tagName() == TAG_FACE){					face.setGroup( gId);					face.setShortcut( e.attribute(ATTR_shortcut, ""));					face.setTip( e.attribute( ATTR_tip, ""));					face.setNumFrames( e.attribute( ATTR_multiframe, 0).toInt() );										QDomNode o = e.firstChild();					if(!o.isNull()){						QDomElement org = o.toElement();						if(!org.isNull()){							face.setOrg( org.text() );						}					}				}			}			break;		}		index++;		n = n.nextSibling();	}		// otherwise, remove failed	return face;}bool CustomFaceConfig::moveFaceUp( const int gId, const int fNo ){	if(!m_Doc) return false;	if(fNo<=0) return false; // the first one	if(gId <0 || gId >= numGroups())		return false; // out of range	QDomNode root = m_Doc->documentElement();	QDomNodeList groups = root.childNodes();	QDomNode node = groups.item(gId);	if(node.isNull()) return false;	QDomElement group = node.toElement();	QDomNode result;	QDomNode n = group.firstChild();	int index = 0;	while(!n.isNull()){		if(index == fNo){			QDomElement e = n.toElement();			if(!e.isNull()){				if( e.tagName() == TAG_FACE){					QDomNode bef = e.previousSibling();					result = group.insertBefore( e, bef);					break;				}			}			break;		}		index++;		n = n.nextSibling();	}	return (!result.isNull());}bool CustomFaceConfig::moveFaceDown( const int gId, const int fNo ){	if(!m_Doc) return false;	if(fNo<=0) return false; // the first one	if(gId <0 || gId >= numGroups())		return false; // out of range	QDomNode root = m_Doc->documentElement();	QDomNodeList groups = root.childNodes();	QDomNode node = groups.item(gId);	if(node.isNull()) return false;	QDomElement group = node.toElement();	QDomNode result;	QDomNode n = group.firstChild();	int index = 0;	while(!n.isNull()){		if(index == fNo){			QDomElement e = n.toElement();			if(!e.isNull()){				if( e.tagName() == TAG_FACE){					QDomNode aft = e.nextSibling();					result = group.insertAfter( e, aft);					break;				}			}			break;		}		index++;		n = n.nextSibling();	}	return (!result.isNull());}bool CustomFaceConfig::moveFaceTo( const int gId, const int fNo, const int gDestId ){	if(!m_Doc) return false;	if(gId <0 || gId >= numGroups())		return false; // out of range	if(gDestId <0 || gDestId >= numGroups())		return false; // out of range	QDomNode root = m_Doc->documentElement();	QDomNodeList groups = root.childNodes();	QDomNode src = groups.item(gId);	if(src.isNull()) return false;	QDomNode dest = groups.item(gDestId);	if(dest.isNull()) return false;	QDomNode n = src.firstChild();	QDomNode sibling;	int index = 0;	while(!n.isNull()){		if(index == fNo){			QDomElement e = n.toElement();			if(!e.isNull()){				if( e.tagName() == TAG_FACE){					n = src.removeChild( n );					dest.appendChild(n);					return true;				}			}			break;		}		index++;		n = n.nextSibling();	}	return true;}bool CustomFaceConfig::removeFace(const CustomFace &face){	if(!m_Doc) return false;	int gId = face.group();	if(gId <0 || gId >= numGroups())		return false; // out of range	QDomNode root = m_Doc->documentElement();	QDomNodeList groups = root.childNodes();	QDomNode node = groups.item(gId);	if(node.isNull()) return false;	QDomElement group = node.toElement();		QDomNode result;	QDomNode n = group.firstChild();	while(!n.isNull()){		QDomElement e = n.toElement();		if(!e.isNull()){			if( e.tagName() == TAG_FACE){				if(face.id() == e.attribute(ATTR_id, "")){					result = group.removeChild(e);					break;				}			}		}		n = n.nextSibling();	}		if(!result.isNull()){		// remove success, so update count attribute		group.setAttribute(ATTR_count, group.childNodes().count());		return true;	}	// otherwise, remove failed	return false;}bool CustomFaceConfig::removeFace(const int gId, const int fNo){	if(!m_Doc) return false;	if(gId <0 || gId >= numGroups())		return false; // out of range	QDomNode root = m_Doc->documentElement();	QDomNodeList groups = root.childNodes();	QDomNode node = groups.item(gId);	if(node.isNull()) return false;	QDomElement group = node.toElement();		int index = 0;	QDomNode result;	QDomNode n = group.firstChild();	while(!n.isNull()){		if(index == fNo){			QDomElement e = n.toElement();			if(!e.isNull()){				if( e.tagName() == TAG_FACE){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -