[Kde-pim] Text formatting stripped from text pasted into kmail composer.

Stephen Kelly steveire at gmail.com
Sat Mar 15 15:52:36 GMT 2008


Hi,

Thanks for that fix and for reviewing the patch.

It's not quite ready to go in. Don't worry anyway, it won't be forgotten.

Thomas McGuire wrote:
> Thanks very much for the patch, Stephen!
> For inserting links, I now use insertHtml with <a href=...>...</a>, that
> works great.
> For removing formatting, cursor.setCharFormat( cursor.block().charFormat()
> );

Actually insertHtml(...) removes existing formatting, as does 
cursor.setCharFormat( cursor.block().charFormat() ). To see it, make some
text bold, or bigger, then make it a link. The text formatting is reset to
plain and normal size. That's why I expected
QTextCharFormat::setAnchor(true) to merge 'link formatting' into the
format. (It does do this, but the document must be reloaded to see it).

Of course 'link formatting' can not be expected to mean underline+blue. I
intend to add some theming capability to kjots via stylesheets, so it could
be anything in that case. I've emailed the TT engineer again to see if 
setAnchor can be made to do that as it looks like it should in the
documentation.

I have a workaround in the meantime:
After applying the formatting I do:
        cursor.insertHtml( cursor.selection().toHtml() );
which applies the correct style.

Using cursor.setCharFormat( cursor.block().charFormat() ) to remove the link
also removes all other formatting (size, colour, font-weight). Removing
only the link formatting is tricky without knowing what that formatting is.

Any ideas on that one?

Another issue I've found is that when editing a link at the beginning of a
line, the preceeding newline is removed. I think it's a qt bug and I
couldn't come up with a workaround for it.

Alignment is currently removed when creating a link one the first word in a
line. This is probably related to the above.

> 
> I've modified the patch in some other places:
> - Insert a space after inserting the link so that the user can type away
>   without the link formatting
> - Don't check the URL, for example www.test.de is a valid URL (for me),
> but
>   KUrl doesn't like it.
> - Set focus to the lineedits of the link edit dialog
> - other small things
> 
> Attached the revised version of your patch. What do you think?
> In my opinion it's ready to go into KDEPIM, not sure how we could share
> this. Any ideas?

I've attached another revision. I changed some of the changes you made :).
It includes the workaround I mentioned above and:
  - Inserts a space only if it is at the last character in the block. In the 
    previous version, in cases where you want to make the word 'here'   
    in '...as he said in the letter (see here). In addition...', a space 
    would be inserted before the ')'. If making text a hyperlink in the 
    middle of a block of text I think that's what you'd want more of the 
    time.
  - Adds 'http://' to the href as a default protocol. If the recipient of a 
    mail recieves a document with <a href="www.google.com">text</a>, I think 
    the href is appended to the url of the parent page. At least with a  
    simple test on my machine with konqi and ff, the link becomes 
        file:///home/stephen/www.google.com
    With the new patch it becomes 
        http://www.google.com
  - Does setAnchor(false) when removing the link. I do still want to cleanly 
    remove link formatting. Just have to figure it out.
  - Show link text and href of a selected link in the statusbar.
  - Add the feature to the class doc.
  - Add methods for KMEditor to return the current link text and url if the 
    cursor is on a link.

> Regards,
> Thomas

In response to Ingo's mail I've also
  - Tried changing 'Link' to 'ki18nc("A Url link.", "Link")', but got 
    compile error:
        error: no matching function for call 
        to ‘KAction::setIconText(KLocalizedString)
  - Fixed the (C) issue. It looks like this needs to be changed all over kde
  - Renamed the methods.
  - Changed the ctor. This made it neccessary to change how focus shifts 
    around the dialog.
  - Fixed whitespace issue
  - Made the dialog non-modal.
  - Removed the margin and spacing settings.
  - Left the handling of an empty text field up to the developer using the 
    dialog. In this case I implemented Ingo's suggestion.
  - Didn't use UI file. Might do so before committing.

Thanks for the comments Ingo.

I also don't like the minimum width thing, but I wasn't sure what to do
about it. I didn't want people to need to have to resize the dialog each
time they use it.

So remaining issues are:
  - Removing only link formatting when removing a link
  - Workaround for removing newline when editing link. I'll submit it to 
    qt-bugs soon. It's happening at the line:
        cursor.insertText( linkText, format );
  - I'd like to show the insert-link icon in the status bar as well. Is that 
    possible?
  - Need to ask artists to create the icon.

As I said, it's a work in progress...

Anything else?

Cheers,

Steve.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kmaileditlink.patch
Type: text/x-diff
Size: 14907 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-pim/attachments/20080315/72f6716f/attachment.patch>
-------------- next part --------------
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/


More information about the kde-pim mailing list