TDE graphics utilities
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

kpthumbnail.cpp 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. #define DEBUG_KP_THUMBNAIL 0
  24. #include <kpthumbnail.h>
  25. #include <tqdockarea.h>
  26. #include <tqdockwindow.h>
  27. #include <tqtimer.h>
  28. #include <kdebug.h>
  29. #include <tdelocale.h>
  30. #include <kpdefs.h>
  31. #include <kpdocument.h>
  32. #include <kpmainwindow.h>
  33. #include <kpthumbnailview.h>
  34. #include <kptool.h>
  35. // TODO: get out of the Alt+Tab list
  36. kpThumbnail::kpThumbnail (kpMainWindow *parent, const char *name)
  37. : TQDockWindow (TQDockWindow::OutsideDock, parent, name),
  38. m_mainWindow (parent),
  39. m_view (0)
  40. {
  41. if (!parent)
  42. kdError () << "kpThumbnail::kpThumbnail() requires parent" << endl;
  43. if (parent)
  44. {
  45. // Prevent thumbnail from docking - it's _really_ irritating otherwise
  46. parent->leftDock ()->setAcceptDockWindow (this, false);
  47. parent->rightDock ()->setAcceptDockWindow (this, false);
  48. parent->topDock ()->setAcceptDockWindow (this, false);
  49. parent->bottomDock ()->setAcceptDockWindow (this, false);
  50. }
  51. TQSize layoutMinimumSize = layout () ? layout ()->minimumSize () : TQSize ();
  52. #if DEBUG_KP_THUMBNAIL
  53. kdDebug () << "\tlayout=" << layout ()
  54. << " minSize=" << (layout () ? layout ()->minimumSize () : TQSize ()) << endl;
  55. kdDebug () << "\tboxLayout=" << boxLayout ()
  56. << " minSize=" << (boxLayout () ? boxLayout ()->minimumSize () : TQSize ())
  57. << endl;
  58. #endif
  59. if (layout ())
  60. layout ()->setResizeMode (TQLayout::FreeResize);
  61. setMinimumSize (TQMAX (layoutMinimumSize.width (), 64),
  62. TQMAX (layoutMinimumSize.height (), 64));
  63. // Enable "X" Close Button
  64. setCloseMode (TQDockWindow::Always);
  65. setResizeEnabled (true);
  66. updateCaption ();
  67. }
  68. kpThumbnail::~kpThumbnail ()
  69. {
  70. }
  71. // public
  72. kpThumbnailView *kpThumbnail::view () const
  73. {
  74. return m_view;
  75. }
  76. // public
  77. void kpThumbnail::setView (kpThumbnailView *view)
  78. {
  79. #if DEBUG_KP_THUMBNAIL
  80. kdDebug () << "kpThumbnail::setView(" << view << ")" << endl;
  81. #endif
  82. if (m_view == view)
  83. return;
  84. if (m_view)
  85. {
  86. disconnect (m_view, TQT_SIGNAL (destroyed ()),
  87. this, TQT_SLOT (slotViewDestroyed ()));
  88. disconnect (m_view, TQT_SIGNAL (zoomLevelChanged (int, int)),
  89. this, TQT_SLOT (updateCaption ()));
  90. boxLayout ()->remove (m_view);
  91. }
  92. m_view = view;
  93. if (m_view)
  94. {
  95. connect (m_view, TQT_SIGNAL (destroyed ()),
  96. this, TQT_SLOT (slotViewDestroyed ()));
  97. connect (m_view, TQT_SIGNAL (zoomLevelChanged (int, int)),
  98. this, TQT_SLOT (updateCaption ()));
  99. updateCaption ();
  100. boxLayout ()->addWidget (m_view);
  101. m_view->show ();
  102. }
  103. }
  104. // public slot
  105. void kpThumbnail::updateCaption ()
  106. {
  107. setCaption (view () ? view ()->caption () : i18n ("Thumbnail"));
  108. }
  109. // public slot virtual [base TQDockWindow]
  110. void kpThumbnail::dock ()
  111. {
  112. #if DEBUG_KP_THUMBNAIL
  113. kdDebug () << "kpThumbnail::dock() CALLED - ignoring request" << endl;
  114. #endif
  115. // --- ignore all requests to dock ---
  116. }
  117. // protected slot
  118. void kpThumbnail::slotViewDestroyed ()
  119. {
  120. #if DEBUG_KP_THUMBNAIL
  121. kdDebug () << "kpThumbnail::slotViewDestroyed()" << endl;
  122. #endif
  123. m_view = 0;
  124. updateCaption ();
  125. }
  126. // protected virtual [base TQWidget]
  127. void kpThumbnail::resizeEvent (TQResizeEvent *e)
  128. {
  129. #if DEBUG_KP_THUMBNAIL
  130. kdDebug () << "kpThumbnail::resizeEvent(" << width ()
  131. << "," << height () << ")" << endl;
  132. #endif
  133. TQDockWindow::resizeEvent (e);
  134. // updateVariableZoom (); TODO: is below a good idea since this commented out
  135. if (m_mainWindow)
  136. {
  137. m_mainWindow->notifyThumbnailGeometryChanged ();
  138. if (m_mainWindow->tool ())
  139. m_mainWindow->tool ()->somethingBelowTheCursorChanged ();
  140. }
  141. }
  142. // protected virtual [base TQWidget]
  143. void kpThumbnail::moveEvent (TQMoveEvent * /*e*/)
  144. {
  145. if (m_mainWindow)
  146. m_mainWindow->notifyThumbnailGeometryChanged ();
  147. }
  148. #include <kpthumbnail.moc>