From c4c4d41a3e75fa49874e43bd09c0f6bca8967d0e Mon Sep 17 00:00:00 2001 From: Volker Krause Date: Fri, 31 Dec 2021 18:10:25 +0100 Subject: [PATCH] Port from deprecated QWeakPointer::data to QWeakPointer::toStrongRef --- kdecoration/breezebutton.cpp | 34 +++++++++++---------- kdecoration/breezedecoration.cpp | 42 +++++++++++++------------- kdecoration/breezedecoration.h | 28 ++++++++++++----- kdecoration/breezesettingsprovider.cpp | 2 +- kdecoration/breezesizegrip.cpp | 14 ++++----- 5 files changed, 67 insertions(+), 53 deletions(-) diff --git a/kdecoration/breezebutton.cpp b/kdecoration/breezebutton.cpp index f578cfe1..190cc8bf 100644 --- a/kdecoration/breezebutton.cpp +++ b/kdecoration/breezebutton.cpp @@ -43,7 +43,7 @@ namespace Breeze setIconSize(QSize( height, height )); // connections - connect(decoration->client().data(), SIGNAL(iconChanged(QIcon)), this, SLOT(update())); + connect(decoration->client().toStrongRef().data(), SIGNAL(iconChanged(QIcon)), this, SLOT(update())); connect(decoration->settings().data(), &KDecoration2::DecorationSettings::reconfigured, this, &Button::reconfigure); connect( this, &KDecoration2::DecorationButton::hoveredChanged, this, &Button::updateAnimationState ); @@ -67,36 +67,37 @@ namespace Breeze if (auto d = qobject_cast(decoration)) { Button *b = new Button(type, d, parent); + const auto c = d->client().toStrongRef(); switch( type ) { case DecorationButtonType::Close: - b->setVisible( d->client().data()->isCloseable() ); - QObject::connect(d->client().data(), &KDecoration2::DecoratedClient::closeableChanged, b, &Breeze::Button::setVisible ); + b->setVisible( c->isCloseable() ); + QObject::connect(c.data(), &KDecoration2::DecoratedClient::closeableChanged, b, &Breeze::Button::setVisible ); break; case DecorationButtonType::Maximize: - b->setVisible( d->client().data()->isMaximizeable() ); - QObject::connect(d->client().data(), &KDecoration2::DecoratedClient::maximizeableChanged, b, &Breeze::Button::setVisible ); + b->setVisible( c->isMaximizeable() ); + QObject::connect(c.data(), &KDecoration2::DecoratedClient::maximizeableChanged, b, &Breeze::Button::setVisible ); break; case DecorationButtonType::Minimize: - b->setVisible( d->client().data()->isMinimizeable() ); - QObject::connect(d->client().data(), &KDecoration2::DecoratedClient::minimizeableChanged, b, &Breeze::Button::setVisible ); + b->setVisible( c->isMinimizeable() ); + QObject::connect(c.data(), &KDecoration2::DecoratedClient::minimizeableChanged, b, &Breeze::Button::setVisible ); break; case DecorationButtonType::ContextHelp: - b->setVisible( d->client().data()->providesContextHelp() ); - QObject::connect(d->client().data(), &KDecoration2::DecoratedClient::providesContextHelpChanged, b, &Breeze::Button::setVisible ); + b->setVisible( c->providesContextHelp() ); + QObject::connect(c.data(), &KDecoration2::DecoratedClient::providesContextHelpChanged, b, &Breeze::Button::setVisible ); break; case DecorationButtonType::Shade: - b->setVisible( d->client().data()->isShadeable() ); - QObject::connect(d->client().data(), &KDecoration2::DecoratedClient::shadeableChanged, b, &Breeze::Button::setVisible ); + b->setVisible( c->isShadeable() ); + QObject::connect(c.data(), &KDecoration2::DecoratedClient::shadeableChanged, b, &Breeze::Button::setVisible ); break; case DecorationButtonType::Menu: - QObject::connect(d->client().data(), &KDecoration2::DecoratedClient::iconChanged, b, [b]() { b->update(); }); + QObject::connect(c.data(), &KDecoration2::DecoratedClient::iconChanged, b, [b]() { b->update(); }); break; default: break; @@ -130,19 +131,20 @@ namespace Breeze { const QRectF iconRect( geometry().topLeft(), m_iconSize ); + const auto c = decoration()->client().toStrongRef(); if (auto deco = qobject_cast(decoration())) { const QPalette activePalette = KIconLoader::global()->customPalette(); - QPalette palette = decoration()->client().data()->palette(); + QPalette palette = c->palette(); palette.setColor(QPalette::Foreground, deco->fontColor()); KIconLoader::global()->setCustomPalette(palette); - decoration()->client().data()->icon().paint(painter, iconRect.toRect()); + c->icon().paint(painter, iconRect.toRect()); if (activePalette == QPalette()) { KIconLoader::global()->resetPalette(); } else { KIconLoader::global()->setCustomPalette(palette); } } else { - decoration()->client().data()->icon().paint(painter, iconRect.toRect()); + c->icon().paint(painter, iconRect.toRect()); } } else { @@ -404,7 +406,7 @@ namespace Breeze } - auto c = d->client().data(); + auto c = d->client().toStrongRef(); QColor redColor( c->color( ColorGroup::Warning, ColorRole::Foreground ) ); if( isPressed() ) { diff --git a/kdecoration/breezedecoration.cpp b/kdecoration/breezedecoration.cpp index 591c7296..c1a238d9 100644 --- a/kdecoration/breezedecoration.cpp +++ b/kdecoration/breezedecoration.cpp @@ -178,7 +178,7 @@ namespace Breeze QColor Decoration::titleBarColor() const { - auto c = client().data(); + const auto c = client().toStrongRef(); if( hideTitleBar() ) return c->color( ColorGroup::Inactive, ColorRole::TitleBar ); else if( m_animation->state() == QAbstractAnimation::Running ) { @@ -194,7 +194,7 @@ namespace Breeze QColor Decoration::fontColor() const { - auto c = client().data(); + const auto c = client().toStrongRef(); if( m_animation->state() == QAbstractAnimation::Running ) { return KColorUtils::mix( @@ -208,7 +208,7 @@ namespace Breeze //________________________________________________________________ void Decoration::init() { - auto c = client().data(); + const auto c = client().toStrongRef(); // active state change animation // It is important start and end value are of the same type, hence 0.0 and not just 0 @@ -254,11 +254,11 @@ namespace Breeze connect(s.data(), &KDecoration2::DecorationSettings::reconfigured, SettingsProvider::self(), &SettingsProvider::reconfigure, Qt::UniqueConnection ); connect(s.data(), &KDecoration2::DecorationSettings::reconfigured, this, &Decoration::updateButtonsGeometryDelayed); - connect(c, &KDecoration2::DecoratedClient::adjacentScreenEdgesChanged, this, &Decoration::recalculateBorders); - connect(c, &KDecoration2::DecoratedClient::maximizedHorizontallyChanged, this, &Decoration::recalculateBorders); - connect(c, &KDecoration2::DecoratedClient::maximizedVerticallyChanged, this, &Decoration::recalculateBorders); - connect(c, &KDecoration2::DecoratedClient::shadedChanged, this, &Decoration::recalculateBorders); - connect(c, &KDecoration2::DecoratedClient::captionChanged, this, + connect(c.data(), &KDecoration2::DecoratedClient::adjacentScreenEdgesChanged, this, &Decoration::recalculateBorders); + connect(c.data(), &KDecoration2::DecoratedClient::maximizedHorizontallyChanged, this, &Decoration::recalculateBorders); + connect(c.data(), &KDecoration2::DecoratedClient::maximizedVerticallyChanged, this, &Decoration::recalculateBorders); + connect(c.data(), &KDecoration2::DecoratedClient::shadedChanged, this, &Decoration::recalculateBorders); + connect(c.data(), &KDecoration2::DecoratedClient::captionChanged, this, [this]() { // update the caption area @@ -266,15 +266,15 @@ namespace Breeze } ); - connect(c, &KDecoration2::DecoratedClient::activeChanged, this, &Decoration::updateAnimationState); - connect(c, &KDecoration2::DecoratedClient::widthChanged, this, &Decoration::updateTitleBar); - connect(c, &KDecoration2::DecoratedClient::maximizedChanged, this, &Decoration::updateTitleBar); - connect(c, &KDecoration2::DecoratedClient::maximizedChanged, this, &Decoration::setOpaque); + connect(c.data(), &KDecoration2::DecoratedClient::activeChanged, this, &Decoration::updateAnimationState); + connect(c.data(), &KDecoration2::DecoratedClient::widthChanged, this, &Decoration::updateTitleBar); + connect(c.data(), &KDecoration2::DecoratedClient::maximizedChanged, this, &Decoration::updateTitleBar); + connect(c.data(), &KDecoration2::DecoratedClient::maximizedChanged, this, &Decoration::setOpaque); - connect(c, &KDecoration2::DecoratedClient::widthChanged, this, &Decoration::updateButtonsGeometry); - connect(c, &KDecoration2::DecoratedClient::maximizedChanged, this, &Decoration::updateButtonsGeometry); - connect(c, &KDecoration2::DecoratedClient::adjacentScreenEdgesChanged, this, &Decoration::updateButtonsGeometry); - connect(c, &KDecoration2::DecoratedClient::shadedChanged, this, &Decoration::updateButtonsGeometry); + connect(c.data(), &KDecoration2::DecoratedClient::widthChanged, this, &Decoration::updateButtonsGeometry); + connect(c.data(), &KDecoration2::DecoratedClient::maximizedChanged, this, &Decoration::updateButtonsGeometry); + connect(c.data(), &KDecoration2::DecoratedClient::adjacentScreenEdgesChanged, this, &Decoration::updateButtonsGeometry); + connect(c.data(), &KDecoration2::DecoratedClient::shadedChanged, this, &Decoration::updateButtonsGeometry); createButtons(); updateShadow(); @@ -284,7 +284,7 @@ namespace Breeze void Decoration::updateTitleBar() { auto s = settings(); - auto c = client().data(); + const auto c = client().toStrongRef(); const bool maximized = isMaximized(); const int width = maximized ? c->width() : c->width() - 2*s->largeSpacing()*Metrics::TitleBar_SideMargin; const int height = maximized ? borderTop() : borderTop() - s->smallSpacing()*Metrics::TitleBar_TopMargin; @@ -299,7 +299,7 @@ namespace Breeze if( m_shadowAnimation->duration() > 0 ) { - auto c = client().data(); + const auto c = client().toStrongRef(); m_shadowAnimation->setDirection( c->isActive() ? QAbstractAnimation::Forward : QAbstractAnimation::Backward ); if( m_shadowAnimation->state() != QAbstractAnimation::Running ) m_shadowAnimation->start(); @@ -312,7 +312,7 @@ namespace Breeze if( m_animation->duration() > 0 ) { - auto c = client().data(); + const auto c = client().toStrongRef(); m_animation->setDirection( c->isActive() ? QAbstractAnimation::Forward : QAbstractAnimation::Backward ); if( m_animation->state() != QAbstractAnimation::Running ) m_animation->start(); @@ -326,7 +326,7 @@ namespace Breeze //________________________________________________________________ void Decoration::updateSizeGripVisibility() { - auto c = client().data(); + const auto c = client().toStrongRef(); if( m_sizeGrip ) { m_sizeGrip->setVisible( c->isResizeable() && !isMaximized() && !c->isShaded() ); } } @@ -405,7 +405,7 @@ namespace Breeze //________________________________________________________________ void Decoration::recalculateBorders() { - auto c = client().data(); + const auto c = client().toStrongRef(); auto s = settings(); // left, right and bottom borders diff --git a/kdecoration/breezedecoration.h b/kdecoration/breezedecoration.h index 528851e9..9a55b2bf 100644 --- a/kdecoration/breezedecoration.h +++ b/kdecoration/breezedecoration.h @@ -165,28 +165,40 @@ namespace Breeze } bool Decoration::isMaximized() const - { return client().data()->isMaximized() && !m_internalSettings->drawBorderOnMaximizedWindows(); } + { return client().toStrongRef()->isMaximized() && !m_internalSettings->drawBorderOnMaximizedWindows(); } bool Decoration::isMaximizedHorizontally() const - { return client().data()->isMaximizedHorizontally() && !m_internalSettings->drawBorderOnMaximizedWindows(); } + { return client().toStrongRef()->isMaximizedHorizontally() && !m_internalSettings->drawBorderOnMaximizedWindows(); } bool Decoration::isMaximizedVertically() const - { return client().data()->isMaximizedVertically() && !m_internalSettings->drawBorderOnMaximizedWindows(); } + { return client().toStrongRef()->isMaximizedVertically() && !m_internalSettings->drawBorderOnMaximizedWindows(); } bool Decoration::isLeftEdge() const - { return (client().data()->isMaximizedHorizontally() || client().data()->adjacentScreenEdges().testFlag( Qt::LeftEdge ) ) && !m_internalSettings->drawBorderOnMaximizedWindows(); } + { + const auto c = client().toStrongRef(); + return (c->isMaximizedHorizontally() || c->adjacentScreenEdges().testFlag( Qt::LeftEdge ) ) && !m_internalSettings->drawBorderOnMaximizedWindows(); + } bool Decoration::isRightEdge() const - { return (client().data()->isMaximizedHorizontally() || client().data()->adjacentScreenEdges().testFlag( Qt::RightEdge ) ) && !m_internalSettings->drawBorderOnMaximizedWindows(); } + { + const auto c = client().toStrongRef(); + return (c->isMaximizedHorizontally() || c->adjacentScreenEdges().testFlag( Qt::RightEdge ) ) && !m_internalSettings->drawBorderOnMaximizedWindows(); + } bool Decoration::isTopEdge() const - { return (client().data()->isMaximizedVertically() || client().data()->adjacentScreenEdges().testFlag( Qt::TopEdge ) ) && !m_internalSettings->drawBorderOnMaximizedWindows(); } + { + const auto c = client().toStrongRef(); + return (c->isMaximizedVertically() || c->adjacentScreenEdges().testFlag( Qt::TopEdge ) ) && !m_internalSettings->drawBorderOnMaximizedWindows(); + } bool Decoration::isBottomEdge() const - { return (client().data()->isMaximizedVertically() || client().data()->adjacentScreenEdges().testFlag( Qt::BottomEdge ) ) && !m_internalSettings->drawBorderOnMaximizedWindows(); } + { + const auto c = client().toStrongRef(); + return (c->isMaximizedVertically() || c->adjacentScreenEdges().testFlag( Qt::BottomEdge ) ) && !m_internalSettings->drawBorderOnMaximizedWindows(); + } bool Decoration::hideTitleBar() const - { return m_internalSettings->hideTitleBar() && !client().data()->isShaded(); } + { return m_internalSettings->hideTitleBar() && !client().toStrongRef()->isShaded(); } } diff --git a/kdecoration/breezesettingsprovider.cpp b/kdecoration/breezesettingsprovider.cpp index a9d48e02..d900fc1b 100644 --- a/kdecoration/breezesettingsprovider.cpp +++ b/kdecoration/breezesettingsprovider.cpp @@ -61,7 +61,7 @@ namespace Breeze QString className; // get the client - auto client = decoration->client().data(); + const auto client = decoration->client().toStrongRef(); foreach( auto internalSettings, m_exceptions ) { diff --git a/kdecoration/breezesizegrip.cpp b/kdecoration/breezesizegrip.cpp index ea9d395b..d62bfa0c 100644 --- a/kdecoration/breezesizegrip.cpp +++ b/kdecoration/breezesizegrip.cpp @@ -49,10 +49,10 @@ namespace Breeze updatePosition(); // connections - auto c = decoration->client().data(); - connect( c, &KDecoration2::DecoratedClient::widthChanged, this, &SizeGrip::updatePosition ); - connect( c, &KDecoration2::DecoratedClient::heightChanged, this, &SizeGrip::updatePosition ); - connect( c, &KDecoration2::DecoratedClient::activeChanged, this, &SizeGrip::updateActiveState ); + const auto c = decoration->client().toStrongRef(); + connect( c.data(), &KDecoration2::DecoratedClient::widthChanged, this, &SizeGrip::updatePosition ); + connect( c.data(), &KDecoration2::DecoratedClient::heightChanged, this, &SizeGrip::updatePosition ); + connect( c.data(), &KDecoration2::DecoratedClient::activeChanged, this, &SizeGrip::updateActiveState ); // show show(); @@ -86,7 +86,7 @@ namespace Breeze #if BREEZE_HAVE_X11 if( !QX11Info::isPlatformX11() ) return; - auto c = m_decoration.data()->client().data(); + const auto c = m_decoration.data()->client().toStrongRef(); xcb_window_t windowId = c->windowId(); if( windowId ) @@ -178,7 +178,7 @@ namespace Breeze #if BREEZE_HAVE_X11 if( !QX11Info::isPlatformX11() ) return; - auto c = m_decoration.data()->client().data(); + const auto c = m_decoration.data()->client().toStrongRef(); QPoint position( c->width() - GripSize - Offset, c->height() - GripSize - Offset ); @@ -200,7 +200,7 @@ namespace Breeze auto connection( QX11Info::connection() ); // client - auto c = m_decoration.data()->client().data(); + const auto c = m_decoration.data()->client().toStrongRef(); /* get root position matching position