File indexing completed on 2025-02-23 04:05:47
0001 /* This file is part of the KDE project 0002 * SPDX-FileCopyrightText: 2009 Jan Hambrecht <jaham@gmx.net> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "KoShapeTransparencyCommand.h" 0008 #include "KoShape.h" 0009 0010 #include <klocalizedstring.h> 0011 #include "kis_command_ids.h" 0012 0013 class Q_DECL_HIDDEN KoShapeTransparencyCommand::Private 0014 { 0015 public: 0016 Private() { 0017 } 0018 ~Private() { 0019 } 0020 0021 QList<KoShape*> shapes; ///< the shapes to set background for 0022 QList<qreal> oldTransparencies; ///< the old transparencies 0023 QList<qreal> newTransparencies; ///< the new transparencies 0024 }; 0025 0026 KoShapeTransparencyCommand::KoShapeTransparencyCommand(const QList<KoShape*> &shapes, qreal transparency, KUndo2Command *parent) 0027 : KUndo2Command(parent) 0028 , d(new Private()) 0029 { 0030 d->shapes = shapes; 0031 Q_FOREACH (KoShape *shape, d->shapes) { 0032 d->oldTransparencies.append(shape->transparency()); 0033 d->newTransparencies.append(transparency); 0034 } 0035 0036 setText(kundo2_i18n("Set opacity")); 0037 } 0038 0039 KoShapeTransparencyCommand::KoShapeTransparencyCommand(KoShape * shape, qreal transparency, KUndo2Command *parent) 0040 : KUndo2Command(parent) 0041 , d(new Private()) 0042 { 0043 d->shapes.append(shape); 0044 d->oldTransparencies.append(shape->transparency()); 0045 d->newTransparencies.append(transparency); 0046 0047 setText(kundo2_i18n("Set opacity")); 0048 } 0049 0050 KoShapeTransparencyCommand::KoShapeTransparencyCommand(const QList<KoShape*> &shapes, const QList<qreal> &transparencies, KUndo2Command *parent) 0051 : KUndo2Command(parent) 0052 , d(new Private()) 0053 { 0054 d->shapes = shapes; 0055 Q_FOREACH (KoShape *shape, d->shapes) { 0056 d->oldTransparencies.append(shape->transparency()); 0057 } 0058 d->newTransparencies = transparencies; 0059 0060 setText(kundo2_i18n("Set opacity")); 0061 } 0062 0063 KoShapeTransparencyCommand::~KoShapeTransparencyCommand() 0064 { 0065 delete d; 0066 } 0067 0068 void KoShapeTransparencyCommand::redo() 0069 { 0070 KUndo2Command::redo(); 0071 QList<qreal>::iterator transparencyIt = d->newTransparencies.begin(); 0072 Q_FOREACH (KoShape *shape, d->shapes) { 0073 shape->setTransparency(*transparencyIt); 0074 shape->update(); 0075 ++transparencyIt; 0076 } 0077 } 0078 0079 void KoShapeTransparencyCommand::undo() 0080 { 0081 KUndo2Command::undo(); 0082 QList<qreal>::iterator transparencyIt = d->oldTransparencies.begin(); 0083 Q_FOREACH (KoShape *shape, d->shapes) { 0084 shape->setTransparency(*transparencyIt); 0085 shape->update(); 0086 ++transparencyIt; 0087 } 0088 } 0089 0090 int KoShapeTransparencyCommand::id() const 0091 { 0092 return KisCommandUtils::ChangeShapeTransparencyId; 0093 } 0094 0095 bool KoShapeTransparencyCommand::mergeWith(const KUndo2Command *command) 0096 { 0097 const KoShapeTransparencyCommand *other = dynamic_cast<const KoShapeTransparencyCommand*>(command); 0098 0099 if (!other || other->d->shapes != d->shapes) { 0100 return false; 0101 } 0102 0103 d->newTransparencies = other->d->newTransparencies; 0104 return true; 0105 }