summaryrefslogtreecommitdiffstats
path: root/kstars/kstars/imageviewer.h
blob: 7ebf8afb6fbf52119fd135134570902dd41a64b8 (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
/***************************************************************************
                          imageviewer.h  -  An ImageViewer for KStars
                             -------------------
    begin                : Mon Aug 27 2001
    copyright            : (C) 2001 by Thomas Kabelmann
    email                : tk78@gmx.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef IMAGEVIEWER_H
#define IMAGEVIEWER_H

#include <tqimage.h>
#include <tqpixmap.h>

#include <kpixmapio.h>
#include <kio/job.h>
#include <ktempfile.h>
#include <kmainwindow.h>

/**@class ImageViewer
	*@short Image viewer widget for KStars
	*@author Thomas Kabelmann
	*@version 1.0
	*
	*This image-viewer automatically resizes the picture. The output 
	*works with kio-slaves and not directly with the TQImage save-routines 
	*because normally the image-files are in GIF-format and QT does not 
	*save these files. For other formats, like PNG, this is not so important 
	*because they can directly saved by TQImage.
	*
	*The download-slave works asynchron so the parent-widget can be used at 
	*this time. The save-slave works synchronously, but this is not important 
	*because the files are at this time local saved and this works not so long.
	*/

class KURL;
class QFile;

class ImageViewer : public KMainWindow  {
	Q_OBJECT

	public:
	/**Constructor. */
		ImageViewer (const KURL *imageName, const TQString &capText, TQWidget *parent, const char *name = 0);

	/**Destructor. If there is a partially downloaded image file, delete it.*/
		~ImageViewer();

	protected:
	/**Bitblt the image onto the viewer widget */
		void paintEvent (TQPaintEvent *ev);

	/**The window is resized when a file finishes downloading, before it is displayed.
		*The resizeEvent converts the downloaded TQImage to a TQPixmap 
		*@note (JH: not sure why this conversion is not done in showImage)
		*/
		void resizeEvent (TQResizeEvent *ev);

	/**Make sure all events have been processed before closing the dialog */
		void closeEvent (TQCloseEvent *ev);

	/**Keyboard shortcuts for saving files and closing the window
		*@note (this should be deprecated; instead just assign KAccel 
		*to the close/save buttons)
		*/
		void keyPressEvent (TQKeyEvent *ev);

	/**Unset the bool variables that indicate keys were pressed.
		*(this should be deprecated; see above)
		*/
		void keyReleaseEvent (TQKeyEvent *ev);

	private:
	/**Display the downloaded image.  Resize the window to fit the image,  If the image is
		*larger than the screen, make the image as large as possible while preserving the
		*original aspect ratio
		*/
		void showImage( void );

	/**Download the image file pointed to by the URL string.
		*/
		void loadImageFromURL( void );

	/**Save the downloaded image to a local file.
		*/
		void saveFile (KURL &url);
		
	/**Kill running download jobs, if close of window is forced.
		*/
		void checkJob();

		TQImage image;
		TQPixmap pix;
		KPixmapIO kpix;
		KTempFile tempfile;
		TQFile *file;
		
		const KURL imageURL;
		bool fileIsImage;
		TQString filename;
		bool ctrl, key_s, key_q;	// the keys

		KIO::Job *downloadJob;  // download job of image -> 0 == no job is running
		
	private slots:
	/**Make sure download has finished, then make sure file exists, then display the image */
		void downloadReady (KIO::Job *);

	/**Saves. File. To. Disc. */
		void saveFileToDisc( void );

	/**Close the window.*/
		void close( void );
};

#endif