9#include "dialogshadows_p.h"
11#include <KWindowShadow>
13class DialogShadows::Private
16 Private(DialogShadows *shadows)
27 void initTile(
const QString &element);
28 void updateShadow(
QWindow *window, KSvg::FrameSvg::EnabledBorders);
29 void clearShadow(
QWindow *window);
31 void windowDestroyed(
QObject *deletedObject);
43DialogShadows *DialogShadows::instance(
const QString &prefix)
45 DialogShadows *&shadow = (*s_privateDialogShadowsInstances)[prefix];
47 shadow =
new DialogShadows(qApp, prefix);
52DialogShadows::DialogShadows(
QObject *parent,
const QString &prefix)
54 , d(new Private(this))
57 connect(
this, SIGNAL(repaintNeeded()),
this, SLOT(updateShadows()));
60DialogShadows::~DialogShadows()
65void DialogShadows::addWindow(
QWindow *window, KSvg::FrameSvg::EnabledBorders enabledBorders)
71 d->m_windows[
window] = enabledBorders;
72 d->updateShadow(window, enabledBorders);
76void DialogShadows::removeWindow(
QWindow *window)
78 if (!d->m_windows.contains(window)) {
82 d->m_windows.remove(window);
83 disconnect(window,
nullptr,
this,
nullptr);
84 d->clearShadow(window);
86 if (d->m_windows.isEmpty()) {
91void DialogShadows::setEnabledBorders(
QWindow *window, KSvg::FrameSvg::EnabledBorders enabledBorders)
93 Q_ASSERT(d->m_windows.contains(window));
94 if (!window || !d->m_windows.contains(window)) {
98 d->updateShadow(window, enabledBorders);
101void DialogShadows::Private::windowDestroyed(
QObject *deletedObject)
113void DialogShadows::Private::updateShadows()
117 for (i = m_windows.constBegin(); i != m_windows.constEnd(); ++i) {
122void DialogShadows::Private::initTile(
const QString &element)
124 const QImage image = q->pixmap(element).toImage();
126 KWindowShadowTile::Ptr tile = KWindowShadowTile::Ptr::create();
127 tile->setImage(image);
132void DialogShadows::Private::setupTiles()
136 initTile(QStringLiteral(
"shadow-top"));
137 initTile(QStringLiteral(
"shadow-topright"));
138 initTile(QStringLiteral(
"shadow-right"));
139 initTile(QStringLiteral(
"shadow-bottomright"));
140 initTile(QStringLiteral(
"shadow-bottom"));
141 initTile(QStringLiteral(
"shadow-bottomleft"));
142 initTile(QStringLiteral(
"shadow-left"));
143 initTile(QStringLiteral(
"shadow-topleft"));
146void DialogShadows::Private::clearTiles()
151void DialogShadows::Private::updateShadow(
QWindow *window, KSvg::FrameSvg::EnabledBorders enabledBorders)
153 if (m_tiles.isEmpty()) {
167 if (enabledBorders & KSvg::FrameSvg::TopBorder) {
173 if (enabledBorders & KSvg::FrameSvg::TopBorder && enabledBorders & KSvg::FrameSvg::RightBorder) {
179 if (enabledBorders & KSvg::FrameSvg::RightBorder) {
185 if (enabledBorders & KSvg::FrameSvg::BottomBorder && enabledBorders & KSvg::FrameSvg::RightBorder) {
191 if (enabledBorders & KSvg::FrameSvg::BottomBorder) {
197 if (enabledBorders & KSvg::FrameSvg::BottomBorder && enabledBorders & KSvg::FrameSvg::LeftBorder) {
203 if (enabledBorders & KSvg::FrameSvg::LeftBorder) {
209 if (enabledBorders & KSvg::FrameSvg::TopBorder && enabledBorders & KSvg::FrameSvg::LeftBorder) {
217 if (enabledBorders & KSvg::FrameSvg::TopBorder) {
218 const QSize marginHint = q->elementSize(QStringLiteral(
"shadow-hint-top-margin")).toSize();
222 padding.
setTop(m_tiles[0]->image().height());
226 if (enabledBorders & KSvg::FrameSvg::RightBorder) {
227 const QSize marginHint = q->elementSize(QStringLiteral(
"shadow-hint-right-margin")).toSize();
231 padding.
setRight(m_tiles[2]->image().width());
235 if (enabledBorders & KSvg::FrameSvg::BottomBorder) {
236 const QSize marginHint = q->elementSize(QStringLiteral(
"shadow-hint-bottom-margin")).toSize();
240 padding.
setBottom(m_tiles[4]->image().height());
244 if (enabledBorders & KSvg::FrameSvg::LeftBorder) {
245 const QSize marginHint = q->elementSize(QStringLiteral(
"shadow-hint-left-margin")).toSize();
249 padding.
setLeft(m_tiles[6]->image().width());
257 qCWarning(LOG_PLASMAQUICK) <<
"Couldn't create KWindowShadow for" <<
window;
261void DialogShadows::Private::clearShadow(
QWindow *window)
263 delete m_shadows.take(window);
266bool DialogShadows::enabled()
const
268 return hasElement(QStringLiteral(
"shadow-left"));
271#include "moc_dialogshadows_p.cpp"
void setBottomLeftTile(KWindowShadowTile::Ptr tile)
void setWindow(QWindow *window)
void setRightTile(KWindowShadowTile::Ptr tile)
void setTopRightTile(KWindowShadowTile::Ptr tile)
void setBottomTile(KWindowShadowTile::Ptr tile)
void setBottomRightTile(KWindowShadowTile::Ptr tile)
void setTopLeftTile(KWindowShadowTile::Ptr tile)
void setTopTile(KWindowShadowTile::Ptr tile)
void setLeftTile(KWindowShadowTile::Ptr tile)
void setPadding(const QMargins &padding)
KGUIADDONS_EXPORT QWindow * window(QObject *job)
const Key & key() const const
const T & value() const const
bool isEmpty() const const
bool remove(const Key &key)
void setBottom(int bottom)
bool isValid() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)