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

scribus-commit scribus-commit at lists.scribus.net
Sat Nov 5 20:33:13 UTC 2011


Author: jghali
Date: Sat Nov  5 20:33:13 2011
New Revision: 16959

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

Modified:
    trunk/Scribus/scribus/ui/storyeditor.cpp
    trunk/Scribus/scribus/ui/storyeditor.h

Modified: trunk/Scribus/scribus/ui/storyeditor.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16959&path=/trunk/Scribus/scribus/ui/storyeditor.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/storyeditor.cpp (original)
+++ trunk/Scribus/scribus/ui/storyeditor.cpp Sat Nov  5 20:33:13 2011
@@ -599,25 +599,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;
 }
 
@@ -789,37 +797,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);
 }
@@ -870,27 +879,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;
 }
 
@@ -1017,17 +1031,6 @@
 	paste();
 }
 
-/*
-Q_3PopupMenu* SEditor::createPopupMenu(const QPoint & pos)
-{
-	Q_3PopupMenu *p = Q_3TextEdit::createPopupMenu(pos);
-	p->removeItemAt(0);
-	p->removeItemAt(0);
-	p->removeItemAt(0);
-	p->removeItemAt(3);
-	return p;
-}
-*/
 void SEditor::SelClipChange()
 {
 	emit PasteAvail();

Modified: trunk/Scribus/scribus/ui/storyeditor.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16959&path=/trunk/Scribus/scribus/ui/storyeditor.h
==============================================================================
--- trunk/Scribus/scribus/ui/storyeditor.h (original)
+++ trunk/Scribus/scribus/ui/storyeditor.h Sat Nov  5 20:33:13 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);
@@ -153,7 +156,6 @@
 	virtual bool canInsertFromMimeData( const QMimeData * source ) const;
 	virtual QMimeData * createMimeDataFromSelection () const;
 	virtual void insertFromMimeData ( const QMimeData * source );
-//	Q3PopupMenu* createPopupMenu(const QPoint & pos);
 	StoryEditor* parentStoryEditor;
 
 protected slots:




More information about the scribus-commit mailing list