Port from deprecated QWeakPointer::data to QWeakPointer::toStrongRef

wilder-5.24
Volker Krause 4 years ago
parent 824d447aa8
commit c4c4d41a3e
  1. 34
      kdecoration/breezebutton.cpp
  2. 42
      kdecoration/breezedecoration.cpp
  3. 28
      kdecoration/breezedecoration.h
  4. 2
      kdecoration/breezesettingsprovider.cpp
  5. 14
      kdecoration/breezesizegrip.cpp

@ -43,7 +43,7 @@ namespace Breeze
setIconSize(QSize( height, height )); setIconSize(QSize( height, height ));
// connections // 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(decoration->settings().data(), &KDecoration2::DecorationSettings::reconfigured, this, &Button::reconfigure);
connect( this, &KDecoration2::DecorationButton::hoveredChanged, this, &Button::updateAnimationState ); connect( this, &KDecoration2::DecorationButton::hoveredChanged, this, &Button::updateAnimationState );
@ -67,36 +67,37 @@ namespace Breeze
if (auto d = qobject_cast<Decoration*>(decoration)) if (auto d = qobject_cast<Decoration*>(decoration))
{ {
Button *b = new Button(type, d, parent); Button *b = new Button(type, d, parent);
const auto c = d->client().toStrongRef();
switch( type ) switch( type )
{ {
case DecorationButtonType::Close: case DecorationButtonType::Close:
b->setVisible( d->client().data()->isCloseable() ); b->setVisible( c->isCloseable() );
QObject::connect(d->client().data(), &KDecoration2::DecoratedClient::closeableChanged, b, &Breeze::Button::setVisible ); QObject::connect(c.data(), &KDecoration2::DecoratedClient::closeableChanged, b, &Breeze::Button::setVisible );
break; break;
case DecorationButtonType::Maximize: case DecorationButtonType::Maximize:
b->setVisible( d->client().data()->isMaximizeable() ); b->setVisible( c->isMaximizeable() );
QObject::connect(d->client().data(), &KDecoration2::DecoratedClient::maximizeableChanged, b, &Breeze::Button::setVisible ); QObject::connect(c.data(), &KDecoration2::DecoratedClient::maximizeableChanged, b, &Breeze::Button::setVisible );
break; break;
case DecorationButtonType::Minimize: case DecorationButtonType::Minimize:
b->setVisible( d->client().data()->isMinimizeable() ); b->setVisible( c->isMinimizeable() );
QObject::connect(d->client().data(), &KDecoration2::DecoratedClient::minimizeableChanged, b, &Breeze::Button::setVisible ); QObject::connect(c.data(), &KDecoration2::DecoratedClient::minimizeableChanged, b, &Breeze::Button::setVisible );
break; break;
case DecorationButtonType::ContextHelp: case DecorationButtonType::ContextHelp:
b->setVisible( d->client().data()->providesContextHelp() ); b->setVisible( c->providesContextHelp() );
QObject::connect(d->client().data(), &KDecoration2::DecoratedClient::providesContextHelpChanged, b, &Breeze::Button::setVisible ); QObject::connect(c.data(), &KDecoration2::DecoratedClient::providesContextHelpChanged, b, &Breeze::Button::setVisible );
break; break;
case DecorationButtonType::Shade: case DecorationButtonType::Shade:
b->setVisible( d->client().data()->isShadeable() ); b->setVisible( c->isShadeable() );
QObject::connect(d->client().data(), &KDecoration2::DecoratedClient::shadeableChanged, b, &Breeze::Button::setVisible ); QObject::connect(c.data(), &KDecoration2::DecoratedClient::shadeableChanged, b, &Breeze::Button::setVisible );
break; break;
case DecorationButtonType::Menu: 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; break;
default: break; default: break;
@ -130,19 +131,20 @@ namespace Breeze
{ {
const QRectF iconRect( geometry().topLeft(), m_iconSize ); const QRectF iconRect( geometry().topLeft(), m_iconSize );
const auto c = decoration()->client().toStrongRef();
if (auto deco = qobject_cast<Decoration*>(decoration())) { if (auto deco = qobject_cast<Decoration*>(decoration())) {
const QPalette activePalette = KIconLoader::global()->customPalette(); const QPalette activePalette = KIconLoader::global()->customPalette();
QPalette palette = decoration()->client().data()->palette(); QPalette palette = c->palette();
palette.setColor(QPalette::Foreground, deco->fontColor()); palette.setColor(QPalette::Foreground, deco->fontColor());
KIconLoader::global()->setCustomPalette(palette); KIconLoader::global()->setCustomPalette(palette);
decoration()->client().data()->icon().paint(painter, iconRect.toRect()); c->icon().paint(painter, iconRect.toRect());
if (activePalette == QPalette()) { if (activePalette == QPalette()) {
KIconLoader::global()->resetPalette(); KIconLoader::global()->resetPalette();
} else { } else {
KIconLoader::global()->setCustomPalette(palette); KIconLoader::global()->setCustomPalette(palette);
} }
} else { } else {
decoration()->client().data()->icon().paint(painter, iconRect.toRect()); c->icon().paint(painter, iconRect.toRect());
} }
} else { } 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 ) ); QColor redColor( c->color( ColorGroup::Warning, ColorRole::Foreground ) );
if( isPressed() ) { if( isPressed() ) {

@ -178,7 +178,7 @@ namespace Breeze
QColor Decoration::titleBarColor() const QColor Decoration::titleBarColor() const
{ {
auto c = client().data(); const auto c = client().toStrongRef();
if( hideTitleBar() ) return c->color( ColorGroup::Inactive, ColorRole::TitleBar ); if( hideTitleBar() ) return c->color( ColorGroup::Inactive, ColorRole::TitleBar );
else if( m_animation->state() == QAbstractAnimation::Running ) else if( m_animation->state() == QAbstractAnimation::Running )
{ {
@ -194,7 +194,7 @@ namespace Breeze
QColor Decoration::fontColor() const QColor Decoration::fontColor() const
{ {
auto c = client().data(); const auto c = client().toStrongRef();
if( m_animation->state() == QAbstractAnimation::Running ) if( m_animation->state() == QAbstractAnimation::Running )
{ {
return KColorUtils::mix( return KColorUtils::mix(
@ -208,7 +208,7 @@ namespace Breeze
//________________________________________________________________ //________________________________________________________________
void Decoration::init() void Decoration::init()
{ {
auto c = client().data(); const auto c = client().toStrongRef();
// active state change animation // active state change animation
// It is important start and end value are of the same type, hence 0.0 and not just 0 // 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, SettingsProvider::self(), &SettingsProvider::reconfigure, Qt::UniqueConnection );
connect(s.data(), &KDecoration2::DecorationSettings::reconfigured, this, &Decoration::updateButtonsGeometryDelayed); connect(s.data(), &KDecoration2::DecorationSettings::reconfigured, this, &Decoration::updateButtonsGeometryDelayed);
connect(c, &KDecoration2::DecoratedClient::adjacentScreenEdgesChanged, this, &Decoration::recalculateBorders); connect(c.data(), &KDecoration2::DecoratedClient::adjacentScreenEdgesChanged, this, &Decoration::recalculateBorders);
connect(c, &KDecoration2::DecoratedClient::maximizedHorizontallyChanged, this, &Decoration::recalculateBorders); connect(c.data(), &KDecoration2::DecoratedClient::maximizedHorizontallyChanged, this, &Decoration::recalculateBorders);
connect(c, &KDecoration2::DecoratedClient::maximizedVerticallyChanged, this, &Decoration::recalculateBorders); connect(c.data(), &KDecoration2::DecoratedClient::maximizedVerticallyChanged, this, &Decoration::recalculateBorders);
connect(c, &KDecoration2::DecoratedClient::shadedChanged, this, &Decoration::recalculateBorders); connect(c.data(), &KDecoration2::DecoratedClient::shadedChanged, this, &Decoration::recalculateBorders);
connect(c, &KDecoration2::DecoratedClient::captionChanged, this, connect(c.data(), &KDecoration2::DecoratedClient::captionChanged, this,
[this]() [this]()
{ {
// update the caption area // update the caption area
@ -266,15 +266,15 @@ namespace Breeze
} }
); );
connect(c, &KDecoration2::DecoratedClient::activeChanged, this, &Decoration::updateAnimationState); connect(c.data(), &KDecoration2::DecoratedClient::activeChanged, this, &Decoration::updateAnimationState);
connect(c, &KDecoration2::DecoratedClient::widthChanged, this, &Decoration::updateTitleBar); connect(c.data(), &KDecoration2::DecoratedClient::widthChanged, this, &Decoration::updateTitleBar);
connect(c, &KDecoration2::DecoratedClient::maximizedChanged, this, &Decoration::updateTitleBar); connect(c.data(), &KDecoration2::DecoratedClient::maximizedChanged, this, &Decoration::updateTitleBar);
connect(c, &KDecoration2::DecoratedClient::maximizedChanged, this, &Decoration::setOpaque); connect(c.data(), &KDecoration2::DecoratedClient::maximizedChanged, this, &Decoration::setOpaque);
connect(c, &KDecoration2::DecoratedClient::widthChanged, this, &Decoration::updateButtonsGeometry); connect(c.data(), &KDecoration2::DecoratedClient::widthChanged, this, &Decoration::updateButtonsGeometry);
connect(c, &KDecoration2::DecoratedClient::maximizedChanged, this, &Decoration::updateButtonsGeometry); connect(c.data(), &KDecoration2::DecoratedClient::maximizedChanged, this, &Decoration::updateButtonsGeometry);
connect(c, &KDecoration2::DecoratedClient::adjacentScreenEdgesChanged, this, &Decoration::updateButtonsGeometry); connect(c.data(), &KDecoration2::DecoratedClient::adjacentScreenEdgesChanged, this, &Decoration::updateButtonsGeometry);
connect(c, &KDecoration2::DecoratedClient::shadedChanged, this, &Decoration::updateButtonsGeometry); connect(c.data(), &KDecoration2::DecoratedClient::shadedChanged, this, &Decoration::updateButtonsGeometry);
createButtons(); createButtons();
updateShadow(); updateShadow();
@ -284,7 +284,7 @@ namespace Breeze
void Decoration::updateTitleBar() void Decoration::updateTitleBar()
{ {
auto s = settings(); auto s = settings();
auto c = client().data(); const auto c = client().toStrongRef();
const bool maximized = isMaximized(); const bool maximized = isMaximized();
const int width = maximized ? c->width() : c->width() - 2*s->largeSpacing()*Metrics::TitleBar_SideMargin; 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; const int height = maximized ? borderTop() : borderTop() - s->smallSpacing()*Metrics::TitleBar_TopMargin;
@ -299,7 +299,7 @@ namespace Breeze
if( m_shadowAnimation->duration() > 0 ) if( m_shadowAnimation->duration() > 0 )
{ {
auto c = client().data(); const auto c = client().toStrongRef();
m_shadowAnimation->setDirection( c->isActive() ? QAbstractAnimation::Forward : QAbstractAnimation::Backward ); m_shadowAnimation->setDirection( c->isActive() ? QAbstractAnimation::Forward : QAbstractAnimation::Backward );
if( m_shadowAnimation->state() != QAbstractAnimation::Running ) m_shadowAnimation->start(); if( m_shadowAnimation->state() != QAbstractAnimation::Running ) m_shadowAnimation->start();
@ -312,7 +312,7 @@ namespace Breeze
if( m_animation->duration() > 0 ) if( m_animation->duration() > 0 )
{ {
auto c = client().data(); const auto c = client().toStrongRef();
m_animation->setDirection( c->isActive() ? QAbstractAnimation::Forward : QAbstractAnimation::Backward ); m_animation->setDirection( c->isActive() ? QAbstractAnimation::Forward : QAbstractAnimation::Backward );
if( m_animation->state() != QAbstractAnimation::Running ) m_animation->start(); if( m_animation->state() != QAbstractAnimation::Running ) m_animation->start();
@ -326,7 +326,7 @@ namespace Breeze
//________________________________________________________________ //________________________________________________________________
void Decoration::updateSizeGripVisibility() void Decoration::updateSizeGripVisibility()
{ {
auto c = client().data(); const auto c = client().toStrongRef();
if( m_sizeGrip ) if( m_sizeGrip )
{ m_sizeGrip->setVisible( c->isResizeable() && !isMaximized() && !c->isShaded() ); } { m_sizeGrip->setVisible( c->isResizeable() && !isMaximized() && !c->isShaded() ); }
} }
@ -405,7 +405,7 @@ namespace Breeze
//________________________________________________________________ //________________________________________________________________
void Decoration::recalculateBorders() void Decoration::recalculateBorders()
{ {
auto c = client().data(); const auto c = client().toStrongRef();
auto s = settings(); auto s = settings();
// left, right and bottom borders // left, right and bottom borders

@ -165,28 +165,40 @@ namespace Breeze
} }
bool Decoration::isMaximized() const bool Decoration::isMaximized() const
{ return client().data()->isMaximized() && !m_internalSettings->drawBorderOnMaximizedWindows(); } { return client().toStrongRef()->isMaximized() && !m_internalSettings->drawBorderOnMaximizedWindows(); }
bool Decoration::isMaximizedHorizontally() const bool Decoration::isMaximizedHorizontally() const
{ return client().data()->isMaximizedHorizontally() && !m_internalSettings->drawBorderOnMaximizedWindows(); } { return client().toStrongRef()->isMaximizedHorizontally() && !m_internalSettings->drawBorderOnMaximizedWindows(); }
bool Decoration::isMaximizedVertically() const bool Decoration::isMaximizedVertically() const
{ return client().data()->isMaximizedVertically() && !m_internalSettings->drawBorderOnMaximizedWindows(); } { return client().toStrongRef()->isMaximizedVertically() && !m_internalSettings->drawBorderOnMaximizedWindows(); }
bool Decoration::isLeftEdge() const 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 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 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 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 bool Decoration::hideTitleBar() const
{ return m_internalSettings->hideTitleBar() && !client().data()->isShaded(); } { return m_internalSettings->hideTitleBar() && !client().toStrongRef()->isShaded(); }
} }

@ -61,7 +61,7 @@ namespace Breeze
QString className; QString className;
// get the client // get the client
auto client = decoration->client().data(); const auto client = decoration->client().toStrongRef();
foreach( auto internalSettings, m_exceptions ) foreach( auto internalSettings, m_exceptions )
{ {

@ -49,10 +49,10 @@ namespace Breeze
updatePosition(); updatePosition();
// connections // connections
auto c = decoration->client().data(); const auto c = decoration->client().toStrongRef();
connect( c, &KDecoration2::DecoratedClient::widthChanged, this, &SizeGrip::updatePosition ); connect( c.data(), &KDecoration2::DecoratedClient::widthChanged, this, &SizeGrip::updatePosition );
connect( c, &KDecoration2::DecoratedClient::heightChanged, this, &SizeGrip::updatePosition ); connect( c.data(), &KDecoration2::DecoratedClient::heightChanged, this, &SizeGrip::updatePosition );
connect( c, &KDecoration2::DecoratedClient::activeChanged, this, &SizeGrip::updateActiveState ); connect( c.data(), &KDecoration2::DecoratedClient::activeChanged, this, &SizeGrip::updateActiveState );
// show // show
show(); show();
@ -86,7 +86,7 @@ namespace Breeze
#if BREEZE_HAVE_X11 #if BREEZE_HAVE_X11
if( !QX11Info::isPlatformX11() ) return; 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(); xcb_window_t windowId = c->windowId();
if( windowId ) if( windowId )
@ -178,7 +178,7 @@ namespace Breeze
#if BREEZE_HAVE_X11 #if BREEZE_HAVE_X11
if( !QX11Info::isPlatformX11() ) return; if( !QX11Info::isPlatformX11() ) return;
auto c = m_decoration.data()->client().data(); const auto c = m_decoration.data()->client().toStrongRef();
QPoint position( QPoint position(
c->width() - GripSize - Offset, c->width() - GripSize - Offset,
c->height() - GripSize - Offset ); c->height() - GripSize - Offset );
@ -200,7 +200,7 @@ namespace Breeze
auto connection( QX11Info::connection() ); auto connection( QX11Info::connection() );
// client // client
auto c = m_decoration.data()->client().data(); const auto c = m_decoration.data()->client().toStrongRef();
/* /*
get root position matching position get root position matching position

Loading…
Cancel
Save