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.

kpviewscrollablecontainer.h 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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_VIEW_SCROLLABLE_CONTAINER_H
  24. #define KP_VIEW_SCROLLABLE_CONTAINER_H
  25. #include <tqpoint.h>
  26. #include <tqscrollview.h>
  27. #include <tqsize.h>
  28. class TQCursor;
  29. class TQRect;
  30. class TQTimer;
  31. class kpGrip;
  32. class kpView;
  33. class kpMainWindow;
  34. // TODO: refactor by sharing iface's with kpTool
  35. class kpGrip : public TQWidget
  36. {
  37. Q_OBJECT
  38. public:
  39. enum GripType
  40. {
  41. Right = 1, Bottom = 2,
  42. BottomRight = Right | Bottom
  43. };
  44. kpGrip (GripType type,
  45. TQWidget *parent, const char *name = 0);
  46. virtual ~kpGrip ();
  47. GripType type () const;
  48. static const TQCursor &cursorForType (GripType type);
  49. TQRect hotRect (bool toGlobal = false) const;
  50. bool isDrawing () const;
  51. signals:
  52. void beganDraw ();
  53. void continuedDraw (int viewDX, int viewDY, bool dueToDragScroll);
  54. void cancelledDraw ();
  55. void endedDraw (int viewDX, int viewDY);
  56. void statusMessageChanged (const TQString &string);
  57. void releasedAllButtons ();
  58. public:
  59. TQString haventBegunDrawUserMessage () const;
  60. TQString userMessage () const;
  61. void setUserMessage (const TQString &message);
  62. protected:
  63. void updatePixmap ();
  64. void cancel ();
  65. protected:
  66. virtual void keyReleaseEvent (TQKeyEvent *e);
  67. virtual void mousePressEvent (TQMouseEvent *e);
  68. public:
  69. TQPoint viewDeltaPoint () const;
  70. void mouseMovedTo (const TQPoint &point, bool dueToDragScroll);
  71. protected:
  72. virtual void mouseMoveEvent (TQMouseEvent *e);
  73. virtual void mouseReleaseEvent (TQMouseEvent *e);
  74. virtual void resizeEvent (TQResizeEvent *e);
  75. virtual void enterEvent (TQEvent *e);
  76. virtual void leaveEvent (TQEvent *e);
  77. virtual void paintEvent (TQPaintEvent *e);
  78. protected:
  79. GripType m_type;
  80. TQPoint m_startPoint, m_currentPoint;
  81. TQString m_userMessage;
  82. bool m_shouldReleaseMouseButtons;
  83. };
  84. class kpViewScrollableContainer : public TQScrollView
  85. {
  86. Q_OBJECT
  87. public:
  88. kpViewScrollableContainer (kpMainWindow *parent, const char *name = 0);
  89. virtual ~kpViewScrollableContainer ();
  90. // Same as contentsX() and contentsY() except that after
  91. // contentsMovingSoon() is emitted and before the scrollview actually
  92. // scrolls, they return the would be values of contentsX() and
  93. // contentsY() after scrolling.
  94. int contentsXSoon ();
  95. int contentsYSoon ();
  96. signals:
  97. // connect to this instead of contentsMoving(int,int) so that
  98. // contentsXSoon() and contentsYSoon() work
  99. void contentsMovingSoon (int contentsX, int contentsY);
  100. void beganDocResize ();
  101. void continuedDocResize (const TQSize &size);
  102. void cancelledDocResize ();
  103. void endedDocResize (const TQSize &size);
  104. // (string.isEmpty() if kpViewScrollableContainer has nothing to say)
  105. void statusMessageChanged (const TQString &string);
  106. void resized ();
  107. public:
  108. TQSize newDocSize () const;
  109. bool haveMovedFromOriginalDocSize () const;
  110. TQString statusMessage () const;
  111. void clearStatusMessage ();
  112. protected:
  113. void connectGripSignals (kpGrip *grip);
  114. TQSize newDocSize (int viewDX, int viewDY) const;
  115. void calculateDocResizingGrip ();
  116. kpGrip *docResizingGrip () const;
  117. int bottomResizeLineWidth () const;
  118. int rightResizeLineWidth () const;
  119. TQRect bottomResizeLineRect () const;
  120. TQRect rightResizeLineRect () const;
  121. TQRect bottomRightResizeLineRect () const;
  122. TQPoint mapViewToViewport (const TQPoint &viewPoint);
  123. TQRect mapViewToViewport (const TQRect &viewRect);
  124. TQRect mapViewportToGlobal (const TQRect &viewportRect);
  125. TQRect mapViewToGlobal (const TQRect &viewRect);
  126. void repaintWidgetAtResizeLineViewRect (TQWidget *widget,
  127. const TQRect &resizeLineViewRect);
  128. void repaintWidgetAtResizeLines (TQWidget *widget);
  129. void eraseResizeLines ();
  130. void drawResizeLines ();
  131. void updateResizeLines (int viewX, int viewY,
  132. int viewDX, int viewDY);
  133. protected slots:
  134. void slotGripBeganDraw ();
  135. void slotGripContinuedDraw (int viewDX, int viewDY, bool dueToScrollView);
  136. void slotGripCancelledDraw ();
  137. void slotGripEndedDraw (int viewDX, int viewDY);
  138. void slotGripStatusMessageChanged (const TQString &string);
  139. public slots:
  140. void recalculateStatusMessage ();
  141. protected slots:
  142. void slotContentsMoving (int x, int y);
  143. void slotContentsMoved ();
  144. protected:
  145. void disconnectViewSignals ();
  146. void connectViewSignals ();
  147. public:
  148. // Calls setView(<widget>) after adding <widget> if it's a kpView.
  149. virtual void addChild (TQWidget *widget, int x = 0, int y = 0);
  150. kpView *view () const;
  151. void setView (kpView *view);
  152. public slots:
  153. void updateGrips ();
  154. protected slots:
  155. void slotViewDestroyed ();
  156. public slots:
  157. // TODO: Why the TQPoint's?
  158. // Why the need for view's zoomLevel? We have the view() anyway.
  159. bool beginDragScroll (const TQPoint &, const TQPoint &,
  160. int zoomLevel,
  161. bool *didSomething);
  162. bool beginDragScroll (const TQPoint &, const TQPoint &,
  163. int zoomLevel);
  164. bool endDragScroll ();
  165. protected slots:
  166. bool slotDragScroll (bool *didSomething);
  167. bool slotDragScroll ();
  168. protected:
  169. TQRect noDragScrollRect () const;
  170. virtual void contentsDragMoveEvent (TQDragMoveEvent *e);
  171. virtual void contentsMouseMoveEvent (TQMouseEvent *e);
  172. virtual void contentsWheelEvent (TQWheelEvent *e);
  173. virtual void mouseMoveEvent (TQMouseEvent *e);
  174. virtual bool eventFilter (TQObject *watchedObject, TQEvent *e);
  175. virtual void viewportPaintEvent (TQPaintEvent *e);
  176. virtual void paintEvent (TQPaintEvent *e);
  177. virtual void resizeEvent (TQResizeEvent *e);
  178. protected:
  179. kpMainWindow *m_mainWindow;
  180. int m_contentsXSoon, m_contentsYSoon;
  181. kpView *m_view;
  182. kpGrip *m_bottomGrip, *m_rightGrip, *m_bottomRightGrip;
  183. kpGrip *m_docResizingGrip;
  184. TQTimer *m_dragScrollTimer;
  185. int m_zoomLevel;
  186. bool m_scrollTimerRunOnce;
  187. int m_resizeRoundedLastViewX, m_resizeRoundedLastViewY;
  188. int m_resizeRoundedLastViewDX, m_resizeRoundedLastViewDY;
  189. bool m_haveMovedFromOriginalDocSize;
  190. TQString m_gripStatusMessage;
  191. };
  192. #endif // KP_VIEW_SCROLLABLE_CONTAINER_H