Watch QQmlParserStatus in dialog

This way we only call the expensive syncToMainItemSize once we have all
the information to accurately position the window.

Using the timer to limit the calls doesn't work entirely (according to
qDebug) especially with the multiple threads to compile things.

Seems to prevent the dialog ever jumping around on load.

REVIEW: 115709
This commit is contained in:
David Edmundson 2014-02-12 23:40:15 +01:00
parent 334e818af0
commit 7c135314aa
2 changed files with 24 additions and 2 deletions

View File

@ -54,7 +54,8 @@ DialogProxy::DialogProxy(QQuickItem *parent)
m_location(Plasma::Types::BottomEdge), m_location(Plasma::Types::BottomEdge),
m_type(Normal), m_type(Normal),
m_hideOnWindowDeactivate(false), m_hideOnWindowDeactivate(false),
m_outputOnly(false) m_outputOnly(false),
m_componentComplete(false)
{ {
QSurfaceFormat format; QSurfaceFormat format;
format.setAlphaBufferSize(8); format.setAlphaBufferSize(8);
@ -453,6 +454,10 @@ void DialogProxy::syncToMainItemSize()
void DialogProxy::requestSyncToMainItemSize(bool delayed) void DialogProxy::requestSyncToMainItemSize(bool delayed)
{ {
if (!m_componentComplete) {
return;
}
if (delayed && !m_syncTimer->isActive()) { if (delayed && !m_syncTimer->isActive()) {
m_syncTimer->start(150); m_syncTimer->start(150);
} else { } else {
@ -524,6 +529,17 @@ void DialogProxy::hideEvent(QHideEvent *event)
QQuickWindow::hideEvent(event); QQuickWindow::hideEvent(event);
} }
void DialogProxy::classBegin()
{
}
void DialogProxy::componentComplete()
{
m_componentComplete = true;
syncToMainItemSize();
}
void DialogProxy::syncBorders() void DialogProxy::syncBorders()
{ {
// FIXME: QWindow::screen() never ever changes if the window is moved across // FIXME: QWindow::screen() never ever changes if the window is moved across

View File

@ -24,6 +24,7 @@
#include <QQuickWindow> #include <QQuickWindow>
#include <QWeakPointer> #include <QWeakPointer>
#include <QPoint> #include <QPoint>
#include <QQmlParserStatus>
#include <Plasma/Plasma> #include <Plasma/Plasma>
#include <Plasma/Theme> #include <Plasma/Theme>
@ -44,9 +45,10 @@ namespace Plasma
* *
* Exposed as `PlasmaCore.Dialog` in QML. * Exposed as `PlasmaCore.Dialog` in QML.
*/ */
class DialogProxy : public QQuickWindow class DialogProxy : public QQuickWindow, public QQmlParserStatus
{ {
Q_OBJECT Q_OBJECT
Q_INTERFACES(QQmlParserStatus)
/** /**
* The main QML item that will be displayed in the Dialog * The main QML item that will be displayed in the Dialog
@ -161,6 +163,9 @@ protected:
void hideEvent(QHideEvent *event); void hideEvent(QHideEvent *event);
bool event(QEvent *event); bool event(QEvent *event);
virtual void classBegin();
virtual void componentComplete();
QTimer *m_syncTimer; QTimer *m_syncTimer;
Plasma::Types::Location m_location; Plasma::Types::Location m_location;
Plasma::FrameSvgItem *m_frameSvgItem; Plasma::FrameSvgItem *m_frameSvgItem;
@ -185,6 +190,7 @@ private:
bool m_hideOnWindowDeactivate; bool m_hideOnWindowDeactivate;
bool m_outputOnly; bool m_outputOnly;
Plasma::Theme m_theme; Plasma::Theme m_theme;
bool m_componentComplete;
//Attached Layout property of mainItem, if any //Attached Layout property of mainItem, if any
QWeakPointer <QObject> m_mainItemLayout; QWeakPointer <QObject> m_mainItemLayout;