r17255 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:17 UTC 2012


Author: fschmid
Date: Sun Jan 29 09:44:17 2012
New Revision: 17255

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

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=17255&path=/trunk/Scribus/scribus/ui/storyeditor.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/storyeditor.cpp (original)
+++ trunk/Scribus/scribus/ui/storyeditor.cpp Sun Jan 29 09:44:17 2012
@@ -269,6 +269,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)
@@ -280,14 +281,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)
@@ -441,6 +476,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)
@@ -2012,6 +2051,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: trunk/Scribus/scribus/ui/storyeditor.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17255&path=/trunk/Scribus/scribus/ui/storyeditor.h
==============================================================================
--- trunk/Scribus/scribus/ui/storyeditor.h (original)
+++ trunk/Scribus/scribus/ui/storyeditor.h Sun Jan 29 09:44:17 2012
@@ -133,6 +133,7 @@
 	int SelParaEnd;
 	int SelCharStart;
 	int SelCharEnd;
+	int SuspendContentsChange;	// input method
 
 protected:
 




More information about the scribus-commit mailing list