[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [calligra/calligra/2.6] libs/kotext: Fix applying style to a caret without selection.
From:       Pierre Stirnweiss <pstirnweiss () googlemail ! com>
Date:       2013-01-06 9:11:55
Message-ID: 20130106091155.6D397A6091 () git ! kde ! org
[Download RAW message or body]

Git commit d4cf733c209f567a0d2993a83db203a24b4bc8cf by Pierre Stirnweiss.
Committed on 05/01/2013 at 08:42.
Pushed by pstirnweiss into branch 'calligra/2.6'.

Fix applying style to a caret without selection.

When applying style to a caret without a selection, the previous
character style properties, which are not set by the style being
applied, were kept. We now reset the caret's format to the frame's text
 properties, apply the paragraph style's properties, and eventually the
 character style (if we set one).
REVIEW = 108191

M  +14   -3    libs/kotext/KoTextEditor_format.cpp

http://commits.kde.org/calligra/d4cf733c209f567a0d2993a83db203a24b4bc8cf

diff --git a/libs/kotext/KoTextEditor_format.cpp \
b/libs/kotext/KoTextEditor_format.cpp index c8e3c3c..93b0fbb 100644
--- a/libs/kotext/KoTextEditor_format.cpp
+++ b/libs/kotext/KoTextEditor_format.cpp
@@ -447,10 +447,18 @@ void KoTextEditor::setStyle(KoCharacterStyle *style)
 
     recursivelyVisitSelection(d->document->rootFrame()->begin(), visitor);
 
-    if (!isEditProtected() && caretAnchor == caretPosition) {
+    if (!isEditProtected() && caretAnchor == caretPosition) { //if there is no \
selection, it can happen that the caret does not get the proper style applied \
(begining of a block). We need to force it. +         //applying a style is absolute, \
so first initialise the caret with the frame's style, then apply the paragraph's. \
Finally apply the character style +        QTextCharFormat charFormat = \
KoTextDocument(d->document).frameCharFormat(); +        KoStyleManager *styleManager \
= KoTextDocument(d->document).styleManager(); +        KoParagraphStyle \
*paragraphStyle = styleManager->paragraphStyle(d->caret.charFormat().intProperty(KoParagraphStyle::StyleId));
 +        if (paragraphStyle) {
+            paragraphStyle->KoCharacterStyle::applyStyle(charFormat);
+        }
+        d->caret.setCharFormat(charFormat);
         style->applyStyle(&(d->caret));
     }
-    else {
+    else { //if the caret has a selection, the visitor has already applied the \
style, reset the caret's position so it picks the proper style.  \
d->caret.setPosition(caretAnchor);  d->caret.setPosition(caretPosition, \
QTextCursor::KeepAnchor);  }
@@ -499,7 +507,10 @@ void KoTextEditor::setStyle(KoParagraphStyle *style)
 
     recursivelyVisitSelection(d->document->rootFrame()->begin(), visitor);
 
-    if (!isEditProtected() && caretAnchor == caretPosition) {
+    if (!isEditProtected() && caretAnchor == caretPosition) { //if there is no \
selection, it can happen that the caret does not get the proper style applied \
(begining of a block). We need to force it. +        //applying a style is absolute, \
so first initialise the caret with the frame's style, then apply the paragraph style \
+        QTextCharFormat charFormat = KoTextDocument(d->document).frameCharFormat(); \
+        d->caret.setCharFormat(charFormat);  \
style->KoCharacterStyle::applyStyle(&(d->caret));  }
     else {


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic