plasma: use the now exported Plasma::DialogShadows class

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-11-07 18:23:05 +02:00
parent ebadaa0c40
commit 5c32f8c9e1
7 changed files with 24 additions and 448 deletions

View file

@ -10,7 +10,6 @@ set(folderview_SRCS
abstractitemview.cpp
listview.cpp
dialog.cpp
dialogshadows.cpp
label.cpp
iconview.cpp
popupview.cpp

View file

@ -18,7 +18,6 @@
*/
#include "dialog.h"
#include "dialogshadows_p.h"
#include <QApplication>
#include <QDesktopWidget>
@ -30,6 +29,7 @@
#include <Plasma/Applet>
#include <Plasma/FrameSvg>
#include <Plasma/DialogShadows>
#ifdef Q_WS_X11
# include <qx11info_x11.h>
@ -38,7 +38,10 @@
Dialog::Dialog(QWidget *parent)
: QWidget(parent, Qt::Popup), m_widget(0)
: QWidget(parent, Qt::Popup),
m_dialogshadows(0),
m_background(0),
m_widget(0)
{
setAttribute(Qt::WA_TranslucentBackground);
@ -53,6 +56,7 @@ Dialog::Dialog(QWidget *parent)
pal.setColor(backgroundRole(), Qt::transparent);
setPalette(pal);
m_dialogshadows = new Plasma::DialogShadows(this, "dialogs/background");
m_background = new Plasma::FrameSvg(this);
m_background->setImagePath("dialogs/background");
@ -66,6 +70,7 @@ Dialog::Dialog(QWidget *parent)
Dialog::~Dialog()
{
m_dialogshadows->removeWindow(this);
}
void Dialog::setGraphicsWidget(QGraphicsWidget *widget)
@ -139,7 +144,7 @@ void Dialog::show(Plasma::Applet *applet)
move(pos);
QWidget::show();
DialogShadows::self()->addWindow(this, borders);
m_dialogshadows->addWindow(this, borders);
}
void Dialog::resizeEvent(QResizeEvent *event)

View file

@ -25,6 +25,7 @@
namespace Plasma {
class Applet;
class FrameSvg;
class DialogShadows;
}
#include <QGraphicsView>
@ -47,6 +48,7 @@ protected:
void paintEvent(QPaintEvent *event);
private:
Plasma::DialogShadows *m_dialogshadows;
Plasma::FrameSvg *m_background;
QGraphicsScene *m_scene;
QGraphicsView *m_view;

View file

@ -1,385 +0,0 @@
/*
* Copyright 2011 by Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License version 2,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "dialogshadows_p.h"
#include <QWidget>
#include <QPainter>
#ifdef Q_WS_X11
#include <QtGui/qx11info_x11.h>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <fixx11h.h>
#endif
#include <kdebug.h>
#include <kglobal.h>
class DialogShadows::Private
{
public:
Private(DialogShadows *shadows)
: q(shadows),
m_managePixmaps(false)
{
}
~Private()
{
clearPixmaps();
}
void clearPixmaps();
void setupPixmaps();
void initPixmap(const QString &element);
QPixmap initEmptyPixmap(const QSize &size);
void updateShadow(const QWidget *window, Plasma::FrameSvg::EnabledBorders);
void clearShadow(const QWidget *window);
void updateShadows();
void windowDestroyed(QObject *deletedObject);
void setupData(Plasma::FrameSvg::EnabledBorders enabledBorders);
DialogShadows *q;
QList<QPixmap> m_shadowPixmaps;
QPixmap m_emptyCornerPix;
QPixmap m_emptyCornerLeftPix;
QPixmap m_emptyCornerTopPix;
QPixmap m_emptyCornerRightPix;
QPixmap m_emptyCornerBottomPix;
QPixmap m_emptyVerticalPix;
QPixmap m_emptyHorizontalPix;
QHash<Plasma::FrameSvg::EnabledBorders, QVector<unsigned long> > data;
QHash<const QWidget *, Plasma::FrameSvg::EnabledBorders> m_windows;
bool m_managePixmaps;
};
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))
{
setImagePath(prefix);
connect(this, SIGNAL(repaintNeeded()), this, SLOT(updateShadows()));
}
DialogShadows *DialogShadows::self()
{
return &privateDialogShadowsSelf->self;
}
void DialogShadows::addWindow(const QWidget *window, Plasma::FrameSvg::EnabledBorders enabledBorders)
{
if (!window || !window->isWindow()) {
return;
}
d->m_windows[window] = enabledBorders;
d->updateShadow(window, enabledBorders);
connect(window, SIGNAL(destroyed(QObject*)),
this, SLOT(windowDestroyed(QObject*)), Qt::UniqueConnection);
}
void DialogShadows::removeWindow(const QWidget *window)
{
if (!d->m_windows.contains(window)) {
return;
}
d->m_windows.remove(window);
disconnect(window, 0, this, 0);
d->clearShadow(window);
if (d->m_windows.isEmpty()) {
d->clearPixmaps();
}
}
void DialogShadows::Private::windowDestroyed(QObject *deletedObject)
{
m_windows.remove(static_cast<QWidget *>(deletedObject));
if (m_windows.isEmpty()) {
clearPixmaps();
}
}
void DialogShadows::Private::updateShadows()
{
setupPixmaps();
QHash<const QWidget *, Plasma::FrameSvg::EnabledBorders>::const_iterator i;
for (i = m_windows.constBegin(); i != m_windows.constEnd(); ++i) {
updateShadow(i.key(), i.value());
}
}
void DialogShadows::Private::initPixmap(const QString &element)
{
#ifdef Q_WS_X11
QPixmap pix = q->pixmap(element);
if (!pix.isNull() && pix.handle() == 0) {
Pixmap xPix = XCreatePixmap(QX11Info::display(), QX11Info::appRootWindow(), pix.width(), pix.height(), 32);
QPixmap tempPix = QPixmap::fromX11Pixmap(xPix, QPixmap::ExplicitlyShared);
tempPix.fill(Qt::transparent);
QPainter p(&tempPix);
p.drawPixmap(QPoint(0, 0), pix);
m_shadowPixmaps << tempPix;
m_managePixmaps = true;
} else {
m_shadowPixmaps << pix;
}
#endif
}
QPixmap DialogShadows::Private::initEmptyPixmap(const QSize &size)
{
#ifdef Q_WS_X11
Pixmap emptyXPix = XCreatePixmap(QX11Info::display(), QX11Info::appRootWindow(), size.width(), size.height(), 32);
QPixmap tempEmptyPix = QPixmap::fromX11Pixmap(emptyXPix, QPixmap::ExplicitlyShared);
#else
QPixmap tempEmptyPix(size.width(), size.height());
#endif
tempEmptyPix.fill(Qt::transparent);
return tempEmptyPix;
}
void DialogShadows::Private::setupPixmaps()
{
clearPixmaps();
initPixmap("shadow-top");
initPixmap("shadow-topright");
initPixmap("shadow-right");
initPixmap("shadow-bottomright");
initPixmap("shadow-bottom");
initPixmap("shadow-bottomleft");
initPixmap("shadow-left");
initPixmap("shadow-topleft");
m_emptyCornerPix = initEmptyPixmap(QSize(1,1));
m_emptyCornerLeftPix = initEmptyPixmap(QSize(q->elementSize("shadow-topleft").width(), 1));
m_emptyCornerTopPix = initEmptyPixmap(QSize(1, q->elementSize("shadow-topleft").height()));
m_emptyCornerRightPix = initEmptyPixmap(QSize(q->elementSize("shadow-bottomright").width(), 1));
m_emptyCornerBottomPix = initEmptyPixmap(QSize(1, q->elementSize("shadow-bottomright").height()));
m_emptyVerticalPix = initEmptyPixmap(QSize(1, q->elementSize("shadow-left").height()));
m_emptyHorizontalPix = initEmptyPixmap(QSize(q->elementSize("shadow-top").width(), 1));
}
void DialogShadows::Private::setupData(Plasma::FrameSvg::EnabledBorders enabledBorders)
{
#ifdef Q_WS_X11
//shadow-top
if (enabledBorders & Plasma::FrameSvg::TopBorder) {
data[enabledBorders] << m_shadowPixmaps[0].handle();
} else {
data[enabledBorders] << m_emptyHorizontalPix.handle();
}
//shadow-topright
if (enabledBorders & Plasma::FrameSvg::TopBorder &&
enabledBorders & Plasma::FrameSvg::RightBorder) {
data[enabledBorders] << m_shadowPixmaps[1].handle();
} else if (enabledBorders & Plasma::FrameSvg::TopBorder) {
data[enabledBorders] << m_emptyCornerTopPix.handle();
} else if (enabledBorders & Plasma::FrameSvg::RightBorder) {
data[enabledBorders] << m_emptyCornerRightPix.handle();
} else {
data[enabledBorders] << m_emptyCornerPix.handle();
}
//shadow-right
if (enabledBorders & Plasma::FrameSvg::RightBorder) {
data[enabledBorders] << m_shadowPixmaps[2].handle();
} else {
data[enabledBorders] << m_emptyVerticalPix.handle();
}
//shadow-bottomright
if (enabledBorders & Plasma::FrameSvg::BottomBorder &&
enabledBorders & Plasma::FrameSvg::RightBorder) {
data[enabledBorders] << m_shadowPixmaps[3].handle();
} else if (enabledBorders & Plasma::FrameSvg::BottomBorder) {
data[enabledBorders] << m_emptyCornerBottomPix.handle();
} else if (enabledBorders & Plasma::FrameSvg::RightBorder) {
data[enabledBorders] << m_emptyCornerRightPix.handle();
} else {
data[enabledBorders] << m_emptyCornerPix.handle();
}
//shadow-bottom
if (enabledBorders & Plasma::FrameSvg::BottomBorder) {
data[enabledBorders] << m_shadowPixmaps[4].handle();
} else {
data[enabledBorders] << m_emptyHorizontalPix.handle();
}
//shadow-bottomleft
if (enabledBorders & Plasma::FrameSvg::BottomBorder &&
enabledBorders & Plasma::FrameSvg::LeftBorder) {
data[enabledBorders] << m_shadowPixmaps[5].handle();
} else if (enabledBorders & Plasma::FrameSvg::BottomBorder) {
data[enabledBorders] << m_emptyCornerBottomPix.handle();
} else if (enabledBorders & Plasma::FrameSvg::LeftBorder) {
data[enabledBorders] << m_emptyCornerLeftPix.handle();
} else {
data[enabledBorders] << m_emptyCornerPix.handle();
}
//shadow-left
if (enabledBorders & Plasma::FrameSvg::LeftBorder) {
data[enabledBorders] << m_shadowPixmaps[6].handle();
} else {
data[enabledBorders] << m_emptyVerticalPix.handle();
}
//shadow-topleft
if (enabledBorders & Plasma::FrameSvg::TopBorder &&
enabledBorders & Plasma::FrameSvg::LeftBorder) {
data[enabledBorders] << m_shadowPixmaps[7].handle();
} else if (enabledBorders & Plasma::FrameSvg::TopBorder) {
data[enabledBorders] << m_emptyCornerTopPix.handle();
} else if (enabledBorders & Plasma::FrameSvg::LeftBorder) {
data[enabledBorders] << m_emptyCornerLeftPix.handle();
} else {
data[enabledBorders] << m_emptyCornerPix.handle();
}
#endif
int left, top, right, bottom = 0;
QSize marginHint;
if (enabledBorders & Plasma::FrameSvg::TopBorder) {
marginHint = q->elementSize("shadow-hint-top-margin");
if (marginHint.isValid()) {
top = marginHint.height();
} else {
top = m_shadowPixmaps[0].height(); // top
}
} else {
top = 1;
}
if (enabledBorders & Plasma::FrameSvg::RightBorder) {
marginHint = q->elementSize("shadow-hint-right-margin");
if (marginHint.isValid()) {
right = marginHint.width();
} else {
right = m_shadowPixmaps[2].width(); // right
}
} else {
right = 1;
}
if (enabledBorders & Plasma::FrameSvg::BottomBorder) {
marginHint = q->elementSize("shadow-hint-bottom-margin");
if (marginHint.isValid()) {
bottom = marginHint.height();
} else {
bottom = m_shadowPixmaps[4].height(); // bottom
}
} else {
bottom = 1;
}
if (enabledBorders & Plasma::FrameSvg::LeftBorder) {
marginHint = q->elementSize("shadow-hint-left-margin");
if (marginHint.isValid()) {
left = marginHint.width();
} else {
left = m_shadowPixmaps[6].width(); // left
}
} else {
left = 1;
}
data[enabledBorders] << top << right << bottom << left;
}
void DialogShadows::Private::clearPixmaps()
{
#ifdef Q_WS_X11
if (m_managePixmaps) {
foreach (const QPixmap &pixmap, m_shadowPixmaps) {
XFreePixmap(QX11Info::display(), pixmap.handle());
}
XFreePixmap(QX11Info::display(), m_emptyCornerPix.handle());
XFreePixmap(QX11Info::display(), m_emptyCornerBottomPix.handle());
XFreePixmap(QX11Info::display(), m_emptyCornerLeftPix.handle());
XFreePixmap(QX11Info::display(), m_emptyCornerRightPix.handle());
XFreePixmap(QX11Info::display(), m_emptyCornerTopPix.handle());
XFreePixmap(QX11Info::display(), m_emptyVerticalPix.handle());
XFreePixmap(QX11Info::display(), m_emptyHorizontalPix.handle());
m_managePixmaps = false;
}
#endif
m_shadowPixmaps.clear();
data.clear();
}
void DialogShadows::Private::updateShadow(const QWidget *window, Plasma::FrameSvg::EnabledBorders enabledBorders)
{
#ifdef Q_WS_X11
if (m_shadowPixmaps.isEmpty()) {
setupPixmaps();
}
if (!data.contains(enabledBorders)) {
setupData(enabledBorders);
}
Display *dpy = QX11Info::display();
Atom atom = XInternAtom(dpy, "_KDE_NET_WM_SHADOW", False);
//kDebug() << "going to set the shadow of" << winId() << "to" << data;
XChangeProperty(dpy, window->winId(), atom, XA_CARDINAL, 32, PropModeReplace,
reinterpret_cast<const unsigned char *>(data[enabledBorders].constData()), data[enabledBorders].size());
#endif
}
void DialogShadows::Private::clearShadow(const QWidget *window)
{
#ifdef Q_WS_X11
Display *dpy = QX11Info::display();
Atom atom = XInternAtom(dpy, "_KDE_NET_WM_SHADOW", False);
XDeleteProperty(dpy, window->winId(), atom);
#endif
}
bool DialogShadows::enabled() const
{
return hasElement("shadow-left");
}
#include "moc_dialogshadows_p.cpp"

View file

@ -1,51 +0,0 @@
/*
* Copyright 2011 by Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License version 2,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_DIALOGSHADOWS_H
#define PLASMA_DIALOGSHADOWS_H
#include <QSet>
#include "plasma/framesvg.h"
#include "plasma/svg.h"
class DialogShadows : public Plasma::Svg
{
Q_OBJECT
public:
explicit DialogShadows(QObject *parent = 0, const QString &prefix = "dialogs/background");
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;
Q_PRIVATE_SLOT(d, void updateShadows())
Q_PRIVATE_SLOT(d, void windowDestroyed(QObject *deletedObject))
};
#endif

View file

@ -18,7 +18,6 @@
*/
#include "popupview.h"
#include "dialogshadows_p.h"
#include <QApplication>
#include <QClipboard>
@ -59,6 +58,7 @@
#include <Plasma/FrameSvg>
#include <Plasma/Theme>
#include <Plasma/WindowEffects>
#include <Plasma/DialogShadows>
QTime PopupView::s_lastOpenClose;
@ -67,6 +67,8 @@ PopupView::PopupView(const QModelIndex &index, const QPoint &pos,
const bool &showPreview, const QStringList &previewPlugins,
const IconView *parentView)
: QWidget(0, Qt::X11BypassWindowManagerHint),
m_dialogshadows(0),
m_background(0),
m_view(0),
m_parentView(parentView),
m_busyWidget(0),
@ -108,6 +110,7 @@ PopupView::PopupView(const QModelIndex &index, const QPoint &pos,
m_url = item.targetUrl();
}
m_dialogshadows = new Plasma::DialogShadows(this, "dialogs/background");
m_background = new Plasma::FrameSvg(this);
m_background->setImagePath("dialogs/background");
@ -146,6 +149,7 @@ PopupView::PopupView(const QModelIndex &index, const QPoint &pos,
PopupView::~PopupView()
{
m_dialogshadows->removeWindow(this);
delete m_newMenu;
s_lastOpenClose.restart();
}
@ -534,7 +538,7 @@ void PopupView::showEvent(QShowEvent *event)
{
Q_UNUSED(event)
DialogShadows::self()->addWindow(this);
m_dialogshadows->addWindow(this);
}
void PopupView::paintEvent(QPaintEvent *event)

View file

@ -22,7 +22,11 @@
#include <QBasicTimer>
#include <QWidget>
#include <QtCore/qdatetime.h>
#include <QDateTime>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QItemSelectionModel>
#include <QModelIndex>
#include <KActionCollection>
#include <KUrl>
@ -30,17 +34,14 @@
namespace Plasma {
class FrameSvg;
class BusyWidget;
class DialogShadows;
}
#include <QGraphicsView>
#include <QGraphicsScene>
class KDirModel;
class KFileItemDelegate;
class KFilePreviewGenerator;
class KNewFileMenu;
class KFileItemActions;
#include <QItemSelectionModel>
#include <QModelIndex>
class ProxyModel;
class IconView;
@ -104,6 +105,7 @@ private slots:
void renameSelectedIcon();
private:
Plasma::DialogShadows *m_dialogshadows;
Plasma::FrameSvg *m_background;
QGraphicsScene *m_scene;
QGraphicsView *m_view;