r17256 by fschmid - Applied Patch from Bug 10550: "Story editor does not show pre-edit strings when a input method is active."

scribus-commit scribus-commit at lists.scribus.net
Sun Jan 29 09:44:55 UTC 2012


Author: fschmid
Date: Sun Jan 29 09:44:55 2012
New Revision: 17256

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17256
Log:
Applied Patch from Bug 10550: "Story editor does not show pre-edit strings when a input method is active."

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

Modified: branches/Version14x/Scribus/scribus/storyeditor.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17256&path=/branches/Version14x/Scribus/scribus/storyeditor.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/storyeditor.cpp (original)
+++ branches/Version14x/Scribus/scribus/storyeditor.cpp Sun Jan 29 09:44:55 2012
@@ -267,6 +267,7 @@
 	setAutoFillBackground(true);
 	connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(ClipChange()));
 	connect(this->document(), SIGNAL(contentsChange(int, int, int)), this, SLOT(handleContentsChange(int, int, int)));
+	SuspendContentsChange = 0;
 }
 
 void SEditor::setCurrentDocument(ScribusDoc *docc)
@@ -278,14 +279,48 @@
 void SEditor::inputMethodEvent(QInputMethodEvent *event)
 {
 	QString uc = event->commitString();
-	if ((!uc.isEmpty()) && ((*doc->AllFonts)[CurrFont].canRender(uc[0])))
+	SuspendContentsChange = 1;	// prevent our handler from doing anything
+	bool changed = false;
+	int pos;
+	if(textCursor().hasSelection())
+	{
+		pos =  textCursor().selectionStart();
+		StyledText.removeChars(pos, textCursor().selectionEnd() - pos);
+		changed = true;
+	}
+	pos = -1;
+	if(!uc.isEmpty())
+	{
+		if ((*doc->AllFonts)[CurrFont].canRender(uc[0]))
+		{
+			pos = textCursor().hasSelection() ? textCursor().selectionStart() : textCursor().position();
+			pos = qMin(pos, StyledText.length());
+		}
+		else
+		{
+			event->setCommitString("");
+		}
+	}
+	QTextEdit::inputMethodEvent(event);
+	SuspendContentsChange = 0;
+	if(pos >= 0)
+	{
+		handleContentsChange(pos, 0, uc.length());
+		changed = true;
+	}
+	if(changed)
+	{
+		emit SideBarUp(true);
+		emit SideBarUpdate();
+	}
+/*	if ((!uc.isEmpty()) && ((*doc->AllFonts)[CurrFont].canRender(uc[0])))
 	{
 		// Should be processed by the handleContentsChange slot
 		// insertCharsInternal(event->commitString());
 		QTextEdit::inputMethodEvent(event);
 		emit SideBarUp(true);
 		emit SideBarUpdate();
-	}
+	} */
 }
 
 void SEditor::keyPressEvent(QKeyEvent *k)
@@ -445,6 +480,10 @@
 
 void SEditor::handleContentsChange(int position, int charsRemoved, int charsAdded)
 {
+	// As of Qt 4.7.4, Cococa-QTextEdit output of input method is broken.
+	// We need a workaround to avoit the bug.
+	if(SuspendContentsChange != 0)
+		return;
 	if (blockContentsChangeHook <= 0)
 	{
 		if (charsRemoved > 0 && StyledText.length() > 0)
@@ -2009,6 +2048,7 @@
 	connect(Editor, SIGNAL(SideBarUp(bool )), EditorBar, SLOT(setRepaint(bool )));
 	connect(Editor, SIGNAL(SideBarUpdate( )), EditorBar, SLOT(doRepaint()));
 	connect(Editor->document(), SIGNAL(contentsChange(int, int, int)), Editor, SLOT(handleContentsChange(int, int, int)));
+	Editor->SuspendContentsChange = 0;
 	// 10/12/2004 - pv - #1203: wrong selection on double click
 //	connect(Editor, SIGNAL(doubleClicked(int, int)), this, SLOT(doubleClick(int, int)));
 	connect(EditorBar, SIGNAL(ChangeStyle(int, const QString& )), this, SLOT(changeStyleSB(int, const QString&)));

Modified: branches/Version14x/Scribus/scribus/storyeditor.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17256&path=/branches/Version14x/Scribus/scribus/storyeditor.h
==============================================================================
--- branches/Version14x/Scribus/scribus/storyeditor.h (original)
+++ branches/Version14x/Scribus/scribus/storyeditor.h Sun Jan 29 09:44:55 2012
@@ -133,6 +133,7 @@
 	int SelParaEnd;
 	int SelCharStart;
 	int SelCharEnd;
+	int SuspendContentsChange;	// input method
 
 protected:
 




More information about the scribus-commit mailing list