Commit 3c12bddb authored by Dmitry Kazakov's avatar Dmitry Kazakov

Compress events in the Advanced Color Selector

Fixes T2370
BUG:362076
parent 7436999f
......@@ -307,11 +307,10 @@ void KisColorSelector::mouseEvent(QMouseEvent *e)
m_grabbingComponent->mouseEvent(e->x(), e->y());
KoColor color = m_mainComponent->currentColor();
Acs::ColorRole role = Acs::buttonsToRole(e->button(), e->buttons());
m_currentRealColor = color;
updateColorPreview(color);
Acs::ColorRole role = Acs::buttonsToRole(e->button(), e->buttons());
updateColor(color, role, false);
requestUpdateColorAndPreview(color, role);
}
}
......
......@@ -109,6 +109,10 @@ KisColorSelectorBase::KisColorSelectorBase(QWidget *parent) :
m_hideTimer->setInterval(0);
m_hideTimer->setSingleShot(true);
connect(m_hideTimer, SIGNAL(timeout()), this, SLOT(hidePopup()));
using namespace std::placeholders; // For _1 placeholder
auto function = std::bind(&KisColorSelectorBase::slotUpdateColorAndPreview, this, _1);
m_updateColorCompressor.reset(new ColorCompressorType(20 /* ms */, function));
}
KisColorSelectorBase::~KisColorSelectorBase()
......@@ -331,6 +335,17 @@ void KisColorSelectorBase::updateColor(const KoColor &color, Acs::ColorRole role
}
}
void KisColorSelectorBase::requestUpdateColorAndPreview(const KoColor &color, Acs::ColorRole role)
{
m_updateColorCompressor->start(qMakePair(color, role));
}
void KisColorSelectorBase::slotUpdateColorAndPreview(QPair<KoColor, Acs::ColorRole> color)
{
updateColorPreview(color.first);
updateColor(color.first, color.second, false);
}
void KisColorSelectorBase::setColor(const KoColor& color)
{
Q_UNUSED(color);
......
......@@ -23,6 +23,8 @@
#include <QPointer>
#include <kis_canvas2.h>
#include "kis_acs_types.h"
#include "kis_signal_compressor_with_param.h"
class KoColor;
class QTimer;
......@@ -80,6 +82,7 @@ protected:
void setHidingTime(int time);
bool isPopup() const { return m_isPopup; }
void mouseMoveEvent(QMouseEvent *event);
void requestUpdateColorAndPreview(const KoColor &color, Acs::ColorRole role);
private:
void commitColor(const KoColor& koColor, Acs::ColorRole role);
......@@ -91,6 +94,11 @@ protected Q_SLOTS:
/// if you overwrite this, keep in mind, that you should set the colour only, if m_colorUpdateAllowed is true
virtual void canvasResourceChanged(int key, const QVariant& v);
public Q_SLOTS:
// This is a private interface for signal compressor, don't use it.
// Use requestUpdateColorAndPreview() instead
void slotUpdateColorAndPreview(QPair<KoColor, Acs::ColorRole> color);
private:
void lazyCreatePopup();
......@@ -109,6 +117,9 @@ private:
bool m_isPopup; //this instance is a popup
bool m_hideOnMouseClick;
KisColorPreviewPopup* m_colorPreviewPopup;
typedef KisSignalCompressorWithParam<QPair<KoColor, Acs::ColorRole>> ColorCompressorType;
QScopedPointer<ColorCompressorType> m_updateColorCompressor;
};
#endif
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