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

List:       kde-commits
Subject:    [krita/krita-testing-wolthera] libs/ui/widgets: Make moving the cursor around more pleasant
From:       Wolthera van Hovell tot Westerflier <griffinvalley () gmail ! com>
Date:       2016-08-15 13:31:57
Message-ID: E1bZHzh-0008NF-0Q () code ! kde ! org
[Download RAW message or body]

Git commit c52ca3f46c8bfd5d53385f84a17d1869e3ae403f by Wolthera van Hovell tot \
Westerflier. Committed on 15/08/2016 at 12:42.
Pushed by woltherav into branch 'krita-testing-wolthera'.

Make moving the cursor around more pleasant

Ref T2337

M  +22   -8    libs/ui/widgets/kis_visual_color_selector.cpp
M  +2    -1    libs/ui/widgets/kis_visual_color_selector.h

http://commits.kde.org/krita/c52ca3f46c8bfd5d53385f84a17d1869e3ae403f

diff --git a/libs/ui/widgets/kis_visual_color_selector.cpp \
b/libs/ui/widgets/kis_visual_color_selector.cpp index 61e4674..cf4f2eb 100644
--- a/libs/ui/widgets/kis_visual_color_selector.cpp
+++ b/libs/ui/widgets/kis_visual_color_selector.cpp
@@ -27,6 +27,7 @@
 #include <QList>
 
 #include "KoColorConversions.h"
+#include "kis_signal_compressor.h"
 
 struct KisVisualColorSelector::Private
 {
@@ -145,6 +146,8 @@ struct KisVisualColorSelectorShape::Private
     KoColor currentColor;
     int channel1;
     int channel2;
+    KisSignalCompressor *updateTimer;
+    bool mousePressActive = false;
 };
 
 KisVisualColorSelectorShape::KisVisualColorSelectorShape(QWidget *parent,
@@ -164,9 +167,7 @@ KisVisualColorSelectorShape::KisVisualColorSelectorShape(QWidget \
*parent,  m_d->channel1 = qBound(0, channel1, maxchannel);
     m_d->channel2 = qBound(0, channel2, maxchannel);
     this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
-    //m_d->gradient = QPixmap(size());
-    //m_d->pixmapsNeedUpdate = true;
-    //getPixmap();
+    m_d->updateTimer = new KisSignalCompressor(100 /* ms */, \
KisSignalCompressor::POSTPONE, this);  }
 
 KisVisualColorSelectorShape::~KisVisualColorSelectorShape()
@@ -314,14 +315,27 @@ QPointF \
KisVisualColorSelectorShape::convertKoColorToShapeCoordinate(KoColor c)  
 void KisVisualColorSelectorShape::mousePressEvent(QMouseEvent *e)
 {
-    QPointF coordinates = convertWidgetCoordinateToShapeCoordinate(e->pos());
-    KoColor col = convertShapeCoordinateToKoColor(coordinates);
-    setColor(col);
-    Q_EMIT sigNewColor(col);
+    m_d->mousePressActive = true;
 }
-void KisVisualColorSelectorShape::mouseReleaseEvent(QMouseEvent *)
+
+void KisVisualColorSelectorShape::mouseMoveEvent(QMouseEvent *e)
 {
+    if (m_d->mousePressActive==true && this->mask().contains(e->pos())) {
+        QPointF coordinates = convertWidgetCoordinateToShapeCoordinate(e->pos());
+        KoColor col = convertShapeCoordinateToKoColor(coordinates);
+        setColor(col);
+        if (!m_d->updateTimer->isActive()) {
+            Q_EMIT sigNewColor(col);
+            m_d->updateTimer->start();
+        }
+    } else {
+        e->ignore();
+    }
+}
 
+void KisVisualColorSelectorShape::mouseReleaseEvent(QMouseEvent *)
+{
+    m_d->mousePressActive = false;
 }
 void KisVisualColorSelectorShape::paintEvent(QPaintEvent*)
 {
diff --git a/libs/ui/widgets/kis_visual_color_selector.h \
b/libs/ui/widgets/kis_visual_color_selector.h index f8ed1bc..21eba9b 100644
--- a/libs/ui/widgets/kis_visual_color_selector.h
+++ b/libs/ui/widgets/kis_visual_color_selector.h
@@ -95,7 +95,8 @@ public Q_SLOTS:
     void slotSetActiveChannels(int channel1, int channel2);
 protected:
     void mousePressEvent(QMouseEvent *e);
-    void mouseReleaseEvent(QMouseEvent *);
+    void mouseMoveEvent(QMouseEvent *e);
+    void mouseReleaseEvent(QMouseEvent *e);
     void paintEvent(QPaintEvent*);
     void resizeEvent(QResizeEvent *);
 private:


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

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