Commit 38398393 authored by Wolthera van Hövell's avatar Wolthera van Hövell 🛍

Remove signal compressor, use block signals instead.

This makes the updating of the spinboxes much easier. Might
be using this method more commonly.

Ref T2337, T2438
parent 55350f02
...@@ -60,7 +60,7 @@ KisInternalColorSelector::KisInternalColorSelector(QWidget *parent, KoColor colo ...@@ -60,7 +60,7 @@ KisInternalColorSelector::KisInternalColorSelector(QWidget *parent, KoColor colo
connect(m_d->spinBoxSelector, SIGNAL(sigNewColor(KoColor)), this, SLOT(slotColorUpdated(KoColor))); connect(m_d->spinBoxSelector, SIGNAL(sigNewColor(KoColor)), this, SLOT(slotColorUpdated(KoColor)));
connect(this, SIGNAL(signalForegroundColorChosen(KoColor)), this, SLOT(slotLockSelector())); connect(this, SIGNAL(signalForegroundColorChosen(KoColor)), this, SLOT(slotLockSelector()));
m_d->compressColorChanges = new KisSignalCompressor(500 /* ms */, KisSignalCompressor::POSTPONE, this); m_d->compressColorChanges = new KisSignalCompressor(100 /* ms */, KisSignalCompressor::POSTPONE, this);
connect(m_d->compressColorChanges, SIGNAL(timeout()), this, SLOT(endUpdateWithNewColor())); connect(m_d->compressColorChanges, SIGNAL(timeout()), this, SLOT(endUpdateWithNewColor()));
} }
......
...@@ -29,25 +29,20 @@ ...@@ -29,25 +29,20 @@
struct KisSpinboxColorSelector::Private struct KisSpinboxColorSelector::Private
{ {
bool allowUpdates = false;
QList <QSpinBox*> spinBoxList; QList <QSpinBox*> spinBoxList;
QList <QDoubleSpinBox*> doubleSpinBoxList; QList <QDoubleSpinBox*> doubleSpinBoxList;
KoColor color; KoColor color;
const KoColorSpace *cs; const KoColorSpace *cs;
KisSignalCompressor *compressUpdates;
}; };
KisSpinboxColorSelector::KisSpinboxColorSelector(QWidget *parent, KoColor color) : QWidget(parent) , m_d(new Private) KisSpinboxColorSelector::KisSpinboxColorSelector(QWidget *parent, KoColor color) : QWidget(parent) , m_d(new Private)
{ {
QFormLayout *layout = new QFormLayout(this); QFormLayout *layout = new QFormLayout(this);
this->setLayout(layout); this->setLayout(layout);
this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
m_d->color = color; m_d->color = color;
slotSetColorSpace(m_d->color.colorSpace()); slotSetColorSpace(m_d->color.colorSpace());
m_d->compressUpdates = new KisSignalCompressor(500 /* ms */, KisSignalCompressor::POSTPONE, this);
connect(m_d->compressUpdates, SIGNAL(timeout()), this, SLOT(slotFinishUpdate()));
} }
KisSpinboxColorSelector::~KisSpinboxColorSelector() KisSpinboxColorSelector::~KisSpinboxColorSelector()
{ {
...@@ -60,9 +55,7 @@ void KisSpinboxColorSelector::slotSetColor(KoColor color) ...@@ -60,9 +55,7 @@ void KisSpinboxColorSelector::slotSetColor(KoColor color)
if (m_d->color.colorSpace() != m_d->cs) { if (m_d->color.colorSpace() != m_d->cs) {
slotSetColorSpace(m_d->color.colorSpace()); slotSetColorSpace(m_d->color.colorSpace());
} }
if (m_d->allowUpdates || QObject::sender() != this) { updateSpinboxesWithNewValues();
updateSpinboxesWithNewValues();
}
} }
void KisSpinboxColorSelector::slotSetColorSpace(const KoColorSpace *cs) void KisSpinboxColorSelector::slotSetColorSpace(const KoColorSpace *cs)
...@@ -151,7 +144,7 @@ void KisSpinboxColorSelector::createColorFromSpinboxValues() ...@@ -151,7 +144,7 @@ void KisSpinboxColorSelector::createColorFromSpinboxValues()
channelValues.fill(1.0); channelValues.fill(1.0);
QList<KoChannelInfo *> channels = KoChannelInfo::displayOrderSorted(m_d->cs->channels()); QList<KoChannelInfo *> channels = KoChannelInfo::displayOrderSorted(m_d->cs->channels());
for (int i=0; i<qMin(channelcount, m_d->spinBoxList.size()); i++) { for (int i=0; i<abs(m_d->cs->colorChannelCount()); i++) {
if (m_d->spinBoxList.at(i)) { if (m_d->spinBoxList.at(i)) {
if (channels.at(i)->channelValueType()==KoChannelInfo::UINT8){ if (channels.at(i)->channelValueType()==KoChannelInfo::UINT8){
int value = m_d->spinBoxList.at(i)->value(); int value = m_d->spinBoxList.at(i)->value();
...@@ -173,15 +166,8 @@ void KisSpinboxColorSelector::createColorFromSpinboxValues() ...@@ -173,15 +166,8 @@ void KisSpinboxColorSelector::createColorFromSpinboxValues()
void KisSpinboxColorSelector::slotUpdateFromSpinBoxes() void KisSpinboxColorSelector::slotUpdateFromSpinBoxes()
{ {
m_d->allowUpdates = false;
createColorFromSpinboxValues(); createColorFromSpinboxValues();
emit sigNewColor(m_d->color); emit sigNewColor(m_d->color);
m_d->compressUpdates->start();
}
void KisSpinboxColorSelector::slotFinishUpdate()
{
m_d->allowUpdates = true;
} }
void KisSpinboxColorSelector::updateSpinboxesWithNewValues() void KisSpinboxColorSelector::updateSpinboxesWithNewValues()
...@@ -192,7 +178,15 @@ void KisSpinboxColorSelector::updateSpinboxesWithNewValues() ...@@ -192,7 +178,15 @@ void KisSpinboxColorSelector::updateSpinboxesWithNewValues()
m_d->cs->normalisedChannelsValue(m_d->color.data(), channelValues); m_d->cs->normalisedChannelsValue(m_d->color.data(), channelValues);
QList<KoChannelInfo *> channels = KoChannelInfo::displayOrderSorted(m_d->cs->channels()); QList<KoChannelInfo *> channels = KoChannelInfo::displayOrderSorted(m_d->cs->channels());
for (int i=0; i<qMin(channelcount, m_d->spinBoxList.size()); i++) { int i;
for (i=0; i<m_d->spinBoxList.size(); i++) {
m_d->spinBoxList.at(i)->blockSignals(true);
}
for (i=0; i<m_d->doubleSpinBoxList.size(); i++) {
m_d->doubleSpinBoxList.at(i)->blockSignals(true);
}
for (i=0; i<abs(m_d->cs->colorChannelCount()); i++) {
if (m_d->spinBoxList.at(i)) { if (m_d->spinBoxList.at(i)) {
if (channels.at(i)->channelValueType() == KoChannelInfo::UINT8) { if (channels.at(i)->channelValueType() == KoChannelInfo::UINT8) {
int value = KoColorSpaceMaths<float, quint8>::scaleToA(channelValues[i]); int value = KoColorSpaceMaths<float, quint8>::scaleToA(channelValues[i]);
...@@ -204,6 +198,13 @@ void KisSpinboxColorSelector::updateSpinboxesWithNewValues() ...@@ -204,6 +198,13 @@ void KisSpinboxColorSelector::updateSpinboxesWithNewValues()
m_d->doubleSpinBoxList.at(i)->setValue(channelValues[i]); m_d->doubleSpinBoxList.at(i)->setValue(channelValues[i]);
} }
} }
for (i=0; i<m_d->spinBoxList.size(); i++) {
m_d->spinBoxList.at(i)->blockSignals(false);
}
for (i=0; i<m_d->doubleSpinBoxList.size(); i++) {
m_d->doubleSpinBoxList.at(i)->blockSignals(false);
}
} }
...@@ -47,7 +47,6 @@ public Q_SLOTS: ...@@ -47,7 +47,6 @@ public Q_SLOTS:
void slotSetColor(KoColor color); void slotSetColor(KoColor color);
private Q_SLOTS: private Q_SLOTS:
void slotUpdateFromSpinBoxes(); void slotUpdateFromSpinBoxes();
void slotFinishUpdate();
private: private:
struct Private; struct Private;
const QScopedPointer<Private> m_d; const QScopedPointer<Private> m_d;
......
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