Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion panels/dock/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ target_link_libraries(dock-plugin PUBLIC
PRIVATE
PkgConfig::WaylandClient
Qt${QT_VERSION_MAJOR}::WaylandCompositorPrivate
dockpanel
)

target_include_directories(dock-plugin
Expand Down
36 changes: 22 additions & 14 deletions panels/dock/dockpositioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,28 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include "dockpositioner.h"
#include "dockpanel.h"
#include <panel.h>

#include <QQuickWindow>
#include <QLoggingCategory>
#include <QQuickItem>
#include <QQuickWindow>
#include <QTimer>

DS_USE_NAMESPACE

namespace dock {

static DockPanel *isInDockPanel(QObject *object)
static DPanel *isInDockPanel(QObject *object)
{
auto dockPanel = qobject_cast<DockPanel*>(DockPanel::qmlAttachedProperties(object));
if (!dockPanel) {
auto dockPanel = qobject_cast<DPanel *>(DPanel::qmlAttachedProperties(object));
if (!dockPanel || dockPanel->pluginId() != "org.deepin.ds.dock") {
qWarning() << "only used in DockPanel.";
return nullptr;
}
return dockPanel;
}

DockPositioner::DockPositioner(DockPanel *panel, QObject *parent)
DockPositioner::DockPositioner(DPanel *panel, QObject *parent)
: QObject(parent)
, m_panel(panel)
, m_positionTimer(new QTimer(this))
Expand All @@ -31,8 +34,8 @@ DockPositioner::DockPositioner(DockPanel *panel, QObject *parent)
connect(m_positionTimer, &QTimer::timeout, this, &DockPositioner::updatePosition);

Q_ASSERT(m_panel);
connect(m_panel, &DockPanel::positionChanged, this, &DockPositioner::update);
connect(m_panel, &DockPanel::geometryChanged, this, &DockPositioner::update);
connect(m_panel, SIGNAL(positionChanged(Position)), this, SLOT(update()));
connect(m_panel, SIGNAL(geometryChanged(QRect)), this, SLOT(update()));
connect(this, &DockPositioner::boundingChanged, this, &DockPositioner::update);
}

Expand Down Expand Up @@ -72,9 +75,14 @@ int DockPositioner::y() const
return m_y;
}

QWindow *DockPositioner::window() const
QRect DockPositioner::dockGeometry() const
{
return m_panel ? m_panel->property("geometry").toRect() : QRect();
}

Position DockPositioner::dockPosition() const
{
return m_panel->window();
return m_panel ? static_cast<Position>(m_panel->property("position").toInt()) : Position::Top;
}

void DockPositioner::setX(int x)
Expand Down Expand Up @@ -102,7 +110,7 @@ void DockPositioner::updatePosition()
{
int xPosition = 0;
int yPosition = 0;
switch(m_panel->position()) {
switch (dockPosition()) {
case dock::Top: {
xPosition = m_bounding.x();
yPosition = m_bounding.y();
Expand Down Expand Up @@ -131,7 +139,7 @@ void DockPositioner::updatePosition()
setY(yPosition);
}

DockPanelPositioner::DockPanelPositioner(DockPanel *panel, QObject *parent)
DockPanelPositioner::DockPanelPositioner(DPanel *panel, QObject *parent)
: DockPositioner(panel, parent)
{
connect(this, &DockPanelPositioner::horizontalOffsetChanged, this, &DockPanelPositioner::update);
Expand Down Expand Up @@ -188,12 +196,12 @@ void DockPanelPositioner::resetVertialOffset()

void DockPanelPositioner::updatePosition()
{
const auto dockWindowRect = window()->geometry();
const auto dockWindowRect = dockGeometry();
int xPosition = 0;
int yPosition = 0;
int horizontalOffset = m_horizontalOffset == -1 ? m_bounding.width() / 2 : m_horizontalOffset;
int vertialOffset = m_vertialOffset == -1 ? m_bounding.height() / 2 : m_vertialOffset;
switch(m_panel->position()) {
switch (dockPosition()) {
case dock::Top: {
xPosition = m_bounding.x() - horizontalOffset;
yPosition = dockWindowRect.height() + 10;
Expand Down
17 changes: 12 additions & 5 deletions panels/dock/dockpositioner.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@

#pragma once

#include "constants.h"
#include <dsglobal.h>

#include <QObject>
#include <QtQml/qqml.h>
#include <QWindow>

DS_BEGIN_NAMESPACE
class DPanel;
DS_END_NAMESPACE

namespace dock {

class DockPanel;
class DockPositioner : public QObject
{
Q_OBJECT
Expand All @@ -21,7 +27,7 @@ class DockPositioner : public QObject
QML_UNCREATABLE("DockPositioner is only available via attached properties.")
QML_ATTACHED(DockPositioner)
public:
explicit DockPositioner(DockPanel *panel, QObject *parent = nullptr);
explicit DockPositioner(DS_NAMESPACE::DPanel *panel, QObject *parent = nullptr);
virtual ~DockPositioner() override;

static DockPositioner *qmlAttachedProperties(QObject *object);
Expand All @@ -30,7 +36,8 @@ class DockPositioner : public QObject
void setBounding(const QRect &newBounding);
int x() const;
int y() const;
QWindow *window() const;
QRect dockGeometry() const;
Position dockPosition() const;

void setX(int x);
void setY(int y);
Expand All @@ -44,7 +51,7 @@ public slots:
void yChanged();

protected:
DockPanel *m_panel = nullptr;
QPointer<DS_NAMESPACE::DPanel> m_panel;
QRect m_bounding {};
int m_x = 0;
int m_y = 0;
Expand All @@ -60,7 +67,7 @@ class DockPanelPositioner : public DockPositioner
QML_UNCREATABLE("DockPanelPositioner is only available via attached properties.")
QML_ATTACHED(DockPanelPositioner)
public:
explicit DockPanelPositioner(DockPanel *panel, QObject *parent = nullptr);
explicit DockPanelPositioner(DS_NAMESPACE::DPanel *panel, QObject *parent = nullptr);
virtual ~DockPanelPositioner() override;

static DockPanelPositioner *qmlAttachedProperties(QObject *object);
Expand Down
Loading