[kdecoration2] Decoration::shadow returns QSharedPointer

Adjust all components to use the QSharedPointer. Aurorae obviously has
to create a QSharedPointer, Shadow holds a QSharedPointer for the
DecorationShadow (advantage: is kept when the Decoration is destroyed),
and the KCM needs to add a property on PreviewItem to get access to the
Shadow. It's no longer a Q_PROPERTY on Decoration and we cannot re-add
it as a dynamic property (cannot be read from QML side).
icc-effect-5.14.5
Martin Gräßlin 2014-12-01 09:40:24 +01:00
parent 6bdd0e96f6
commit 027a7a1646
5 changed files with 44 additions and 24 deletions

View File

@ -347,7 +347,7 @@ void Decoration::init()
} else {
// create a dummy shadow for the configuration interface
if (m_padding) {
KDecoration2::DecorationShadow *s = new KDecoration2::DecorationShadow(this);
auto s = QSharedPointer<KDecoration2::DecorationShadow>::create();
s->setPadding(*m_padding);
s->setInnerShadowRect(QRect(m_padding->left(), m_padding->top(), 1, 1));
setShadow(s);
@ -394,20 +394,16 @@ void Decoration::paint(QPainter *painter, const QRect &repaintRegion)
(m_padding->left() > 0 || m_padding->top() > 0 || m_padding->right() > 0 || m_padding->bottom() > 0) &&
!client().data()->isMaximized()) {
r = r.adjusted(m_padding->left(), m_padding->top(), -m_padding->right(), -m_padding->bottom());
KDecoration2::DecorationShadow *s = new KDecoration2::DecorationShadow(this);
auto s = QSharedPointer<KDecoration2::DecorationShadow>::create();
s->setShadow(m_buffer);
s->setPadding(*m_padding);
s->setInnerShadowRect(QRect(m_padding->left(),
m_padding->top(),
m_buffer.width() - m_padding->left() - m_padding->right(),
m_buffer.height() - m_padding->top() - m_padding->bottom()));
auto oldShadow = shadow();
setShadow(s);
if (oldShadow) {
delete oldShadow.data();
}
} else {
setShadow(QPointer<KDecoration2::DecorationShadow>());
setShadow(QSharedPointer<KDecoration2::DecorationShadow>());
}
painter->drawImage(rect(), m_buffer, r);
}

View File

