Warning, file /graphics/kolourpaint/views/manager/kpViewManager_ViewUpdates.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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_VIEW_MANAGER 0 0030 0031 0032 #include "views/manager/kpViewManager.h" 0033 #include "kpViewManagerPrivate.h" 0034 0035 0036 #include "kpLogCategories.h" 0037 0038 #include "kpDefs.h" 0039 #include "document/kpDocument.h" 0040 #include "mainWindow/kpMainWindow.h" 0041 #include "layers/tempImage/kpTempImage.h" 0042 #include "layers/selections/text/kpTextSelection.h" 0043 #include "tools/kpTool.h" 0044 #include "views/kpView.h" 0045 0046 0047 // public slot 0048 bool kpViewManager::queueUpdates () const 0049 { 0050 return (d->queueUpdatesCounter > 0); 0051 } 0052 0053 // public slot 0054 void kpViewManager::setQueueUpdates () 0055 { 0056 d->queueUpdatesCounter++; 0057 #if DEBUG_KP_VIEW_MANAGER && 1 0058 qCDebug(kpLogViews) << "kpViewManager::setQueueUpdates() counter=" 0059 << d->queueUpdatesCounter << endl; 0060 #endif 0061 } 0062 0063 //-------------------------------------------------------------------------------- 0064 0065 // public slot 0066 void kpViewManager::restoreQueueUpdates () 0067 { 0068 d->queueUpdatesCounter--; 0069 #if DEBUG_KP_VIEW_MANAGER && 1 0070 qCDebug(kpLogViews) << "kpViewManager::restoreQueueUpdates() counter=" 0071 << d->queueUpdatesCounter; 0072 #endif 0073 Q_ASSERT (d->queueUpdatesCounter >= 0); 0074 0075 if (d->queueUpdatesCounter == 0) 0076 { 0077 for (kpView *view : std::as_const(d->views)) 0078 view->updateQueuedArea(); 0079 } 0080 } 0081 0082 //-------------------------------------------------------------------------------- 0083 0084 // public slot 0085 bool kpViewManager::fastUpdates () const 0086 { 0087 return (d->fastUpdatesCounter > 0); 0088 } 0089 0090 // public slot 0091 void kpViewManager::setFastUpdates () 0092 { 0093 d->fastUpdatesCounter++; 0094 #if DEBUG_KP_VIEW_MANAGER && 0 0095 qCDebug(kpLogViews) << "kpViewManager::setFastUpdates() counter=" 0096 << d->fastUpdatesCounter << endl; 0097 #endif 0098 } 0099 0100 // public slot 0101 void kpViewManager::restoreFastUpdates () 0102 { 0103 d->fastUpdatesCounter--; 0104 #if DEBUG_KP_VIEW_MANAGER && 0 0105 qCDebug(kpLogViews) << "kpViewManager::restoreFastUpdates() counter=" 0106 << d->fastUpdatesCounter << endl; 0107 #endif 0108 Q_ASSERT (d->fastUpdatesCounter >= 0); 0109 } 0110 0111 0112 // public slot 0113 void kpViewManager::updateView (kpView *v) 0114 { 0115 updateView (v, QRect (0, 0, v->width (), v->height ())); 0116 } 0117 0118 // public slot 0119 void kpViewManager::updateView (kpView *v, const QRect &viewRect) 0120 { 0121 if (!queueUpdates ()) 0122 { 0123 if (fastUpdates ()) { 0124 v->repaint (viewRect); 0125 } 0126 else { 0127 v->update (viewRect); 0128 } 0129 } 0130 else { 0131 v->addToQueuedArea (viewRect); 0132 } 0133 } 0134 0135 // public slot 0136 void kpViewManager::updateView (kpView *v, int x, int y, int w, int h) 0137 { 0138 updateView (v, QRect (x, y, w, h)); 0139 } 0140 0141 // public slot 0142 void kpViewManager::updateView (kpView *v, const QRegion &viewRegion) 0143 { 0144 if (!queueUpdates ()) 0145 { 0146 if (fastUpdates ()) { 0147 v->repaint (viewRegion); 0148 } 0149 else { 0150 v->update (viewRegion.boundingRect ()); 0151 } 0152 } 0153 else { 0154 v->addToQueuedArea (viewRegion); 0155 } 0156 } 0157 0158 0159 // public slot 0160 void kpViewManager::updateViewRectangleEdges (kpView *v, const QRect &viewRect) 0161 { 0162 if (viewRect.height () <= 0 || viewRect.width () <= 0) { 0163 return; 0164 } 0165 0166 // Top line 0167 updateView (v, QRect (viewRect.x (), viewRect.y (), 0168 viewRect.width (), 1)); 0169 0170 if (viewRect.height () >= 2) 0171 { 0172 // Bottom line 0173 updateView (v, QRect (viewRect.x (), viewRect.bottom (), 0174 viewRect.width (), 1)); 0175 0176 if (viewRect.height () > 2) 0177 { 0178 // Left line 0179 updateView (v, QRect (viewRect.x (), viewRect.y () + 1, 0180 1, viewRect.height () - 2)); 0181 0182 if (viewRect.width () >= 2) 0183 { 0184 // Right line 0185 updateView (v, QRect (viewRect.right (), viewRect.y () + 1, 0186 1, viewRect.height () - 2)); 0187 } 0188 } 0189 } 0190 } 0191 0192 // public slot 0193 void kpViewManager::updateViews (const QRect &docRect) 0194 { 0195 #if DEBUG_KP_VIEW_MANAGER && 0 0196 qCDebug(kpLogViews) << "kpViewManager::updateViews (" << docRect << ")"; 0197 #endif 0198 0199 for (kpView *view : std::as_const(d->views)) 0200 { 0201 #if DEBUG_KP_VIEW_MANAGER && 0 0202 qCDebug(kpLogViews) << "\tupdating view " << view->name (); 0203 #endif 0204 if (view->zoomLevelX () % 100 == 0 && view->zoomLevelY () % 100 == 0) 0205 { 0206 #if DEBUG_KP_VIEW_MANAGER && 0 0207 qCDebug(kpLogViews) << "\t\tviewRect=" << view->transformDocToView (docRect); 0208 #endif 0209 updateView (view, view->transformDocToView (docRect)); 0210 } 0211 else 0212 { 0213 QRect viewRect = view->transformDocToView (docRect); 0214 0215 int diff = qRound (double (qMax (view->zoomLevelX (), view->zoomLevelY ())) / 100.0) + 1; 0216 0217 QRect newRect = QRect (viewRect.x () - diff, 0218 viewRect.y () - diff, 0219 viewRect.width () + 2 * diff, 0220 viewRect.height () + 2 * diff) 0221 .intersected (QRect (0, 0, view->width (), view->height ())); 0222 0223 #if DEBUG_KP_VIEW_MANAGER && 0 0224 qCDebug(kpLogViews) << "\t\tviewRect (+compensate)=" << newRect; 0225 #endif 0226 updateView (view, newRect); 0227 } 0228 } 0229 } 0230 0231 //-------------------------------------------------------------------------------- 0232 0233 // public slot 0234 void kpViewManager::adjustViewsToEnvironment () 0235 { 0236 #if DEBUG_KP_VIEW_MANAGER && 1 0237 qCDebug(kpLogViews) << "kpViewManager::adjustViewsToEnvironment()" 0238 << " numViews=" << d->views.count () 0239 << endl; 0240 #endif 0241 for (kpView *view : std::as_const(d->views)) 0242 { 0243 #if DEBUG_KP_VIEW_MANAGER && 1 0244 qCDebug(kpLogViews) << "\tview: " << view->name () 0245 << endl; 0246 #endif 0247 view->adjustToEnvironment (); 0248 } 0249 } 0250 0251 //--------------------------------------------------------------------------------