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.

141 lines
4.1KB

  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_ZOOMED_THUMBNAIL_VIEW 0
  24. #include <kpzoomedthumbnailview.h>
  25. #include <kdebug.h>
  26. #include <tdelocale.h>
  27. #include <kpdocument.h>
  28. #include <kpviewmanager.h>
  29. kpZoomedThumbnailView::kpZoomedThumbnailView (kpDocument *document,
  30. kpToolToolBar *toolToolBar,
  31. kpViewManager *viewManager,
  32. kpView *buddyView,
  33. kpViewScrollableContainer *scrollableContainer,
  34. TQWidget *parent, const char *name)
  35. : kpThumbnailView (document, toolToolBar, viewManager,
  36. buddyView,
  37. scrollableContainer,
  38. parent, name)
  39. {
  40. // Call to virtual function - this is why the class is sealed
  41. adjustToEnvironment ();
  42. }
  43. kpZoomedThumbnailView::~kpZoomedThumbnailView ()
  44. {
  45. }
  46. // public virtual [base kpThumbnailView]
  47. TQString kpZoomedThumbnailView::caption () const
  48. {
  49. return i18n ("%1% - Thumbnail").arg (zoomLevelX ());
  50. }
  51. // public slot virtual [base kpView]
  52. void kpZoomedThumbnailView::adjustToEnvironment ()
  53. {
  54. #if DEBUG_KP_ZOOMED_THUMBNAIL_VIEW
  55. kdDebug () << "kpZoomedThumbnailView(" << name ()
  56. << ")::adjustToEnvironment()"
  57. << " width=" << width ()
  58. << " height=" << height ()
  59. << endl;
  60. #endif
  61. if (!document ())
  62. return;
  63. #if DEBUG_KP_ZOOMED_THUMBNAIL_VIEW
  64. kdDebug () << "\tdoc: width=" << document ()->width ()
  65. << " height=" << document ()->height ()
  66. << endl;
  67. #endif
  68. if (document ()->width () <= 0 || document ()->height () <= 0)
  69. {
  70. kdError () << "kpZoomedThumbnailView::adjustToEnvironment() doc:"
  71. << " width=" << document ()->width ()
  72. << " height=" << document ()->height ()
  73. << endl;
  74. return;
  75. }
  76. int hzoom = TQMAX (1, width () * 100 / document ()->width ());
  77. int vzoom = TQMAX (1, height () * 100 / document ()->height ());
  78. // keep aspect ratio
  79. if (hzoom < vzoom)
  80. vzoom = hzoom;
  81. else
  82. hzoom = vzoom;
  83. #if DEBUG_KP_ZOOMED_THUMBNAIL_VIEW && 1
  84. kdDebug () << "\tproposed zoom=" << hzoom << endl;
  85. #endif
  86. if (hzoom > 100 || vzoom > 100)
  87. {
  88. #if DEBUG_KP_ZOOMED_THUMBNAIL_VIEW && 1
  89. kdDebug () << "\twon't magnify - setting zoom to 100%" << endl;
  90. #endif
  91. hzoom = 100, vzoom = 100;
  92. }
  93. if (viewManager ())
  94. viewManager ()->setQueueUpdates ();
  95. {
  96. setZoomLevel (hzoom, vzoom);
  97. setOrigin (TQPoint ((width () - zoomedDocWidth ()) / 2,
  98. (height () - zoomedDocHeight ()) / 2));
  99. setMaskToCoverDocument ();
  100. if (viewManager ())
  101. viewManager ()->updateView (this);
  102. }
  103. if (viewManager ())
  104. viewManager ()->restoreQueueUpdates ();
  105. }
  106. #include <kpzoomedthumbnailview.moc>