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.

kpselection.h 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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 __kpselection_h__
  24. #define __kpselection_h__
  25. #include <tqbitmap.h>
  26. #include <tqdatastream.h>
  27. #include <tqobject.h>
  28. #include <tqpixmap.h>
  29. #include <tqpoint.h>
  30. #include <tqpointarray.h>
  31. #include <tqvaluevector.h>
  32. #include <tqrect.h>
  33. #include <tqstring.h>
  34. #include <kpcolor.h>
  35. #include <kppixmapfx.h>
  36. #include <kpselectiontransparency.h>
  37. #include <kptextstyle.h>
  38. class TQSize;
  39. /*
  40. * Holds a selection - will also be used for the clipboard
  41. * so that we can retain the border.
  42. */
  43. class kpSelection : public TQObject
  44. {
  45. Q_OBJECT
  46. public:
  47. enum Type
  48. {
  49. Rectangle,
  50. Ellipse,
  51. Points,
  52. Text
  53. };
  54. // (for any)
  55. kpSelection (const kpSelectionTransparency &transparency = kpSelectionTransparency ());
  56. // (for Rectangle & Ellipse)
  57. kpSelection (Type type, const TQRect &rect, const TQPixmap &pixmap = TQPixmap (),
  58. const kpSelectionTransparency &transparency = kpSelectionTransparency ());
  59. kpSelection (Type type, const TQRect &rect, const kpSelectionTransparency &transparency);
  60. // (for Text)
  61. kpSelection (const TQRect &rect, const TQValueVector <TQString> &textLines_, const kpTextStyle &textStyle_);
  62. // (for Points)
  63. kpSelection (const TQPointArray &points, const TQPixmap &pixmap = TQPixmap (),
  64. const kpSelectionTransparency &transparency = kpSelectionTransparency ());
  65. kpSelection (const TQPointArray &points, const kpSelectionTransparency &transparency);
  66. kpSelection (const kpSelection &rhs);
  67. kpSelection &operator= (const kpSelection &rhs);
  68. friend TQDataStream &operator<< (TQDataStream &stream, const kpSelection &selection);
  69. friend TQDataStream &operator>> (TQDataStream &stream, kpSelection &selection);
  70. void readFromStream (TQDataStream &stream,
  71. const kpPixmapFX::WarnAboutLossInfo &wali =
  72. kpPixmapFX::WarnAboutLossInfo ());
  73. ~kpSelection ();
  74. private:
  75. void calculatePoints ();
  76. public:
  77. Type type () const;
  78. bool isRectangular () const;
  79. bool isText () const;
  80. // returns either i18n ("Selection") or i18n ("Text")
  81. TQString name () const;
  82. int size () const;
  83. TQBitmap maskForOwnType (bool nullForRectangular = false) const;
  84. // synonyms
  85. TQPoint topLeft () const;
  86. TQPoint point () const;
  87. int x () const;
  88. int y () const;
  89. void moveBy (int dx, int dy);
  90. void moveTo (int dx, int dy);
  91. void moveTo (const TQPoint &topLeftPoint);
  92. // synonyms
  93. TQPointArray points () const;
  94. TQPointArray pointArray () const;
  95. TQRect boundingRect () const;
  96. int width () const;
  97. int height () const;
  98. // (for non-rectangular selections, may return false even if
  99. // kpView::onSelectionResizeHandle())
  100. bool contains (const TQPoint &point) const;
  101. bool contains (int x, int y);
  102. // (Avoid using for text selections since text selection may
  103. // require a background for antialiasing purposes - use paint()
  104. // instead, else no antialising)
  105. TQPixmap *pixmap () const;
  106. void setPixmap (const TQPixmap &pixmap);
  107. bool usesBackgroundPixmapToPaint () const;
  108. private:
  109. void paintOpaqueText (TQPixmap *destPixmap, const TQRect &docRect) const;
  110. TQPixmap transparentForegroundTextPixmap () const;
  111. public:
  112. // (<docRect> is the document rectangle that <*destPixmap> represents)
  113. void paint (TQPixmap *destPixmap, const TQRect &docRect) const;
  114. private:
  115. void calculateTextPixmap ();
  116. public:
  117. static TQString textForTextLines (const TQValueVector <TQString> &textLines_);
  118. TQString text () const; // textLines() as one long string
  119. TQValueVector <TQString> textLines () const;
  120. void setTextLines (const TQValueVector <TQString> &textLines_);
  121. static int textBorderSize ();
  122. TQRect textAreaRect () const;
  123. bool pointIsInTextBorderArea (const TQPoint &globalPoint) const;
  124. bool pointIsInTextArea (const TQPoint &globalPoint) const;
  125. void textResize (int width, int height);
  126. // TODO: Enforce in kpSelection, not just in kpToolSelection & when pasting
  127. // (in kpMainWindow).
  128. // Be more robust when external enforcement fails.
  129. static int minimumWidthForTextStyle (const kpTextStyle &);
  130. static int minimumHeightForTextStyle (const kpTextStyle &);
  131. static TQSize minimumSizeForTextStyle (const kpTextStyle &);
  132. static int preferredMinimumWidthForTextStyle (const kpTextStyle &textStyle);
  133. static int preferredMinimumHeightForTextStyle (const kpTextStyle &textStyle);
  134. static TQSize preferredMinimumSizeForTextStyle (const kpTextStyle &textStyle);
  135. int minimumWidth () const;
  136. int minimumHeight () const;
  137. TQSize minimumSize () const;
  138. int textRowForPoint (const TQPoint &globalPoint) const;
  139. int textColForPoint (const TQPoint &globalPoint) const;
  140. TQPoint pointForTextRowCol (int row, int col);
  141. kpTextStyle textStyle () const;
  142. void setTextStyle (const kpTextStyle &textStyle);
  143. // TODO: ret val inconstent with pixmap()
  144. // - fix when merge with kpTempPixmap
  145. TQPixmap opaquePixmap () const; // same as pixmap()
  146. private:
  147. void calculateTransparencyMask ();
  148. public:
  149. // Returns opaquePixmap() after applying kpSelectionTransparency
  150. TQPixmap transparentPixmap () const;
  151. kpSelectionTransparency transparency () const;
  152. // Returns whether or not the selection changed due to setting the
  153. // transparency info. If <checkTransparentPixmapChanged> is set,
  154. // it will try harder to return false (although the check is
  155. // expensive).
  156. bool setTransparency (const kpSelectionTransparency &transparency,
  157. bool checkTransparentPixmapChanged = false);
  158. private:
  159. void flipPoints (bool horiz, bool vert);
  160. public:
  161. void flip (bool horiz, bool vert);
  162. signals:
  163. void changed (const TQRect &docRect);
  164. private:
  165. // OPT: use implicit sharing
  166. Type m_type;
  167. TQRect m_rect;
  168. TQPointArray m_points;
  169. TQPixmap *m_pixmap;
  170. TQValueVector <TQString> m_textLines;
  171. kpTextStyle m_textStyle;
  172. kpSelectionTransparency m_transparency;
  173. TQBitmap m_transparencyMask;
  174. private:
  175. // There is no need to maintain binary compatibility at this stage.
  176. // The d-pointer is just so that you can experiment without recompiling
  177. // the kitchen sink.
  178. class kpSelectionPrivate *d;
  179. };
  180. #endif // __kpselection_h__