forked from Ramblurr/PietCreator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UndoHandler.cpp
45 lines (35 loc) · 1.35 KB
/
UndoHandler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "UndoHandler.h"
#include "ImageModel.h"
#include "UndoCommands.h"
#include <QUndoStack>
#include <QDebug>
UndoHandler::UndoHandler( QUndoStack* undostack, ImageModel* model ) : mUndoStack( undostack ), mModel( model )
{
}
void UndoHandler::createEditPixel(int x, int y, QColor new_color, bool dragging)
{
qDebug() << "createEditPixel" << dragging;
EditPixelCommand* parent = 0;
if (dragging) {
const QUndoCommand* cmd = mUndoStack->command( mUndoStack->index() );
const EditPixelCommand* const_parent = dynamic_cast<const EditPixelCommand*>(cmd);
qDebug() << const_parent;
if( const_parent )
parent = const_cast<EditPixelCommand*>(const_parent);
}
QColor old_color = mModel->data( mModel->index(y, x), Qt::DisplayRole ).value<QColor>();
EditPixelCommand *cmd = new EditPixelCommand(x, y, old_color, new_color, mModel, parent );
mUndoStack->push(cmd);
}
void UndoHandler::insertImage(int x, int y, QImage imageToInsert, QSize scaleAfter)
{
QImage before = mModel->image();
InsertImageCommand *cmd = new InsertImageCommand(x,y,before, imageToInsert, scaleAfter, mModel);
mUndoStack->push(cmd);
}
void UndoHandler::scaleImage(QSize newSize)
{
QImage before = mModel->image();
ScaleImageCommand *cmd = new ScaleImageCommand(before, newSize, mModel);
mUndoStack->push(cmd);
}