# HG changeset patch
# User insilmaril
# Date 1243337091 0
# Node ID 2f002657dada9375f77b905529d3bdb96e1168ca
# Parent  340bc29da9a00268eaaf65f3514c5e427837433a
added missing new files

diff -r 340bc29da9a0 -r 2f002657dada flag.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flag.cpp	Tue May 26 11:24:51 2009 +0000
@@ -0,0 +1,136 @@
+#include "flag.h"
+
+#include <iostream>
+using namespace std;
+
+/////////////////////////////////////////////////////////////////
+// Flag
+/////////////////////////////////////////////////////////////////
+Flag::Flag()
+{
+	//cout << "Const Flag ()\n";
+    init ();
+}
+
+Flag::Flag (Flag* io)
+{
+	//cout << "Const Flag (Flag)\n";
+    copy (io);
+}
+
+Flag::~Flag()
+{
+   //cout << "Destr Flag  this="<<this <<"  " << qPrintable(name) << "\n";
+}
+
+
+void Flag::init ()
+{
+	action=NULL;
+	name="undefined";
+	visible=true;
+	unsetGroup();
+
+	state=false;
+	used=false;
+}
+
+void Flag::copy (Flag* other)
+{
+	action=other->action;
+	name=other->name;
+	group=other->group;
+	tooltip=other->tooltip;
+	state=other->state;
+	used=other->used;
+	pixmap=other->pixmap;
+}
+
+
+void Flag::load (const QString &fn)
+{
+	pixmap.load(fn);
+}
+
+void Flag::load (const QPixmap &pm)
+{
+	pixmap=pm;
+}
+
+void Flag::setName(const QString &n)
+{
+	name=n;
+}
+
+const QString Flag::getName()
+{
+	return name;
+}
+
+void Flag::setVisible (bool b)
+{
+	visible=b;
+}
+
+bool Flag::isVisible ()
+{
+	return visible;
+}
+
+void Flag::setGroup (const QString &n)
+{
+	group=n;
+}
+
+const QString Flag::getGroup()
+{
+	return group;
+}
+
+void Flag::unsetGroup()
+{
+	group.clear();
+}
+
+void Flag::setToolTip(const QString &n)
+{
+	tooltip=n;
+}
+
+const QString Flag::getToolTip()
+{
+	return tooltip;
+}
+
+QPixmap Flag::getPixmap()
+{
+	return pixmap;
+}
+
+void Flag::setAction (QAction *a)
+{
+	action=a;
+}
+
+QAction* Flag::getAction ()
+{
+	return action;
+}
+
+void Flag::setUsed (bool b)
+{
+	used=b;
+}
+
+bool Flag::isUsed()
+{
+	return used;
+}
+
+void Flag::saveToDir (const QString &tmpdir, const QString &prefix)
+{
+	QString fn=tmpdir + prefix + name + ".png";
+	pixmap.save (fn,"PNG");
+}
+
+
diff -r 340bc29da9a0 -r 2f002657dada flag.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flag.h	Tue May 26 11:24:51 2009 +0000
@@ -0,0 +1,55 @@
+#ifndef FLAG_H
+#define FLAG_H
+
+
+#include <QAction>
+#include <QPixmap>
+
+#include "xmlobj.h"
+
+/*! \brief One flag belonging to a FlagRow.
+
+	Each TreeItem in a VymModel has a set of standard flags and system
+	flags.
+*/
+
+
+/////////////////////////////////////////////////////////////////////////////
+class Flag:public XMLObj {
+public:
+    Flag ();
+    Flag (Flag*);
+    ~Flag ();
+    virtual void init ();
+    virtual void copy (Flag*);
+	void load (const QString&);
+	void load (const QPixmap&);
+	void setName (const QString&);
+	const QString getName ();
+	void setVisible (bool b);
+	bool isVisible ();
+	void setGroup (const QString&);
+	const QString getGroup();
+	void unsetGroup ();
+	void setToolTip(const QString&);
+	const QString getToolTip();
+	QPixmap getPixmap();
+	void setAction (QAction *a);
+	QAction* getAction ();
+	void setUsed (bool);	//FIXME-3 needed?
+	bool isUsed();
+	void saveToDir (const QString&, const QString&);
+	
+protected:	
+	QString name;
+	bool visible;
+	QString group;
+	QString tooltip;
+	QAction *action;
+	bool state;
+	bool used;
+private:
+	QPixmap pixmap;
+};
+
+#endif
diff -r 340bc29da9a0 -r 2f002657dada flagrow.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flagrow.cpp	Tue May 26 11:24:51 2009 +0000
@@ -0,0 +1,164 @@
+#include "flagrow.h"
+
+#include <iostream>
+using namespace std;
+
+/////////////////////////////////////////////////////////////////
+// FlagRow
+/////////////////////////////////////////////////////////////////
+FlagRow::FlagRow()
+{
+	toolBar=NULL;
+	masterRow=NULL;
+//    cout << "Const FlagRow ()\n";
+//    init ();
+}
+
+FlagRow::~FlagRow()
+{
+	//cout << "Destr FlagRow\n";
+//	while (!flag.isEmpty())
+//		delete (flag.takeFirst() );
+}
+
+void FlagRow::addFlag (Flag *flag)
+{
+	Flag *f=new Flag;
+	f->copy (flag);
+	flags.append (f);
+	activeNames.append (flag->getName());
+}
+
+Flag* FlagRow::getFlag (const QString &name)
+{
+	int i=0;
+	while (i<=flags.size()-1)
+	{
+		if (flags.at(i)->getName()==name)
+			return flags.at(i);
+		i++;	
+	}
+	return NULL;
+}
+
+QStringList FlagRow::activeFlagNames()
+{
+	return activeNames;
+}
+
+
+bool FlagRow::isActive (const QString &name)
+{
+	return activeNames.contains (name);
+}
+
+void FlagRow::toggle (const QString &name, FlagRow *masterRow)
+{
+	if (isActive(name) )
+		deactivate (name);
+	else
+	{
+		activate (name);	
+		if (!masterRow) return;
+
+		Flag *flag=masterRow->getFlag (name);
+		if (!flag) return;
+		QString mygroup=flag->getGroup();
+
+		for (int i=0;i<activeNames.size();++i)
+		{
+			flag=masterRow->getFlag (activeNames.at(i) );
+			if (name!=activeNames.at(i) && !mygroup.isEmpty() && mygroup==flag->getGroup())
+				deactivate (activeNames.at(i));
+		}
+	}
+}
+
+void FlagRow::activate (const QString &name)
+{
+	if (!activeNames.contains (name))
+		activeNames.append (name);
+	else
+		qWarning (QString("FlagRow::activate - %1 is already active").arg(name));
+}
+
+
+void FlagRow::deactivate (const QString &name)
+{
+	int n=activeNames.indexOf (name);
+	if (n>=0)
+		activeNames.removeAt(n);
+	else
+		qWarning (QString("FlagRow::deactivate - %1 is not active").arg(name));
+}
+
+void FlagRow::deactivateAll ()
+{
+	if (!toolBar) activeNames.clear();
+}
+
+
+void FlagRow::resetUsedCounter()
+{
+	for (int i=0; i<flags.size(); ++i)
+		flags.at(i)->setUsed (false);
+}
+
+QString FlagRow::saveToDir (const QString &tmpdir,const QString &prefix, bool writeflags) 
+{
+	// Build xml string
+	QString s;
+	
+	if (!toolBar)
+	{
+		if (!activeNames.isEmpty())
+		for (int i=0; i<activeNames.size(); ++i)
+		{
+			// save flag to xml, if flag is set 
+			s+=valueElement("standardflag",activeNames.at(i));
+
+			// and tell parentRow, that this flag is used	
+			masterRow->getFlag(activeNames.at(i))->setUsed(true);
+		}	
+	} else
+		// Save icons to dir, if verbose is set (xml export)
+		// and I am a master
+		// and this flag is really used somewhere
+		if (writeflags)
+			for (int i=0; i<flags.size(); ++i)
+				if (flags.at(i)->isUsed()) flags.at(i)->saveToDir (tmpdir,prefix);
+	return s;		
+}
+
+void FlagRow::setName (const QString &n)
+{
+	rowName=n;
+}
+
+void FlagRow::setToolBar (QToolBar *tb)
+{
+	toolBar=tb;
+}
+
+void FlagRow::setMasterRow (FlagRow *row)
+{
+	masterRow=row;
+}
+
+void FlagRow::updateToolBar (const QStringList &activeNames)
+{
+	if (toolBar )
+	{
+		if (activeNames.isEmpty() )
+			for (int i=0;i<flags.size();++i)
+				flags.at(i)->getAction()->setChecked (false);
+		else		
+			for (int i=0;i<flags.size();++i)
+				flags.at(i)->getAction()->setChecked (
+					activeNames.contains (flags.at(i)->getName()));
+	}
+	return;
+		
+}
+
+
diff -r 340bc29da9a0 -r 2f002657dada flagrow.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flagrow.h	Tue May 26 11:24:51 2009 +0000
@@ -0,0 +1,52 @@
+#ifndef FLAGROW_H
+#define FLAGROW_H
+
+#include <QStringList>
+#include <QToolBar>
+
+#include "flag.h"
+#include "xmlobj.h"
+
+/*! \brief A set of flags (Flag). 
+
+   A toolbar can be created from the flags in this row.
+   The data needed for represention in a vym map 
+   is stored in FlagRowObj.
+ */
+
+class FlagRow:public XMLObj {
+public:
+    FlagRow ();
+    ~FlagRow ();
+	void addFlag (Flag *flag);
+	Flag *getFlag (const QString &name);
+	QStringList  activeFlagNames();
+	bool isActive(const QString &name);
+
+	/*! \brief Toggle a Flag 
+		
+		To activate a flag it will be copied from masterRow to current row.
+	*/	
+	void toggle (const QString&, FlagRow *masterRow=NULL);
+	void activate(const QString&);
+	void deactivate(const QString&);
+	void deactivateAll();
+	void setEnabled (bool);
+	void setShowFlags (bool);
+	void resetUsedCounter();
+	QString saveToDir (const QString &,const QString &,bool);
+	void setName (const QString&);			// prefix for exporting flags to dir
+	void setToolBar   (QToolBar *tb);
+	void setMasterRow (FlagRow *row);
+	void updateToolBar(const QStringList &activeNames);
+
+private:	
+	QToolBar *toolBar;
+	FlagRow *masterRow;
+	QList <Flag*> flags; 
+	QStringList activeNames;	//! Lists all names of currently active flags
+	QString rowName;			//! Name of this collection of flags
+//	bool showFlags;				// FloatObjects want to hide their flags
+};
+#endif
+
diff -r 340bc29da9a0 -r 2f002657dada icons/newmapcenter.png
Binary file icons/newmapcenter.png has changed