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.

kptoolautocrop.h 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 __kptoolautocrop_h__
  24. #define __kptoolautocrop_h__
  25. #include <tqrect.h>
  26. #include <kpcommandhistory.h>
  27. #include <kpcolor.h>
  28. #include <kpselection.h>
  29. class TQPixmap;
  30. class kpDocument;
  31. class kpMainWindow;
  32. class kpViewManager;
  33. // (returns true on success (even if it did nothing) or false on error)
  34. bool kpToolAutoCrop (kpMainWindow *mainWindow);
  35. class kpToolAutoCropBorder
  36. {
  37. public:
  38. kpToolAutoCropBorder (const TQPixmap *pixmapPtr, int processedColorSimilarity);
  39. int size () const;
  40. const TQPixmap *pixmap () const;
  41. int processedColorSimilarity () const;
  42. TQRect rect () const;
  43. int left () const;
  44. int right () const;
  45. int top () const;
  46. int bottom () const;
  47. kpColor referenceColor () const;
  48. kpColor averageColor () const;
  49. bool isSingleColor () const;
  50. // (returns true on success (even if no rect) or false on error)
  51. bool calculate (int isX, int dir);
  52. bool fillsEntirePixmap () const;
  53. bool exists () const;
  54. void invalidate ();
  55. private:
  56. const TQPixmap *m_pixmapPtr;
  57. int m_processedColorSimilarity;
  58. TQRect m_rect;
  59. kpColor m_referenceColor;
  60. int m_redSum, m_greenSum, m_blueSum;
  61. bool m_isSingleColor;
  62. };
  63. class kpToolAutoCropCommand : public kpNamedCommand
  64. {
  65. public:
  66. kpToolAutoCropCommand (bool actOnSelection,
  67. const kpToolAutoCropBorder &leftBorder,
  68. const kpToolAutoCropBorder &rightBorder,
  69. const kpToolAutoCropBorder &topBorder,
  70. const kpToolAutoCropBorder &botBorder,
  71. kpMainWindow *mainWindow);
  72. virtual ~kpToolAutoCropCommand ();
  73. enum NameOptions
  74. {
  75. DontShowAccel = 0,
  76. ShowAccel = 1
  77. };
  78. static TQString name (bool actOnSelection, int options);
  79. virtual int size () const;
  80. private:
  81. void getUndoPixmap (const kpToolAutoCropBorder &border, TQPixmap **pixmap);
  82. void getUndoPixmaps ();
  83. void deleteUndoPixmaps ();
  84. public:
  85. virtual void execute ();
  86. virtual void unexecute ();
  87. private:
  88. TQRect contentsRect () const;
  89. bool m_actOnSelection;
  90. kpToolAutoCropBorder m_leftBorder, m_rightBorder, m_topBorder, m_botBorder;
  91. TQPixmap *m_leftPixmap, *m_rightPixmap, *m_topPixmap, *m_botPixmap;
  92. TQRect m_contentsRect;
  93. int m_oldWidth, m_oldHeight;
  94. kpSelection m_oldSelection;
  95. };
  96. #endif // __kptoolautocrop_h__