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

« back to all changes in this revision

Viewing changes to lib/transformimageoperation.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>
31
31
#include "document/abstractdocumenteditor.h"
32
32
#include "document/documentjob.h"
33
33
 
34
 
namespace Gwenview {
35
 
 
 
34
namespace Gwenview
 
35
{
36
36
 
37
37
struct TransformImageOperationPrivate {
38
 
        Orientation mOrientation;
 
38
    Orientation mOrientation;
39
39
};
40
40
 
41
 
 
42
 
class TransformJob : public ThreadedDocumentJob {
 
41
class TransformJob : public ThreadedDocumentJob
 
42
{
43
43
public:
44
 
        TransformJob(Orientation orientation)
45
 
        : mOrientation(orientation)
46
 
        {}
 
44
    TransformJob(Orientation orientation)
 
45
        : mOrientation(orientation)
 
46
    {}
47
47
 
48
 
        virtual void threadedStart() {
49
 
                if (!checkDocumentEditor()) {
50
 
                        return;
51
 
                }
52
 
                document()->editor()->applyTransformation(mOrientation);
53
 
                setError(NoError);
54
 
        }
 
48
    virtual void threadedStart()
 
49
    {
 
50
        if (!checkDocumentEditor()) {
 
51
            return;
 
52
        }
 
53
        document()->editor()->applyTransformation(mOrientation);
 
54
        setError(NoError);
 
55
    }
55
56
 
56
57
private:
57
 
        Orientation mOrientation;
 
58
    Orientation mOrientation;
58
59
};
59
60
 
60
 
 
61
61
TransformImageOperation::TransformImageOperation(Orientation orientation)
62
 
: d(new TransformImageOperationPrivate) {
63
 
        d->mOrientation = orientation;
64
 
        switch (d->mOrientation) {
65
 
        case ROT_90:
66
 
                setText(i18nc("(qtundo-format)", "Rotate Right"));
67
 
                break;
68
 
        case ROT_270:
69
 
                setText(i18nc("(qtundo-format)", "Rotate Left"));
70
 
                break;
71
 
        case HFLIP:
72
 
                setText(i18nc("(qtundo-format)", "Mirror"));
73
 
                break;
74
 
        case VFLIP:
75
 
                setText(i18nc("(qtundo-format)", "Flip"));
76
 
                break;
77
 
        default:
78
 
                // We should not get there because the transformations listed above are
79
 
                // the only one available from the UI. Define a default text nevertheless.
80
 
                setText(i18nc("(qtundo-format)", "Transform"));
81
 
                break;
82
 
        }
83
 
}
84
 
 
85
 
 
86
 
TransformImageOperation::~TransformImageOperation() {
87
 
        delete d;
88
 
}
89
 
 
90
 
 
91
 
void TransformImageOperation::redo() {
92
 
        redoAsDocumentJob(new TransformJob(d->mOrientation));
93
 
}
94
 
 
95
 
 
96
 
void TransformImageOperation::undo() {
97
 
        Orientation orientation;
98
 
        switch (d->mOrientation) {
99
 
        case ROT_90:
100
 
                orientation = ROT_270;
101
 
                break;
102
 
        case ROT_270:
103
 
                orientation = ROT_90;
104
 
                break;
105
 
        default:
106
 
                orientation = d->mOrientation;
107
 
                break;
108
 
        }
109
 
        document()->enqueueJob(new TransformJob(orientation));
110
 
}
111
 
 
 
62
: d(new TransformImageOperationPrivate)
 
63
{
 
64
    d->mOrientation = orientation;
 
65
    switch (d->mOrientation) {
 
66
    case ROT_90:
 
67
        setText(i18nc("(qtundo-format)", "Rotate Right"));
 
68
        break;
 
69
    case ROT_270:
 
70
        setText(i18nc("(qtundo-format)", "Rotate Left"));
 
71
        break;
 
72
    case HFLIP:
 
73
        setText(i18nc("(qtundo-format)", "Mirror"));
 
74
        break;
 
75
    case VFLIP:
 
76
        setText(i18nc("(qtundo-format)", "Flip"));
 
77
        break;
 
78
    default:
 
79
        // We should not get there because the transformations listed above are
 
80
        // the only one available from the UI. Define a default text nevertheless.
 
81
        setText(i18nc("(qtundo-format)", "Transform"));
 
82
        break;
 
83
    }
 
84
}
 
85
 
 
86
TransformImageOperation::~TransformImageOperation()
 
87
{
 
88
    delete d;
 
89
}
 
90
 
 
91
void TransformImageOperation::redo()
 
92
{
 
93
    redoAsDocumentJob(new TransformJob(d->mOrientation));
 
94
}
 
95
 
 
96
void TransformImageOperation::undo()
 
97
{
 
98
    Orientation orientation;
 
99
    switch (d->mOrientation) {
 
100
    case ROT_90:
 
101
        orientation = ROT_270;
 
102
        break;
 
103
    case ROT_270:
 
104
        orientation = ROT_90;
 
105
        break;
 
106
    default:
 
107
        orientation = d->mOrientation;
 
108
        break;
 
109
    }
 
110
    document()->enqueueJob(new TransformJob(orientation));
 
111
}
112
112
 
113
113
} // namespace