File indexing completed on 2024-05-12 04:19:34

0001 /*
0002 Gwenview: an image viewer
0003 Copyright 2022 Ilya Pominov <ipominov@astralinux.ru>
0004 
0005 This program is free software; you can redistribute it and/or
0006 modify it under the terms of the GNU General Public License
0007 as published by the Free Software Foundation; either version 2
0008 of the License, or (at your option) any later version.
0009 
0010 This program is distributed in the hope that it will be useful,
0011 but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 GNU General Public License for more details.
0014 
0015 You should have received a copy of the GNU General Public License
0016 along with this program; if not, write to the Free Software
0017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0018 
0019 */
0020 // Self
0021 #include "annotateoperation.h"
0022 
0023 // Qt
0024 #include <QImage>
0025 
0026 // KF
0027 #include <KLocalizedString>
0028 
0029 // Local
0030 #include "document/abstractdocumenteditor.h"
0031 #include "document/document.h"
0032 #include "gwenview_lib_debug.h"
0033 
0034 namespace Gwenview
0035 {
0036 class AnnotateOperationPrivate
0037 {
0038 public:
0039     AnnotateOperationPrivate()
0040     {
0041     }
0042 
0043     QImage mNewImage;
0044     QImage mOriginalImage;
0045 };
0046 
0047 AnnotateOperation::AnnotateOperation(const QImage &image)
0048     : d(new AnnotateOperationPrivate())
0049 {
0050     d->mNewImage = image;
0051     setText(i18nc("@action:intoolbar", "Annotate"));
0052 }
0053 
0054 AnnotateOperation::~AnnotateOperation()
0055 {
0056     delete d;
0057 }
0058 
0059 void AnnotateOperation::redo()
0060 {
0061     if (!document()->editor()) {
0062         qCWarning(GWENVIEW_LIB_LOG) << "!document->editor()";
0063         return;
0064     }
0065 
0066     d->mOriginalImage = document()->image();
0067     document()->editor()->setImage(d->mNewImage);
0068     finish(true);
0069 }
0070 
0071 void AnnotateOperation::undo()
0072 {
0073     if (!document()->editor()) {
0074         qCWarning(GWENVIEW_LIB_LOG) << "!document->editor()";
0075         return;
0076     }
0077     document()->editor()->setImage(d->mOriginalImage);
0078     finish(true);
0079 }
0080 
0081 } // namespace