Undo and Redo and KisPainter
Boudewijn Rempt
boud at valdyas.org
Thu Dec 11 21:42:05 CET 2003
Paint me silly, but I cannot work out what I'm doing wrong here. I've tried
to fix the brush tool to include undo/redo -- and I cannot get it to work.
Here's what I'm doing:
Define a KMacroCommand as a private variable:
private:
KMacroCommand *m_macro;
And then, in the implementation, I first initialize this to 0:
KisToolBrush::KisToolBrush()
: super(),
m_mode( HOVER )
{
m_macro = 0;
}
When the user presses the mousebutton I start the transaction and
begin to paint -- this is bitBlt-ing, so all paint actions should
be accumulated into the KMacroCommand, if I read the KisPainter source
correctly:
void KisToolBrush::mousePress(QMouseEvent *e)
{
...
if (e->button() == QMouseEvent::LeftButton) {
m_mode = PAINT;
KisImageSP currentImage = m_subject -> currentImg();
KisPaintDeviceSP device;
if (currentImage && (device = currentImage -> activeDevice())) {
KisPainter p( device );
if (m_macro)
delete m_macro;
m_macro = new KMacroCommand("brush");
p.beginTransaction(m_macro);
}
paint(e->pos(), 128, 0, 0);
}
}
And then, upon release, I finish the transaction, and add the result to
the undo-adaptor:
void KisToolBrush::mouseRelease(QMouseEvent* e)
{
if (e->button() == QMouseEvent::LeftButton) {
m_mode = HOVER;
KisImageSP currentImage = m_subject -> currentImg();
KisPaintDeviceSP device;
if (currentImage && (device = currentImage -> activeDevice())) {
KisPainter p( device );
KisUndoAdapter *adapter = currentImage -> undoAdapter();
if (adapter)
adapter -> addCommand(p.endTransaction());
m_macro = 0;
}
}
}
And nothing happens... If I add m_macro directly (but m_macro should point to
the same object as the result of p.endTransaction(), shouldn't it -- and it
should have accumulated all the KisTileCommands), then I do get an undo
entry, but it doesn't do anything.
--
Boudewijn Rempt | http://www.valdyas.org/index2.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: signature
Url : http://mail.kde.org/pipermail/kimageshop/attachments/20031211/fff641f3/attachment.pgp
More information about the kimageshop
mailing list