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

« back to all changes in this revision

Viewing changes to lib/abstractimageoperation.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/documentfactory.h"
32
32
#include "document/documentjob.h"
33
33
 
34
 
namespace Gwenview {
 
34
namespace Gwenview
 
35
{
35
36
 
36
 
class ImageOperationCommand : public QUndoCommand {
 
37
class ImageOperationCommand : public QUndoCommand
 
38
{
37
39
public:
38
 
        ImageOperationCommand(AbstractImageOperation* op)
39
 
        : mOp(op)
40
 
        {}
41
 
 
42
 
        ~ImageOperationCommand() {
43
 
                delete mOp;
44
 
        }
45
 
 
46
 
        virtual void undo() {
47
 
                mOp->undo();
48
 
        }
 
40
    ImageOperationCommand(AbstractImageOperation* op)
 
41
        : mOp(op)
 
42
    {}
 
43
 
 
44
    ~ImageOperationCommand() {
 
45
        delete mOp;
 
46
    }
 
47
 
 
48
    virtual void undo()
 
49
    {
 
50
        mOp->undo();
 
51
    }
49
52
 
50
53
private:
51
 
        AbstractImageOperation* mOp;
 
54
    AbstractImageOperation* mOp;
52
55
};
53
56
 
54
 
 
55
57
struct AbstractImageOperationPrivate {
56
 
        QString mText;
57
 
        KUrl mUrl;
 
58
    QString mText;
 
59
    KUrl mUrl;
58
60
};
59
61
 
60
 
 
61
62
AbstractImageOperation::AbstractImageOperation()
62
 
: d(new AbstractImageOperationPrivate) {
63
 
}
64
 
 
65
 
 
66
 
AbstractImageOperation::~AbstractImageOperation() {
67
 
        delete d;
68
 
}
69
 
 
70
 
 
71
 
void AbstractImageOperation::applyToDocument(Document::Ptr doc) {
72
 
        d->mUrl = doc->url();
73
 
        redo();
74
 
}
75
 
 
76
 
 
77
 
Document::Ptr AbstractImageOperation::document() const {
78
 
        Document::Ptr doc = DocumentFactory::instance()->load(d->mUrl);
79
 
        doc->startLoadingFullImage();
80
 
        return doc;
81
 
}
82
 
 
83
 
 
84
 
void AbstractImageOperation::finish(bool ok) {
85
 
        if (ok) {
86
 
                ImageOperationCommand* command = new ImageOperationCommand(this);
87
 
                command->setText(d->mText);
88
 
                document()->undoStack()->push(command);
89
 
        } else {
90
 
                deleteLater();
91
 
        }
92
 
}
93
 
 
94
 
 
95
 
void AbstractImageOperation::finishFromKJob(KJob* job) {
96
 
        finish(job->error() == KJob::NoError);
97
 
}
98
 
 
99
 
 
100
 
void AbstractImageOperation::setText(const QString& text) {
101
 
        d->mText = text;
102
 
}
103
 
 
104
 
 
105
 
void AbstractImageOperation::redoAsDocumentJob(DocumentJob* job) {
106
 
        connect(job, SIGNAL(result(KJob*)), SLOT(finishFromKJob(KJob*)));
107
 
        document()->enqueueJob(job);
108
 
}
109
 
 
 
63
: d(new AbstractImageOperationPrivate)
 
64
{
 
65
}
 
66
 
 
67
AbstractImageOperation::~AbstractImageOperation()
 
68
{
 
69
    delete d;
 
70
}
 
71
 
 
72
void AbstractImageOperation::applyToDocument(Document::Ptr doc)
 
73
{
 
74
    d->mUrl = doc->url();
 
75
    redo();
 
76
}
 
77
 
 
78
Document::Ptr AbstractImageOperation::document() const
 
79
{
 
80
    Document::Ptr doc = DocumentFactory::instance()->load(d->mUrl);
 
81
    doc->startLoadingFullImage();
 
82
    return doc;
 
83
}
 
84
 
 
85
void AbstractImageOperation::finish(bool ok)
 
86
{
 
87
    if (ok) {
 
88
        ImageOperationCommand* command = new ImageOperationCommand(this);
 
89
        command->setText(d->mText);
 
90
        document()->undoStack()->push(command);
 
91
    } else {
 
92
        deleteLater();
 
93
    }
 
94
}
 
95
 
 
96
void AbstractImageOperation::finishFromKJob(KJob* job)
 
97
{
 
98
    finish(job->error() == KJob::NoError);
 
99
}
 
100
 
 
101
void AbstractImageOperation::setText(const QString& text)
 
102
{
 
103
    d->mText = text;
 
104
}
 
105
 
 
106
void AbstractImageOperation::redoAsDocumentJob(DocumentJob* job)
 
107
{
 
108
    connect(job, SIGNAL(result(KJob*)), SLOT(finishFromKJob(KJob*)));
 
109
    document()->enqueueJob(job);
 
110
}
110
111
 
111
112
} // namespace