Commit 706f382a authored by Dmitry Kazakov's avatar Dmitry Kazakov

Connect onion skins dialog to the compositor to update image dynamically on every change

Conflicts:
	krita/image/kis_paint_layer.cc
	krita/plugins/extensions/dockers/animation/kis_onion_skin_dialog.h
parent b7875041
......@@ -176,4 +176,5 @@ QRect KisOnionSkinCompositor::calculateExtent(const KisPaintDeviceSP device)
void KisOnionSkinCompositor::configChanged()
{
m_d->refreshConfig();
emit sigOnionSkinChanged();
}
......@@ -21,7 +21,7 @@
#include "kis_types.h"
class KRITAIMAGE_EXPORT KisOnionSkinCompositor : QObject
class KRITAIMAGE_EXPORT KisOnionSkinCompositor : public QObject
{
Q_OBJECT
......@@ -37,6 +37,9 @@ public:
public Q_SLOTS:
void configChanged();
Q_SIGNALS:
void sigOnionSkinChanged();
private:
struct Private;
QScopedPointer<Private> m_d;
......
......@@ -41,12 +41,15 @@
#include "kis_onion_skin_compositor.h"
#include "kis_raster_keyframe_channel.h"
#include "kis_signal_auto_connection.h"
struct Q_DECL_HIDDEN KisPaintLayer::Private
{
public:
KisPaintDeviceSP paintDevice;
QBitArray paintChannelFlags;
KisRasterKeyframeChannel *contentChannel;
KisSignalAutoConnectionsStore onionSkinConnection;
};
KisPaintLayer::KisPaintLayer(KisImageWSP image, const QString& name, quint8 opacity, KisPaintDeviceSP dev)
......@@ -258,16 +261,39 @@ bool KisPaintLayer::onionSkinEnabled() const
void KisPaintLayer::setOnionSkinEnabled(bool state)
{
if (state == false && onionSkinEnabled()) {
int oldState = onionSkinEnabled();
if (oldState == state) return;
if (state == false && oldState) {
// FIXME: change ordering! race condition possible!
// Turning off onionskins shrinks our extent. Let's clean up the onion skins first
setDirty(KisOnionSkinCompositor::instance()->calculateExtent(m_d->paintDevice));
}
if (state) {
m_d->onionSkinConnection.addConnection(KisOnionSkinCompositor::instance(),
SIGNAL(sigOnionSkinChanged()),
this,
SLOT(slotExternalUpdateOnionSkins()));
} else {
m_d->onionSkinConnection.clear();
}
nodeProperties().setProperty("onionskin", state);
baseNodeChangedCallback();
}
void KisPaintLayer::slotExternalUpdateOnionSkins()
{
// here we update the whole image because the number of onion
// skins could have been reduced and the compositor will not be
// able to calculate the correct area
const QRect dirtyRect = m_d->paintDevice->defaultBounds()->bounds();
setDirty(dirtyRect);
}
void KisPaintLayer::enableAnimation()
{
m_d->contentChannel = m_d->paintDevice->createKeyframeChannel(KisKeyframeChannel::Content, this);
......
......@@ -149,6 +149,10 @@ public:
void enableAnimation();
public Q_SLOTS:
void slotExternalUpdateOnionSkins();
public:
// KisIndirectPaintingSupport
KisLayer* layer() {
......
......@@ -26,11 +26,13 @@
#include "kis_image_config.h"
#include "kis_onion_skin_compositor.h"
static const int MAX_SKIN_COUNT = 10;
KisOnionSkinDialog::KisOnionSkinDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::KisOnionSkinDialog)
ui(new Ui::KisOnionSkinDialog),
m_updatesCompressor(1000, KisSignalCompressor::FIRST_INACTIVE)
{
KisImageConfig config;
ui->setupUi(this);
......@@ -95,6 +97,8 @@ KisOnionSkinDialog::KisOnionSkinDialog(QWidget *parent) :
connect(ui->btnBackwardColor, SIGNAL(changed(QColor)), this, SLOT(changed()));
connect(ui->btnForwardColor, SIGNAL(changed(QColor)), this, SLOT(changed()));
connect(ui->doubleTintFactor, SIGNAL(valueChanged(qreal)), this, SLOT(changed()));
connect(&m_updatesCompressor, SIGNAL(timeout()),
KisOnionSkinCompositor::instance(), SLOT(configChanged()));
}
KisOnionSkinDialog::~KisOnionSkinDialog()
......@@ -117,5 +121,5 @@ void KisOnionSkinDialog::changed()
config.setOnionSkinTintColorBackward(ui->btnBackwardColor->color());
config.setOnionSkinTintColorForward(ui->btnForwardColor->color());
KisOnionSkinCompositor::instance()->configChanged();
m_updatesCompressor.start();
}
......@@ -22,6 +22,8 @@
#include <QDialog>
#include <QSlider>
#include "kis_signal_compressor.h"
namespace Ui {
class KisOnionSkinDialog;
}
......@@ -41,6 +43,8 @@ private:
QVector<QSlider*> forwardOpacities;
QVector<QSlider*> backwardOpacities;
KisSignalCompressor m_updatesCompressor;
private Q_SLOTS:
void changed();
};
......
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