33// SPDX-License-Identifier: GPL-3.0-or-later
44
55#include " dockpositioner.h"
6- #include " dockpanel.h "
6+ #include < panel.h >
77
8- #include < QQuickWindow>
98#include < QLoggingCategory>
109#include < QQuickItem>
10+ #include < QQuickWindow>
11+ #include < QTimer>
12+
13+ DS_USE_NAMESPACE
1114
1215namespace dock {
1316
14- static DockPanel *isInDockPanel (QObject *object)
17+ static DPanel *isInDockPanel (QObject *object)
1518{
16- auto dockPanel = qobject_cast<DockPanel *>(DockPanel ::qmlAttachedProperties (object));
17- if (!dockPanel) {
19+ auto dockPanel = qobject_cast<DPanel *>(DPanel ::qmlAttachedProperties (object));
20+ if (!dockPanel || dockPanel-> pluginId () != " org.deepin.ds.dock " ) {
1821 qWarning () << " only used in DockPanel." ;
1922 return nullptr ;
2023 }
2124 return dockPanel;
2225}
2326
24- DockPositioner::DockPositioner (DockPanel *panel, QObject *parent)
27+ DockPositioner::DockPositioner (DPanel *panel, QObject *parent)
2528 : QObject(parent)
2629 , m_panel(panel)
2730 , m_positionTimer(new QTimer(this ))
@@ -31,8 +34,8 @@ DockPositioner::DockPositioner(DockPanel *panel, QObject *parent)
3134 connect (m_positionTimer, &QTimer::timeout, this , &DockPositioner::updatePosition);
3235
3336 Q_ASSERT (m_panel);
34- connect (m_panel, &DockPanel:: positionChanged, this , &DockPositioner:: update);
35- connect (m_panel, &DockPanel:: geometryChanged, this , &DockPositioner:: update);
37+ connect (m_panel, SIGNAL ( positionChanged (Position)) , this , SLOT ( update ()) );
38+ connect (m_panel, SIGNAL ( geometryChanged (QRect)) , this , SLOT ( update ()) );
3639 connect (this , &DockPositioner::boundingChanged, this , &DockPositioner::update);
3740}
3841
@@ -72,9 +75,14 @@ int DockPositioner::y() const
7275 return m_y;
7376}
7477
75- QWindow *DockPositioner::window () const
78+ QRect DockPositioner::dockGeometry () const
79+ {
80+ return m_panel ? m_panel->property (" geometry" ).toRect () : QRect ();
81+ }
82+
83+ Position DockPositioner::dockPosition () const
7684{
77- return m_panel-> window () ;
85+ return m_panel ? static_cast <Position>(m_panel-> property ( " position " ). toInt ()) : Position::Top ;
7886}
7987
8088void DockPositioner::setX (int x)
@@ -102,7 +110,7 @@ void DockPositioner::updatePosition()
102110{
103111 int xPosition = 0 ;
104112 int yPosition = 0 ;
105- switch (m_panel-> position ()) {
113+ switch ( dockPosition ()) {
106114 case dock::Top: {
107115 xPosition = m_bounding.x ();
108116 yPosition = m_bounding.y ();
@@ -131,7 +139,7 @@ void DockPositioner::updatePosition()
131139 setY (yPosition);
132140}
133141
134- DockPanelPositioner::DockPanelPositioner (DockPanel *panel, QObject *parent)
142+ DockPanelPositioner::DockPanelPositioner (DPanel *panel, QObject *parent)
135143 : DockPositioner(panel, parent)
136144{
137145 connect (this , &DockPanelPositioner::horizontalOffsetChanged, this , &DockPanelPositioner::update);
@@ -188,12 +196,12 @@ void DockPanelPositioner::resetVertialOffset()
188196
189197void DockPanelPositioner::updatePosition ()
190198{
191- const auto dockWindowRect = window ()-> geometry ();
199+ const auto dockWindowRect = dockGeometry ();
192200 int xPosition = 0 ;
193201 int yPosition = 0 ;
194202 int horizontalOffset = m_horizontalOffset == -1 ? m_bounding.width () / 2 : m_horizontalOffset;
195203 int vertialOffset = m_vertialOffset == -1 ? m_bounding.height () / 2 : m_vertialOffset;
196- switch (m_panel-> position ()) {
204+ switch ( dockPosition ()) {
197205 case dock::Top: {
198206 xPosition = m_bounding.x () - horizontalOffset;
199207 yPosition = dockWindowRect.height () + 10 ;
0 commit comments