File indexing completed on 2024-04-28 16:44:34
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 #define DELEGATE(type, name) \ 0108 type DecorationShadow::name() const \ 0109 { \ 0110 return d->name; \ 0111 } 0112 0113 DELEGATE(QImage, shadow) 0114 DELEGATE(QMargins, padding) 0115 DELEGATE(QRect, innerShadowRect) 0116 0117 #define I(name, Name) \ 0118 int DecorationShadow::padding##Name() const \ 0119 { \ 0120 return d->padding.name(); \ 0121 } 0122 I(top, Top) 0123 I(bottom, Bottom) 0124 I(right, Right) 0125 I(left, Left) 0126 #undef I 0127 0128 #undef DELEGATE 0129 0130 #define SETTER(type, setName, name) \ 0131 void DecorationShadow::setName(type arg) \ 0132 { \ 0133 if (d->name == arg) { \ 0134 return; \ 0135 } \ 0136 d->name = arg; \ 0137 Q_EMIT name##Changed(d->name); \ 0138 } 0139 0140 SETTER(const QImage &, setShadow, shadow) 0141 0142 #undef SETTER 0143 #endif 0144 0145 void DecorationShadow::setPadding(const QMargins &margins) 0146 { 0147 if (d->padding == margins) { 0148 return; 0149 } 0150 d->padding = margins; 0151 Q_EMIT paddingChanged(); 0152 } 0153 0154 void DecorationShadow::setInnerShadowRect(const QRect &rect) 0155 { 0156 if (d->innerShadowRect == rect) { 0157 return; 0158 } 0159 d->innerShadowRect = rect; 0160 Q_EMIT innerShadowRectChanged(); 0161 } 0162 0163 }