File indexing completed on 2024-05-05 05:29:54
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 #include "decorationshadow.h" 0007 #include "decorationshadow_p.h" 0008 0009 namespace KDecoration2 0010 { 0011 DecorationShadow::Private::Private(DecorationShadow *parent) 0012 : q(parent) 0013 { 0014 } 0015 0016 DecorationShadow::Private::~Private() = default; 0017 0018 DecorationShadow::DecorationShadow() 0019 : QObject() 0020 , d(new Private(this)) 0021 { 0022 } 0023 0024 DecorationShadow::~DecorationShadow() = default; 0025 0026 QRect DecorationShadow::topLeftGeometry() const 0027 { 0028 if (d->innerShadowRect.isNull() || d->shadow.isNull()) { 0029 return QRect(); 0030 } 0031 return QRect(0, 0, d->innerShadowRect.left(), d->innerShadowRect.top()); 0032 } 0033 0034 QRect DecorationShadow::topGeometry() const 0035 { 0036 if (d->innerShadowRect.isNull() || d->shadow.isNull()) { 0037 return QRect(); 0038 } 0039 return QRect(d->innerShadowRect.left(), 0, d->innerShadowRect.width(), d->innerShadowRect.top()); 0040 } 0041 0042 QRect DecorationShadow::topRightGeometry() const 0043 { 0044 if (d->innerShadowRect.isNull() || d->shadow.isNull()) { 0045 return QRect(); 0046 } 0047 return QRect(d->innerShadowRect.left() + d->innerShadowRect.width(), 0048 0, 0049 d->shadow.width() - d->innerShadowRect.width() - d->innerShadowRect.left(), 0050 d->innerShadowRect.top()); 0051 } 0052 0053 QRect DecorationShadow::rightGeometry() const 0054 { 0055 if (d->innerShadowRect.isNull() || d->shadow.isNull()) { 0056 return QRect(); 0057 } 0058 return QRect(d->innerShadowRect.left() + d->innerShadowRect.width(), 0059 d->innerShadowRect.top(), 0060 d->shadow.width() - d->innerShadowRect.width() - d->innerShadowRect.left(), 0061 d->innerShadowRect.height()); 0062 } 0063 0064 QRect DecorationShadow::bottomRightGeometry() const 0065 { 0066 if (d->innerShadowRect.isNull() || d->shadow.isNull()) { 0067 return QRect(); 0068 } 0069 return QRect(d->innerShadowRect.left() + d->innerShadowRect.width(), 0070 d->innerShadowRect.top() + d->innerShadowRect.height(), 0071 d->shadow.width() - d->innerShadowRect.width() - d->innerShadowRect.left(), 0072 d->shadow.height() - d->innerShadowRect.top() - d->innerShadowRect.height()); 0073 } 0074 0075 QRect DecorationShadow::bottomGeometry() const 0076 { 0077 if (d->innerShadowRect.isNull() || d->shadow.isNull()) { 0078 return QRect(); 0079 } 0080 return QRect(d->innerShadowRect.left(), 0081 d->innerShadowRect.top() + d->innerShadowRect.height(), 0082 d->innerShadowRect.width(), 0083 d->shadow.height() - d->innerShadowRect.top() - d->innerShadowRect.height()); 0084 } 0085 0086 QRect DecorationShadow::bottomLeftGeometry() const 0087 { 0088 if (d->innerShadowRect.isNull() || d->shadow.isNull()) { 0089 return QRect(); 0090 } 0091 return QRect(0, 0092 d->innerShadowRect.top() + d->innerShadowRect.height(), 0093 d->innerShadowRect.left(), 0094 d->shadow.height() - d->innerShadowRect.top() - d->innerShadowRect.height()); 0095 } 0096 0097 QRect DecorationShadow::leftGeometry() const 0098 { 0099 if (d->innerShadowRect.isNull() || d->shadow.isNull()) { 0100 return QRect(); 0101 } 0102 return QRect(0, d->innerShadowRect.top(), d->innerShadowRect.left(), d->innerShadowRect.height()); 0103 } 0104 0105 #ifndef K_DOXYGEN 0106 0107 QImage DecorationShadow::shadow() const 0108 { 0109 return d->shadow; 0110 } 0111 0112 QMargins DecorationShadow::padding() const 0113 { 0114 return d->padding; 0115 } 0116 0117 QRect DecorationShadow::innerShadowRect() const 0118 { 0119 return d->innerShadowRect; 0120 } 0121 0122 int DecorationShadow::paddingTop() const 0123 { 0124 return d->padding.top(); 0125 } 0126 0127 int DecorationShadow::paddingBottom() const 0128 { 0129 return d->padding.bottom(); 0130 } 0131 0132 int DecorationShadow::paddingRight() const 0133 { 0134 return d->padding.right(); 0135 } 0136 0137 int DecorationShadow::paddingLeft() const 0138 { 0139 return d->padding.left(); 0140 } 0141 0142 void DecorationShadow::setShadow(const QImage &shadow) 0143 { 0144 if (d->shadow == shadow) { 0145 return; 0146 } 0147 d->shadow = shadow; 0148 Q_EMIT shadowChanged(d->shadow); 0149 } 0150 0151 #endif 0152 0153 void DecorationShadow::setPadding(const QMargins &margins) 0154 { 0155 if (d->padding == margins) { 0156 return; 0157 } 0158 d->padding = margins; 0159 Q_EMIT paddingChanged(); 0160 } 0161 0162 void DecorationShadow::setInnerShadowRect(const QRect &rect) 0163 { 0164 if (d->innerShadowRect == rect) { 0165 return; 0166 } 0167 d->innerShadowRect = rect; 0168 Q_EMIT innerShadowRectChanged(); 0169 } 0170 0171 } 0172 0173 #include "moc_decorationshadow.cpp"