From 38cc86db415d460bf959f9b153ea2cafd2e24223 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Mon, 7 Nov 2022 18:05:08 +0200 Subject: [PATCH] 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 --- includes/CMakeLists.txt | 1 + includes/Plasma/DialogShadows | 1 + plasma/CMakeLists.txt | 3 +- plasma/dialog.cpp | 11 ++-- plasma/{private => }/dialogshadows.cpp | 55 +++++++------------ .../dialogshadows_p.h => dialogshadows.h} | 20 ++++--- plasma/private/dialog_p.h | 3 + plasma/tooltipmanager.cpp | 2 +- 8 files changed, 46 insertions(+), 50 deletions(-) create mode 100644 includes/Plasma/DialogShadows rename plasma/{private => }/dialogshadows.cpp (91%) rename plasma/{private/dialogshadows_p.h => dialogshadows.h} (82%) diff --git a/includes/CMakeLists.txt b/includes/CMakeLists.txt index c5ced18c..fafaea40 100644 --- a/includes/CMakeLists.txt +++ b/includes/CMakeLists.txt @@ -558,6 +558,7 @@ install( Plasma/DeclarativeWidget Plasma/Delegate Plasma/Dialog + Plasma/DialogShadows Plasma/Extender Plasma/ExtenderGroup Plasma/ExtenderItem diff --git a/includes/Plasma/DialogShadows b/includes/Plasma/DialogShadows new file mode 100644 index 00000000..3a520266 --- /dev/null +++ b/includes/Plasma/DialogShadows @@ -0,0 +1 @@ +#include "../../plasma/dialogshadows.h" diff --git a/plasma/CMakeLists.txt b/plasma/CMakeLists.txt index 44ed7220..78a54a2e 100644 --- a/plasma/CMakeLists.txt +++ b/plasma/CMakeLists.txt @@ -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 diff --git a/plasma/dialog.cpp b/plasma/dialog.cpp index 13f2ccb7..3129c86e 100644 --- a/plasma/dialog.cpp +++ b/plasma/dialog.cpp @@ -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" diff --git a/plasma/private/dialogshadows.cpp b/plasma/dialogshadows.cpp similarity index 91% rename from plasma/private/dialogshadows.cpp rename to plasma/dialogshadows.cpp index fa044acb..d8cf841a 100644 --- a/plasma/private/dialogshadows.cpp +++ b/plasma/dialogshadows.cpp @@ -16,7 +16,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "dialogshadows_p.h" +#include "dialogshadows.h" #include #include @@ -29,17 +29,19 @@ #endif #include -#include -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 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(deletedObject)); @@ -138,7 +123,7 @@ void DialogShadows::Private::windowDestroyed(QObject *deletedObject) } } -void DialogShadows::Private::updateShadows() +void DialogShadowsPrivate::updateShadows() { setupPixmaps(); QHashIterator 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" diff --git a/plasma/private/dialogshadows_p.h b/plasma/dialogshadows.h similarity index 82% rename from plasma/private/dialogshadows_p.h rename to plasma/dialogshadows.h index d762e576..b7b9d7c7 100644 --- a/plasma/private/dialogshadows_p.h +++ b/plasma/dialogshadows.h @@ -21,32 +21,34 @@ #include -#include "plasma/framesvg.h" -#include "plasma/svg.h" +#include +#include +#include +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 diff --git a/plasma/private/dialog_p.h b/plasma/private/dialog_p.h index a625401f..37f0608d 100644 --- a/plasma/private/dialog_p.h +++ b/plasma/private/dialog_p.h @@ -26,6 +26,7 @@ #include #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. diff --git a/plasma/tooltipmanager.cpp b/plasma/tooltipmanager.cpp index 1a376a7b..6c3cb102 100644 --- a/plasma/tooltipmanager.cpp +++ b/plasma/tooltipmanager.cpp @@ -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 {