Dialog: Replace QWeakPointer with QPointer
This simplifies the code as we do not have to call .data() everywhere
This commit is contained in:
parent
7fd87741de
commit
67810adbf1
@ -30,6 +30,7 @@
|
|||||||
#include <QLayout>
|
#include <QLayout>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
#include <QPointer>
|
||||||
|
|
||||||
#include <kwindowsystem.h>
|
#include <kwindowsystem.h>
|
||||||
#include <KWindowSystem/KWindowInfo>
|
#include <KWindowSystem/KWindowInfo>
|
||||||
@ -101,8 +102,8 @@ public:
|
|||||||
QTimer *syncTimer;
|
QTimer *syncTimer;
|
||||||
Plasma::Types::Location location;
|
Plasma::Types::Location location;
|
||||||
Plasma::FrameSvgItem *frameSvgItem;
|
Plasma::FrameSvgItem *frameSvgItem;
|
||||||
QWeakPointer<QQuickItem> mainItem;
|
QPointer<QQuickItem> mainItem;
|
||||||
QWeakPointer<QQuickItem> visualParent;
|
QPointer<QQuickItem> visualParent;
|
||||||
|
|
||||||
QRect cachedGeometry;
|
QRect cachedGeometry;
|
||||||
Dialog::WindowType type;
|
Dialog::WindowType type;
|
||||||
@ -114,7 +115,7 @@ public:
|
|||||||
Dialog::BackgroundHints backgroundHints;
|
Dialog::BackgroundHints backgroundHints;
|
||||||
|
|
||||||
//Attached Layout property of mainItem, if any
|
//Attached Layout property of mainItem, if any
|
||||||
QWeakPointer <QObject> mainItemLayout;
|
QPointer <QObject> mainItemLayout;
|
||||||
};
|
};
|
||||||
|
|
||||||
void DialogPrivate::syncBorders()
|
void DialogPrivate::syncBorders()
|
||||||
@ -196,8 +197,8 @@ void DialogPrivate::updateTheme()
|
|||||||
void DialogPrivate::updateVisibility(bool visible)
|
void DialogPrivate::updateVisibility(bool visible)
|
||||||
{
|
{
|
||||||
if (visible) {
|
if (visible) {
|
||||||
if (visualParent && visualParent.data()->window()) {
|
if (visualParent && visualParent->window()) {
|
||||||
q->setTransientParent(visualParent.data()->window());
|
q->setTransientParent(visualParent->window());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (q->location() == Plasma::Types::FullScreen) {
|
if (q->location() == Plasma::Types::FullScreen) {
|
||||||
@ -264,12 +265,12 @@ void DialogPrivate::updateMinimumWidth()
|
|||||||
Q_ASSERT(mainItem);
|
Q_ASSERT(mainItem);
|
||||||
Q_ASSERT(mainItemLayout);
|
Q_ASSERT(mainItemLayout);
|
||||||
|
|
||||||
mainItem.data()->disconnect(q);
|
mainItem->disconnect(q);
|
||||||
|
|
||||||
syncBorders();
|
syncBorders();
|
||||||
updateTheme();
|
updateTheme();
|
||||||
|
|
||||||
int minimumWidth = mainItemLayout.data()->property("minimumWidth").toInt();
|
int minimumWidth = mainItemLayout->property("minimumWidth").toInt();
|
||||||
auto margin = frameSvgItem->margins();
|
auto margin = frameSvgItem->margins();
|
||||||
|
|
||||||
int oldWidth = q->width();
|
int oldWidth = q->width();
|
||||||
@ -277,7 +278,7 @@ void DialogPrivate::updateMinimumWidth()
|
|||||||
q->setMinimumWidth(minimumWidth + margin->left() + margin->right());
|
q->setMinimumWidth(minimumWidth + margin->left() + margin->right());
|
||||||
q->setWidth(qMax(q->width(), q->minimumWidth()));
|
q->setWidth(qMax(q->width(), q->minimumWidth()));
|
||||||
|
|
||||||
mainItem.data()->setWidth(q->width() - margin->left() - margin->right());
|
mainItem->setWidth(q->width() - margin->left() - margin->right());
|
||||||
frameSvgItem->setWidth(q->width());
|
frameSvgItem->setWidth(q->width());
|
||||||
|
|
||||||
if (location == Plasma::Types::RightEdge) {
|
if (location == Plasma::Types::RightEdge) {
|
||||||
@ -285,8 +286,8 @@ void DialogPrivate::updateMinimumWidth()
|
|||||||
}
|
}
|
||||||
repositionIfOffScreen();
|
repositionIfOffScreen();
|
||||||
|
|
||||||
QObject::connect(mainItem.data(), SIGNAL(widthChanged()), q, SLOT(slotMainItemSizeChanged()));
|
QObject::connect(mainItem, SIGNAL(widthChanged()), q, SLOT(slotMainItemSizeChanged()));
|
||||||
QObject::connect(mainItem.data(), SIGNAL(heightChanged()), q, SLOT(slotMainItemSizeChanged()));
|
QObject::connect(mainItem, SIGNAL(heightChanged()), q, SLOT(slotMainItemSizeChanged()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogPrivate::updateMinimumHeight()
|
void DialogPrivate::updateMinimumHeight()
|
||||||
@ -294,20 +295,20 @@ void DialogPrivate::updateMinimumHeight()
|
|||||||
Q_ASSERT(mainItem);
|
Q_ASSERT(mainItem);
|
||||||
Q_ASSERT(mainItemLayout);
|
Q_ASSERT(mainItemLayout);
|
||||||
|
|
||||||
mainItem.data()->disconnect(q);
|
mainItem->disconnect(q);
|
||||||
|
|
||||||
syncBorders();
|
syncBorders();
|
||||||
updateTheme();
|
updateTheme();
|
||||||
|
|
||||||
int minimumHeight = mainItemLayout.data()->property("minimumHeight").toInt();
|
int minimumHeight = mainItemLayout->property("minimumHeight").toInt();
|
||||||
auto margin = frameSvgItem->margins();
|
auto margin = frameSvgItem->margins();
|
||||||
|
|
||||||
int oldHeight = mainItem.data()->height();
|
int oldHeight = mainItem->height();
|
||||||
|
|
||||||
q->setMinimumHeight(minimumHeight + margin->left() + margin->right());
|
q->setMinimumHeight(minimumHeight + margin->left() + margin->right());
|
||||||
q->setHeight(qMax(q->height(), q->minimumHeight()));
|
q->setHeight(qMax(q->height(), q->minimumHeight()));
|
||||||
|
|
||||||
mainItem.data()->setHeight(q->height() - margin->top() - margin->bottom());
|
mainItem->setHeight(q->height() - margin->top() - margin->bottom());
|
||||||
frameSvgItem->setHeight(q->height());
|
frameSvgItem->setHeight(q->height());
|
||||||
|
|
||||||
if (location == Plasma::Types::BottomEdge) {
|
if (location == Plasma::Types::BottomEdge) {
|
||||||
@ -315,8 +316,8 @@ void DialogPrivate::updateMinimumHeight()
|
|||||||
}
|
}
|
||||||
repositionIfOffScreen();
|
repositionIfOffScreen();
|
||||||
|
|
||||||
QObject::connect(mainItem.data(), SIGNAL(widthChanged()), q, SLOT(slotMainItemSizeChanged()));
|
QObject::connect(mainItem, SIGNAL(widthChanged()), q, SLOT(slotMainItemSizeChanged()));
|
||||||
QObject::connect(mainItem.data(), SIGNAL(heightChanged()), q, SLOT(slotMainItemSizeChanged()));
|
QObject::connect(mainItem, SIGNAL(heightChanged()), q, SLOT(slotMainItemSizeChanged()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogPrivate::updateMaximumWidth()
|
void DialogPrivate::updateMaximumWidth()
|
||||||
@ -324,25 +325,25 @@ void DialogPrivate::updateMaximumWidth()
|
|||||||
Q_ASSERT(mainItem);
|
Q_ASSERT(mainItem);
|
||||||
Q_ASSERT(mainItemLayout);
|
Q_ASSERT(mainItemLayout);
|
||||||
|
|
||||||
mainItem.data()->disconnect(q);
|
mainItem->disconnect(q);
|
||||||
|
|
||||||
syncBorders();
|
syncBorders();
|
||||||
updateTheme();
|
updateTheme();
|
||||||
|
|
||||||
int maximumWidth = mainItemLayout.data()->property("maximumWidth").toInt();
|
int maximumWidth = mainItemLayout->property("maximumWidth").toInt();
|
||||||
maximumWidth = maximumWidth ? maximumWidth : DIALOGSIZE_MAX;
|
maximumWidth = maximumWidth ? maximumWidth : DIALOGSIZE_MAX;
|
||||||
auto margin = frameSvgItem->margins();
|
auto margin = frameSvgItem->margins();
|
||||||
|
|
||||||
q->setMaximumWidth(maximumWidth + margin->left() + margin->right());
|
q->setMaximumWidth(maximumWidth + margin->left() + margin->right());
|
||||||
q->setWidth(qBound(q->minimumWidth(), q->width(), q->maximumWidth()));
|
q->setWidth(qBound(q->minimumWidth(), q->width(), q->maximumWidth()));
|
||||||
|
|
||||||
mainItem.data()->setWidth(q->width() - margin->left() - margin->right());
|
mainItem->setWidth(q->width() - margin->left() - margin->right());
|
||||||
frameSvgItem->setWidth(q->width());
|
frameSvgItem->setWidth(q->width());
|
||||||
|
|
||||||
repositionIfOffScreen();
|
repositionIfOffScreen();
|
||||||
|
|
||||||
QObject::connect(mainItem.data(), SIGNAL(widthChanged()), q, SLOT(slotMainItemSizeChanged()));
|
QObject::connect(mainItem, SIGNAL(widthChanged()), q, SLOT(slotMainItemSizeChanged()));
|
||||||
QObject::connect(mainItem.data(), SIGNAL(heightChanged()), q, SLOT(slotMainItemSizeChanged()));
|
QObject::connect(mainItem, SIGNAL(heightChanged()), q, SLOT(slotMainItemSizeChanged()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogPrivate::updateMaximumHeight()
|
void DialogPrivate::updateMaximumHeight()
|
||||||
@ -350,25 +351,25 @@ void DialogPrivate::updateMaximumHeight()
|
|||||||
Q_ASSERT(mainItem);
|
Q_ASSERT(mainItem);
|
||||||
Q_ASSERT(mainItemLayout);
|
Q_ASSERT(mainItemLayout);
|
||||||
|
|
||||||
mainItem.data()->disconnect(q);
|
mainItem->disconnect(q);
|
||||||
|
|
||||||
syncBorders();
|
syncBorders();
|
||||||
updateTheme();
|
updateTheme();
|
||||||
|
|
||||||
int maximumHeight = mainItemLayout.data()->property("maximumHeight").toInt();
|
int maximumHeight = mainItemLayout->property("maximumHeight").toInt();
|
||||||
maximumHeight = maximumHeight ? maximumHeight : DIALOGSIZE_MAX;
|
maximumHeight = maximumHeight ? maximumHeight : DIALOGSIZE_MAX;
|
||||||
auto margin = frameSvgItem->margins();
|
auto margin = frameSvgItem->margins();
|
||||||
|
|
||||||
q->setMaximumHeight(maximumHeight + margin->left() + margin->right());
|
q->setMaximumHeight(maximumHeight + margin->left() + margin->right());
|
||||||
q->setHeight(qBound(q->minimumHeight(), q->height(), q->maximumHeight()));
|
q->setHeight(qBound(q->minimumHeight(), q->height(), q->maximumHeight()));
|
||||||
|
|
||||||
mainItem.data()->setHeight(q->height() - margin->top() - margin->bottom());
|
mainItem->setHeight(q->height() - margin->top() - margin->bottom());
|
||||||
frameSvgItem->setHeight(q->height());
|
frameSvgItem->setHeight(q->height());
|
||||||
|
|
||||||
repositionIfOffScreen();
|
repositionIfOffScreen();
|
||||||
|
|
||||||
QObject::connect(mainItem.data(), SIGNAL(widthChanged()), q, SLOT(slotMainItemSizeChanged()));
|
QObject::connect(mainItem, SIGNAL(widthChanged()), q, SLOT(slotMainItemSizeChanged()));
|
||||||
QObject::connect(mainItem.data(), SIGNAL(heightChanged()), q, SLOT(slotMainItemSizeChanged()));
|
QObject::connect(mainItem, SIGNAL(heightChanged()), q, SLOT(slotMainItemSizeChanged()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogPrivate::repositionIfOffScreen()
|
void DialogPrivate::repositionIfOffScreen()
|
||||||
@ -445,10 +446,10 @@ void DialogPrivate::syncMainItemToSize()
|
|||||||
updateTheme();
|
updateTheme();
|
||||||
|
|
||||||
if (mainItem) {
|
if (mainItem) {
|
||||||
mainItem.data()->setX(frameSvgItem->margins()->left());
|
mainItem->setX(frameSvgItem->margins()->left());
|
||||||
mainItem.data()->setY(frameSvgItem->margins()->top());
|
mainItem->setY(frameSvgItem->margins()->top());
|
||||||
mainItem.data()->setWidth(q->width() - frameSvgItem->margins()->left() - frameSvgItem->margins()->right());
|
mainItem->setWidth(q->width() - frameSvgItem->margins()->left() - frameSvgItem->margins()->right());
|
||||||
mainItem.data()->setHeight(q->height() - frameSvgItem->margins()->top() - frameSvgItem->margins()->bottom());
|
mainItem->setHeight(q->height() - frameSvgItem->margins()->top() - frameSvgItem->margins()->bottom());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (q->visualParent()) {
|
if (q->visualParent()) {
|
||||||
@ -467,7 +468,7 @@ void DialogPrivate::syncToMainItemSize()
|
|||||||
|
|
||||||
syncBorders();
|
syncBorders();
|
||||||
|
|
||||||
const QSize s = QSize(mainItem.data()->width(), mainItem.data()->height()) +
|
const QSize s = QSize(mainItem->width(), mainItem->height()) +
|
||||||
QSize(frameSvgItem->margins()->left() + frameSvgItem->margins()->right(),
|
QSize(frameSvgItem->margins()->left() + frameSvgItem->margins()->right(),
|
||||||
frameSvgItem->margins()->top() + frameSvgItem->margins()->bottom());
|
frameSvgItem->margins()->top() + frameSvgItem->margins()->bottom());
|
||||||
|
|
||||||
@ -487,8 +488,8 @@ void DialogPrivate::syncToMainItemSize()
|
|||||||
q->resize(s);
|
q->resize(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
mainItem.data()->setX(frameSvgItem->margins()->left());
|
mainItem->setX(frameSvgItem->margins()->left());
|
||||||
mainItem.data()->setY(frameSvgItem->margins()->top());
|
mainItem->setY(frameSvgItem->margins()->top());
|
||||||
|
|
||||||
updateTheme();
|
updateTheme();
|
||||||
}
|
}
|
||||||
@ -569,14 +570,14 @@ Dialog::~Dialog()
|
|||||||
|
|
||||||
QQuickItem *Dialog::mainItem() const
|
QQuickItem *Dialog::mainItem() const
|
||||||
{
|
{
|
||||||
return d->mainItem.data();
|
return d->mainItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dialog::setMainItem(QQuickItem *mainItem)
|
void Dialog::setMainItem(QQuickItem *mainItem)
|
||||||
{
|
{
|
||||||
if (d->mainItem.data() != mainItem) {
|
if (d->mainItem != mainItem) {
|
||||||
if (d->mainItem) {
|
if (d->mainItem) {
|
||||||
d->mainItem.data()->setParent(parent());
|
d->mainItem->setParent(parent());
|
||||||
}
|
}
|
||||||
|
|
||||||
d->mainItem = mainItem;
|
d->mainItem = mainItem;
|
||||||
@ -607,7 +608,7 @@ void Dialog::setMainItem(QQuickItem *mainItem)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (d->mainItemLayout) {
|
if (d->mainItemLayout) {
|
||||||
disconnect(d->mainItemLayout.data(), 0, this, 0);
|
disconnect(d->mainItemLayout, 0, this, 0);
|
||||||
}
|
}
|
||||||
d->mainItemLayout = layout;
|
d->mainItemLayout = layout;
|
||||||
|
|
||||||
@ -638,12 +639,12 @@ void DialogPrivate::slotMainItemSizeChanged()
|
|||||||
|
|
||||||
QQuickItem *Dialog::visualParent() const
|
QQuickItem *Dialog::visualParent() const
|
||||||
{
|
{
|
||||||
return d->visualParent.data();
|
return d->visualParent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dialog::setVisualParent(QQuickItem *visualParent)
|
void Dialog::setVisualParent(QQuickItem *visualParent)
|
||||||
{
|
{
|
||||||
if (d->visualParent.data() == visualParent) {
|
if (d->visualParent == visualParent) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
|
|
||||||
#include <QQuickItem>
|
#include <QQuickItem>
|
||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
#include <QWeakPointer>
|
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
#include <QQmlParserStatus>
|
#include <QQmlParserStatus>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user