summaryrefslogtreecommitdiffstats
path: root/src/gvcore/document.h
blob: 0a1dba4893f65147bf32d92cb5268b5a04cb574b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// vim: set tabstop=4 shiftwidth=4 noexpandtab
/*
Gwenview - A simple image viewer for KDE
Copyright 2000-2006 Aurelien Gateau
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

*/
#ifndef DOCUMENT_H
#define DOCUMENT_H

// TQt 
#include <tqcstring.h>
#include <tqobject.h>
#include <tqimage.h>

// KDE 
#include <kurl.h>
#include <kprinter.h>

// Local 
#include "imageutils/orientation.h"
#include "mimetypeutils.h"
#include "libgwenview_export.h"
namespace KIO { class Job; }

namespace Gwenview {
class DocumentPrivate;
class DocumentImpl;

/**
 * The application document.
 * It knows what the current url is and will emit signals when
 * loading/loaded/modified...
 * 
 * The ordering of loading() and loaded() signals is:
 * - setURL() is called
 * - URL is stated
 * - loading() is emitted (may be skipped if no loading is needed, e.g. wrong URL)
 * - image is being loaded
 * - loaded() is emitted
 */
class LIBGWENVIEW_EXPORT Document : public TQObject {
Q_OBJECT
  
public:
	enum CommentState { NONE=0, READ_ONLY=1, WRITABLE=2 };
	
	Document(TQObject*);
	~Document();

	// Properties
	const TQImage& image() const;
	KURL url() const;
	KURL dirURL() const;
	TQString filename() const;
	const TQCString& imageFormat() const;
	int fileSize() const;
	TQString mimeType() const;
	MimeTypeUtils::Kind urlKind() const;
	bool isModified() const;

	/**
	 * Returns true if Gwenview knows how to save such an image
	 */
	bool canBeSaved() const;

	// Convenience methods
	bool isNull() const { return image().isNull(); }
	int width() const { return image().width(); }
	int height() const { return image().height(); }

	Document::CommentState commentState() const;
	TQString comment() const;
	void setComment(const TQString&);
	TQString aperture() const;
	TQString exposureTime() const;
	TQString iso() const;
	TQString focalLength() const;

	int duration() const;
	
public slots:
	void setURL(const KURL&);
	void setDirURL(const KURL&);
	void reload();

	/**
	 * Save to the current file.
	 */
	void save();
	void saveAs();
	
	/** print the selected file */
	void print(KPrinter *pPrinter);
	
	/**
	 * If the image has been modified, prompt the user to save the changes.
	 */
	void saveBeforeClosing();

	// "Image manipulation"
	void transform(ImageUtils::Orientation);

signals:
	/**
	 * Emitted when the class starts to load the image.
	 */
	void loading();

	/**
	 * Emitted when the class has finished loading the image.
	 * Also emitted if the image could not be loaded.
	 */
	void loaded(const KURL& url);

	/**
	 * Emitted when the image has been modified.
	 */
	void modified();

	/**
	 * Emitted when the image has been saved on disk.
	 */
	void saved(const KURL& url);

	/**
	 * Emitted when the image has been reloaded.
	 */ 
	void reloaded(const KURL& url);

	/**
	 * Emitted to show a part of the image must be refreshed
	 */
	void rectUpdated(const TQRect& rect);

	/**
	 * Emitted when the size is known
	 */
	void sizeUpdated();

	/**
	 * Emitted when something goes wrong, like when save fails
	 */
	void errorHappened(const TQString& message);

private slots:
	void slotStatResult(KIO::Job*); 
	void slotFinished(bool success);
	void slotLoading();
	void slotLoaded();
	
private:
	friend class DocumentImpl;
	friend class DocumentPrivate;

	DocumentPrivate* d;

	// These methods are used by DocumentImpl and derived
	void switchToImpl(DocumentImpl*);
	void setImage(TQImage);
	void setImageFormat(const TQCString&);
	void setMimeType(const TQString&);
	void setFileSize(int); 
	
	void reset();
	void load();
	void doPaint(KPrinter *pPrinter, TQPainter *p);

	/**
	 * The returned string is null if the image was successfully saved,
	 * otherwise it's the translated error message.
	 */
	TQString saveInternal(const KURL& url, const TQCString& format);

	Document(const Document&);
	Document &operator=(const Document&);
};


} // namespace
#endif