~ubuntu-branches/ubuntu/precise/gwenview/precise-proposed

« back to all changes in this revision

Viewing changes to lib/crop/cropimageoperation.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-15 14:17:54 UTC
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: package-import@ubuntu.com-20111215141754-z043hyx69dulbggf
Tags: upstream-4.7.90
Import upstream version 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// vim: set tabstop=4 shiftwidth=4 noexpandtab:
 
1
// vim: set tabstop=4 shiftwidth=4 expandtab:
2
2
/*
3
3
Gwenview: an image viewer
4
4
Copyright 2007 Aurélien Gâteau <agateau@kde.org>
33
33
#include "document/documentjob.h"
34
34
#include "document/abstractdocumenteditor.h"
35
35
 
36
 
namespace Gwenview {
 
36
namespace Gwenview
 
37
{
37
38
 
38
 
class CropJob : public ThreadedDocumentJob {
 
39
class CropJob : public ThreadedDocumentJob
 
40
{
39
41
public:
40
 
        CropJob(const QRect& rect)
41
 
        : mRect(rect)
42
 
        {}
 
42
    CropJob(const QRect& rect)
 
43
        : mRect(rect)
 
44
    {}
43
45
 
44
 
        virtual void threadedStart() {
45
 
                if (!checkDocumentEditor()) {
46
 
                        return;
47
 
                }
48
 
                const QImage src = document()->image();
49
 
                const QImage dst = src.copy(mRect);
50
 
                document()->editor()->setImage(dst);
51
 
                setError(NoError);
52
 
        }
 
46
    virtual void threadedStart()
 
47
    {
 
48
        if (!checkDocumentEditor()) {
 
49
            return;
 
50
        }
 
51
        const QImage src = document()->image();
 
52
        const QImage dst = src.copy(mRect);
 
53
        document()->editor()->setImage(dst);
 
54
        setError(NoError);
 
55
    }
53
56
 
54
57
private:
55
 
        QRect mRect;
 
58
    QRect mRect;
56
59
};
57
60
 
58
 
 
59
61
struct CropImageOperationPrivate {
60
 
        QRect mRect;
61
 
        QImage mOriginalImage;
 
62
    QRect mRect;
 
63
    QImage mOriginalImage;
62
64
};
63
65
 
64
 
 
65
66
CropImageOperation::CropImageOperation(const QRect& rect)
66
 
: d(new CropImageOperationPrivate) {
67
 
        d->mRect = rect;
68
 
        setText(i18n("Crop"));
69
 
}
70
 
 
71
 
 
72
 
CropImageOperation::~CropImageOperation() {
73
 
        delete d;
74
 
}
75
 
 
76
 
 
77
 
void CropImageOperation::redo() {
78
 
        d->mOriginalImage = document()->image();
79
 
        redoAsDocumentJob(new CropJob(d->mRect));
80
 
}
81
 
 
82
 
 
83
 
void CropImageOperation::undo() {
84
 
        if (!document()->editor()) {
85
 
                kWarning() << "!document->editor()";
86
 
                return;
87
 
        }
88
 
        document()->editor()->setImage(d->mOriginalImage);
89
 
}
90
 
 
 
67
: d(new CropImageOperationPrivate)
 
68
{
 
69
    d->mRect = rect;
 
70
    setText(i18n("Crop"));
 
71
}
 
72
 
 
73
CropImageOperation::~CropImageOperation()
 
74
{
 
75
    delete d;
 
76
}
 
77
 
 
78
void CropImageOperation::redo()
 
79
{
 
80
    d->mOriginalImage = document()->image();
 
81
    redoAsDocumentJob(new CropJob(d->mRect));
 
82
}
 
83
 
 
84
void CropImageOperation::undo()
 
85
{
 
86
    if (!document()->editor()) {
 
87
        kWarning() << "!document->editor()";
 
88
        return;
 
89
    }
 
90
    document()->editor()->setImage(d->mOriginalImage);
 
91
}
91
92
 
92
93
} // namespace