refactor:move dock freeEdges to Layout

pull/3/head
Michail Vourlakos 6 years ago
parent 8fadd31020
commit ab2dc47fd9

@ -979,23 +979,6 @@ bool DockView::event(QEvent *e)
return ContainmentView::event(e);; return ContainmentView::event(e);;
} }
QList<int> DockView::freeEdges() const
{
if (!m_managedLayout) {
const QList<int> emptyEdges;
return emptyEdges;
}
const auto edges = m_managedLayout->freeEdges(screen());
QList<int> edgesInt;
foreach (Plasma::Types::Location edge, edges) {
edgesInt.append(static_cast<int>(edge));
}
return edgesInt;
}
void DockView::deactivateApplets() void DockView::deactivateApplets()
{ {
if (!containment()) { if (!containment()) {

@ -174,7 +174,6 @@ public slots:
Q_INVOKABLE void removeDock(); Q_INVOKABLE void removeDock();
Q_INVOKABLE void copyDock(); Q_INVOKABLE void copyDock();
Q_INVOKABLE QList<int> freeEdges() const;
Q_INVOKABLE QVariantList containmentActions(); Q_INVOKABLE QVariantList containmentActions();
Q_INVOKABLE void deactivateApplets(); Q_INVOKABLE void deactivateApplets();

@ -89,6 +89,7 @@ void Positioner::init()
connect(m_view, &QQuickWindow::yChanged, this, &Positioner::validateDockGeometry); connect(m_view, &QQuickWindow::yChanged, this, &Positioner::validateDockGeometry);
connect(m_view, &QQuickWindow::widthChanged, this, &Positioner::validateDockGeometry); connect(m_view, &QQuickWindow::widthChanged, this, &Positioner::validateDockGeometry);
connect(m_view, &QQuickWindow::heightChanged, this, &Positioner::validateDockGeometry); connect(m_view, &QQuickWindow::heightChanged, this, &Positioner::validateDockGeometry);
connect(m_view, &QQuickWindow::screenChanged, this, &Positioner::currentScreenChanged);
connect(m_view, &QQuickWindow::screenChanged, this, &Positioner::screenChanged); connect(m_view, &QQuickWindow::screenChanged, this, &Positioner::screenChanged);
connect(m_view, &Latte::DockView::absGeometryChanged, this, &Positioner::syncGeometry); connect(m_view, &Latte::DockView::absGeometryChanged, this, &Positioner::syncGeometry);
@ -126,6 +127,17 @@ void Positioner::init()
initSignalingForLocationChangeSliding(); initSignalingForLocationChangeSliding();
} }
int Positioner::currentScreenId() const
{
auto *dockCorona = qobject_cast<DockCorona *>(m_view->corona());
if (dockCorona) {
return dockCorona->screenPool()->id(m_screenToFollowId);
}
return -1;
}
QString Positioner::currentScreenName() const QString Positioner::currentScreenName() const
{ {
return m_screenToFollowId; return m_screenToFollowId;

@ -42,18 +42,20 @@ class Positioner: public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(int currentScreenId READ currentScreenId NOTIFY currentScreenChanged)
Q_PROPERTY(QString currentScreenName READ currentScreenName NOTIFY currentScreenChanged) Q_PROPERTY(QString currentScreenName READ currentScreenName NOTIFY currentScreenChanged)
public: public:
Positioner(DockView *parent); Positioner(DockView *parent);
virtual ~Positioner(); virtual ~Positioner();
void reconsiderScreen(); int currentScreenId() const;
QString currentScreenName() const;
bool inLocationChangeAnimation(); bool inLocationChangeAnimation();
void setScreenToFollow(QScreen *scr, bool updateScreenId = true); void setScreenToFollow(QScreen *scr, bool updateScreenId = true);
QString currentScreenName() const; void reconsiderScreen();
public slots: public slots:
Q_INVOKABLE void hideDockDuringLocationChange(int goToLocation); Q_INVOKABLE void hideDockDuringLocationChange(int goToLocation);

@ -1791,6 +1791,23 @@ QList<Plasma::Types::Location> Layout::availableEdgesForView(QScreen *scr, DockV
return edges; return edges;
} }
QList<int> Layout::qmlFreeEdges(int screen) const
{
if (!m_corona) {
const QList<int> emptyEdges;
return emptyEdges;
}
const auto edges = freeEdges(screen);
QList<int> edgesInt;
foreach (Plasma::Types::Location edge, edges) {
edgesInt.append(static_cast<int>(edge));
}
return edgesInt;
}
QList<Plasma::Types::Location> Layout::freeEdges(QScreen *scr) const QList<Plasma::Types::Location> Layout::freeEdges(QScreen *scr) const
{ {
using Plasma::Types; using Plasma::Types;

@ -154,6 +154,10 @@ public:
int docksCount(int screen) const; int docksCount(int screen) const;
int docksCount(QScreen *screen) const; int docksCount(QScreen *screen) const;
public slots:
//change <Plasma::Types::Location> to <int> types
Q_INVOKABLE QList<int> qmlFreeEdges(int screen) const;
signals: signals:
void activitiesChanged(); void activitiesChanged();
void backgroundChanged(); void backgroundChanged();

@ -189,6 +189,8 @@ PlasmaComponents.Page {
onDocksCountChanged: locationLayout.lockReservedEdges(); onDocksCountChanged: locationLayout.lockReservedEdges();
} }
Component.onCompleted: lockReservedEdges()
ExclusiveGroup { ExclusiveGroup {
id: locationGroup id: locationGroup
property bool inStartup: true property bool inStartup: true
@ -202,64 +204,64 @@ PlasmaComponents.Page {
} }
function lockReservedEdges() { function lockReservedEdges() {
var buttons = visibleChildren var edges = dock.managedLayout.qmlFreeEdges(dock.positioner.currentScreenId);
var edges = dock.freeEdges()
for (var i = 0; i < buttons.length; i++) { bottomEdgeBtn.edgeIsFree = (edges.indexOf(bottomEdgeBtn.edge)>=0);
buttons[i].enabled = buttons[i].checked || freeEdge(buttons[i].edge, edges) topEdgeBtn.edgeIsFree = (edges.indexOf(topEdgeBtn.edge)>=0);
} leftEdgeBtn.edgeIsFree = (edges.indexOf(leftEdgeBtn.edge)>=0);
} rightEdgeBtn.edgeIsFree = (edges.indexOf(rightEdgeBtn.edge)>=0);
function freeEdge(edge, edges) {
for (var i = 0; i < edges.length; i++) {
if (edges[i] === edge)
return true
}
return false
} }
PlasmaComponents.Button { PlasmaComponents.Button {
id: bottomEdgeBtn
Layout.fillWidth: true Layout.fillWidth: true
text: i18nc("bottom location", "Bottom") text: i18nc("bottom location", "Bottom")
iconSource: "arrow-down" iconSource: "arrow-down"
checked: dock.location === edge checked: dock.location === edge
checkable: true checkable: true
enabled: checked || locationLayout.freeEdge(edge, dock.freeEdges()) enabled: checked || edgeIsFree
exclusiveGroup: locationGroup exclusiveGroup: locationGroup
property bool edgeIsFree: true
readonly property int edge: PlasmaCore.Types.BottomEdge readonly property int edge: PlasmaCore.Types.BottomEdge
} }
PlasmaComponents.Button { PlasmaComponents.Button {
id: leftEdgeBtn
Layout.fillWidth: true Layout.fillWidth: true
text: i18nc("left location", "Left") text: i18nc("left location", "Left")
iconSource: "arrow-left" iconSource: "arrow-left"
checked: dock.location === edge checked: dock.location === edge
checkable: true checkable: true
enabled: checked || locationLayout.freeEdge(edge, dock.freeEdges()) enabled: checked || edgeIsFree
exclusiveGroup: locationGroup exclusiveGroup: locationGroup
property bool edgeIsFree: true
readonly property int edge: PlasmaCore.Types.LeftEdge readonly property int edge: PlasmaCore.Types.LeftEdge
} }
PlasmaComponents.Button { PlasmaComponents.Button {
id: topEdgeBtn
Layout.fillWidth: true Layout.fillWidth: true
text: i18nc("top location", "Top") text: i18nc("top location", "Top")
iconSource: "arrow-up" iconSource: "arrow-up"
checked: dock.location === edge checked: dock.location === edge
checkable: true checkable: true
enabled: checked || locationLayout.freeEdge(edge, dock.freeEdges()) enabled: checked || edgeIsFree
exclusiveGroup: locationGroup exclusiveGroup: locationGroup
property bool edgeIsFree: true
readonly property int edge: PlasmaCore.Types.TopEdge readonly property int edge: PlasmaCore.Types.TopEdge
} }
PlasmaComponents.Button { PlasmaComponents.Button {
id: rightEdgeBtn
Layout.fillWidth: true Layout.fillWidth: true
text: i18nc("right location", "Right") text: i18nc("right location", "Right")
iconSource: "arrow-right" iconSource: "arrow-right"
checked: dock.location === edge checked: dock.location === edge
checkable: true checkable: true
enabled: checked || locationLayout.freeEdge(edge, dock.freeEdges()) enabled: checked || edgeIsFree
exclusiveGroup: locationGroup exclusiveGroup: locationGroup
property bool edgeIsFree: true
readonly property int edge: PlasmaCore.Types.RightEdge readonly property int edge: PlasmaCore.Types.RightEdge
} }
} }

@ -490,7 +490,8 @@ FocusScope {
} }
function updateEnabled() { function updateEnabled() {
addDock.enabled = dock.docksCount < 4 && dock.freeEdges().length > 0 var screenFreeEdges = dock.managedLayout.qmlFreeEdges(dock.positioner.currentScreenId);
addDock.enabled = dock.docksCount < 4 && screenFreeEdges.length > 0
removeDock.enabled = dock.docksCount>1 && !(dock.docksWithTasks()===1 && dock.tasksPresent()) removeDock.enabled = dock.docksCount>1 && !(dock.docksWithTasks()===1 && dock.tasksPresent())
} }
@ -574,7 +575,8 @@ FocusScope {
onClicked: dock.addNewDock() onClicked: dock.addNewDock()
Component.onCompleted: { Component.onCompleted: {
enabled = dock.freeEdges().length > 0 var screenFreeEdges = dock.managedLayout.qmlFreeEdges(dock.positioner.currentScreenId);
enabled = screenFreeEdges.length > 0
} }
} }
} }

Loading…
Cancel
Save