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

List:       kde-commits
Subject:    [krita/krita-testing-wolthera] libs/ui/widgets: Improve the view selection when color picking
From:       Boudewijn Rempt <boud () valdyas ! org>
Date:       2016-09-02 12:31:02
Message-ID: E1bfncc-0002Kv-6r () code ! kde ! org
[Download RAW message or body]

Git commit 99b11b2bfa6a5b3af93c83de5877e4b1edbe07ee by Boudewijn Rempt.
Committed on 02/09/2016 at 12:30.
Pushed by rempt into branch 'krita-testing-wolthera'.

Improve the view selection when color picking

We can easily grab a list of all existing views and check whether
they are under the cursor. Color picking from a krita image now
gets the color directly no matter the active window or view.

M  +11   -15   libs/ui/widgets/kis_screen_color_picker.cpp

http://commits.kde.org/krita/99b11b2bfa6a5b3af93c83de5877e4b1edbe07ee

diff --git a/libs/ui/widgets/kis_screen_color_picker.cpp \
b/libs/ui/widgets/kis_screen_color_picker.cpp index a7b89f2..c637db0 100644
--- a/libs/ui/widgets/kis_screen_color_picker.cpp
+++ b/libs/ui/widgets/kis_screen_color_picker.cpp
@@ -32,6 +32,7 @@
 #include "KisMainWindow.h"
 #include <kis_canvas2.h>
 #include "kis_wrapped_rect.h"
+#include "KisPart.h"
 
 struct KisScreenColorPicker::Private
 {
@@ -122,23 +123,17 @@ void KisScreenColorPicker::setCurrentColor(KoColor c)
 
 KoColor KisScreenColorPicker::grabScreenColor(const QPoint &p)
 {
-    QWidget* topLevelWidget = parentWidget();
-    while (topLevelWidget->parentWidget())
-        topLevelWidget = topLevelWidget->parentWidget();
-
-    KisMainWindow* window = dynamic_cast<KisMainWindow*>(topLevelWidget);
-    KisView* activeView = window->activeView();
-    if(activeView) {
-        QWidget* canvasWidget = activeView->canvasBase()->canvasWidget();
+    // First check whether we're clicking on a Krita window for some real color \
picking +    Q_FOREACH(KisView *view, KisPart::instance()->views()) {
+        QWidget *canvasWidget = view->canvasBase()->canvasWidget();
         QPoint widgetPoint = canvasWidget->mapFromGlobal(p);
 
-        if(canvasWidget->rect().contains(widgetPoint))
-        {
-            QPointF imagePoint = \
                activeView->canvasBase()->coordinatesConverter()->widgetToImage(widgetPoint);
                
-            KisImageWSP image = activeView->image();
-            if(image)
-            {
-                if (activeView->image()->wrapAroundModePermitted()) {
+        if (canvasWidget->rect().contains(widgetPoint)) {
+            QPointF imagePoint = \
view->canvasBase()->coordinatesConverter()->widgetToImage(widgetPoint); +            \
KisImageWSP image = view->image(); +
+            if (image) {
+                if (image->wrapAroundModePermitted()) {
                     imagePoint = KisWrappedRect::ptToWrappedPt(imagePoint.toPoint(), \
image->bounds());  }
                 KoColor pickedColor = KoColor();
@@ -148,6 +143,7 @@ KoColor KisScreenColorPicker::grabScreenColor(const QPoint &p)
         }
     }
 
+    // And otherwise, we'll check the desktop
     const QDesktopWidget *desktop = QApplication::desktop();
     const QPixmap pixmap = \
                QGuiApplication::screens().at(desktop->screenNumber())->grabWindow(desktop->winId(),
                
                                                                                      \
p.x(), p.y(), 1, 1);


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

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