r16518 by jghali - #9865: wrong restore paragraph`s alignment changes

scribus-commit scribus-commit at lists.scribus.net
Sat Mar 26 15:05:18 CET 2011


Author: jghali
Date: Sat Mar 26 14:05:18 2011
New Revision: 16518

URL: http://scribus.info/websvn/listing.php?repname=Scribus&sc=1&rev=16518
Log:
#9865: wrong restore paragraph`s alignment changes

Modified:
    branches/Version135/Scribus/scribus/pageitem.cpp
    branches/Version135/Scribus/scribus/pageitem.h
    branches/Version135/Scribus/scribus/pageitem_textframe.cpp
    branches/Version135/Scribus/scribus/pageitem_textframe.h
    branches/Version135/Scribus/scribus/propertiespalette.cpp

Modified: branches/Version135/Scribus/scribus/pageitem.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16518&path=/branches/Version135/Scribus/scribus/pageitem.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/pageitem.cpp (original)
+++ branches/Version135/Scribus/scribus/pageitem.cpp Sat Mar 26 14:05:18 2011
@@ -3874,7 +3874,13 @@
 				int SelStart = state->getInt("STEXT_SELSTART");
 				itemText.select(SelStart,state->getInt("STEXT_SELLEN"));
 				asTextFrame()->deleteSelectedTextFromFrame();
+				int ItemLength = itemText.length();
 				itemText.insert(SelStart, *story);
+				// If we have inserted at end of text we have to restore trailing style
+				if (ItemLength == SelStart && story->length() > 0 && story->text(-1) != SpecialChars::PARSEP)
+				{
+					itemText.setStyle(-1, story->paragraphStyle(story->length()));
+				}
 				itemText.select(SelStart, story->length());
 				HasSel = true;
 			}
@@ -3985,7 +3991,7 @@
 				StartOldSel = itemText.startOfSelection();
 				LenOldSel = itemText.lengthOfSelection();
 			}
-			asTextFrame()->ExpandParSel();
+			asTextFrame()->expandParaSelection(true);
 		}
 		else if (undoItem == CHAR || (undoItem == SELECTION && !HasSel))
 		{
@@ -4015,6 +4021,42 @@
 	SaxXML xmlStream(xmlString);
 	xmlStream.beginDoc();
 	iT.saxx(xmlStream, "SCRIBUSTEXT");
+	xmlStream.endDoc();
+	std::string xml(xmlString.str());
+	return QString(xml.c_str());
+}
+
+QString PageItem::getItemTextSaxed(int selStart, int selLength)
+{
+	if (selStart < 0 || selLength < 0)
+		return QString();
+	
+	StoryText it(m_Doc);
+	it.setDefaultStyle(itemText.defaultStyle());
+
+	int oldSelStart = -1, oldSelLength = -1;
+	oldSelStart  = itemText.startOfSelection();
+	oldSelLength = itemText.lengthOfSelection();
+
+	itemText.select(selStart, selLength);
+	it.insert(0, itemText, (selLength > 0));
+	
+	if (oldSelLength > 0) //restoring old selection if undoItem was PARAPGRAPH
+	{
+		itemText.select(oldSelStart, oldSelLength);
+		HasSel = true;
+	}
+	else if (oldSelLength == 0)
+	{
+		itemText.deselectAll();
+		HasSel = false;
+	}
+
+	//saxing text
+	std::ostringstream xmlString;
+	SaxXML xmlStream(xmlString);
+	xmlStream.beginDoc();
+	it.saxx(xmlStream, "SCRIBUSTEXT");
 	xmlStream.endDoc();
 	std::string xml(xmlString.str());
 	return QString(xml.c_str());

Modified: branches/Version135/Scribus/scribus/pageitem.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16518&path=/branches/Version135/Scribus/scribus/pageitem.h
==============================================================================
--- branches/Version135/Scribus/scribus/pageitem.h (original)
+++ branches/Version135/Scribus/scribus/pageitem.h Sat Mar 26 14:05:18 2011
@@ -469,6 +469,7 @@
 	int oldCPos;
 	QString itemTextSaxed;
 	QString getItemTextSaxed(EditActPlace undoItem);
+	QString getItemTextSaxed(int selStart, int selLength);
 	QString getTextSaxed(QString str);
   /** Flag fuer PDF-Bookmark */
 	bool isBookmark;

Modified: branches/Version135/Scribus/scribus/pageitem_textframe.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16518&path=/branches/Version135/Scribus/scribus/pageitem_textframe.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/pageitem_textframe.cpp (original)
+++ branches/Version135/Scribus/scribus/pageitem_textframe.cpp Sat Mar 26 14:05:18 2011
@@ -3356,6 +3356,29 @@
 	HasSel = true;
 }
 
