moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kstars / kstars / imageviewer.h
blob7b1d3d4506dffe62f7b7be9f4a80a73c817fb517
1 /***************************************************************************
2 imageviewer.h - An ImageViewer for KStars
3 -------------------
4 begin : Mon Aug 27 2001
5 copyright : (C) 2001 by Thomas Kabelmann
6 email : tk78@gmx.de
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
18 #ifndef IMAGEVIEWER_H
19 #define IMAGEVIEWER_H
21 #include <qimage.h>
22 #include <qpixmap.h>
24 #include <kpixmapio.h>
25 #include <kio/job.h>
26 #include <ktempfile.h>
27 #include <kmainwindow.h>
29 /**@class ImageViewer
30 *@short Image viewer widget for KStars
31 *@author Thomas Kabelmann
32 *@version 1.0
34 *This image-viewer automatically resizes the picture. The output
35 *works with kio-slaves and not directly with the QImage save-routines
36 *because normally the image-files are in GIF-format and QT does not
37 *save these files. For other formats, like PNG, this is not so important
38 *because they can directly saved by QImage.
40 *The download-slave works asynchron so the parent-widget can be used at
41 *this time. The save-slave works synchronously, but this is not important
42 *because the files are at this time local saved and this works not so long.
45 class KURL;
46 class QFile;
48 class ImageViewer : public KMainWindow {
49 Q_OBJECT
51 public:
52 /**Constructor. */
53 ImageViewer (const KURL *imageName, const QString &capText, QWidget *parent, const char *name = 0);
55 /**Destructor. If there is a partially downloaded image file, delete it.*/
56 ~ImageViewer();
58 protected:
59 /**Bitblt the image onto the viewer widget */
60 void paintEvent (QPaintEvent *ev);
62 /**The window is resized when a file finishes downloading, before it is displayed.
63 *The resizeEvent converts the downloaded QImage to a QPixmap
64 *@note (JH: not sure why this conversion is not done in showImage)
66 void resizeEvent (QResizeEvent *ev);
68 /**Make sure all events have been processed before closing the dialog */
69 void closeEvent (QCloseEvent *ev);
71 /**Keyboard shortcuts for saving files and closing the window
72 *@note (this should be deprecated; instead just assign KAccel
73 *to the close/save buttons)
75 void keyPressEvent (QKeyEvent *ev);
77 /**Unset the bool variables that indicate keys were pressed.
78 *(this should be deprecated; see above)
80 void keyReleaseEvent (QKeyEvent *ev);
82 private:
83 /**Display the downloaded image. Resize the window to fit the image, If the image is
84 *larger than the screen, make the image as large as possible while preserving the
85 *original aspect ratio
87 void showImage( void );
89 /**Download the image file pointed to by the URL string.
91 void loadImageFromURL( void );
93 /**Save the downloaded image to a local file.
95 void saveFile (KURL &url);
97 /**Kill running download jobs, if close of window is forced.
99 void checkJob();
101 QImage image;
102 QPixmap pix;
103 KPixmapIO kpix;
104 KTempFile tempfile;
105 QFile *file;
107 const KURL imageURL;
108 bool fileIsImage;
109 QString filename;
110 bool ctrl, key_s, key_q; // the keys
112 KIO::Job *downloadJob; // download job of image -> 0 == no job is running
114 private slots:
115 /**Make sure download has finished, then make sure file exists, then display the image */
116 void downloadReady (KIO::Job *);
118 /**Saves. File. To. Disc. */
119 void saveFileToDisc( void );
121 /**Close the window.*/
122 void close( void );
125 #endif