flagrow.cpp
author insilmaril
Sat, 06 Mar 2010 20:05:02 +0000
changeset 826 e715694b0f47
parent 824 36eb4b8f409e
permissions -rw-r--r--
Changed animTicks to uint
     1 #include <QDebug>
     2 
     3 #include "flagrow.h"
     4 
     5 /////////////////////////////////////////////////////////////////
     6 // FlagRow
     7 /////////////////////////////////////////////////////////////////
     8 FlagRow::FlagRow()
     9 {
    10 	toolBar=NULL;
    11 	masterRow=NULL;
    12 //    cout << "Const FlagRow ()\n";
    13 //    init ();
    14 }
    15 
    16 FlagRow::~FlagRow()
    17 {
    18 	//cout << "Destr FlagRow\n";
    19 //	while (!flag.isEmpty())
    20 //		delete (flag.takeFirst() );
    21 }
    22 
    23 void FlagRow::addFlag (Flag *flag)
    24 {
    25 	Flag *f=new Flag;
    26 	f->copy (flag);
    27 	flags.append (f);
    28 	activeNames.append (flag->getName());
    29 }
    30 
    31 Flag* FlagRow::getFlag (const QString &name)
    32 {
    33 	int i=0;
    34 	while (i<=flags.size()-1)
    35 	{
    36 		if (flags.at(i)->getName()==name)
    37 			return flags.at(i);
    38 		i++;	
    39 	}
    40 	return NULL;
    41 }
    42 
    43 QStringList FlagRow::activeFlagNames()
    44 {
    45 	return activeNames;
    46 }
    47 
    48 
    49 bool FlagRow::isActive (const QString &name)
    50 {
    51 	QString n;
    52 	foreach (n,activeNames)
    53 		if (n==name) return true;
    54 	return false;	
    55 }
    56 
    57 void FlagRow::toggle (const QString &name, FlagRow *masterRow)
    58 {
    59 	if (isActive(name) )
    60 		deactivate (name);
    61 	else
    62 	{
    63 		activate (name);	
    64 		if (!masterRow) return;
    65 
    66 		Flag *flag=masterRow->getFlag (name);
    67 		if (!flag) return;
    68 		QString mygroup=flag->getGroup();
    69 
    70 		for (int i=0;i<activeNames.size();++i)
    71 		{
    72 			flag=masterRow->getFlag (activeNames.at(i) );
    73 			if (name!=activeNames.at(i) && !mygroup.isEmpty() && mygroup==flag->getGroup())
    74 				deactivate (activeNames.at(i));
    75 		}
    76 	}
    77 }
    78 
    79 void FlagRow::activate (const QString &name)
    80 {
    81 	if (!isActive (name))
    82 		activeNames.append (name);
    83 	else
    84 		qWarning (QString("FlagRow::activate - %1 is already active").arg(name));
    85 }
    86 
    87 
    88 void FlagRow::deactivate (const QString &name)	//FIXME-4 complaints if CTRL-E is pressed with focus on NoteEditor ?!
    89 {
    90 	int n=activeNames.indexOf (name);
    91 	if (n>=0)
    92 		activeNames.removeAt(n);
    93 	else
    94 		qWarning (QString("FlagRow::deactivate - %1 is not active").arg(name));
    95 }
    96 
    97 void FlagRow::deactivateAll ()
    98 {
    99 	if (!toolBar) activeNames.clear();
   100 }
   101 
   102 
   103 void FlagRow::resetUsedCounter()
   104 {
   105 	for (int i=0; i<flags.size(); ++i)
   106 		flags.at(i)->setUsed (false);
   107 }
   108 
   109 QString FlagRow::saveToDir (const QString &tmpdir,const QString &prefix, bool writeflags) 
   110 {
   111 	// Build xml string
   112 	QString s;
   113 	
   114 	if (!toolBar)
   115 	{
   116 		if (!activeNames.isEmpty())
   117 		for (int i=0; i<activeNames.size(); ++i)
   118 		{
   119 			// save flag to xml, if flag is set 
   120 			s+=valueElement("standardflag",activeNames.at(i));
   121 
   122 			// and tell parentRow, that this flag is used	
   123 			masterRow->getFlag(activeNames.at(i))->setUsed(true);
   124 		}	
   125 	} else
   126 		// Save icons to dir, if verbose is set (xml export)
   127 		// and I am a master
   128 		// and this flag is really used somewhere
   129 		if (writeflags)
   130 			for (int i=0; i<flags.size(); ++i)
   131 				if (flags.at(i)->isUsed()) flags.at(i)->saveToDir (tmpdir,prefix);
   132 	return s;		
   133 }
   134 
   135 void FlagRow::setName (const QString &n)
   136 {
   137 	rowName=n;
   138 }
   139 
   140 void FlagRow::setToolBar (QToolBar *tb)
   141 {
   142 	toolBar=tb;
   143 }
   144 
   145 void FlagRow::setMasterRow (FlagRow *row)
   146 {
   147 	masterRow=row; 
   148 }
   149 
   150 void FlagRow::updateToolBar (const QStringList &activeNames)
   151 {
   152 	if (toolBar )
   153 	{
   154 		for (int i=0;i<flags.size();++i)
   155 			flags.at(i)->getAction()->setChecked (false);
   156 		for (int i=0;i<flags.size();++i)
   157 		{
   158 			int n=activeNames.indexOf (flags.at(i)->getName());
   159 			if (n>=0)
   160 				flags.at(i)->getAction()->setChecked (true);	
   161 		}
   162 	}
   163 }
   164 
   165