home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / KoPicture.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-30  |  6.7 KB  |  260 lines

  1. /* This file is part of the KDE project
  2.    Copyright (c) 2001 Simon Hausmann <hausmann@kde.org>
  3.    Copyright (C) 2002, 2003, 2004 Nicolas GOUTTE <goutte@kde.org>
  4.  
  5.    This library is free software; you can redistribute it and/or
  6.    modify it under the terms of the GNU Library General Public
  7.    License as published by the Free Software Foundation; either
  8.    version 2 of the License, or (at your option) any later version.
  9.  
  10.    This library is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.    Library General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU Library General Public License
  16.    along with this library; see the file COPYING.LIB.  If not, write to
  17.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.  * Boston, MA 02110-1301, USA.
  19. */
  20. #ifndef __koPicture_h__
  21. #define __koPicture_h__
  22.  
  23. #include <qstring.h>
  24. #include <qiodevice.h>
  25. #include <qpixmap.h>
  26. #include <koffice_export.h>
  27.  
  28. #include "KoPictureKey.h"
  29.  
  30. class KoXmlWriter;
  31. class QPainter;
  32. class QSize;
  33. class QDragObject;
  34. class KURL;
  35.  
  36. class KoPictureShared;
  37.  
  38. /**
  39.  * KoPicture is a container class for various types of pictures supported by %KOffice.
  40.  *
  41.  * @short A picture container class
  42.  */
  43. class KOFFICECORE_EXPORT KoPicture
  44. {
  45. public:
  46.     /**
  47.      * Default constructor.
  48.      */
  49.     KoPicture(void);
  50.  
  51.     /**
  52.      * Destructor.
  53.      */
  54.     ~KoPicture(void);
  55.  
  56.     /**
  57.      * Copy constructor
  58.      */
  59.     KoPicture(const KoPicture &other);
  60.  
  61.     /**
  62.      * Assignment operator
  63.      */
  64.     KoPicture& operator=(const KoPicture& other);
  65.  
  66.     KoPictureType::Type getType(void) const;
  67.  
  68.     /**
  69.      * Retrieve the key structure describing the picture in a unique way.
  70.      */
  71.     KoPictureKey getKey(void) const;
  72.  
  73.     /**
  74.      * Set the key structure describing the picture in a unique way
  75.      */
  76.     void setKey(const KoPictureKey& key);
  77.  
  78.     /**
  79.      * Returns true if the picture is null.
  80.      */
  81.     bool isNull(void) const;
  82.  
  83.     /**
  84.      * @brief Draw the picture in a painter.
  85.      *
  86.      * The parameter @p fastMode allows the picture to be re-sized and drawn quicker if possible
  87.      *
  88.      * The parameters @p width, @p height define the desired size for the picture
  89.      *
  90.      * The other parameters are very similar to QPainter::drawPixmap :
  91.      * (@p x, @p y) define the position in the painter,
  92.      * (@p sx, @p sy) specify the top-left point in picture that is to be drawn. The default is (0, 0).
  93.      * (@p sw, @p sh) specify the size of the picture that is to be drawn. The default, (-1, -1), means all the way to the bottom
  94.      * right of the pixmap.
  95.      *
  96.      */
  97.     void draw(QPainter& painter, int x, int y, int width, int height, int sx = 0, int sy = 0,
  98.               int sw = -1, int sh = -1, bool fastMode = false);
  99.  
  100.     /**
  101.      * Create a dragobject containing this picture.
  102.      * @param dragSource must be 0 when copying to the clipboard
  103.      * @param name name for the QDragObject
  104.      * @return 0L if the picture is null, or if a dragobject for it isn't implemented [yet]
  105.      */
  106.     QDragObject* dragObject( QWidget *dragSource = 0L, const char *name = 0L );
  107.  
  108.     bool load(QIODevice* io, const QString& extension);
  109.  
  110.     /**
  111.      * Save picture into a QIODevice
  112.      * @param io QIODevice used for saving
  113.      */
  114.     bool save(QIODevice* io) const;
  115.  
  116.     /**
  117.      * OASIS FlatXML support:
  118.      * Save picture as base64-encoded data into an XML writer.
  119.      * The caller will usually do something like
  120.      * @code
  121.      *  writer.startElement( "office:binary-data" );
  122.      *  m_picture.saveAsBase64( writer );
  123.      *  writer.endElement();
  124.      * @endcode
  125.      */
  126.     bool saveAsBase64( KoXmlWriter& writer ) const;
  127.  
  128.     /**
  129.      * @return the image extension (e.g. png)
  130.      */
  131.     QString getExtension(void) const;
  132.  
  133.     /**
  134.      * @return the image MIME type
  135.      */
  136.     QString getMimeType(void) const;
  137.  
  138.     /**
  139.      * @return the original image size
  140.      */
  141.     QSize getOriginalSize(void) const;
  142.  
  143.     /**
  144.      * Clear and set the mode of this KoPicture
  145.      *
  146.      * @param newMode a file extension (like "png") giving the wanted mode
  147.      */
  148.     void clearAndSetMode(const QString& newMode);
  149.  
  150.     /**
  151.      * Reset the KoPicture (but not the key!)
  152.      */
  153.     void clear(void);
  154.  
  155.     /**
  156.      * Load the picture from a file named @p fileName
  157.      */
  158.     bool loadFromFile(const QString& fileName);
  159.  
  160.     /**
  161.      * Load the picture from base64-encoded data
  162.      */
  163.     bool loadFromBase64(const QCString& str);
  164.  
  165.     /**
  166.      * Load a potentially broken XPM file (for old files of KPresenter)
  167.      */
  168.     bool loadXpm(QIODevice* io);
  169.  
  170.     /**
  171.      * @deprecated To be replaced by @ref KoPicture::draw
  172.      *
  173.      * Returns a QPixmap from an image
  174.      * Returns an empty QPixmap if the KoPicture is not an image.
  175.      */
  176.     QPixmap generatePixmap(const QSize& size, bool smoothScale = false);
  177.  
  178.     /**
  179.      * Download and set the key for a possibly remote file.
  180.      *
  181.      * @param url the url to download from
  182.      * @param window the parent widget for the download. You can pass
  183.      *               NULL (0) if you absolutely cannot find a parent
  184.      *               widget to use.
  185.      */
  186.     bool setKeyAndDownloadPicture(const KURL& url, QWidget *window);
  187.  
  188.     /**
  189.      * Generate a QImage
  190.      * (always in slow mode)
  191.      *
  192.      * @param size the wanted size for the QImage
  193.      */
  194.     QImage generateImage(const QSize& size);
  195.  
  196.     /**
  197.      * @return TRUE if the alpha channel processing has been enabled
  198.      */
  199.     bool hasAlphaBuffer() const;
  200.  
  201.     /**
  202.      * Respect the image alpha buffer
  203.      */
  204.     void setAlphaBuffer(bool enable);
  205.  
  206.     /**
  207.      * Creates an alpha mask for the picture
  208.      * (first you have to call @ref #setAlphaBuffer).
  209.      *
  210.      * @see hasAlphaBuffer() setAlphaBuffer()
  211.      */
  212.     QImage createAlphaMask(int conversion_flags = 0) const;
  213.  
  214.     /**
  215.      * @brief Clear any cache
  216.      *
  217.      * This is used to avoid using too much memory
  218.      * especially if the application somehow also caches the KoPicture's output
  219.      */
  220.     void clearCache(void);
  221.  
  222.     QString uniquePictureId() const;
  223.     void assignPictureId( uint _id);
  224.  
  225. protected:
  226.     /**
  227.      * @internal
  228.      * Unregister shared data
  229.      */
  230.     void unlinkSharedData(void);
  231.     /**
  232.      * @internal
  233.      * Register shared data
  234.      */
  235.     void linkSharedData(void) const;
  236.     /**
  237.      * @internal
  238.      * Creare the shared data if needed
  239.      */
  240.     void createSharedData(void);
  241.     QString uniqueName() const;
  242.  
  243. protected:
  244.     /**
  245.      * @internal
  246.      * The key
  247.      */
  248.     KoPictureKey m_key;
  249.     /**
  250.      * @internal
  251.      * The shared data
  252.      */
  253.     KoPictureShared* m_sharedData;
  254.     static uint uniqueValue;
  255.  
  256.     QString m_uniqueName;
  257. };
  258.  
  259. #endif /* __koPicture_h__ */
  260.