a simple way to enable/disable background

This commit is contained in:
Marco Martin 2014-08-20 16:33:38 +02:00
parent 93052bf263
commit 38bcec95b0
2 changed files with 61 additions and 5 deletions

View File

@ -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 <QObject> 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,11 +763,15 @@ void Dialog::setType(WindowType type)
setFlags(Qt::FramelessWindowHint | flags());
}
if (type == Tooltip) {
if (d->backgroundHints == Dialog::NoBackground) {
d->frameSvgItem->setImagePath(QString());
} else {
if (d->type == Tooltip) {
d->frameSvgItem->setImagePath("widgets/tooltip");
} else {
d->frameSvgItem->setImagePath("dialogs/background");
}
}
if (type == Dock) {
KWindowSystem::setOnAllDesktops(winId(), true);
@ -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"

View File

@ -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.