Bug 408445 - Enhancements in Reference tool
Summary: Enhancements in Reference tool
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: Usability (show other bugs)
Version: git master (please specify the git hash!)
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Krita Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-06-08 06:08 UTC by Dmitrii Utkin
Modified: 2019-06-21 08:48 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitrii Utkin 2019-06-08 06:08:03 UTC
I continue using/testing the updated reference image tool, and faced with few flaws:

1) Unable to paste reference image from clipboard when the image copied from browser (it's copied as multi mime-type but queried as an plain image)
2) No menu item to paste reference image from clipboard (like Edit -> Paste as Reference Image)
3) No shortcut to paste reference image from clipboard (Like Shift+Ctrl+R)
4) The Paste button on the reference tool dock has non-standard behavior and disables and enables in depends on is there any picture in the clipboard or not. The usual Paste action is always active, so it just pastes whenever is there any picture in clipboard.
5) If you copy a large picture into clipboard and switch to reference image tool krita freezes for few seconds. That's because of the availability of the picture in clipboard is checked by decoding the full picture (and then decoding it again upon paste reference image). 
6) There is disappointing message "Could not load image from clipboard." when you try to paste reference image (actually unreachable in normal case)..


So I'd like to make changes here:
1) Add support for multi mime-type clipboard
2,3) Add menu item and shortcut
4,5,6) Make Paste from clipboard button on the reference tool dock always enabled and just do nothing upon unsuccessful image decoding.
Comment 1 Dmitrii Utkin 2019-06-08 07:42:08 UTC
Also I found that "paste image" tool decodes image ineffectively - it decodes all supported variants and then chose one by the priority. In my test it was decoding 4 times and Krita freezes for 6 seconds.. I'd like to optimize it too by:

1) querying the clipboard image, return it in case of success
2) else traverse the supported mime-types in *order of priority* and try to decode the image, return it in case of success



In addition to 5) there is a KisClipboard::clipboardDataChanged() slot which freezes Krita for few seconds when you copy a large image to clipboard and just switch to Krita/create new image. The way of detecting "is there an image" is unreliable too. "cb->image()" just decodes (and freezes Krita) the main image without respecting the multi-mime-type images. There should be a way to detect clipboard image data without full reading of the image. Maybe QImageReader or QImageIOHandler is the way to go.
For me this piece of code looks strange:


        if (cb->mimeData()->hasImage()) {

            QImage qimage = cb->image();
            if (!qimage.isNull())
                m_hasClip = true;

            const QMimeData *cbData = cb->mimeData();
            QByteArray mimeType("application/x-krita-selection");
            if (cbData && cbData->hasFormat(mimeType))
                m_hasClip = true;
        }


I think it may be rewritten like this without losing anything (in exception of freeze):

        if (cb->mimeData()->hasImage()) {
            m_hasClip = true;
        }

For now I just leave it as is, because it needs more testing. Maybe will re-create it as a new bug.
Comment 2 Dmitrii Utkin 2019-06-08 08:15:12 UTC
MR: https://invent.kde.org/kde/krita/merge_requests/39
Comment 3 Halla Rempt 2019-06-21 08:48:39 UTC
Ha, that was merged, so we can close this bug :-) Thanks for the patch!