+void PageItem_TextFrame::expandParaSelection(bool includeEOL)
+{
+	int selStart, selLength;
+	if (HasSel)
+	{
+		//extend selection to whole paragraphs
+		selStart  = itemText.startOfParagraph(itemText.nrOfParagraph(itemText.startOfSelection()));
+		selLength = itemText.endOfParagraph(itemText.nrOfParagraph(itemText.endOfSelection())) - selStart;
+	}
+	else
+	{
+		//extend selection to whole paragraph
+		selStart  = itemText.startOfParagraph(itemText.nrOfParagraph(CPos));
+		selLength = itemText.endOfParagraph(itemText.nrOfParagraph(CPos)) - selStart;
+	}
+	if (includeEOL)
+		selLength += 1;
+	selLength = qMin(selLength, itemText.length() - selStart);
+
+	itemText.select(selStart, selLength);
+	HasSel = true;
+}
+
 void PageItem_TextFrame::deselectAll()
 {
 	if ( itemText.lengthOfSelection() > 0 )
@@ -3647,10 +3670,10 @@
 		if (action == PARAMFULL && m_Doc->appMode == modeEdit)
 		{
 			//action is for paragraph where cursor is
-			ExpandParSel();
+			expandParaSelection(true);
 			action = PARAMSEL;
 		}
-		if (CPos >= itemText.length() && itemTextSaxed.isEmpty() && action == PARAMSEL && m_Doc->appMode == modeEdit)
+		if (CPos >= itemText.length() && itemTextSaxed.isEmpty() && action == PARAMFULL && m_Doc->appMode == modeEdit)
 		{ 
 			//case when cursor is after last character without selection and nothing was and will be done
 			//changes will be ignored
@@ -3667,8 +3690,17 @@
 			{
 				if (action == PARAMFULL || action == PARAMSEL)
 				{
-					itemTextSaxed = ss->get("STEXT_OLD");
 					newState = false;
+					if (itemTextSaxed.length() > 0)
+					{
+						/*QString tmpStr = ss->get("STEXT_NEW");
+						newState = (tmpStr.length() > 0 && tmpStr != itemTextSaxed);*/
+						newState = true;
+					}
+					if (newState == false)
+					{
+						itemTextSaxed = ss->get("STEXT_OLD");
+					}
 				}
 				else if (action == INSSAX || action == INS)
 				{
@@ -3698,7 +3730,7 @@
 			if (action == PARAMFULL && m_Doc->appMode == modeEdit)
 			{
 				//action is for paragraph where cursor is
-				ExpandParSel();
+				expandParaSelection(true);
 				action = PARAMSEL;
 			}
 			if (action == PARAMSEL)

Modified: branches/Version135/Scribus/scribus/pageitem_textframe.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16518&path=/branches/Version135/Scribus/scribus/pageitem_textframe.h
==============================================================================
--- branches/Version135/Scribus/scribus/pageitem_textframe.h (original)
+++ branches/Version135/Scribus/scribus/pageitem_textframe.h Sat Mar 26 14:05:18 2011
@@ -67,6 +67,7 @@
 	void setNewPos(int oldPos, int len, int dir);
 	void ExpandSel(int dir, int oldPos);
 	void ExpandParSel(); //expand selection to whole paragrpah(s)
+	void expandParaSelection(bool includeEOL = false);
 	void deselectAll();
 	
 	virtual void invalidateLayout();

Modified: branches/Version135/Scribus/scribus/propertiespalette.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=16518&path=/branches/Version135/Scribus/scribus/propertiespalette.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/propertiespalette.cpp (original)
+++ branches/Version135/Scribus/scribus/propertiespalette.cpp Sat Mar 26 14:05:18 2011
@@ -4276,43 +4276,30 @@
 
 void PropertiesPalette::NewAlignement(int a)
 {
-	int StartSel = 0, EndSel = 0, LenSel = 0;
+	int selStart = 0, selEnd = 0, selLength = 0;
 	if (!HaveDoc || !HaveItem || !m_ScMW || m_ScMW->scriptIsRunning())
 		return;
 	if (CurItem->asTextFrame())
 	{
 		// hack for apply left align for text with no align at all
 		//so during Undo/Redo some align will be applied
+		StoryText& itemText(CurItem->itemText);
 		if (doc->appMode == modeEdit)
 		{
 			//selected parapgraph(s) only
-			CurItem->asTextFrame()->ExpandParSel();
-			StartSel = CurItem->itemText.startOfSelection();
-			EndSel = CurItem->itemText.endOfSelection();
-			for (uint i = CurItem->itemText.nrOfParagraph(StartSel); i <= CurItem->itemText.nrOfParagraph(EndSel); i++)
-			{
-				if (CurItem->itemText.paragraphStyle(CurItem->itemText.startOfParagraph(i)).alignment() == 0)
-				{
-					CurItem->itemText.select(CurItem->itemText.startOfParagraph(i), CurItem->itemText.endOfParagraph(i) - CurItem->itemText.startOfParagraph(i));
-					CurItem->HasSel = true;
-					doc->itemSelection_SetAlignment(0);
-				}
-			}
+			selStart = (itemText.lengthOfSelection() > 0) ? itemText.startOfSelection() : CurItem->CPos;
+			selEnd   = (itemText.lengthOfSelection() > 0) ? itemText.endOfSelection() : CurItem->CPos;
+			selStart = itemText.startOfParagraph( itemText.nrOfParagraph(selStart) );
+			selEnd   = itemText.endOfParagraph  ( itemText.nrOfParagraph(selEnd) );
 		}
 		else
 		{
 			//for whole frame
-			for (uint i = 0; i <= CurItem->itemText.nrOfParagraph(CurItem->itemText.lastInFrame()); i++)
-			{
-				if (CurItem->itemText.paragraphStyle(CurItem->itemText.startOfParagraph(i)).alignment() == 0)
-				{
-					CurItem->CPos = CurItem->itemText.startOfParagraph(i);
-					doc->itemSelection_SetAlignment(0);
-				}
-
-			}
-		}
-		CurItem->itemTextSaxed = CurItem->getItemTextSaxed(doc->appMode == modeEdit? PageItem::PARAGRAPH : PageItem::FRAME);
+			selStart = itemText.startOfParagraph( 0 );
+			selEnd   = itemText.endOfParagraph  ( itemText.nrOfParagraph(itemText.lastInFrame()) );
+		}
+		selLength = qMin(selEnd - selStart + 1, itemText.length() - selStart);
+		CurItem->itemTextSaxed = CurItem->getItemTextSaxed(selStart, selLength);
 //		CurItem->asTextFrame()->lastAction4Paragraph = true;
 	}
 	doc->itemSelection_SetAlignment(a);




More information about the scribus-commit mailing list