plasma: export DialogShadows class

there are 3 copies of the sources for that class because it is not
exported (one here, one in kde-workspace and one in kde-extraapps) with
one class that is very similar to it - PanelShadows (in kde-workspace
repo, part of plasmagenericshell library)

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-11-07 18:05:08 +02:00
parent 6b7cd4e1e4
commit 38cc86db41
8 changed files with 46 additions and 50 deletions

View file

@ -558,6 +558,7 @@ install(
Plasma/DeclarativeWidget
Plasma/Delegate
Plasma/Dialog
Plasma/DialogShadows
Plasma/Extender
Plasma/ExtenderGroup
Plasma/ExtenderItem

View file

@ -0,0 +1 @@
#include "../../plasma/dialogshadows.h"

View file

@ -80,6 +80,7 @@ set(plasma_LIB_SRCS
dataenginemanager.cpp
delegate.cpp
dialog.cpp
dialogshadows.cpp
abstractdialogmanager.cpp
extenders/extender.cpp
extenders/extendergroup.cpp
@ -95,7 +96,6 @@ set(plasma_LIB_SRCS
private/dataenginebindings.cpp
private/dataengineconsumer.cpp
private/dataengineservice.cpp
private/dialogshadows.cpp
private/extenderapplet.cpp
private/extenderitemmimedata.cpp
private/focusindicator.cpp
@ -211,6 +211,7 @@ install(
dataenginemanager.h
delegate.h
dialog.h
dialogshadows.h
extenders/extender.h
extenders/extendergroup.h
extenders/extenderitem.h

View file

@ -49,7 +49,6 @@
#include "plasma/corona.h"
#include "plasma/extenders/extender.h"
#include "plasma/private/extender_p.h"
#include "plasma/private/dialogshadows_p.h"
#include "plasma/framesvg.h"
#include "plasma/theme.h"
#include "plasma/widgets/scrollwidget.h"
@ -231,7 +230,7 @@ void DialogPrivate::checkBorders(bool updateMaskIfNeeded)
}
background->setEnabledBorders(borders);
DialogShadows::self()->addWindow(q, borders);
dialogshadows->addWindow(q, borders);
if (extender) {
FrameSvg::EnabledBorders disabledBorders = FrameSvg::NoBorder;
@ -376,6 +375,7 @@ Dialog::Dialog(QWidget *parent, Qt::WindowFlags f)
{
setMouseTracking(true);
setAttribute(Qt::WA_TranslucentBackground);
d->dialogshadows = new DialogShadows(this);
d->background = new FrameSvg(this);
d->background->setImagePath("dialogs/background");
d->background->setEnabledBorders(FrameSvg::AllBorders);
@ -399,7 +399,7 @@ Dialog::Dialog(QWidget *parent, Qt::WindowFlags f)
Dialog::~Dialog()
{
DialogShadows::self()->removeWindow(this);
d->dialogshadows->removeWindow(this);
delete d;
}
@ -713,7 +713,7 @@ void Dialog::showEvent(QShowEvent * event)
}
emit dialogVisible(true);
DialogShadows::self()->addWindow(this, d->background->enabledBorders());
d->dialogshadows->addWindow(this, d->background->enabledBorders());
}
void Dialog::focusInEvent(QFocusEvent *event)
@ -877,5 +877,6 @@ void Dialog::setAspectRatioMode(Plasma::AspectRatioMode mode)
d->aspectRatioMode = mode;
}
}
} // Plasma namespace
#include "moc_dialog.cpp"

View file

