File indexing completed on 2024-05-12 15:58:14
0001 /* 0002 * SPDX-FileCopyrightText: 2010 Boudewijn Rempt <boud@valdyas.org> 0003 * SPDX-FileCopyrightText: 2010 Dmitry Kazakov <dimula73@gmail.com> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 0009 #include "kis_global.h" 0010 #include "kis_default_bounds.h" 0011 #include "kis_paint_device.h" 0012 #include "kis_image_animation_interface.h" 0013 #include "kis_image.h" 0014 0015 0016 const QRect KisDefaultBounds::infiniteRect = 0017 QRect(qint32_MIN/2, qint32_MIN/2, qint32_MAX, qint32_MAX); 0018 0019 0020 /******************************************************************/ 0021 /* KisDefaultBounds */ 0022 /******************************************************************/ 0023 0024 struct Q_DECL_HIDDEN KisDefaultBounds::Private 0025 { 0026 KisImageWSP image; 0027 }; 0028 0029 KisDefaultBounds::KisDefaultBounds() 0030 : KisDefaultBounds(0) 0031 { 0032 } 0033 0034 KisDefaultBounds::KisDefaultBounds(KisImageWSP image) 0035 : m_d(new Private()) 0036 { 0037 m_d->image = image; 0038 } 0039 0040 KisDefaultBounds::~KisDefaultBounds() 0041 { 0042 delete m_d; 0043 } 0044 0045 QRect KisDefaultBounds::bounds() const 0046 { 0047 /** 0048 * By default return infinite rect to cover everything 0049 */ 0050 return m_d->image ? m_d->image->effectiveLodBounds() : infiniteRect; 0051 } 0052 0053 bool KisDefaultBounds::wrapAroundMode() const 0054 { 0055 return m_d->image ? m_d->image->wrapAroundModeActive() : false; 0056 } 0057 0058 int KisDefaultBounds::currentLevelOfDetail() const 0059 { 0060 return m_d->image ? m_d->image->currentLevelOfDetail() : 0; 0061 } 0062 0063 int KisDefaultBounds::currentTime() const 0064 { 0065 KisImageAnimationInterface *interface = m_d->image ? m_d->image->animationInterface() : 0; 0066 return interface ? interface->currentTime() : 0; 0067 } 0068 0069 bool KisDefaultBounds::externalFrameActive() const 0070 { 0071 KisImageAnimationInterface *interface = m_d->image ? m_d->image->animationInterface() : 0; 0072 return interface ? interface->externalFrameActive() : false; 0073 } 0074 0075 void *KisDefaultBounds::sourceCookie() const 0076 { 0077 return m_d->image.data(); 0078 } 0079 0080 /******************************************************************/ 0081 /* KisSelectionDefaultBounds */ 0082 /******************************************************************/ 0083 0084 struct Q_DECL_HIDDEN KisSelectionDefaultBounds::Private 0085 { 0086 KisPaintDeviceWSP parentDevice; 0087 }; 0088 0089 KisSelectionDefaultBounds::KisSelectionDefaultBounds(KisPaintDeviceSP parentDevice) 0090 : m_d(new Private()) 0091 { 0092 m_d->parentDevice = parentDevice; 0093 } 0094 0095 KisSelectionDefaultBounds::~KisSelectionDefaultBounds() 0096 { 0097 delete m_d; 0098 } 0099 0100 QRect KisSelectionDefaultBounds::bounds() const 0101 { 0102 return m_d->parentDevice ? 0103 m_d->parentDevice->extent() | m_d->parentDevice->defaultBounds()->bounds() : QRect(); 0104 } 0105 0106 QRect KisSelectionDefaultBounds::imageBorderRect() const 0107 { 0108 return m_d->parentDevice ? 0109 m_d->parentDevice->defaultBounds()->bounds() : QRect(); 0110 } 0111 0112 bool KisSelectionDefaultBounds::wrapAroundMode() const 0113 { 0114 return m_d->parentDevice ? 0115 m_d->parentDevice->defaultBounds()->wrapAroundMode() : false; 0116 } 0117 0118 int KisSelectionDefaultBounds::currentLevelOfDetail() const 0119 { 0120 return m_d->parentDevice ? 0121 m_d->parentDevice->defaultBounds()->currentLevelOfDetail() : 0; 0122 } 0123 0124 int KisSelectionDefaultBounds::currentTime() const 0125 { 0126 return m_d->parentDevice ? 0127 m_d->parentDevice->defaultBounds()->currentTime() : 0; 0128 } 0129 0130 bool KisSelectionDefaultBounds::externalFrameActive() const 0131 { 0132 return m_d->parentDevice ? 0133 m_d->parentDevice->defaultBounds()->externalFrameActive() : false; 0134 } 0135 0136 void *KisSelectionDefaultBounds::sourceCookie() const 0137 { 0138 return m_d->parentDevice.data(); 0139 } 0140 0141 /******************************************************************/ 0142 /* KisSelectionEmptyBounds */ 0143 /******************************************************************/ 0144 0145 KisSelectionEmptyBounds::KisSelectionEmptyBounds(KisImageWSP image) 0146 : KisDefaultBounds(image) 0147 { 0148 } 0149 0150 KisSelectionEmptyBounds::~KisSelectionEmptyBounds() 0151 { 0152 } 0153 0154 QRect KisSelectionEmptyBounds::bounds() const 0155 { 0156 return QRect(0, 0, 0, 0); 0157 } 0158 0159 /******************************************************************/ 0160 /* KisWrapAroundBoundsWrapper */ 0161 /******************************************************************/ 0162 0163 0164 struct Q_DECL_HIDDEN KisWrapAroundBoundsWrapper::Private 0165 { 0166 KisDefaultBoundsBaseSP base; 0167 QRect bounds; 0168 }; 0169 0170 KisWrapAroundBoundsWrapper::KisWrapAroundBoundsWrapper(KisDefaultBoundsBaseSP base, QRect bounds) 0171 : m_d(new Private()) 0172 { 0173 m_d->base = base; 0174 m_d->bounds = bounds; 0175 } 0176 0177 KisWrapAroundBoundsWrapper::~KisWrapAroundBoundsWrapper() 0178 { 0179 } 0180 0181 QRect KisWrapAroundBoundsWrapper::bounds() const 0182 { 0183 return m_d->bounds; 0184 } 0185 0186 bool KisWrapAroundBoundsWrapper::wrapAroundMode() const 0187 { 0188 return true; 0189 } 0190 0191 int KisWrapAroundBoundsWrapper::currentLevelOfDetail() const 0192 { 0193 return m_d->base->currentLevelOfDetail(); 0194 } 0195 0196 int KisWrapAroundBoundsWrapper::currentTime() const 0197 { 0198 return m_d->base->currentTime(); 0199 } 0200 0201 bool KisWrapAroundBoundsWrapper::externalFrameActive() const 0202 { 0203 return m_d->base->externalFrameActive(); 0204 } 0205 0206 void *KisWrapAroundBoundsWrapper::sourceCookie() const 0207 { 0208 return m_d->base->sourceCookie(); 0209 }