~ubuntu-branches/ubuntu/intrepid/gwenview/intrepid

« back to all changes in this revision

Viewing changes to src/gvdocument.h

  • Committer: Bazaar Package Importer
  • Author(s): Christopher Martin
  • Date: 2005-04-06 11:33:06 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20050406113306-7zovl7z0io5bacpd
Tags: 1.2.0-1
* New upstream release.
  + Fixes crashes when using "Back" to navigate. (Closes: #301811)
* Enable KIPI support.
* Add a doc-base file for the handbook.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// vim: set tabstop=4 shiftwidth=4 noexpandtab
 
2
/*
 
3
Gwenview - A simple image viewer for KDE
 
4
Copyright 2000-2004 Aur�lien G�teau
 
5
 
 
6
 This program is free software; you can redistribute it and/or
 
7
 modify it under the terms of the GNU General Public License
 
8
 as published by the Free Software Foundation; either version 2
 
9
 of the License, or (at your option) any later version.
 
10
 
 
11
 This program is distributed in the hope that it will be useful,
 
12
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 GNU General Public License for more details.
 
15
 
 
16
 You should have received a copy of the GNU General Public License
 
17
 along with this program; if not, write to the Free Software
 
18
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
19
 
 
20
*/
 
21
#ifndef GVDOCUMENT_H
 
22
#define GVDOCUMENT_H
 
23
 
 
24
// Qt 
 
25
#include <qcstring.h>
 
26
#include <qobject.h>
 
27
#include <qimage.h>
 
28
 
 
29
// KDE 
 
30
#include <kurl.h>
 
31
#include <kprinter.h>
 
32
 
 
33
// Local 
 
34
#include "gvimageutils/orientation.h"
 
35
#include "gvbusylevelmanager.h"
 
36
 
 
37
class GVDocumentPrivate;
 
38
class GVDocumentImpl;
 
39
 
 
40
namespace KIO { class Job; }
 
41
/**
 
42
 * The application document.
 
43
 * It knows what the current url is and will emit signals when
 
44
 * loading/loaded/modified...
 
45
 * 
 
46
 * The ordering of loading() and loaded() signals is:
 
47
 * - setURL() is called
 
48
 * - URL is stated
 
49
 * - loading() is emitted (may be skipped if no loading is needed, e.g. wrong URL)
 
50
 * - image is being loaded
 
51
 * - loaded() is emitted
 
52
 */
 
53
class GVDocument : public QObject {
 
54
Q_OBJECT
 
55
public:
 
56
        enum ModifiedBehavior { ASK=0, SAVE_SILENTLY=1, DISCARD_CHANGES=2 };
 
57
        enum CommentState { NONE=0, READ_ONLY=1, VALID=READ_ONLY, WRITABLE=3 };
 
58
        
 
59
        GVDocument(QObject*);
 
60
        ~GVDocument();
 
61
 
 
62
        // Properties
 
63
        const QImage& image() const;
 
64
        KURL url() const;
 
65
        KURL dirURL() const;
 
66
        QString filename() const;
 
67
        const QCString& imageFormat() const;
 
68
        int fileSize() const;
 
69
 
 
70
        // Convenience methods
 
71
        bool isNull() const { return image().isNull(); }
 
72
        int width() const { return image().width(); }
 
73
        int height() const { return image().height(); }
 
74
 
 
75
        void setModifiedBehavior(ModifiedBehavior);
 
76
        ModifiedBehavior modifiedBehavior() const;
 
77
 
 
78
        GVDocument::CommentState commentState() const;
 
79
        QString comment() const;
 
80
        void setComment(const QString&);
 
81
        
 
82
public slots:
 
83
        void setURL(const KURL&);
 
84
        void setDirURL(const KURL&);
 
85
        void reload();
 
86
 
 
87
        /**
 
88
         * Save to the current file.
 
89
         */
 
90
        void save();
 
91
        void saveAs();
 
92
        
 
93
        /** print the selected file */
 
94
        void print(KPrinter *pPrinter);
 
95
        
 
96
        /**
 
97
         * If the image has been modified, prompt the user to save the changes.
 
98
         * Returns true if it's safe to switch to another image.
 
99
         */
 
100
        bool saveBeforeClosing();
 
101
 
 
102
        // "Image manipulation"
 
103
        void transform(GVImageUtils::Orientation);
 
104
 
 
105
signals:
 
106
        /**
 
107
         * Emitted when the class starts to load the image.
 
108
         */
 
109
        void loading();
 
110
 
 
111
        /**
 
112
         * Emitted when the class has finished loading the image.
 
113
         * Also emitted if the image could not be loaded.
 
114
         */
 
115
        void loaded(const KURL& url);
 
116
 
 
117
        /**
 
118
         * Emitted when the image has been modified.
 
119
         */
 
120
        void modified();
 
121
 
 
122
        /**
 
123
         * Emitted when the image has been saved on disk.
 
124
         */
 
125
        void saved(const KURL& url);
 
126
 
 
127
        /**
 
128
         * Emitted when the image has been reloaded.
 
129
         */ 
 
130
        void reloaded(const KURL& url);
 
131
 
 
132
        /**
 
133
         * Emitted to show a part of the image must be refreshed
 
134
         */
 
135
        void rectUpdated(const QRect& rect);
 
136
 
 
137
        /**
 
138
         * Emitted when the size is known (or when it has changed)
 
139
         */
 
140
        void sizeUpdated(int width, int height);
 
141
 
 
142
        /**
 
143
         * Emitted when something goes wrong, like when save fails
 
144
         */
 
145
        void errorHappened(const QString& message);
 
146
 
 
147
private slots:
 
148
        void slotStatResult(KIO::Job*); 
 
149
        void slotFinished(bool success);
 
150
        void slotLoading();
 
151
        void slotLoaded();
 
152
        void slotBusyLevelChanged(GVBusyLevel level);
 
153
        
 
154
private:
 
155
        friend class GVDocumentImpl;
 
156
        friend class GVDocumentPrivate;
 
157
 
 
158
        GVDocumentPrivate* d;
 
159
 
 
160
        // These methods are used by GVDocumentImpl and derived
 
161
        void switchToImpl(GVDocumentImpl*);
 
162
        // update == true triggers also sizeUpdated() and rectUpdated()
 
163
        void setImage(QImage, bool update);
 
164
        void setImageFormat(const QCString&);
 
165
        void setFileSize(int); 
 
166
        
 
167
        void reset();
 
168
        void load();
 
169
        void doPaint(KPrinter *pPrinter, QPainter *p);
 
170
 
 
171
        /**
 
172
         * The returned string is null if the image was successfully saved,
 
173
         * otherwise it's the translated error message.
 
174
         */
 
175
        QString saveInternal(const KURL& url, const QCString& format);
 
176
 
 
177
        GVDocument(const GVDocument&);
 
178
        GVDocument &operator=(const GVDocument&);
 
179
};
 
180
 
 
181
 
 
182
#endif