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

List:       kde-commits
Subject:    [calligra] libs/kotext: Fix applying style to a caret without selection.
From:       Pierre Stirnweiss <pstirnweiss () googlemail ! com>
Date:       2013-01-12 12:42:57
Message-ID: 20130112124257.C00C8A6091 () git ! kde ! org
[Download RAW message or body]

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

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/bb199de88d8b27ca1062becc20dd0e34d8c3fcba

diff --git a/libs/kotext/KoTextEditor_format.cpp \
b/libs/kotext/KoTextEditor_format.cpp index 125be99..5a35fe8 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);  }
@@ -500,7 +508,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