File indexing completed on 2024-05-19 04:26:11

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 WrapAroundAxis KisDefaultBounds::wrapAroundModeAxis() const
0059 {
0060     return m_d->image ? m_d->image->wrapAroundModeAxis() : WRAPAROUND_BOTH;
0061 }
0062 
0063 int KisDefaultBounds::currentLevelOfDetail() const
0064 {
0065     return m_d->image ? m_d->image->currentLevelOfDetail() : 0;
0066 }
0067 
0068 int KisDefaultBounds::currentTime() const
0069 {
0070     KisImageAnimationInterface *interface = m_d->image ? m_d->image->animationInterface() : 0;
0071     return interface ? interface->currentTime() : 0;
0072 }
0073 
0074 bool KisDefaultBounds::externalFrameActive() const
0075 {
0076     KisImageAnimationInterface *interface = m_d->image ? m_d->image->animationInterface() : 0;
0077     return interface ? interface->externalFrameActive() : false;
0078 }
0079 
0080 void *KisDefaultBounds::sourceCookie() const
0081 {
0082     return m_d->image.data();
0083 }
0084 
0085 /******************************************************************/
0086 /*                  KisSelectionDefaultBounds                     */
0087 /******************************************************************/
0088 
0089 struct Q_DECL_HIDDEN KisSelectionDefaultBounds::Private
0090 {
0091     KisPaintDeviceWSP parentDevice;
0092 };
0093 
0094 KisSelectionDefaultBounds::KisSelectionDefaultBounds(KisPaintDeviceSP parentDevice)
0095     : m_d(new Private())
0096 {
0097     m_d->parentDevice = parentDevice;
0098 }
0099 
0100 KisSelectionDefaultBounds::~KisSelectionDefaultBounds()
0101 {
0102     delete m_d;
0103 }
0104 
0105 QRect KisSelectionDefaultBounds::bounds() const
0106 {
0107     return m_d->parentDevice ?
0108                 m_d->parentDevice->extent() | m_d->parentDevice->defaultBounds()->bounds() : QRect();
0109 }
0110 
0111 QRect KisSelectionDefaultBounds::imageBorderRect() const
0112 {
0113     return m_d->parentDevice ?
0114                 m_d->parentDevice->defaultBounds()->bounds() : QRect();
0115 }
0116 
0117 bool KisSelectionDefaultBounds::wrapAroundMode() const
0118 {
0119     return m_d->parentDevice ?
0120         m_d->parentDevice->defaultBounds()->wrapAroundMode() : false;
0121 }
0122 
0123 WrapAroundAxis KisSelectionDefaultBounds::wrapAroundModeAxis() const
0124 {
0125     return m_d->parentDevice ?
0126         m_d->parentDevice->defaultBounds()->wrapAroundModeAxis() : WRAPAROUND_BOTH;
0127 }
0128 
0129 int KisSelectionDefaultBounds::currentLevelOfDetail() const
0130 {
0131     return m_d->parentDevice ?
0132         m_d->parentDevice->defaultBounds()->currentLevelOfDetail() : 0;
0133 }
0134 
0135 int KisSelectionDefaultBounds::currentTime() const
0136 {
0137     return m_d->parentDevice ?
0138         m_d->parentDevice->defaultBounds()->currentTime() : 0;
0139 }
0140 
0141 bool KisSelectionDefaultBounds::externalFrameActive() const
0142 {
0143     return m_d->parentDevice ?
0144                 m_d->parentDevice->defaultBounds()->externalFrameActive() : false;
0145 }
0146 
0147 void *KisSelectionDefaultBounds::sourceCookie() const
0148 {
0149     return m_d->parentDevice.data();
0150 }
0151 
0152 /******************************************************************/
0153 /*                   KisSelectionEmptyBounds                      */
0154 /******************************************************************/
0155 
0156 KisSelectionEmptyBounds::KisSelectionEmptyBounds()
0157     : KisSelectionEmptyBounds(nullptr)
0158 {
0159 }
0160 
0161 KisSelectionEmptyBounds::KisSelectionEmptyBounds(KisImageWSP image)
0162     : KisDefaultBounds(image)
0163 {
0164 }
0165 
0166 KisSelectionEmptyBounds::~KisSelectionEmptyBounds()
0167 {
0168 }
0169 
0170 QRect KisSelectionEmptyBounds::bounds() const
0171 {
0172     return QRect(0, 0, 0, 0);
0173 }
0174 
0175 /******************************************************************/
0176 /*                 KisWrapAroundBoundsWrapper                     */
0177 /******************************************************************/
0178 
0179 
0180 struct Q_DECL_HIDDEN KisWrapAroundBoundsWrapper::Private
0181 {
0182     KisDefaultBoundsBaseSP base;
0183     QRect bounds;
0184 };
0185 
0186 KisWrapAroundBoundsWrapper::KisWrapAroundBoundsWrapper(KisDefaultBoundsBaseSP base, QRect bounds)
0187 : m_d(new Private())
0188 {
0189     m_d->base = base;
0190     m_d->bounds = bounds;
0191 }
0192 
0193 KisWrapAroundBoundsWrapper::~KisWrapAroundBoundsWrapper()
0194 {
0195 }
0196 
0197 QRect KisWrapAroundBoundsWrapper::bounds() const
0198 {
0199     return m_d->bounds;
0200 }
0201 
0202 bool KisWrapAroundBoundsWrapper::wrapAroundMode() const
0203 {
0204     return true;
0205 }
0206 
0207 WrapAroundAxis KisWrapAroundBoundsWrapper::wrapAroundModeAxis() const
0208 {
0209     return m_d->base->wrapAroundModeAxis();
0210 }
0211 
0212 int KisWrapAroundBoundsWrapper::currentLevelOfDetail() const
0213 {
0214     return m_d->base->currentLevelOfDetail();
0215 }
0216 
0217 int KisWrapAroundBoundsWrapper::currentTime() const
0218 {
0219     return m_d->base->currentTime();
0220 }
0221 
0222 bool KisWrapAroundBoundsWrapper::externalFrameActive() const
0223 {
0224     return m_d->base->externalFrameActive();
0225 }
0226 
0227 void *KisWrapAroundBoundsWrapper::sourceCookie() const
0228 {
0229     return m_d->base->sourceCookie();
0230 }