r16958 by jghali - #10348: unwanted text center align in Story editor

scribus-commit scribus-commit at lists.scribus.net
Sat Nov 5 20:31:47 UTC 2011


Author: jghali
Date: Sat Nov  5 20:31:47 2011
New Revision: 16958

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=16958
Log:
#10348: unwanted text center align in Story editor

Modified:
    branches/Version135/Scribus/scribus/storyeditor.cpp
    branches/Version135/Scribus/scribus/storyeditor.h

Modified: branches/Version135/Scribus/scribus/storyeditor.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16958&path=/branches/Version135/Scribus/scribus/storyeditor.cpp
==============================================================================
--- branches/Version135/Scribus/scribus/storyeditor.cpp (original)
+++ branches/Version135/Scribus/scribus/storyeditor.cpp Sat Nov  5 20:31:47 2011
@@ -594,25 +594,33 @@
 
 void SEditor::setAlign(int align)
 {
+	QTextCursor tCursor = this->textCursor();
+	setAlign(tCursor, align);
+}
+
+void SEditor::setAlign(QTextCursor& tCursor, int align)
+{
 	++blockContentsChangeHook;
+	QTextBlockFormat blockFormat;
 	switch (align)
 	{
 	case 0:
-		setAlignment(Qt::AlignLeft);
+		blockFormat.setAlignment(Qt::AlignLeft);
 		break;
 	case 1:
-		setAlignment(Qt::AlignCenter);
+		blockFormat.setAlignment(Qt::AlignCenter);
 		break;
 	case 2:
-		setAlignment(Qt::AlignRight);
+		blockFormat.setAlignment(Qt::AlignRight);
 		break;
 	case 3:
 	case 4:
-		setAlignment(Qt::AlignJustify);
+		blockFormat.setAlignment(Qt::AlignJustify);
 		break;
 	default:
 		break;
 	}
+	tCursor.setBlockFormat(blockFormat);
 	--blockContentsChangeHook;
 }
 
@@ -784,37 +792,38 @@
 void SEditor::updateFromChars(int pa)
 {
 	int start = StyledText.startOfParagraph(pa);
-	int end = StyledText.endOfParagraph(pa);
+	int end   = StyledText.endOfParagraph(pa);
 	if (start >= end)
 		return;
 	setUpdatesEnabled(false);
 	int SelStart = start;
-	int SelEnd = 0;
+	int SelEnd   = start;
 	int pos = textCursor().position();
 	textCursor().clearSelection();
-	int Csty = StyledText.charStyle(start).effects();
+	int effects = StyledText.charStyle(start).effects();
 	for (int a = start; a < end; ++a)
 	{
-		if (Csty == StyledText.charStyle(a).effects())
+		if (effects == StyledText.charStyle(a).effects())
 			SelEnd++;
 		else
 		{
 			textCursor().setPosition(SelStart);
 			textCursor().setPosition(SelEnd, QTextCursor::KeepAnchor);
-			setEffects(Csty);
+			setEffects(effects);
 			textCursor().clearSelection();
-			Csty = StyledText.charStyle(a).effects();
+			effects = StyledText.charStyle(a).effects();
 			SelStart = SelEnd;
 			SelEnd++;
 		}
 	}
-	textCursor().setPosition(SelStart);
-	textCursor().setPosition(SelEnd, QTextCursor::KeepAnchor);
-	setEffects(Csty);
-	textCursor().clearSelection();
-	setAlign(StyledText.paragraphStyle(start).alignment());
+	QTextCursor tCursor = textCursor();
+	tCursor.setPosition(SelStart);
+	tCursor.setPosition(SelEnd, QTextCursor::KeepAnchor);
+	setEffects(tCursor, effects);
+	setAlign(tCursor, StyledText.paragraphStyle(start).alignment());
+	tCursor.clearSelection();
 	setUpdatesEnabled(true);
-	QTextCursor tCursor = textCursor();
+	tCursor = textCursor();
 	tCursor.setPosition(pos);
 	setTextCursor(tCursor);
 }
@@ -865,27 +874,32 @@
 	StoredSel = false;
 }
 
-void SEditor::setEffects(int Csty)
+void SEditor::setEffects(int effects)
+{
+	QTextCursor tCursor = textCursor();
+	setEffects(tCursor, effects);
+	//setTextCursor(tCursor);
+}
+
+void SEditor::setEffects(QTextCursor& tCursor, int effects)
 {
 	++blockContentsChangeHook;
 	QTextCharFormat charF;
-	if (Csty & 8)
+	if (effects & 8)
 		charF.setFontUnderline(true);
 	else
 		charF.setFontUnderline(false);
-	if (Csty & 16)
+	if (effects & 16)
 		charF.setFontStrikeOut(true);
 	else
 		charF.setFontStrikeOut(false);
-	if (Csty & 1)
+	if (effects & 1)
 		charF.setVerticalAlignment(QTextCharFormat::AlignSuperScript);
-	else if (Csty & 2)
+	else if (effects & 2)
 		charF.setVerticalAlignment(QTextCharFormat::AlignSubScript);
 	else
 		charF.setVerticalAlignment(QTextCharFormat::AlignNormal);
-	QTextCursor tCursor = textCursor();
 	tCursor.setCharFormat(charF);
-	setTextCursor(tCursor);
 	--blockContentsChangeHook;
 }
 

Modified: branches/Version135/Scribus/scribus/storyeditor.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16958&path=/branches/Version135/Scribus/scribus/storyeditor.h
==============================================================================
--- branches/Version135/Scribus/scribus/storyeditor.h (original)
+++ branches/Version135/Scribus/scribus/storyeditor.h Sat Nov  5 20:31:47 2011
@@ -84,7 +84,7 @@
 	SEditor (QWidget* parent, ScribusDoc *docc, StoryEditor* parentSE);
 	~SEditor() {};
 	void setCurrentDocument(ScribusDoc *docc);
-	void setAlign(int style);
+	void setAlign(int align);
 	void saveItemText(PageItem *currItem);
 	void loadItemText(PageItem *currItem);
 	void loadText(QString tx, PageItem *currItem);
@@ -93,7 +93,7 @@
 	void updateSel(const CharStyle& style);
 	void updateSel(const ParagraphStyle& style);
 	void deleteSel();
-	void setEffects(int Csty);
+	void setEffects(int effects);
 	void setColor(bool marker);
 
 	void insertChars(const QString& text);
@@ -144,6 +144,9 @@
 
 	void insertUpdate(int position, int len);
 
+	void setAlign(QTextCursor& tCursor, int style);
+	void setEffects(QTextCursor& tCursor, int effects);
+
 	int  blockContentsChangeHook;
 	void keyPressEvent(QKeyEvent *k);
 	void inputMethodEvent(QInputMethodEvent *event);




More information about the scribus-commit mailing list