6#include "plasmawindow.h"
8#include "dialogbackground_p.h"
9#include "dialogshadows_p.h"
14#include <KWindowEffects>
15#include <KWindowSystem>
18#include <Plasma/Theme>
24class PlasmaWindowPrivate
27 PlasmaWindowPrivate(PlasmaWindow *_q)
31 void handleFrameChanged();
32 void updateMainItemGeometry();
34 DialogShadows *shadows;
41 PlasmaWindow::BackgroundHints backgroundHints = PlasmaWindow::StandardBackground;
44PlasmaWindow::PlasmaWindow(
const QString &svgPrefix)
46 , d(new PlasmaWindowPrivate(this))
51 d->shadows = DialogShadows::instance(svgPrefix);
53 d->dialogBackground->setImagePath(svgPrefix);
54 connect(d->dialogBackground, &DialogBackground::fixedMarginsChanged,
this, [
this]() {
55 d->updateMainItemGeometry();
56 Q_EMIT paddingChanged();
58 connect(d->dialogBackground, &DialogBackground::maskChanged,
this, [
this]() {
59 d->handleFrameChanged();
62 d->shadows->addWindow(
this, d->dialogBackground->enabledBorders());
65PlasmaWindow::~PlasmaWindow()
69void PlasmaWindow::setMainItem(
QQuickItem *mainItem)
71 if (d->mainItem == mainItem)
75 d->mainItem->setParentItem(
nullptr);
78 d->mainItem = mainItem;
79 Q_EMIT mainItemChanged();
83 d->updateMainItemGeometry();
92static KSvg::FrameSvg::EnabledBorders edgeToBorder(
Qt::Edges edges)
94 KSvg::FrameSvg::EnabledBorders borders = KSvg::FrameSvg::EnabledBorders(0);
96 if (edges & Qt::Edge::TopEdge) {
97 borders |= KSvg::FrameSvg::EnabledBorder::TopBorder;
99 if (edges & Qt::Edge::BottomEdge) {
100 borders |= KSvg::FrameSvg::EnabledBorder::BottomBorder;
102 if (edges & Qt::Edge::LeftEdge) {
103 borders |= KSvg::FrameSvg::EnabledBorder::LeftBorder;
105 if (edges & Qt::Edge::RightEdge) {
106 borders |= KSvg::FrameSvg::EnabledBorder::RightBorder;
112static Qt::Edges bordersToEdge(KSvg::FrameSvg::EnabledBorders borders)
115 if (borders & KSvg::FrameSvg::EnabledBorder::TopBorder) {
116 edges |= Qt::Edge::TopEdge;
118 if (borders & KSvg::FrameSvg::EnabledBorder::BottomBorder) {
119 edges |= Qt::Edge::BottomEdge;
121 if (borders & KSvg::FrameSvg::EnabledBorder::LeftBorder) {
122 edges |= Qt::Edge::LeftEdge;
124 if (borders & KSvg::FrameSvg::EnabledBorder::RightBorder) {
125 edges |= Qt::Edge::RightEdge;
130void PlasmaWindow::setBorders(
Qt::Edges bordersToShow)
132 d->dialogBackground->setEnabledBorders(edgeToBorder(bordersToShow));
133 d->shadows->setEnabledBorders(
this, d->dialogBackground->enabledBorders());
134 Q_EMIT bordersChanged();
139 return bordersToEdge(d->dialogBackground->enabledBorders());
156 d->dialogBackground->setSize(windowSize);
159 d->mainItem->setSize(contentSize);
163void PlasmaWindowPrivate::handleFrameChanged()
165 const QRegion mask = dialogBackground->mask();
168 theme.backgroundContrastEnabled(),
169 theme.backgroundContrast(),
170 theme.backgroundIntensity(),
171 theme.backgroundSaturation(),
181void PlasmaWindowPrivate::updateMainItemGeometry()
186 const QMargins frameMargins = q->padding();
187 const QSize windowSize = q->size();
189 mainItem->
setX(frameMargins.
left());
190 mainItem->
setY(frameMargins.
top());
193 mainItem->
setSize(contentSize);
196QMargins PlasmaWindow::padding()
const
198 return QMargins(d->dialogBackground->leftMargin(),
199 d->dialogBackground->topMargin(),
200 d->dialogBackground->rightMargin(),
201 d->dialogBackground->bottomMargin());
204PlasmaWindow::BackgroundHints PlasmaWindow::backgroundHints()
const
206 return d->backgroundHints;
209void PlasmaWindow::setBackgroundHints(BackgroundHints hints)
211 if (d->backgroundHints == hints) {
214 d->backgroundHints = hints;
216 auto prefix = QStringLiteral(
"");
217 if (d->backgroundHints == PlasmaWindow::SolidBackground) {
218 prefix = QStringLiteral(
"solid/");
220 d->dialogBackground->setImagePath(prefix + QStringLiteral(
"dialogs/background"));
222 Q_EMIT backgroundHintsChanged();
225qreal PlasmaWindow::topPadding()
const
227 return d->dialogBackground->topMargin();
230qreal PlasmaWindow::bottomPadding()
const
232 return d->dialogBackground->bottomMargin();
235qreal PlasmaWindow::leftPadding()
const
237 return d->dialogBackground->leftMargin();
240qreal PlasmaWindow::rightPadding()
const
242 return d->dialogBackground->rightMargin();
246#include "moc_plasmawindow.cpp"
Internal type used by DialogBackground in plasmaquick to load the actual background SVG.
static bool isPlatformX11()
Interface to the Plasma theme.
KCRASH_EXPORT void setFlags(KCrash::CrashFlags flags)
void enableBlurBehind(QWindow *window, bool enable=true, const QRegion ®ion=QRegion())
void enableBackgroundContrast(QWindow *window, bool enable=true, qreal contrast=1, qreal intensity=1, qreal saturation=1, const QRegion ®ion=QRegion())
The EdgeEventForwarder class This class forwards edge events to be replayed within the given margin T...
Namespace for everything in libplasma.
void setParentItem(QQuickItem *parent)
void setSize(const QSizeF &size)
virtual void resizeEvent(QResizeEvent *ev) override
virtual void showEvent(QShowEvent *) override
const QSize & size() const const
QSize shrunkBy(QMargins margins) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)