libs/flake
KoShapeBackgroundCommand.cppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "KoShapeBackgroundCommand.h"
00022 #include "KoShape.h"
00023 #include "KoShapeBackground.h"
00024
00025 #include <klocale.h>
00026
00027 class KoShapeBackgroundCommand::Private
00028 {
00029 public:
00030 Private() {
00031 }
00032 ~Private() {
00033 foreach(KoShapeBackground* fill, oldFills) {
00034 if (fill && ! fill->removeUser())
00035 delete fill;
00036 }
00037 foreach(KoShapeBackground* fill, newFills) {
00038 if (fill && ! fill->removeUser())
00039 delete fill;
00040 }
00041 }
00042
00043 void addOldFill( KoShapeBackground * oldFill )
00044 {
00045 if (oldFill)
00046 oldFill->addUser();
00047 oldFills.append(oldFill);
00048 }
00049
00050 void addNewFill( KoShapeBackground * newFill )
00051 {
00052 if (newFill)
00053 newFill->addUser();
00054 newFills.append(newFill);
00055 }
00056
00057 QList<KoShape*> shapes;
00058 QList<KoShapeBackground*> oldFills;
00059 QList<KoShapeBackground*> newFills;
00060 };
00061
00062 KoShapeBackgroundCommand::KoShapeBackgroundCommand(const QList<KoShape*> &shapes, KoShapeBackground * fill,
00063 QUndoCommand *parent)
00064 : QUndoCommand(parent)
00065 , d(new Private())
00066 {
00067 d->shapes = shapes;
00068 foreach(KoShape *shape, d->shapes) {
00069 d->addOldFill(shape->background());
00070 d->addNewFill(fill);
00071 }
00072
00073 setText(i18n("Set background"));
00074 }
00075
00076 KoShapeBackgroundCommand::KoShapeBackgroundCommand(KoShape * shape, KoShapeBackground * fill, QUndoCommand *parent)
00077 : QUndoCommand(parent)
00078 , d(new Private())
00079 {
00080 d->shapes.append(shape);
00081 d->addOldFill(shape->background());
00082 d->addNewFill(fill);
00083
00084 setText(i18n("Set background"));
00085 }
00086
00087 KoShapeBackgroundCommand::KoShapeBackgroundCommand(const QList<KoShape*> &shapes, const QList<KoShapeBackground*> &fills, QUndoCommand *parent)
00088 : QUndoCommand(parent)
00089 , d(new Private())
00090 {
00091 d->shapes = shapes;
00092 foreach(KoShape *shape, d->shapes) {
00093 d->addOldFill(shape->background());
00094 }
00095 foreach(KoShapeBackground * fill, fills ) {
00096 d->addNewFill(fill);
00097 }
00098
00099 setText(i18n("Set background"));
00100 }
00101
00102 void KoShapeBackgroundCommand::redo()
00103 {
00104 QUndoCommand::redo();
00105 QList<KoShapeBackground*>::iterator brushIt = d->newFills.begin();
00106 foreach(KoShape *shape, d->shapes) {
00107 shape->setBackground(*brushIt);
00108 shape->update();
00109 brushIt++;
00110 }
00111 }
00112
00113 void KoShapeBackgroundCommand::undo()
00114 {
00115 QUndoCommand::undo();
00116 QList<KoShapeBackground*>::iterator brushIt = d->oldFills.begin();
00117 foreach(KoShape *shape, d->shapes) {
00118 shape->setBackground(*brushIt);
00119 shape->update();
00120 brushIt++;
00121 }
00122 }
00123
00124 KoShapeBackgroundCommand::~KoShapeBackgroundCommand()
00125 {
00126 delete d;
00127 }
|