@ -126,6 +126,7 @@ void PreviewItem::setDecoration(Decoration *deco)
}
}
);
connect(m_decoration, &KDecoration2::Decoration::shadowChanged, this, &PreviewItem::shadowChanged);
emit decorationChanged(m_decoration);
}
@ -165,7 +166,7 @@ void PreviewItem::paint(QPainter *painter)
void PreviewItem::paintShadow(QPainter *painter, int &paddingLeft, int &paddingRight, int &paddingTop, int &paddingBottom)
{
const DecorationShadow *shadow = ((const Decoration*)(m_decoration))->shadow();
const auto &shadow = ((const Decoration*)(m_decoration))->shadow();
if (!shadow) {
return;
}
@ -208,7 +209,8 @@ void PreviewItem::paintShadow(QPainter *painter, int &paddingLeft, int &paddingR
void PreviewItem::mouseDoubleClickEvent(QMouseEvent *event)
{
if (const DecorationShadow *shadow = ((const Decoration*)(m_decoration))->shadow()) {
const auto &shadow = m_decoration->shadow();
if (shadow) {
QMouseEvent e(event->type(),
event->localPos() - QPointF(shadow->paddingLeft(), shadow->paddingTop()),
event->button(),
@ -222,7 +224,8 @@ void PreviewItem::mouseDoubleClickEvent(QMouseEvent *event)
void PreviewItem::mousePressEvent(QMouseEvent *event)
{
if (const DecorationShadow *shadow = ((const Decoration*)(m_decoration))->shadow()) {
const auto &shadow = m_decoration->shadow();
if (shadow) {
QMouseEvent e(event->type(),
event->localPos() - QPointF(shadow->paddingLeft(), shadow->paddingTop()),
event->button(),
@ -236,7 +239,8 @@ void PreviewItem::mousePressEvent(QMouseEvent *event)
void PreviewItem::mouseReleaseEvent(QMouseEvent *event)
{
if (const DecorationShadow *shadow = ((const Decoration*)(m_decoration))->shadow()) {
const auto &shadow = m_decoration->shadow();
if (shadow) {
QMouseEvent e(event->type(),
event->localPos() - QPointF(shadow->paddingLeft(), shadow->paddingTop()),
event->button(),
@ -250,7 +254,8 @@ void PreviewItem::mouseReleaseEvent(QMouseEvent *event)
void PreviewItem::mouseMoveEvent(QMouseEvent *event)
{
if (const DecorationShadow *shadow = ((const Decoration*)(m_decoration))->shadow()) {
const auto &shadow = m_decoration->shadow();
if (shadow) {
QMouseEvent e(event->type(),
event->localPos() - QPointF(shadow->paddingLeft(), shadow->paddingTop()),
event->button(),
@ -264,7 +269,8 @@ void PreviewItem::mouseMoveEvent(QMouseEvent *event)
void PreviewItem::hoverEnterEvent(QHoverEvent *event)
{
if (const DecorationShadow *shadow = ((const Decoration*)(m_decoration))->shadow()) {
const auto &shadow = m_decoration->shadow();
if (shadow) {
QHoverEvent e(event->type(),
event->posF() - QPointF(shadow->paddingLeft(), shadow->paddingTop()),
event->oldPosF() - QPointF(shadow->paddingLeft(), shadow->paddingTop()),
@ -277,7 +283,8 @@ void PreviewItem::hoverEnterEvent(QHoverEvent *event)
void PreviewItem::hoverLeaveEvent(QHoverEvent *event)
{
if (const DecorationShadow *shadow = ((const Decoration*)(m_decoration))->shadow()) {
const auto &shadow = m_decoration->shadow();
if (shadow) {
QHoverEvent e(event->type(),
event->posF() - QPointF(shadow->paddingLeft(), shadow->paddingTop()),
event->oldPosF() - QPointF(shadow->paddingLeft(), shadow->paddingTop()),
@ -290,7 +297,8 @@ void PreviewItem::hoverLeaveEvent(QHoverEvent *event)
void PreviewItem::hoverMoveEvent(QHoverEvent *event)
{
if (const DecorationShadow *shadow = ((const Decoration*)(m_decoration))->shadow()) {
const auto &shadow = m_decoration->shadow();
if (shadow) {
QHoverEvent e(event->type(),
event->posF() - QPointF(shadow->paddingLeft(), shadow->paddingTop()),
event->oldPosF() - QPointF(shadow->paddingLeft(), shadow->paddingTop()),
@ -370,5 +378,17 @@ void PreviewItem::syncSize()
m_client->setHeight(height() - m_decoration->borderTop() - m_decoration->borderBottom() - heightOffset);
}
DecorationShadow *PreviewItem::shadow() const
{
if (!m_decoration) {
return nullptr;
}
const auto &s = m_decoration->shadow();
if (!s) {
return nullptr;
}
return s.data();
}
}
}

View File

@ -26,6 +26,7 @@
namespace KDecoration2
{
class Decoration;
class DecorationShadow;
class DecorationSettings;
namespace Preview
@ -41,6 +42,7 @@ class PreviewItem : public QQuickPaintedItem
Q_PROPERTY(KDecoration2::Preview::PreviewBridge *bridge READ bridge WRITE setBridge NOTIFY bridgeChanged)
Q_PROPERTY(KDecoration2::Preview::Settings *settings READ settings WRITE setSettings NOTIFY settingsChanged)
Q_PROPERTY(KDecoration2::Preview::PreviewClient *client READ client)
Q_PROPERTY(KDecoration2::DecorationShadow *shadow READ shadow NOTIFY shadowChanged)
Q_PROPERTY(QColor windowColor READ windowColor WRITE setWindowColor NOTIFY windowColorChanged)
Q_PROPERTY(bool drawBackground READ isDrawingBackground WRITE setDrawingBackground NOTIFY drawingBackgroundChanged)
public:
@ -64,6 +66,7 @@ public:
void setSettings(Settings *settings);
PreviewClient *client();
DecorationShadow *shadow() const;
Q_SIGNALS:
void decorationChanged(KDecoration2::Decoration *deco);
@ -71,6 +74,7 @@ Q_SIGNALS:
void drawingBackgroundChanged(bool);
void bridgeChanged();
void settingsChanged();
void shadowChanged();
protected:
void mouseDoubleClickEvent(QMouseEvent *event) override;

View File

@ -54,10 +54,10 @@ ScrollView {
Component.onCompleted: {
client.caption = Qt.binding(function() { return model["display"]; });
client.active = false;
anchors.leftMargin = Qt.binding(function() { return 40 - (inactivePreview.decoration.shadow ? inactivePreview.decoration.shadow.paddingLeft : 0);});
anchors.rightMargin = Qt.binding(function() { return 10 - (inactivePreview.decoration.shadow ? inactivePreview.decoration.shadow.paddingRight : 0);});
anchors.topMargin = Qt.binding(function() { return 10 - (inactivePreview.decoration.shadow ? inactivePreview.decoration.shadow.paddingTop : 0);});
anchors.bottomMargin = Qt.binding(function() { return 40 - (inactivePreview.decoration.shadow ? inactivePreview.decoration.shadow.paddingBottom : 0);});
anchors.leftMargin = Qt.binding(function() { return 40 - (inactivePreview.shadow ? inactivePreview.shadow.paddingLeft : 0);});
anchors.rightMargin = Qt.binding(function() { return 10 - (inactivePreview.shadow ? inactivePreview.shadow.paddingRight : 0);});
anchors.topMargin = Qt.binding(function() { return 10 - (inactivePreview.shadow ? inactivePreview.shadow.paddingTop : 0);});
anchors.bottomMargin = Qt.binding(function() { return 40 - (inactivePreview.shadow ? inactivePreview.shadow.paddingBottom : 0);});
}
}
KDecoration.Decoration {
@ -68,10 +68,10 @@ ScrollView {
Component.onCompleted: {
client.caption = Qt.binding(function() { return model["display"]; });
client.active = true;
anchors.leftMargin = Qt.binding(function() { return 10 - (activePreview.decoration.shadow ? activePreview.decoration.shadow.paddingLeft : 0);});
anchors.rightMargin = Qt.binding(function() { return 40 - (activePreview.decoration.shadow ? activePreview.decoration.shadow.paddingRight : 0);});
anchors.topMargin = Qt.binding(function() { return 40 - (activePreview.decoration.shadow ? activePreview.decoration.shadow.paddingTop : 0);});
anchors.bottomMargin = Qt.binding(function() { return 10 - (activePreview.decoration.shadow ? activePreview.decoration.shadow.paddingBottom : 0);});
anchors.leftMargin = Qt.binding(function() { return 10 - (activePreview.shadow ? activePreview.shadow.paddingLeft : 0);});
anchors.rightMargin = Qt.binding(function() { return 40 - (activePreview.shadow ? activePreview.shadow.paddingRight : 0);});
anchors.topMargin = Qt.binding(function() { return 40 - (activePreview.shadow ? activePreview.shadow.paddingTop : 0);});
anchors.bottomMargin = Qt.binding(function() { return 10 - (activePreview.shadow ? activePreview.shadow.paddingBottom : 0);});
}
}
MouseArea {

View File

@ -170,7 +170,7 @@ private:
QRegion m_shadowRegion;
QSize m_cachedSize;
// Decoration based shadows
QPointer<KDecoration2::DecorationShadow> m_decorationShadow;
QSharedPointer<KDecoration2::DecorationShadow> m_decorationShadow;
};
}