[go: up one dir, main page]

File: imageloader.h

package info (click to toggle)
showimg 0.9.4.1-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 8,436 kB
  • ctags: 3,644
  • sloc: cpp: 32,420; sh: 11,559; perl: 2,779; makefile: 220
file content (208 lines) | stat: -rw-r--r-- 5,568 bytes parent folder | download
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
196
197
198
199
200
201
202
203
204
205
206
207
208
/***************************************************************************
                         imageloader.h  -  description
                             -------------------
    begin                : Sat Dec 1 2001
    copyright            : (C) 2001 by Richard Groult
    email                : rgroult@jalix.org 
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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., 59 Temple Place, Suite 330, Boston, MA 02111-1307   *
 *   USA.                                                                  *
 *                                                                         *
 *   For license exceptions see LICENSE.EXC file, attached with the source *
 *   code.                                                                 *
 *                                                                         *
 ***************************************************************************/

#ifndef __IMAGELOADER_H__
#define __IMAGELOADER_H__

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

// KDE 
#include <kurl.h>

// QT
#include <qevent.h>
#include <qobject.h>
#include <qptrlist.h>
#include <qpixmap.h>
#include <qimage.h>

#ifndef Q_WS_WIN
#include <pthread.h>
#endif

#define	Event_ImageLoad	QEvent::Enter

class ImageListView;

class KFileItem;
class KPixmapIO;

class QFileInfo;

class ImageLoadEvent : public QEvent
{
public:
	ImageLoadEvent (QFileInfo * fi, bool t = true, bool f = false, bool fEXIF=false)
	: QEvent (Event_ImageLoad),
	  Info (fi),
	  Threaded (t),
	  Force(f),
	  ForceEXIF(fEXIF)
	 { }
	
	QFileInfo *fileInfo () const
	{
		return Info;
	}
	bool threaded () const
	{
		return Threaded;
	}
	bool force () const
	{
		return Force;
	}
	bool forceEXIF () const
	{
		return ForceEXIF;
	}
private:
	QFileInfo * Info;
	bool Threaded;
	bool Force;
	bool ForceEXIF;
};



#define	Event_NextImage		QEvent::Close
class NextImageEvent:public QEvent
{
public:
	NextImageEvent ():QEvent (Event_NextImage)
	{
	}
};

class ImageLoader:public QObject
{
	friend void *__thread_start (void *);
	friend void __thread_cleanup (void *);

public:
enum Orientation {
	NOT_AVAILABLE=0,
	NORMAL=1,
	HFLIP=2,
	ROT_180=3,
	VFLIP=4,
	ROT_90_HFLIP=5,
	ROT_90=6,
	ROT_90_VFLIP=7,
	ROT_270=8
};

	ImageLoader (ImageListView * parent = 0, const char *name = 0);
	~ImageLoader ();

	void loadMiniImage (QFileInfo * fi, bool threaded = true, bool force = false, bool forceEXIF=false);
	void stopLoading (bool clean = true);

	void setThumbnailSize(const QSize newSize);
	QSize getThumbnailSize();
	
	void setShowFrame(bool show);
	void setUseEXIF(bool useexif);
	
	void setStoreThumbnails(bool store);
	bool getStoreThumbnails();

	void rotateThumbnailLeft(QFileInfo *fi);
	void rotateThumbnailRight(QFileInfo *fi);
	
	QString thumbnailRootPath();
	QString thumbnailPath(const QString& path);
	
	KURL::List clearThumbnailDir(const QString& dirpath);
	KURL::List updateThumbnailDir(const QString& dirpath);
	
	static bool setEXIFThumbnail(const QString& path, const QImage& thumbnail);
	static bool rotateEXIFThumbnail(const QString& path, const Orientation orient);
	static bool setEXIFOrientation(const QString& path, const Orientation orient);

	
 
protected:
	QSize size;
	bool showFrame, useEXIF;

	void startLoading ();
	void loadImageInternal (ImageLoadEvent * e);
	void cantLoad (ImageLoadEvent * e);
	bool initLoading (ImageLoadEvent * e);
	void finishLoading (ImageLoadEvent * e);
	void loadWithNoThread (QFileInfo * fi, QWidget * w);
	void nextImage ();
	QPixmap addBorder(QPixmap *pix, bool hasAlpha=false);
	QPixmap addForeground(QPixmap *pix, bool hasAlpha);
	
	void reduce(QImage *im, int w, int h, bool force=false);

	virtual bool eventFilter (QObject * o, QEvent * e);
	virtual void timerEvent (QTimerEvent * e);

	void thread_start ();
	void thread_cleanup ();
	
	QString createCahePath(const QString& path);

private:
	QPtrList < ImageLoadEvent > EventList;
	QPtrList < ImageLoadEvent > ImageLoadedList;
#ifndef Q_WS_WIN
	pthread_t ThreadID;
	pthread_mutex_t Mutex;
#endif
	bool Running;
	
	bool mini_image_outdated, mini_image_file_exists, xvpics_dir_exists;
	QString mini_image_path, xvpics_path, image_path;
	QPixmap mini_image;
	KURL image_url;
	bool Loading;
	QImage InternalImage;
	QString InternalPath;
	ImageLoadEvent *InternalEvent;
	
	QImage ptop, pbottom, pright, pleft;
	QPixmap pbgxpm; 
	
	KPixmapIO *kPio;
	
	ImageListView *imageList;
	
	bool storeth;
	
	QString thumbRoot_KDE, thumbRoot_ShowImg;
};

#endif