@ -16,7 +16,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "dialogshadows_p.h"
#include "dialogshadows.h"
#include <QWidget>
#include <QPainter>
@ -29,17 +29,19 @@
#endif
#include <kdebug.h>
#include <kglobal.h>
class DialogShadows::Private
namespace Plasma
{
class DialogShadowsPrivate
{
public:
Private(DialogShadows *shadows)
DialogShadowsPrivate(DialogShadows *shadows)
: q(shadows)
{
}
~Private()
~DialogShadowsPrivate()
{
// Do not call clearPixmaps() from here: it creates new QPixmap(),
// which causes a crash when application is stopping.
@ -72,21 +74,9 @@ public:
QHash<const QWidget *, Plasma::FrameSvg::EnabledBorders> m_windows;
};
class DialogShadowsSingleton
{
public:
DialogShadowsSingleton()
{
}
DialogShadows self;
};
K_GLOBAL_STATIC(DialogShadowsSingleton, privateDialogShadowsSelf)
DialogShadows::DialogShadows(QObject *parent, const QString &prefix)
: Plasma::Svg(parent),
d(new Private(this))
d(new DialogShadowsPrivate(this))
{
setImagePath(prefix);
connect(this, SIGNAL(repaintNeeded()), this, SLOT(updateShadows()));
@ -97,11 +87,6 @@ DialogShadows::~DialogShadows()
delete d;
}
DialogShadows *DialogShadows::self()
{
return &privateDialogShadowsSelf->self;
}
void DialogShadows::addWindow(const QWidget *window, Plasma::FrameSvg::EnabledBorders enabledBorders)
{
if (!window || !window->isWindow()) {
@ -129,7 +114,7 @@ void DialogShadows::removeWindow(const QWidget *window)
}
}
void DialogShadows::Private::windowDestroyed(QObject *deletedObject)
void DialogShadowsPrivate::windowDestroyed(QObject *deletedObject)
{
m_windows.remove(static_cast<QWidget *>(deletedObject));
@ -138,7 +123,7 @@ void DialogShadows::Private::windowDestroyed(QObject *deletedObject)
}
}
void DialogShadows::Private::updateShadows()
void DialogShadowsPrivate::updateShadows()
{
setupPixmaps();
QHashIterator<const QWidget *, Plasma::FrameSvg::EnabledBorders> it(m_windows);
@ -148,7 +133,7 @@ void DialogShadows::Private::updateShadows()
}
}
void DialogShadows::Private::initPixmap(const QString &element)
void DialogShadowsPrivate::initPixmap(const QString &element)
{
#ifdef Q_WS_X11
QPixmap pix = q->pixmap(element);
@ -165,7 +150,7 @@ void DialogShadows::Private::initPixmap(const QString &element)
#endif
}
QPixmap DialogShadows::Private::initEmptyPixmap(const QSize &size)
QPixmap DialogShadowsPrivate::initEmptyPixmap(const QSize &size)
{
#ifdef Q_WS_X11
QPixmap tempEmptyPix;
@ -180,7 +165,7 @@ QPixmap DialogShadows::Private::initEmptyPixmap(const QSize &size)
#endif
}
void DialogShadows::Private::setupPixmaps()
void DialogShadowsPrivate::setupPixmaps()
{
clearPixmaps();
initPixmap("shadow-top");
@ -203,7 +188,7 @@ void DialogShadows::Private::setupPixmaps()
}
void DialogShadows::Private::setupData(Plasma::FrameSvg::EnabledBorders enabledBorders)
void DialogShadowsPrivate::setupData(Plasma::FrameSvg::EnabledBorders enabledBorders)
{
#ifdef Q_WS_X11
//shadow-top
@ -333,7 +318,7 @@ void DialogShadows::Private::setupData(Plasma::FrameSvg::EnabledBorders enabledB
data[enabledBorders] << top << right << bottom << left;
}
void DialogShadows::Private::freeX11Pixmaps()
void DialogShadowsPrivate::freeX11Pixmaps()
{
#ifdef Q_WS_X11
foreach (const QPixmap &pixmap, m_shadowPixmaps) {
@ -369,7 +354,7 @@ void DialogShadows::Private::freeX11Pixmaps()
#endif
}
void DialogShadows::Private::clearPixmaps()
void DialogShadowsPrivate::clearPixmaps()
{
#ifdef Q_WS_X11
freeX11Pixmaps();
@ -386,7 +371,7 @@ void DialogShadows::Private::clearPixmaps()
data.clear();
}
void DialogShadows::Private::updateShadow(const QWidget *window, Plasma::FrameSvg::EnabledBorders enabledBorders)
void DialogShadowsPrivate::updateShadow(const QWidget *window, Plasma::FrameSvg::EnabledBorders enabledBorders)
{
#ifdef Q_WS_X11
if (m_shadowPixmaps.isEmpty()) {
@ -406,7 +391,7 @@ void DialogShadows::Private::updateShadow(const QWidget *window, Plasma::FrameSv
#endif
}
void DialogShadows::Private::clearShadow(const QWidget *window)
void DialogShadowsPrivate::clearShadow(const QWidget *window)
{
#ifdef Q_WS_X11
Display *dpy = QX11Info::display();
@ -420,5 +405,7 @@ bool DialogShadows::enabled() const
return hasElement("shadow-left");
}
#include "moc_dialogshadows_p.cpp"
} // Plasma namespace
#include "moc_dialogshadows.cpp"

View file

@ -21,32 +21,34 @@
#include <QSet>
#include "plasma/framesvg.h"
#include "plasma/svg.h"
#include <plasma/plasma_export.h>
#include <plasma/framesvg.h>
#include <plasma/svg.h>
namespace Plasma
{
class DialogShadows : public Plasma::Svg
class DialogShadowsPrivate;
class PLASMA_EXPORT DialogShadows : public Plasma::Svg
{
Q_OBJECT
public:
explicit DialogShadows(QObject *parent = 0, const QString &prefix = "dialogs/background");
~DialogShadows();
static DialogShadows *self();
void addWindow(const QWidget *window, Plasma::FrameSvg::EnabledBorders enabledBorders = Plasma::FrameSvg::AllBorders);
void removeWindow(const QWidget *window);
bool enabled() const;
private:
class Private;
Private * const d;
DialogShadowsPrivate * const d;
Q_PRIVATE_SLOT(d, void updateShadows())
Q_PRIVATE_SLOT(d, void windowDestroyed(QObject *deletedObject))
};
#endif
} // Plasma namespace
#endif // PLASMA_DIALOGSHADOWS_H

View file

@ -26,6 +26,7 @@
#include <QTimer>
#include "plasma/dialog.h"
#include "plasma/dialogshadows.h"
namespace Plasma {
@ -37,6 +38,7 @@ class DialogPrivate
public:
DialogPrivate(Dialog *dialog)
: q(dialog),
dialogshadows(0),
background(0),
view(0),
resizeCorners(Dialog::NoCorner),
@ -66,6 +68,7 @@ public:
Plasma::Dialog *q;
Plasma::DialogShadows *dialogshadows;
/**
* Holds the background SVG, to be re-rendered when the cache is invalidated,
* for example by resizing the dialogue.

View file

@ -47,8 +47,8 @@
#include "plasma/popupapplet.h"
#include "plasma/theme.h"
#include "plasma/view.h"
#include "plasma/dialogshadows.h"
#include "plasma/private/tooltip_p.h"
#include "plasma/private/dialogshadows_p.h"
namespace Plasma
{