Commit c5621355 authored by Sven Langkamp's avatar Sven Langkamp

Pick color from canvas directly if the cursor is over the canvas

parent 1afa4384
...@@ -29,6 +29,9 @@ ...@@ -29,6 +29,9 @@
#include "kis_icon.h" #include "kis_icon.h"
#include "kis_screen_color_picker.h" #include "kis_screen_color_picker.h"
#include "KisMainWindow.h"
#include <kis_canvas2.h>
#include "kis_wrapped_rect.h"
struct KisScreenColorPicker::Private struct KisScreenColorPicker::Private
{ {
...@@ -119,6 +122,32 @@ void KisScreenColorPicker::setCurrentColor(KoColor c) ...@@ -119,6 +122,32 @@ void KisScreenColorPicker::setCurrentColor(KoColor c)
KoColor KisScreenColorPicker::grabScreenColor(const QPoint &p) 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();
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()) {
imagePoint = KisWrappedRect::ptToWrappedPt(imagePoint.toPoint(), image->bounds());
}
KoColor pickedColor = KoColor();
image->projection()->pixel(imagePoint.x(), imagePoint.y(), &pickedColor);
return pickedColor;
}
}
}
const QDesktopWidget *desktop = QApplication::desktop(); const QDesktopWidget *desktop = QApplication::desktop();
const QPixmap pixmap = QGuiApplication::screens().at(desktop->screenNumber())->grabWindow(desktop->winId(), const QPixmap pixmap = QGuiApplication::screens().at(desktop->screenNumber())->grabWindow(desktop->winId(),
p.x(), p.y(), 1, 1); p.x(), p.y(), 1, 1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment