TDE graphics utilities
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

kpdocument.h 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*
  2. Copyright (c) 2003,2004,2005 Clarence Dang <dang@kde.org>
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions
  6. are met:
  7. 1. Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  13. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  14. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  15. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  16. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  17. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  18. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  19. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  20. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  21. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. */
  23. #ifndef KP_DOCUMENT_H
  24. #define KP_DOCUMENT_H
  25. #include <tqbitmap.h>
  26. #include <tqobject.h>
  27. #include <tqstring.h>
  28. #include <kurl.h>
  29. #include <kppixmapfx.h>
  30. class TQImage;
  31. class TQIODevice;
  32. class TQPixmap;
  33. class TQPoint;
  34. class TQRect;
  35. class TQSize;
  36. class kpColor;
  37. class kpDocumentSaveOptions;
  38. class kpDocumentMetaInfo;
  39. class kpMainWindow;
  40. class kpSelection;
  41. class kpDocument : public TQObject
  42. {
  43. Q_OBJECT
  44. public:
  45. kpDocument (int w, int h, kpMainWindow *mainWindow);
  46. ~kpDocument ();
  47. kpMainWindow *mainWindow () const;
  48. void setMainWindow (kpMainWindow *mainWindow);
  49. /*
  50. * File I/O
  51. */
  52. // Wraps kpPixmapFX::convertToPixmapAsLosslessAsPossible() but also
  53. // returns document meta information.
  54. static TQPixmap convertToPixmapAsLosslessAsPossible (
  55. const TQImage &image,
  56. const kpPixmapFX::WarnAboutLossInfo &wali = kpPixmapFX::WarnAboutLossInfo (),
  57. kpDocumentSaveOptions *saveOptions = 0,
  58. kpDocumentMetaInfo *metaInfo = 0);
  59. static TQPixmap getPixmapFromFile (const KURL &url, bool suppressDoesntExistDialog,
  60. TQWidget *parent,
  61. kpDocumentSaveOptions *saveOptions = 0,
  62. kpDocumentMetaInfo *metaInfo = 0);
  63. // TODO: fix: open*() should only be called once.
  64. // Create a new kpDocument() if you want to open again.
  65. void openNew (const KURL &url);
  66. bool open (const KURL &url, bool newDocSameNameIfNotExist = false);
  67. static bool lossyPromptContinue (const TQPixmap &pixmap,
  68. const kpDocumentSaveOptions &saveOptions,
  69. TQWidget *parent);
  70. static bool savePixmapToDevice (const TQPixmap &pixmap,
  71. TQIODevice *device,
  72. const kpDocumentSaveOptions &saveOptions,
  73. const kpDocumentMetaInfo &metaInfo,
  74. bool lossyPrompt,
  75. TQWidget *parent,
  76. bool *userCancelled = 0);
  77. static bool savePixmapToFile (const TQPixmap &pixmap,
  78. const KURL &url,
  79. const kpDocumentSaveOptions &saveOptions,
  80. const kpDocumentMetaInfo &metaInfo,
  81. bool overwritePrompt,
  82. bool lossyPrompt,
  83. TQWidget *parent);
  84. bool save (bool overwritePrompt = false, bool lossyPrompt = false);
  85. bool saveAs (const KURL &url,
  86. const kpDocumentSaveOptions &saveOptions,
  87. bool overwritePrompt = true,
  88. bool lossyPrompt = true);
  89. // Returns whether save() or saveAs() have ever been called and returned true
  90. bool savedAtLeastOnceBefore () const;
  91. KURL url () const;
  92. void setURL (const KURL &url, bool isFromURL);
  93. // Returns whether the document's pixmap was successfully opened from
  94. // or saved to the URL returned by url(). This is not true for a
  95. // new kpDocument and in the case of open() being passed
  96. // "newDocSameNameIfNotExist = true" when the URL doesn't exist.
  97. //
  98. // If this returns true and the kpDocument hasn't been modified,
  99. // this gives a pretty good indication that the pixmap stored at url()
  100. // is equal to pixmap() (unless the something has happened to that url
  101. // outside of KolourPaint).
  102. bool isFromURL (bool checkURLStillExists = true) const;
  103. // (will convert: empty URL --> "Untitled")
  104. static TQString prettyURLForURL (const KURL &url);
  105. TQString prettyURL () const;
  106. // (will convert: empty URL --> "Untitled")
  107. static TQString prettyFilenameForURL (const KURL &url);
  108. TQString prettyFilename () const;
  109. // (guaranteed to return valid pointer)
  110. const kpDocumentSaveOptions *saveOptions () const;
  111. void setSaveOptions (const kpDocumentSaveOptions &saveOptions);
  112. const kpDocumentMetaInfo *metaInfo () const;
  113. void setMetaInfo (const kpDocumentMetaInfo &metaInfo);
  114. /*
  115. * Properties (modified, width, height, color depth...)
  116. */
  117. void setModified (bool yes = true);
  118. bool isModified () const;
  119. bool isEmpty () const;
  120. int constructorWidth () const; // as passed to the constructor
  121. int width (bool ofSelection = false) const;
  122. int oldWidth () const; // only valid in a slot connected to sizeChanged()
  123. void setWidth (int w, const kpColor &backgroundColor);
  124. int constructorHeight () const; // as passed to the constructor
  125. int height (bool ofSelection = false) const;
  126. int oldHeight () const; // only valid in a slot connected to sizeChanged()
  127. void setHeight (int h, const kpColor &backgroundColor);
  128. TQRect rect (bool ofSelection = false) const;
  129. /*
  130. * Pixmap access
  131. */
  132. // get a copy of a bit of the doc's pixmap
  133. // (not including the selection)
  134. TQPixmap getPixmapAt (const TQRect &rect) const;
  135. void setPixmapAt (const TQPixmap &pixmap, const TQPoint &at);
  136. void paintPixmapAt (const TQPixmap &pixmap, const TQPoint &at);
  137. // (not including the selection)
  138. TQPixmap *pixmap (bool ofSelection = false) const;
  139. void setPixmap (const TQPixmap &pixmap);
  140. void setPixmap (bool ofSelection, const TQPixmap &pixmap);
  141. private:
  142. void updateToolsSingleKeyTriggersEnabled ();
  143. public:
  144. kpSelection *selection () const;
  145. void setSelection (const kpSelection &selection);
  146. // TODO: this always returns opaque pixmap - need transparent ver
  147. TQPixmap getSelectedPixmap (const TQBitmap &maskBitmap = TQBitmap ()) const;
  148. bool selectionPullFromDocument (const kpColor &backgroundColor);
  149. bool selectionDelete ();
  150. bool selectionCopyOntoDocument (bool useTransparentPixmap = true);
  151. bool selectionPushOntoDocument (bool useTransparentPixmap = true);
  152. // same as pixmap() but returns a _copy_ of the current pixmap
  153. // + any selection pasted on top
  154. TQPixmap pixmapWithSelection () const;
  155. /*
  156. * Transformations
  157. * (convenience only - you could achieve the same effect (and more) with
  158. * kpPixmapFX: these functions do not affect the selection)
  159. */
  160. void fill (const kpColor &color);
  161. void resize (int w, int h, const kpColor &backgroundColor, bool fillNewAreas = true);
  162. public slots:
  163. // these will emit signals!
  164. void slotContentsChanged (const TQRect &rect);
  165. void slotSizeChanged (int newWidth, int newHeight);
  166. void slotSizeChanged (const TQSize &newSize);
  167. signals:
  168. void documentOpened ();
  169. void documentSaved ();
  170. // Emitted whenever the isModified() flag changes from false to true.
  171. // This is the _only_ signal that may be emitted in addition to the others.
  172. void documentModified ();
  173. void contentsChanged (const TQRect &rect);
  174. void sizeChanged (int newWidth, int newHeight); // see oldWidth(), oldHeight()
  175. void sizeChanged (const TQSize &newSize);
  176. void selectionEnabled (bool on);
  177. // HACK: until we support Text Selection -> Rectangular Selection for Image ops
  178. void selectionIsTextChanged (bool isText);
  179. private:
  180. int m_constructorWidth, m_constructorHeight;
  181. kpMainWindow *m_mainWindow;
  182. TQPixmap *m_pixmap;
  183. KURL m_url;
  184. bool m_isFromURL;
  185. bool m_savedAtLeastOnceBefore;
  186. kpDocumentSaveOptions *m_saveOptions;
  187. kpDocumentMetaInfo *m_metaInfo;
  188. bool m_modified;
  189. kpSelection *m_selection;
  190. int m_oldWidth, m_oldHeight;
  191. // There is no need to maintain binary compatibility at this stage.
  192. // The d-pointer is just so that you can experiment without recompiling
  193. // the kitchen sink.
  194. class kpDocumentPrivate *d;
  195. };
  196. #endif // KP_DOCUMENT_H