File indexing completed on 2024-05-05 04:21:20
0001 0002 /* 0003 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org> 0004 All rights reserved. 0005 0006 Redistribution and use in source and binary forms, with or without 0007 modification, are permitted provided that the following conditions 0008 are met: 0009 0010 1. Redistributions of source code must retain the above copyright 0011 notice, this list of conditions and the following disclaimer. 0012 2. Redistributions in binary form must reproduce the above copyright 0013 notice, this list of conditions and the following disclaimer in the 0014 documentation and/or other materials provided with the distribution. 0015 0016 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 0017 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 0018 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 0019 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 0020 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 0021 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0022 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0023 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 0025 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0026 */ 0027 0028 0029 #define DEBUG_KP_ZOOMED_THUMBNAIL_VIEW 0 0030 0031 0032 #include "views/kpZoomedThumbnailView.h" 0033 0034 #include "kpLogCategories.h" 0035 #include "document/kpDocument.h" 0036 #include "views/manager/kpViewManager.h" 0037 0038 #include <KLocalizedString> 0039 0040 //-------------------------------------------------------------------------------- 0041 0042 kpZoomedThumbnailView::kpZoomedThumbnailView (kpDocument *document, 0043 kpToolToolBar *toolToolBar, 0044 kpViewManager *viewManager, 0045 kpView *buddyView, 0046 kpViewScrollableContainer *scrollableContainer, 0047 QWidget *parent ) 0048 0049 : kpThumbnailView (document, toolToolBar, viewManager, 0050 buddyView, 0051 scrollableContainer, 0052 parent) 0053 { 0054 // Call to virtual function - this is why the class is sealed 0055 adjustToEnvironment (); 0056 } 0057 0058 0059 kpZoomedThumbnailView::~kpZoomedThumbnailView () = default; 0060 0061 0062 // public virtual [base kpThumbnailView] 0063 QString kpZoomedThumbnailView::caption () const 0064 { 0065 return i18n ("%1% - Thumbnail", zoomLevelX ()); 0066 } 0067 0068 0069 // public slot virtual [base kpView] 0070 void kpZoomedThumbnailView::adjustToEnvironment () 0071 { 0072 #if DEBUG_KP_ZOOMED_THUMBNAIL_VIEW 0073 qCDebug(kpLogViews) << "kpZoomedThumbnailView(" << name () 0074 << ")::adjustToEnvironment()" 0075 << " width=" << width () 0076 << " height=" << height () 0077 << endl; 0078 #endif 0079 0080 if (!document ()) { 0081 return; 0082 } 0083 0084 #if DEBUG_KP_ZOOMED_THUMBNAIL_VIEW 0085 qCDebug(kpLogViews) << "\tdoc: width=" << document ()->width () 0086 << " height=" << document ()->height () 0087 << endl; 0088 #endif 0089 0090 if (document ()->width () <= 0 || document ()->height () <= 0) 0091 { 0092 qCCritical(kpLogViews) << "kpZoomedThumbnailView::adjustToEnvironment() doc:" 0093 << " width=" << document ()->width () 0094 << " height=" << document ()->height (); 0095 return; 0096 } 0097 0098 0099 int hzoom = qMax (1, width () * 100 / document ()->width ()); 0100 int vzoom = qMax (1, height () * 100 / document ()->height ()); 0101 0102 // keep aspect ratio 0103 if (hzoom < vzoom) { 0104 vzoom = hzoom; 0105 } 0106 else { 0107 hzoom = vzoom; 0108 } 0109 0110 #if DEBUG_KP_ZOOMED_THUMBNAIL_VIEW && 1 0111 qCDebug(kpLogViews) << "\tproposed zoom=" << hzoom; 0112 #endif 0113 if (hzoom > 100 || vzoom > 100) 0114 { 0115 #if DEBUG_KP_ZOOMED_THUMBNAIL_VIEW && 1 0116 qCDebug(kpLogViews) << "\twon't magnify - setting zoom to 100%"; 0117 #endif 0118 hzoom = 100; 0119 vzoom = 100; 0120 } 0121 0122 0123 if (viewManager ()) { 0124 viewManager ()->setQueueUpdates (); 0125 } 0126 0127 { 0128 setZoomLevel (hzoom, vzoom); 0129 0130 setOrigin (QPoint ((width () - zoomedDocWidth ()) / 2, 0131 (height () - zoomedDocHeight ()) / 2)); 0132 setMaskToCoverDocument (); 0133 0134 if (viewManager ()) { 0135 viewManager ()->updateView (this); 0136 } 0137 } 0138 0139 if (viewManager ()) { 0140 viewManager ()->restoreQueueUpdates (); 0141 } 0142 } 0143 0144 #include "moc_kpZoomedThumbnailView.cpp"