From 38bcec95b012724bbafdfe8e4aea3f99634411d0 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 20 Aug 2014 16:33:38 +0200 Subject: [PATCH 1/6] a simple way to enable/disable background --- src/plasmaquick/dialog.cpp | 49 ++++++++++++++++++++++++++++++++++---- src/plasmaquick/dialog.h | 17 +++++++++++++ 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/src/plasmaquick/dialog.cpp b/src/plasmaquick/dialog.cpp index 64fb4a974..51fd055bd 100644 --- a/src/plasmaquick/dialog.cpp +++ b/src/plasmaquick/dialog.cpp @@ -61,7 +61,8 @@ public: hideOnWindowDeactivate(false), outputOnly(false), componentComplete(dialog->parent() == 0), - resizeOrigin(Undefined) + resizeOrigin(Undefined), + backgroundHints(Dialog::StandardBackground) { } @@ -101,6 +102,7 @@ public: Plasma::Theme theme; bool componentComplete; ResizeOrigin resizeOrigin; + Dialog::BackgroundHints backgroundHints; //Attached Layout property of mainItem, if any QWeakPointer mainItemLayout; @@ -460,7 +462,7 @@ Dialog::Dialog(QQuickItem *parent) property("data"); //Create the FrameSvg background. d->frameSvgItem = new Plasma::FrameSvgItem(contentItem()); - d->frameSvgItem->setImagePath("dialogs/background"); + //d->frameSvgItem->setImagePath("dialogs/background"); connect(&d->theme, SIGNAL(themeChanged()), this, SLOT(updateTheme())); @@ -761,10 +763,14 @@ void Dialog::setType(WindowType type) setFlags(Qt::FramelessWindowHint | flags()); } - if (type == Tooltip) { - d->frameSvgItem->setImagePath("widgets/tooltip"); + if (d->backgroundHints == Dialog::NoBackground) { + d->frameSvgItem->setImagePath(QString()); } else { - d->frameSvgItem->setImagePath("dialogs/background"); + if (d->type == Tooltip) { + d->frameSvgItem->setImagePath("widgets/tooltip"); + } else { + d->frameSvgItem->setImagePath("dialogs/background"); + } } if (type == Dock) { @@ -850,6 +856,15 @@ void Dialog::classBegin() void Dialog::componentComplete() { + if (d->backgroundHints == NoBackground) { + d->frameSvgItem->setImagePath(QString()); + } else { + if (d->type == Tooltip) { + d->frameSvgItem->setImagePath("widgets/tooltip"); + } else { + d->frameSvgItem->setImagePath("dialogs/background"); + } + } d->componentComplete = true; d->syncToMainItemSize(); } @@ -882,6 +897,30 @@ void Dialog::setOutputOnly(bool outputOnly) emit outputOnlyChanged(); } +Dialog::BackgroundHints Dialog::backgroundHints() const +{ + return d->backgroundHints; +} + +void Dialog::setBackgroundHints(Dialog::BackgroundHints hints) +{ + if (d->backgroundHints == hints) { + return; + } + + d->backgroundHints = hints; + if (hints == NoBackground) { + d->frameSvgItem->setImagePath(QString()); + } else { + if (d->type == Tooltip) { + d->frameSvgItem->setImagePath("widgets/tooltip"); + } else { + d->frameSvgItem->setImagePath("dialogs/background"); + } + } + emit backgroundHintsChanged(); +} + } #include "moc_dialog.cpp" diff --git a/src/plasmaquick/dialog.h b/src/plasmaquick/dialog.h index 27b3b5a14..bc12098bd 100644 --- a/src/plasmaquick/dialog.h +++ b/src/plasmaquick/dialog.h @@ -116,6 +116,13 @@ class PLASMAQUICK_EXPORT Dialog : public QQuickWindow, public QQmlParserStatus */ Q_PROPERTY(Qt::WindowFlags flags READ flags WRITE setFramelessFlags NOTIFY flagsChanged) + /** + * This property holds how (and if at all) the dialog should draw its own background + * or if it complete responsibility of the content to render a background. + * Note that in this case it loses kwin side shadows and blur + */ + Q_PROPERTY(BackgroundHints backgroundHints READ backgroundHints WRITE setBackgroundHints NOTIFY backgroundHintsChanged) + Q_CLASSINFO("DefaultProperty", "mainItem") public: @@ -129,6 +136,12 @@ public: }; Q_ENUMS(WindowType) + enum BackgroundHints { + NoBackground = 0, /**< Not drawing a background under the applet, the dialog has its own implementation */ + StandardBackground = 1 /**< The standard background from the theme is drawn */ + }; + Q_ENUMS(BackgroundHints) + Dialog(QQuickItem *parent = 0); ~Dialog(); @@ -155,6 +168,9 @@ public: void setOutputOnly(bool outputOnly); bool isOutputOnly() const; + BackgroundHints backgroundHints() const; + void setBackgroundHints(BackgroundHints hints); + /** * @returns The suggested screen position for the popup * @arg item the item the popup has to be positioned relatively to. if null, the popup will be positioned in the center of the window @@ -170,6 +186,7 @@ Q_SIGNALS: void hideOnWindowDeactivateChanged(); void outputOnlyChanged(); void flagsChanged(); + void backgroundHintsChanged(); /** * Emitted when the @see hideOnWindowDeactivate property is @c true and this dialog lost focus to a * window that is neither a parent dialog to nor a child dialog of this dialog. From c7d16008d7bfbb8928550eb45e1b8a0f613558d9 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 20 Aug 2014 16:46:46 +0200 Subject: [PATCH 2/6] centralize theme enable/disable --- src/plasmaquick/dialog.cpp | 60 ++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/src/plasmaquick/dialog.cpp b/src/plasmaquick/dialog.cpp index 51fd055bd..20a5ef7e5 100644 --- a/src/plasmaquick/dialog.cpp +++ b/src/plasmaquick/dialog.cpp @@ -162,17 +162,33 @@ void DialogPrivate::syncBorders() void DialogPrivate::updateTheme() { - KWindowEffects::enableBackgroundContrast(q->winId(), theme.backgroundContrastEnabled(), - theme.backgroundContrast(), - theme.backgroundIntensity(), - theme.backgroundSaturation(), - frameSvgItem->frameSvg()->mask()); - - if (KWindowSystem::compositingActive()) { + if (backgroundHints == Dialog::NoBackground) { + frameSvgItem->setImagePath(QString()); + KWindowEffects::enableBlurBehind(q->winId(), false); + KWindowEffects::enableBackgroundContrast(q->winId(), false); q->setMask(QRegion()); } else { - q->setMask(frameSvgItem->frameSvg()->mask()); + if (type == Dialog::Tooltip) { + frameSvgItem->setImagePath("widgets/tooltip"); + } else { + frameSvgItem->setImagePath("dialogs/background"); + } + + KWindowEffects::enableBlurBehind(q->winId(), true, frameSvgItem->frameSvg()->mask()); + + KWindowEffects::enableBackgroundContrast(q->winId(), theme.backgroundContrastEnabled(), + theme.backgroundContrast(), + theme.backgroundIntensity(), + theme.backgroundSaturation(), + frameSvgItem->frameSvg()->mask()); + + if (KWindowSystem::compositingActive()) { + q->setMask(QRegion()); + } else { + q->setMask(frameSvgItem->frameSvg()->mask()); + } } + updateInputShape(); } void DialogPrivate::updateVisibility(bool visible) @@ -312,7 +328,12 @@ void DialogPrivate::updateInputShape() if (!q->isVisible()) { return; } + #if HAVE_XCB_SHAPE + if (backgroundHints == Dialog::NoBackground) { + return; + } + if (QGuiApplication::platformName() == QStringLiteral("xcb")) { xcb_connection_t *c = QX11Info::connection(); static bool s_shapeExtensionChecked = false; @@ -350,7 +371,6 @@ void DialogPrivate::syncMainItemToSize() { syncBorders(); - KWindowEffects::enableBlurBehind(q->winId(), true, frameSvgItem->frameSvg()->mask()); updateTheme(); if (mainItem) { @@ -397,7 +417,7 @@ void DialogPrivate::syncToMainItemSize() syncBorders(); mainItem.data()->setX(frameSvgItem->margins()->left()); mainItem.data()->setY(frameSvgItem->margins()->top()); - KWindowEffects::enableBlurBehind(q->winId(), true, frameSvgItem->frameSvg()->mask()); + updateTheme(); } @@ -856,15 +876,7 @@ void Dialog::classBegin() void Dialog::componentComplete() { - if (d->backgroundHints == NoBackground) { - d->frameSvgItem->setImagePath(QString()); - } else { - if (d->type == Tooltip) { - d->frameSvgItem->setImagePath("widgets/tooltip"); - } else { - d->frameSvgItem->setImagePath("dialogs/background"); - } - } + d->updateTheme(); d->componentComplete = true; d->syncToMainItemSize(); } @@ -909,15 +921,7 @@ void Dialog::setBackgroundHints(Dialog::BackgroundHints hints) } d->backgroundHints = hints; - if (hints == NoBackground) { - d->frameSvgItem->setImagePath(QString()); - } else { - if (d->type == Tooltip) { - d->frameSvgItem->setImagePath("widgets/tooltip"); - } else { - d->frameSvgItem->setImagePath("dialogs/background"); - } - } + d->updateTheme(); emit backgroundHintsChanged(); } From a135c4de7d92ba3a6f18598b8260e291f9527491 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 20 Aug 2014 18:01:47 +0200 Subject: [PATCH 3/6] correctly enable/disable shadow --- src/plasmaquick/dialog.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/plasmaquick/dialog.cpp b/src/plasmaquick/dialog.cpp index 20a5ef7e5..83ab0d077 100644 --- a/src/plasmaquick/dialog.cpp +++ b/src/plasmaquick/dialog.cpp @@ -155,7 +155,7 @@ void DialogPrivate::syncBorders() } } - if (q->isVisible()) { + if (q->isVisible() && backgroundHints != Dialog::NoBackground) { DialogShadows::self()->addWindow(q, frameSvgItem->enabledBorders()); } } @@ -167,6 +167,7 @@ void DialogPrivate::updateTheme() KWindowEffects::enableBlurBehind(q->winId(), false); KWindowEffects::enableBackgroundContrast(q->winId(), false); q->setMask(QRegion()); + DialogShadows::self()->removeWindow(q); } else { if (type == Dialog::Tooltip) { frameSvgItem->setImagePath("widgets/tooltip"); @@ -187,6 +188,9 @@ void DialogPrivate::updateTheme() } else { q->setMask(frameSvgItem->frameSvg()->mask()); } + if (q->isVisible()) { + DialogShadows::self()->addWindow(q, frameSvgItem->enabledBorders()); + } } updateInputShape(); } @@ -845,7 +849,9 @@ void Dialog::focusOutEvent(QFocusEvent *ev) void Dialog::showEvent(QShowEvent *event) { - DialogShadows::self()->addWindow(this, d->frameSvgItem->enabledBorders()); + if (d->backgroundHints != Dialog::NoBackground) { + DialogShadows::self()->addWindow(this, d->frameSvgItem->enabledBorders()); + } QQuickWindow::showEvent(event); } From e0fd14903c6a8c87b432cd1259ae1f6c887dc58c Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 21 Aug 2014 14:55:16 +0200 Subject: [PATCH 4/6] fix comment --- src/plasmaquick/dialog.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plasmaquick/dialog.h b/src/plasmaquick/dialog.h index bc12098bd..f207f88b9 100644 --- a/src/plasmaquick/dialog.h +++ b/src/plasmaquick/dialog.h @@ -118,8 +118,8 @@ class PLASMAQUICK_EXPORT Dialog : public QQuickWindow, public QQmlParserStatus /** * This property holds how (and if at all) the dialog should draw its own background - * or if it complete responsibility of the content to render a background. - * Note that in this case it loses kwin side shadows and blur + * or if it is complete responsibility of the content item to render a background. + * Note that in case of NoBackground it loses kwin side shadows and blur */ Q_PROPERTY(BackgroundHints backgroundHints READ backgroundHints WRITE setBackgroundHints NOTIFY backgroundHintsChanged) From fcb8c859511c580ecef8bae2bcfa51070d74051e Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 21 Aug 2014 15:47:37 +0200 Subject: [PATCH 5/6] remove dead code --- src/plasmaquick/dialog.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/plasmaquick/dialog.cpp b/src/plasmaquick/dialog.cpp index 83ab0d077..50324ddab 100644 --- a/src/plasmaquick/dialog.cpp +++ b/src/plasmaquick/dialog.cpp @@ -154,10 +154,6 @@ void DialogPrivate::syncBorders() updateMaximumHeight(); } } - - if (q->isVisible() && backgroundHints != Dialog::NoBackground) { - DialogShadows::self()->addWindow(q, frameSvgItem->enabledBorders()); - } } void DialogPrivate::updateTheme() @@ -486,7 +482,6 @@ Dialog::Dialog(QQuickItem *parent) property("data"); //Create the FrameSvg background. d->frameSvgItem = new Plasma::FrameSvgItem(contentItem()); - //d->frameSvgItem->setImagePath("dialogs/background"); connect(&d->theme, SIGNAL(themeChanged()), this, SLOT(updateTheme())); From f74bf9a8b8a8b7bd6ecd2cbaf4174436733bd732 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 21 Aug 2014 15:49:29 +0200 Subject: [PATCH 6/6] don't call updateTheme 2 times --- src/plasmaquick/dialog.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plasmaquick/dialog.cpp b/src/plasmaquick/dialog.cpp index 50324ddab..02271e452 100644 --- a/src/plasmaquick/dialog.cpp +++ b/src/plasmaquick/dialog.cpp @@ -877,7 +877,6 @@ void Dialog::classBegin() void Dialog::componentComplete() { - d->updateTheme(); d->componentComplete = true; d->syncToMainItemSize(); }