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);;
}
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()
{
if (!containment()) {

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

@ -89,6 +89,7 @@ void Positioner::init()
connect(m_view, &QQuickWindow::yChanged, this, &Positioner::validateDockGeometry);
connect(m_view, &QQuickWindow::widthChanged, 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, &Latte::DockView::absGeometryChanged, this, &Positioner::syncGeometry);
@ -126,6 +127,17 @@ void Positioner::init()
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
{
return m_screenToFollowId;

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

@ -1791,6 +1791,23 @@ QList<Plasma::Types::Location> Layout::availableEdgesForView(QScreen *scr, DockV
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
{
using Plasma::Types;

@ -154,6 +154,10 @@ public:
int docksCount(int 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:
void activitiesChanged();
void backgroundChanged();

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

@ -490,7 +490,8 @@ FocusScope {
}
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())
}
@ -574,7 +575,8 @@ FocusScope {
onClicked: dock.addNewDock()
Component.onCompleted: {
enabled = dock.freeEdges().length > 0
var screenFreeEdges = dock.managedLayout.qmlFreeEdges(dock.positioner.currentScreenId);
enabled = screenFreeEdges.length > 0
}
}
}

Loading…
Cancel
Save