added missing new files
authorinsilmaril
Tue, 26 May 2009 11:24:51 +0000
changeset 7742f002657dada
parent 773 340bc29da9a0
child 775 6e4b586aa88a
added missing new files
flag.cpp
flag.h
flagrow.cpp
flagrow.h
icons/newmapcenter.png
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/flag.cpp	Tue May 26 11:24:51 2009 +0000
     1.3 @@ -0,0 +1,136 @@
     1.4 +#include "flag.h"
     1.5 +
     1.6 +#include <iostream>
     1.7 +using namespace std;
     1.8 +
     1.9 +/////////////////////////////////////////////////////////////////
    1.10 +// Flag
    1.11 +/////////////////////////////////////////////////////////////////
    1.12 +Flag::Flag()
    1.13 +{
    1.14 +	//cout << "Const Flag ()\n";
    1.15 +    init ();
    1.16 +}
    1.17 +
    1.18 +Flag::Flag (Flag* io)
    1.19 +{
    1.20 +	//cout << "Const Flag (Flag)\n";
    1.21 +    copy (io);
    1.22 +}
    1.23 +
    1.24 +Flag::~Flag()
    1.25 +{
    1.26 +   //cout << "Destr Flag  this="<<this <<"  " << qPrintable(name) << "\n";
    1.27 +}
    1.28 +
    1.29 +
    1.30 +void Flag::init ()
    1.31 +{
    1.32 +	action=NULL;
    1.33 +	name="undefined";
    1.34 +	visible=true;
    1.35 +	unsetGroup();
    1.36 +
    1.37 +	state=false;
    1.38 +	used=false;
    1.39 +}
    1.40 +
    1.41 +void Flag::copy (Flag* other)
    1.42 +{
    1.43 +	action=other->action;
    1.44 +	name=other->name;
    1.45 +	group=other->group;
    1.46 +	tooltip=other->tooltip;
    1.47 +	state=other->state;
    1.48 +	used=other->used;
    1.49 +	pixmap=other->pixmap;
    1.50 +}
    1.51 +
    1.52 +
    1.53 +void Flag::load (const QString &fn)
    1.54 +{
    1.55 +	pixmap.load(fn);
    1.56 +}
    1.57 +
    1.58 +void Flag::load (const QPixmap &pm)
    1.59 +{
    1.60 +	pixmap=pm;
    1.61 +}
    1.62 +
    1.63 +void Flag::setName(const QString &n)
    1.64 +{
    1.65 +	name=n;
    1.66 +}
    1.67 +
    1.68 +const QString Flag::getName()
    1.69 +{
    1.70 +	return name;
    1.71 +}
    1.72 +
    1.73 +void Flag::setVisible (bool b)
    1.74 +{
    1.75 +	visible=b;
    1.76 +}
    1.77 +
    1.78 +bool Flag::isVisible ()
    1.79 +{
    1.80 +	return visible;
    1.81 +}
    1.82 +
    1.83 +void Flag::setGroup (const QString &n)
    1.84 +{
    1.85 +	group=n;
    1.86 +}
    1.87 +
    1.88 +const QString Flag::getGroup()
    1.89 +{
    1.90 +	return group;
    1.91 +}
    1.92 +
    1.93 +void Flag::unsetGroup()
    1.94 +{
    1.95 +	group.clear();
    1.96 +}
    1.97 +
    1.98 +void Flag::setToolTip(const QString &n)
    1.99 +{
   1.100 +	tooltip=n;
   1.101 +}
   1.102 +
   1.103 +const QString Flag::getToolTip()
   1.104 +{
   1.105 +	return tooltip;
   1.106 +}
   1.107 +
   1.108 +QPixmap Flag::getPixmap()
   1.109 +{
   1.110 +	return pixmap;
   1.111 +}
   1.112 +
   1.113 +void Flag::setAction (QAction *a)
   1.114 +{
   1.115 +	action=a;
   1.116 +}
   1.117 +
   1.118 +QAction* Flag::getAction ()
   1.119 +{
   1.120 +	return action;
   1.121 +}
   1.122 +
   1.123 +void Flag::setUsed (bool b)
   1.124 +{
   1.125 +	used=b;
   1.126 +}
   1.127 +
   1.128 +bool Flag::isUsed()
   1.129 +{
   1.130 +	return used;
   1.131 +}
   1.132 +
   1.133 +void Flag::saveToDir (const QString &tmpdir, const QString &prefix)
   1.134 +{
   1.135 +	QString fn=tmpdir + prefix + name + ".png";
   1.136 +	pixmap.save (fn,"PNG");
   1.137 +}
   1.138 +
   1.139 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/flag.h	Tue May 26 11:24:51 2009 +0000
     2.3 @@ -0,0 +1,55 @@
     2.4 +#ifndef FLAG_H
     2.5 +#define FLAG_H
     2.6 +
     2.7 +
     2.8 +#include <QAction>
     2.9 +#include <QPixmap>
    2.10 +
    2.11 +#include "xmlobj.h"
    2.12 +
    2.13 +/*! \brief One flag belonging to a FlagRow.
    2.14 +
    2.15 +	Each TreeItem in a VymModel has a set of standard flags and system
    2.16 +	flags.
    2.17 +*/
    2.18 +
    2.19 +
    2.20 +/////////////////////////////////////////////////////////////////////////////
    2.21 +class Flag:public XMLObj {
    2.22 +public:
    2.23 +    Flag ();
    2.24 +    Flag (Flag*);
    2.25 +    ~Flag ();
    2.26 +    virtual void init ();
    2.27 +    virtual void copy (Flag*);
    2.28 +	void load (const QString&);
    2.29 +	void load (const QPixmap&);
    2.30 +	void setName (const QString&);
    2.31 +	const QString getName ();
    2.32 +	void setVisible (bool b);
    2.33 +	bool isVisible ();
    2.34 +	void setGroup (const QString&);
    2.35 +	const QString getGroup();
    2.36 +	void unsetGroup ();
    2.37 +	void setToolTip(const QString&);
    2.38 +	const QString getToolTip();
    2.39 +	QPixmap getPixmap();
    2.40 +	void setAction (QAction *a);
    2.41 +	QAction* getAction ();
    2.42 +	void setUsed (bool);	//FIXME-3 needed?
    2.43 +	bool isUsed();
    2.44 +	void saveToDir (const QString&, const QString&);
    2.45 +	
    2.46 +protected:	
    2.47 +	QString name;
    2.48 +	bool visible;
    2.49 +	QString group;
    2.50 +	QString tooltip;
    2.51 +	QAction *action;
    2.52 +	bool state;
    2.53 +	bool used;
    2.54 +private:
    2.55 +	QPixmap pixmap;
    2.56 +};
    2.57 +
    2.58 +#endif
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/flagrow.cpp	Tue May 26 11:24:51 2009 +0000
     3.3 @@ -0,0 +1,164 @@
     3.4 +#include "flagrow.h"
     3.5 +
     3.6 +#include <iostream>
     3.7 +using namespace std;
     3.8 +
     3.9 +/////////////////////////////////////////////////////////////////
    3.10 +// FlagRow
    3.11 +/////////////////////////////////////////////////////////////////
    3.12 +FlagRow::FlagRow()
    3.13 +{
    3.14 +	toolBar=NULL;
    3.15 +	masterRow=NULL;
    3.16 +//    cout << "Const FlagRow ()\n";
    3.17 +//    init ();
    3.18 +}
    3.19 +
    3.20 +FlagRow::~FlagRow()
    3.21 +{
    3.22 +	//cout << "Destr FlagRow\n";
    3.23 +//	while (!flag.isEmpty())
    3.24 +//		delete (flag.takeFirst() );
    3.25 +}
    3.26 +
    3.27 +void FlagRow::addFlag (Flag *flag)
    3.28 +{
    3.29 +	Flag *f=new Flag;
    3.30 +	f->copy (flag);
    3.31 +	flags.append (f);
    3.32 +	activeNames.append (flag->getName());
    3.33 +}
    3.34 +
    3.35 +Flag* FlagRow::getFlag (const QString &name)
    3.36 +{
    3.37 +	int i=0;
    3.38 +	while (i<=flags.size()-1)
    3.39 +	{
    3.40 +		if (flags.at(i)->getName()==name)
    3.41 +			return flags.at(i);
    3.42 +		i++;	
    3.43 +	}
    3.44 +	return NULL;
    3.45 +}
    3.46 +
    3.47 +QStringList FlagRow::activeFlagNames()
    3.48 +{
    3.49 +	return activeNames;
    3.50 +}
    3.51 +
    3.52 +
    3.53 +bool FlagRow::isActive (const QString &name)
    3.54 +{
    3.55 +	return activeNames.contains (name);
    3.56 +}
    3.57 +
    3.58 +void FlagRow::toggle (const QString &name, FlagRow *masterRow)
    3.59 +{
    3.60 +	if (isActive(name) )
    3.61 +		deactivate (name);
    3.62 +	else
    3.63 +	{
    3.64 +		activate (name);	
    3.65 +		if (!masterRow) return;
    3.66 +
    3.67 +		Flag *flag=masterRow->getFlag (name);
    3.68 +		if (!flag) return;
    3.69 +		QString mygroup=flag->getGroup();
    3.70 +
    3.71 +		for (int i=0;i<activeNames.size();++i)
    3.72 +		{
    3.73 +			flag=masterRow->getFlag (activeNames.at(i) );
    3.74 +			if (name!=activeNames.at(i) && !mygroup.isEmpty() && mygroup==flag->getGroup())
    3.75 +				deactivate (activeNames.at(i));
    3.76 +		}
    3.77 +	}
    3.78 +}
    3.79 +
    3.80 +void FlagRow::activate (const QString &name)
    3.81 +{
    3.82 +	if (!activeNames.contains (name))
    3.83 +		activeNames.append (name);
    3.84 +	else
    3.85 +		qWarning (QString("FlagRow::activate - %1 is already active").arg(name));
    3.86 +}
    3.87 +
    3.88 +
    3.89 +void FlagRow::deactivate (const QString &name)
    3.90 +{
    3.91 +	int n=activeNames.indexOf (name);
    3.92 +	if (n>=0)
    3.93 +		activeNames.removeAt(n);
    3.94 +	else
    3.95 +		qWarning (QString("FlagRow::deactivate - %1 is not active").arg(name));
    3.96 +}
    3.97 +
    3.98 +void FlagRow::deactivateAll ()
    3.99 +{
   3.100 +	if (!toolBar) activeNames.clear();
   3.101 +}
   3.102 +
   3.103 +
   3.104 +void FlagRow::resetUsedCounter()
   3.105 +{
   3.106 +	for (int i=0; i<flags.size(); ++i)
   3.107 +		flags.at(i)->setUsed (false);
   3.108 +}
   3.109 +
   3.110 +QString FlagRow::saveToDir (const QString &tmpdir,const QString &prefix, bool writeflags) 
   3.111 +{
   3.112 +	// Build xml string
   3.113 +	QString s;
   3.114 +	
   3.115 +	if (!toolBar)
   3.116 +	{
   3.117 +		if (!activeNames.isEmpty())
   3.118 +		for (int i=0; i<activeNames.size(); ++i)
   3.119 +		{
   3.120 +			// save flag to xml, if flag is set 
   3.121 +			s+=valueElement("standardflag",activeNames.at(i));
   3.122 +
   3.123 +			// and tell parentRow, that this flag is used	
   3.124 +			masterRow->getFlag(activeNames.at(i))->setUsed(true);
   3.125 +		}	
   3.126 +	} else
   3.127 +		// Save icons to dir, if verbose is set (xml export)
   3.128 +		// and I am a master
   3.129 +		// and this flag is really used somewhere
   3.130 +		if (writeflags)
   3.131 +			for (int i=0; i<flags.size(); ++i)
   3.132 +				if (flags.at(i)->isUsed()) flags.at(i)->saveToDir (tmpdir,prefix);
   3.133 +	return s;		
   3.134 +}
   3.135 +
   3.136 +void FlagRow::setName (const QString &n)
   3.137 +{
   3.138 +	rowName=n;
   3.139 +}
   3.140 +
   3.141 +void FlagRow::setToolBar (QToolBar *tb)
   3.142 +{
   3.143 +	toolBar=tb;
   3.144 +}
   3.145 +
   3.146 +void FlagRow::setMasterRow (FlagRow *row)
   3.147 +{
   3.148 +	masterRow=row;
   3.149 +}
   3.150 +
   3.151 +void FlagRow::updateToolBar (const QStringList &activeNames)
   3.152 +{
   3.153 +	if (toolBar )
   3.154 +	{
   3.155 +		if (activeNames.isEmpty() )
   3.156 +			for (int i=0;i<flags.size();++i)
   3.157 +				flags.at(i)->getAction()->setChecked (false);
   3.158 +		else		
   3.159 +			for (int i=0;i<flags.size();++i)
   3.160 +				flags.at(i)->getAction()->setChecked (
   3.161 +					activeNames.contains (flags.at(i)->getName()));
   3.162 +	}
   3.163 +	return;
   3.164 +		
   3.165 +}
   3.166 +
   3.167 +
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/flagrow.h	Tue May 26 11:24:51 2009 +0000
     4.3 @@ -0,0 +1,52 @@
     4.4 +#ifndef FLAGROW_H
     4.5 +#define FLAGROW_H
     4.6 +
     4.7 +#include <QStringList>
     4.8 +#include <QToolBar>
     4.9 +
    4.10 +#include "flag.h"
    4.11 +#include "xmlobj.h"
    4.12 +
    4.13 +/*! \brief A set of flags (Flag). 
    4.14 +
    4.15 +   A toolbar can be created from the flags in this row.
    4.16 +   The data needed for represention in a vym map 
    4.17 +   is stored in FlagRowObj.
    4.18 + */
    4.19 +
    4.20 +class FlagRow:public XMLObj {
    4.21 +public:
    4.22 +    FlagRow ();
    4.23 +    ~FlagRow ();
    4.24 +	void addFlag (Flag *flag);
    4.25 +	Flag *getFlag (const QString &name);
    4.26 +	QStringList  activeFlagNames();
    4.27 +	bool isActive(const QString &name);
    4.28 +
    4.29 +	/*! \brief Toggle a Flag 
    4.30 +		
    4.31 +		To activate a flag it will be copied from masterRow to current row.
    4.32 +	*/	
    4.33 +	void toggle (const QString&, FlagRow *masterRow=NULL);
    4.34 +	void activate(const QString&);
    4.35 +	void deactivate(const QString&);
    4.36 +	void deactivateAll();
    4.37 +	void setEnabled (bool);
    4.38 +	void setShowFlags (bool);
    4.39 +	void resetUsedCounter();
    4.40 +	QString saveToDir (const QString &,const QString &,bool);
    4.41 +	void setName (const QString&);			// prefix for exporting flags to dir
    4.42 +	void setToolBar   (QToolBar *tb);
    4.43 +	void setMasterRow (FlagRow *row);
    4.44 +	void updateToolBar(const QStringList &activeNames);
    4.45 +
    4.46 +private:	
    4.47 +	QToolBar *toolBar;
    4.48 +	FlagRow *masterRow;
    4.49 +	QList <Flag*> flags; 
    4.50 +	QStringList activeNames;	//! Lists all names of currently active flags
    4.51 +	QString rowName;			//! Name of this collection of flags
    4.52 +//	bool showFlags;				// FloatObjects want to hide their flags
    4.53 +};
    4.54 +#endif
    4.55 +
     5.1 Binary file icons/newmapcenter.png has changed