Beispiel #1
0
void gtAction::writeUnstyled(const QString& text)
{
	if (isFirstWrite)
	{
		if (!doAppend)
		{
			if (it->nextInChain() != 0)
			{
				PageItem *nextItem = it->nextInChain();
				while (nextItem != 0)
				{
					nextItem->itemText.clear();
					nextItem = nextItem->nextInChain();
				}
			}
			it->itemText.clear();
		}
	}

	QChar ch0(0), ch5(5), ch10(10), ch13(13); 
	for (int a = 0; a < text.length(); ++a)
	{
		if ((text.at(a) == ch0) || (text.at(a) == ch13))
			continue;
		QChar ch = text.at(a);
		if ((ch == ch10) || (ch == ch5))
			ch = ch13;
		
		int pos = it->itemText.length();
		it->itemText.insertChars(pos, QString(ch));
	}
	
	lastCharWasLineChange = text.right(1) == "\n";
	isFirstWrite = false;
}
void gtAction::writeUnstyled(const QString& text)
{
	UndoTransaction* activeTransaction = NULL;
	if (isFirstWrite)
	{
		if (!doAppend)
		{
			if (UndoManager::undoEnabled())
				activeTransaction = new UndoTransaction(undoManager->beginTransaction(Um::Selection, Um::IGroup, Um::ImportText, "", Um::IDelete));
			if (it->nextInChain() != 0)
			{
				PageItem *nextItem = it->nextInChain();
				while (nextItem != 0)
				{
					nextItem->itemText.selectAll();
					nextItem->asTextFrame()->deleteSelectedTextFromFrame();
					nextItem = nextItem->nextInChain();
				}
			}
			it->itemText.selectAll();
			it->asTextFrame()->deleteSelectedTextFromFrame();
		}
	}

	QChar ch0(0), ch5(5), ch10(10), ch13(13);
	QString textStr = text;
	textStr.remove(ch0);
	textStr.remove(ch13);
	textStr.replace(ch10,ch13);
	textStr.replace(ch5,ch13);
	textStr.replace(QString(0x2028),SpecialChars::LINEBREAK);
	textStr.replace(QString(0x2029),SpecialChars::PARSEP);
	int pos = it->itemText.length();
	if (UndoManager::undoEnabled())
	{
		SimpleState *ss = new SimpleState(Um::AppendText,"",Um::ICreate);
			ss->set("INSERT_FRAMETEXT", "insert_frametext");
			ss->set("TEXT_STR",textStr);
			ss->set("START", pos);
			undoManager->action(it, ss);
	}
	it->itemText.insertChars(pos, textStr);
	lastCharWasLineChange = text.right(1) == "\n";
	isFirstWrite = false;
	if (activeTransaction)
	{
		activeTransaction->commit();
		delete activeTransaction;
		activeTransaction = NULL;
	}
}
Beispiel #3
0
void gtAction::write(const QString& text, gtStyle *style, bool isNote)
{
	if (isFirstWrite)
	{
		if (!doAppend)
		{
			if (it->nextInChain() != 0)
			{
				PageItem *nextItem = it->nextInChain();
				while (nextItem != 0)
				{
					nextItem->itemText.clear();
					nextItem = nextItem->nextInChain();
				}
			}
			it->itemText.clear();
		}
	}
	int paragraphStyle = -1;
	if (style->target() == "paragraph")
	{
		gtParagraphStyle* pstyle = dynamic_cast<gtParagraphStyle*>(style);
		assert(pstyle != NULL);
		paragraphStyle = applyParagraphStyle(pstyle);
		if (isFirstWrite)
			inPara = true;
	}
	else if (style->target() == "frame")
	{
		gtFrameStyle* fstyle = dynamic_cast<gtFrameStyle*>(style);
		assert(fstyle != NULL);
		applyFrameStyle(fstyle);
	}

	if ((inPara) && (!lastCharWasLineChange) && (text.left(1) != "\n") && (lastParagraphStyle != -1))
		paragraphStyle = lastParagraphStyle;

	if (paragraphStyle == -1)
		paragraphStyle = 0; //::findParagraphStyle(textFrame->doc(), textFrame->doc()->currentStyle);

	const ParagraphStyle& paraStyle = textFrame->doc()->paragraphStyles()[paragraphStyle];

	gtFont* font = style->getFont();
	QString fontName = validateFont(font).scName();
	CharStyle lastStyle, newStyle;
	int lastStyleStart = 0;
	
	if ((inPara) && (!overridePStyleFont))
	{
		if (paraStyle.charStyle().font().isNone())
		{
			gtFont font2(*font);
			font2.setName(paraStyle.charStyle().font().scName());
			QString fontName2 = validateFont(&font2).scName();
			newStyle.setFont((*textFrame->doc()->AllFonts)[fontName2]);
		}
	}
	else
	{
		setCharStyleAttributes(font, newStyle);
	}
	/*newStyle.eraseCharStyle(paraStyle.charStyle());*/

	lastStyle = newStyle;
	lastStyleStart = it->itemText.length();
	StoryText* story = NULL;
	if (isNote)
	{
		if (noteStory == NULL)
		{
			note = it->m_Doc->newNote(it->m_Doc->m_docNotesStylesList.at(0));
			noteStory = new StoryText(it->m_Doc);
		}
		story = noteStory;
	}
	else
		story = &it->itemText;

	QChar ch0(0), ch5(5), ch10(10), ch13(13); 
	for (int a = 0; a < text.length(); ++a)
	{
		if ((text.at(a) == ch0) || (text.at(a) == ch13))
			continue;
		QChar ch = text.at(a);
		if ((ch == ch10) || (ch == ch5))
			ch = ch13;
		
		int pos = story->length();
		if (isNote && ch == SpecialChars::OBJECT)
		{
			NotesStyle* nStyle = note->notesStyle();
			QString label = "NoteMark_" + nStyle->name();
			if (nStyle->range() == NSRsection)
				label += " in section " + it->m_Doc->getSectionNameForPageIndex(it->OwnPage) + " page " + QString::number(it->OwnPage +1);
			else if (nStyle->range() == NSRpage)
				label += " on page " + QString::number(it->OwnPage +1);
			else if (nStyle->range() == NSRstory)
				label += " in " + it->firstInChain()->itemName();
			else if (nStyle->range() == NSRframe)
				label += " in frame" + it->itemName();
			if (it->m_Doc->getMark(label + "_1", MARKNoteMasterType) != NULL)
				getUniqueName(label,it->m_Doc->marksLabelsList(MARKNoteMasterType), "_"); //FIX ME here user should be warned that inserted mark`s label was changed
			else
				label = label + "_1";
			Mark* mrk = it->m_Doc->newMark();
			mrk->label = label;
			mrk->setType(MARKNoteMasterType);
			mrk->setNotePtr(note);
			note->setMasterMark(mrk);
			mrk->setString("");
			mrk->OwnPage = it->OwnPage;
			it->itemText.insertMark(mrk);
			story->applyCharStyle(lastStyleStart, story->length()-lastStyleStart, lastStyle);
			if (paraStyle.hasName())
			{
				ParagraphStyle pStyle;
				pStyle.setParent(paraStyle.name());
				story->applyStyle(qMax(0,story->length()-1), pStyle);
			}
			else
				story->applyStyle(qMax(0,story->length()-1), paraStyle);
			
			lastCharWasLineChange = text.right(1) == "\n";
			inPara = style->target() == "paragraph";
			lastParagraphStyle = paragraphStyle;
			if (isFirstWrite)
				isFirstWrite = false;
			if (story->text(pos -1) == SpecialChars::PARSEP)
				story->removeChars(pos-1, 1);
			note->setSaxedText(saxedText(story));
			note = NULL;
			delete noteStory;
			noteStory = NULL;
			return;
		}
		else
			story->insertChars(pos, QString(ch));
		if (ch == SpecialChars::PARSEP) 
		{
			if (paraStyle.hasName())
			{
				ParagraphStyle pstyle;
				pstyle.setParent(paraStyle.name());
				story->applyStyle(pos, pstyle);
			}
			else
				story->applyStyle(pos, paraStyle);
		}
	}
	story->applyCharStyle(lastStyleStart, story->length()-lastStyleStart, lastStyle);
	if (paraStyle.hasName())
	{
		ParagraphStyle pStyle;
		pStyle.setParent(paraStyle.name());
		story->applyStyle(qMax(0,story->length()-1), pStyle);
	}
	else
		story->applyStyle(qMax(0,story->length()-1), paraStyle);
	
	lastCharWasLineChange = text.right(1) == "\n";
	inPara = style->target() == "paragraph";
	lastParagraphStyle = paragraphStyle;
	if (isFirstWrite)
		isFirstWrite = false;
}
Beispiel #4
0
void gtAction::writeUnstyled(const QString& text, bool isNote)
{
	UndoTransaction activeTransaction;
	if (isFirstWrite && it->itemText.length() > 0)
	{
		if (!doAppend)
		{
			if (UndoManager::undoEnabled())
				activeTransaction = undoManager->beginTransaction(Um::Selection, Um::IGroup, Um::ImportText, "", Um::IDelete);
			if (it->nextInChain() != 0)
			{
				PageItem *nextItem = it->nextInChain();
				while (nextItem != 0)
				{
					nextItem->itemText.selectAll();
					nextItem->asTextFrame()->deleteSelectedTextFromFrame();
					nextItem = nextItem->nextInChain();
				}
			}
			it->itemText.selectAll();
			it->asTextFrame()->deleteSelectedTextFromFrame();
		}
	}

	QChar ch0(0), ch5(5), ch10(10), ch13(13);
	QString textStr = text;
	textStr.remove(ch0);
	textStr.remove(ch13);
	textStr.replace(ch10,ch13);
	textStr.replace(ch5,ch13);
	textStr.replace(QString(0x2028),SpecialChars::LINEBREAK);
	textStr.replace(QString(0x2029),SpecialChars::PARSEP);
	if (isNote)
	{
		if (note == NULL)
		{
			note = it->m_Doc->newNote(it->m_Doc->m_docNotesStylesList.at(0));
			Q_ASSERT(noteStory == NULL);
			noteStory = new StoryText(it->m_Doc);
		}
		if (textStr == SpecialChars::OBJECT)
		{
			NotesStyle* nStyle = note->notesStyle();
			QString label = "NoteMark_" + nStyle->name();
			if (nStyle->range() == NSRsection)
				label += " in section " + it->m_Doc->getSectionNameForPageIndex(it->OwnPage) + " page " + QString::number(it->OwnPage +1);
			else if (nStyle->range() == NSRpage)
				label += " on page " + QString::number(it->OwnPage +1);
			else if (nStyle->range() == NSRstory)
				label += " in " + it->firstInChain()->itemName();
			else if (nStyle->range() == NSRframe)
				label += " in frame" + it->itemName();
			if (it->m_Doc->getMark(label + "_1", MARKNoteMasterType) != NULL)
				getUniqueName(label,it->m_Doc->marksLabelsList(MARKNoteMasterType), "_"); //FIX ME here user should be warned that inserted mark`s label was changed
			else
				label = label + "_1";
			Mark* mrk = it->m_Doc->newMark();
			mrk->label = label;
			mrk->setType(MARKNoteMasterType);
			mrk->setNotePtr(note);
			note->setMasterMark(mrk);
			if (noteStory->text(noteStory->length() -1) == SpecialChars::PARSEP)
				noteStory->removeChars(noteStory->length() -1, 1);
			note->setSaxedText(saxedText(noteStory));
			mrk->setString("");
			mrk->OwnPage = it->OwnPage;
			it->itemText.insertMark(mrk);
			if (UndoManager::undoEnabled())
			{
				ScItemsState* is = new ScItemsState(UndoManager::InsertNote);
				is->set("ETEA", mrk->label);
				is->set("MARK", QString("new"));
				is->set("label", mrk->label);
				is->set("type", (int) MARKNoteMasterType);
				is->set("strtxt", QString(""));
				is->set("nStyle", nStyle->name());
				is->set("at", it->itemText.cursorPosition() -1);
				is->insertItem("inItem", it);
				undoManager->action(it->m_Doc, is);
			}
			note = NULL;
			delete noteStory;
		}
		else
			noteStory->insertChars(noteStory->length(), textStr);
	}
	else
	{
		int pos = it->itemText.length();
		if (UndoManager::undoEnabled())
		{
			SimpleState *ss = new SimpleState(Um::AppendText,"",Um::ICreate);
			ss->set("INSERT_FRAMETEXT", "insert_frametext");
			ss->set("TEXT_STR",textStr);
			ss->set("START", pos);
			undoManager->action(it, ss);
		}
		it->itemText.insertChars(pos, textStr);
	}
	lastCharWasLineChange = text.right(1) == "\n";
	isFirstWrite = false;
	if (activeTransaction)
	{
		activeTransaction.commit();
	}
}
Beispiel #5
0
void gtAction::write(const QString& text, gtStyle *style)
{
	if (isFirstWrite)
	{
		if (!doAppend)
		{
			if (it->nextInChain() != 0)
			{
				PageItem *nextItem = it->nextInChain();
				while (nextItem != 0)
				{
					nextItem->itemText.clear();
					nextItem = nextItem->nextInChain();
				}
			}
			it->itemText.clear();
		}
	}
	int paragraphStyle = -1;
	if (style->target() == "paragraph")
	{
		gtParagraphStyle* pstyle = dynamic_cast<gtParagraphStyle*>(style);
		assert(pstyle != NULL);
		paragraphStyle = applyParagraphStyle(pstyle);
		if (isFirstWrite)
			inPara = true;
	}
	else if (style->target() == "frame")
	{
		gtFrameStyle* fstyle = dynamic_cast<gtFrameStyle*>(style);
		assert(fstyle != NULL);
		applyFrameStyle(fstyle);
	}

	if ((inPara) && (!lastCharWasLineChange) && (text.left(1) != "\n") && (lastParagraphStyle != -1))
		paragraphStyle = lastParagraphStyle;

	if (paragraphStyle == -1)
		paragraphStyle = 0; //::findParagraphStyle(textFrame->doc(), textFrame->doc()->currentStyle);

	const ParagraphStyle& paraStyle = textFrame->doc()->paragraphStyles()[paragraphStyle];

	gtFont* font = style->getFont();
	QString fontName = validateFont(font).scName();
	CharStyle lastStyle, newStyle;
	int lastStyleStart = 0;
	
	if ((inPara) && (!overridePStyleFont))
	{
		if (paraStyle.charStyle().font().isNone())
		{
			gtFont font2(*font);
			font2.setName(paraStyle.charStyle().font().scName());
			QString fontName2 = validateFont(&font2).scName();
			newStyle.setFont((*textFrame->doc()->AllFonts)[fontName2]);
		}
	}
	else
	{
		setCharStyleAttributes(font, newStyle);
	}
	/*newStyle.eraseCharStyle(paraStyle.charStyle());*/

	lastStyle = newStyle;
	lastStyleStart = it->itemText.length();

	QChar ch0(0), ch5(5), ch10(10), ch13(13);
	for (int a = 0; a < text.length(); ++a)
	{
		if ((text.at(a) == ch0) || (text.at(a) == ch13))
			continue;
		QChar ch = text.at(a);
		if ((ch == ch10) || (ch == ch5))
			ch = ch13;
		else if (ch.unicode() == 0x2028)
			ch = SpecialChars::LINEBREAK;
		else if (ch.unicode() == 0x2029)
			ch = SpecialChars::PARSEP;
		
		int pos = it->itemText.length();
		it->itemText.insertChars(pos, QString(ch));
		if (ch == SpecialChars::PARSEP) 
		{
			if (paraStyle.hasName())
			{
				ParagraphStyle pstyle;
				pstyle.setParent(paraStyle.name());
				it->itemText.applyStyle(pos, pstyle);
			}
			else
				it->itemText.applyStyle(pos, paraStyle);
		}
	}
	it->itemText.applyCharStyle(lastStyleStart, it->itemText.length()-lastStyleStart, lastStyle);
	if (paraStyle.hasName())
	{
		ParagraphStyle pStyle;
		pStyle.setParent(paraStyle.name());
		it->itemText.applyStyle(qMax(0,it->itemText.length()-1), pStyle);
	}
	else
		it->itemText.applyStyle(qMax(0,it->itemText.length()-1), paraStyle);
	
	lastCharWasLineChange = text.right(1) == "\n";
	inPara = style->target() == "paragraph";
	lastParagraphStyle = paragraphStyle;
	if (isFirstWrite)
		isFirstWrite = false;
}