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.

kpviewmanager.h 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 __kpviewmanager_h__
  24. #define __kpviewmanager_h__
  25. #include <tqcursor.h>
  26. #include <tqobject.h>
  27. #include <tqptrlist.h>
  28. #include <tqrect.h>
  29. class TQPixmap;
  30. class TQRect;
  31. class TQTimer;
  32. class kpDocument;
  33. class kpView;
  34. class kpMainWindow;
  35. class kpTempPixmap;
  36. class kpViewManager : public TQObject
  37. {
  38. Q_OBJECT
  39. public:
  40. kpViewManager (kpMainWindow *mainWindow);
  41. ~kpViewManager ();
  42. //
  43. // Registering views
  44. //
  45. void registerView (kpView *view);
  46. void unregisterView (kpView *view);
  47. void unregisterAllViews ();
  48. //
  49. // Temp Pixmap
  50. //
  51. const kpTempPixmap *tempPixmap () const;
  52. void setTempPixmap (const kpTempPixmap &tempPixmap);
  53. void invalidateTempPixmap ();
  54. //
  55. // Selections
  56. //
  57. bool selectionBorderVisible () const;
  58. void setSelectionBorderVisible (bool yes = true);
  59. bool selectionBorderFinished () const;
  60. void setSelectionBorderFinished (bool yes = true);
  61. //
  62. // Text Cursor
  63. //
  64. bool textCursorEnabled () const;
  65. void setTextCursorEnabled (bool yes = true);
  66. int textCursorRow () const;
  67. int textCursorCol () const;
  68. void setTextCursorPosition (int row, int col, bool isUpdateMicroFocusHint = false);
  69. bool textCursorBlinkState () const;
  70. void setTextCursorBlinkState (bool on = true);
  71. protected:
  72. void updateTextCursor ();
  73. TQTimer *m_textCursorBlinkTimer;
  74. int m_textCursorRow, m_textCursorCol;
  75. bool m_textCursorBlinkState;
  76. protected slots:
  77. void slotTextCursorBlink ();
  78. public:
  79. //
  80. // Cursors
  81. //
  82. void setCursor (const TQCursor &cursor);
  83. void unsetCursor ();
  84. //
  85. // View
  86. //
  87. kpView *viewUnderCursor (bool usingTQt = false) const;
  88. //
  89. // TQWidget::hasMouse() is unreliable:
  90. //
  91. // "bool TQWidget::hasMouse () const
  92. // ... See the "underMouse" property for details.
  93. // .
  94. // .
  95. // .
  96. // bool underMouse
  97. // ... This value is not updated properly during drag and drop operations."
  98. //
  99. // i.e. it's possible that hasMouse() returns false in a mousePressEvent()!
  100. //
  101. // This hack needs to be called from kpView so that viewUnderCursor() works
  102. // as a reasonable replacement (although there is at least one case where
  103. // it still won't work - just after a fake drag onto the view).
  104. //
  105. void setViewUnderCursor (kpView *view);
  106. // Returns a pointer to the view that has keyboard focus or else, 0
  107. // TODO: rename to "anActiveView()" or "aViewIsActive()" as more than
  108. // 1 view can be active at the same time?
  109. kpView *activeView () const;
  110. // Specifies whether KolourPaint will queue _all_ paint events
  111. // (generated by you or the window system), until the
  112. // corresponding call to restoreQueueUpdates(). Use this
  113. // before multiple, big, non-interactive changes to the
  114. // document to eliminate virtually all flicker.
  115. //
  116. // This is better than TQWidget::setUpdatesEnabled() because
  117. // restoreQueueUpdates() automatically restores only the regions
  118. // of the views that need to be repainted, per view.
  119. bool queueUpdates () const;
  120. void setQueueUpdates ();
  121. void restoreQueueUpdates ();
  122. // Controls behaviour of updateViews():
  123. //
  124. // Slow: Let TQt buffer paint events via TQWidget::update().
  125. // Results in less flicker. Paint events are probably merged
  126. // so long-term efficiency is increased at the expense of
  127. // reduced responsiveness (default).
  128. // Fast: Force TQt to redraw immediately. No paint events
  129. // are merged so there is great potential for flicker,
  130. // if used inappropriately. Use this when the redraw
  131. // area is small and KolourPaint's responsiveness is
  132. // critical. Continual use of this mode can result in
  133. // unnecessary redraws and incredibly slugish performance.
  134. bool fastUpdates () const;
  135. void setFastUpdates ();
  136. void restoreFastUpdates ();
  137. private:
  138. int m_queueUpdatesCounter, m_fastUpdatesCounter;
  139. public slots:
  140. // updating views
  141. void updateView (kpView *v);
  142. void updateView (kpView *v, const TQRect &viewRect);
  143. void updateView (kpView *v, int x, int y, int w, int h);
  144. void updateView (kpView *v, const TQRegion &viewRegion);
  145. void updateViewRectangleEdges (kpView *v, const TQRect &viewRect);
  146. void updateViews ();
  147. void updateViews (const TQRect &docRect);
  148. void updateViews (int x, int y, int w, int h);
  149. void adjustViewsToEnvironment ();
  150. private:
  151. // don't use
  152. kpViewManager (const kpViewManager &);
  153. bool operator= (const kpViewManager &);
  154. kpDocument *document () const;
  155. kpMainWindow *m_mainWindow;
  156. TQPtrList <kpView> m_views;
  157. TQCursor m_cursor;
  158. kpTempPixmap *m_tempPixmap;
  159. kpView *m_viewUnderCursor;
  160. bool m_selectionBorderVisible;
  161. bool m_selectionBorderFinished;
  162. // There is no need to maintain binary compatibility at this stage.
  163. // The d-pointer is just so that you can experiment without recompiling
  164. // the kitchen sink.
  165. class kpViewManagerPrivate *d;
  166. };
  167. #endif // __kpviewmanager_h__