noteobj.cpp
author insilmaril
Mon, 25 Jul 2005 20:35:01 +0000
changeset 137 88d2a027ef14
parent 0 7a96bd401351
child 185 6691000c3262
permissions -rw-r--r--
changed MapEditor::undo and saveState so that selection is saved, too (bugfix)
insilmaril@0
     1
#include <qfile.h>
insilmaril@0
     2
#include <qtextstream.h>
insilmaril@0
     3
#include <qmessagebox.h>
insilmaril@0
     4
#include <qregexp.h>
insilmaril@0
     5
insilmaril@0
     6
#include "noteobj.h"
insilmaril@0
     7
insilmaril@0
     8
/////////////////////////////////////////////////////////////////
insilmaril@0
     9
// NoteObj
insilmaril@0
    10
/////////////////////////////////////////////////////////////////
insilmaril@0
    11
insilmaril@0
    12
NoteObj::NoteObj()
insilmaril@0
    13
{
insilmaril@0
    14
	clear();
insilmaril@0
    15
}
insilmaril@0
    16
insilmaril@0
    17
void NoteObj::copy (NoteObj other)
insilmaril@0
    18
{
insilmaril@0
    19
	note=other.note;
insilmaril@0
    20
	fonthint=other.fonthint;
insilmaril@0
    21
	filenamehint="";
insilmaril@0
    22
}
insilmaril@0
    23
insilmaril@0
    24
void NoteObj::clear()
insilmaril@0
    25
{
insilmaril@0
    26
	note="";
insilmaril@0
    27
	fonthint="undef";
insilmaril@0
    28
	filenamehint="";
insilmaril@0
    29
}
insilmaril@0
    30
insilmaril@0
    31
void NoteObj::setNote (const QString &s)
insilmaril@0
    32
{
insilmaril@0
    33
	note=s;
insilmaril@0
    34
}
insilmaril@0
    35
insilmaril@0
    36
QString NoteObj::getNote()
insilmaril@0
    37
{
insilmaril@0
    38
	return note;
insilmaril@0
    39
}
insilmaril@0
    40
insilmaril@0
    41
void NoteObj::setFontHint (const QString &s)
insilmaril@0
    42
{
insilmaril@0
    43
	// only for backward compatibility (pre 1.5 )
insilmaril@0
    44
	fonthint=s;
insilmaril@0
    45
}
insilmaril@0
    46
insilmaril@0
    47
QString NoteObj::getFontHint()
insilmaril@0
    48
{
insilmaril@0
    49
	// only for backward compatibility (pre 1.5 )
insilmaril@0
    50
	return fonthint;
insilmaril@0
    51
}
insilmaril@0
    52
insilmaril@0
    53
void NoteObj::setFilenameHint (const QString &s)
insilmaril@0
    54
{
insilmaril@0
    55
	filenamehint=s;
insilmaril@0
    56
}
insilmaril@0
    57
insilmaril@0
    58
QString NoteObj::getFilenameHint()
insilmaril@0
    59
{
insilmaril@0
    60
	return filenamehint;
insilmaril@0
    61
}
insilmaril@0
    62
insilmaril@0
    63
bool NoteObj::isEmpty ()
insilmaril@0
    64
{
insilmaril@0
    65
	return note.isEmpty();
insilmaril@0
    66
}
insilmaril@0
    67
insilmaril@0
    68
QString NoteObj::saveToDir ()
insilmaril@0
    69
{
insilmaril@0
    70
	// QTextEdit may generate fontnames with unquoted &, like
insilmaril@0
    71
	// in "Lucida B&H". This is invalid in XML and thus would crash
insilmaril@0
    72
	// the XML parser
insilmaril@0
    73
	uint pos=0;
insilmaril@0
    74
	uint pos2;
insilmaril@0
    75
	bool inbracket=false;
insilmaril@0
    76
	bool inquot=false;
insilmaril@0
    77
	while (pos<note.length())
insilmaril@0
    78
	{
insilmaril@0
    79
		if (note.mid(pos,1)=="<") inbracket=true;
insilmaril@0
    80
		if (note.mid(pos,1)==">") inbracket=false;
insilmaril@0
    81
		if (note.mid(pos,1)=="\"" && inbracket)
insilmaril@0
    82
		{
insilmaril@0
    83
			if (!inquot)
insilmaril@0
    84
				inquot=true;
insilmaril@0
    85
			else
insilmaril@0
    86
				inquot=false;
insilmaril@0
    87
		}
insilmaril@0
    88
		if (note.mid(pos,1)=="&" && inquot)
insilmaril@0
    89
		{
insilmaril@0
    90
			// Now we are inside  <  "  "  >
insilmaril@0
    91
			// look for ending "
insilmaril@0
    92
			pos2=pos+1;
insilmaril@0
    93
			while (note.mid(pos2,1)!=";" && note.mid(pos2,1)!="\"")
insilmaril@0
    94
				pos2++;
insilmaril@0
    95
			if (note.mid(pos2,1)=="\"")
insilmaril@0
    96
			{
insilmaril@0
    97
				note.replace(pos,1,"&amp;");
insilmaril@0
    98
				pos=pos2;
insilmaril@0
    99
			}
insilmaril@0
   100
		}
insilmaril@0
   101
		pos++;
insilmaril@0
   102
	}
insilmaril@0
   103
	return beginElement ("htmlnote",attribut("fonthint",fonthint)) + "\n"+ note+ "\n" +endElement ("htmlnote");
insilmaril@0
   104
}
insilmaril@0
   105