differentiate dockNo perScreen and total

--improve the signaling between the configuration window
and the dockview concerning freeEdges for current screens
and docks count. Now the docks counting is different
between screens and in general
pull/1/head
Michail Vourlakos 8 years ago
parent 97b3c4f854
commit a05785e34b

@ -633,8 +633,21 @@ int DockCorona::docksCount() const
int docks{0}; int docks{0};
for (const auto &view : m_dockViews) { for (const auto &view : m_dockViews) {
if (view && view->containment() if (view && view->containment() && !view->containment()->destroyed()) {
&& !view->containment()->destroyed()) { ++docks;
}
}
// qDebug() << docks << "docks on screen:" << screen;
return docks;
}
int DockCorona::docksCount(QScreen *screen) const
{
int docks{0};
for (const auto &view : m_dockViews) {
if (view && view->screen() == screen && !view->containment()->destroyed()) {
++docks; ++docks;
} }
} }

@ -69,8 +69,10 @@ public:
QList<Plasma::Types::Location> freeEdges(int screen) const; QList<Plasma::Types::Location> freeEdges(int screen) const;
QList<Plasma::Types::Location> freeEdges(QScreen *screen) const; QList<Plasma::Types::Location> freeEdges(QScreen *screen) const;
int docksCount(int screen) const;
int docksCount() const; int docksCount() const;
int docksCount(int screen) const;
int docksCount(QScreen *screen) const;
int noDocksWithTasks() const; int noDocksWithTasks() const;
int screenForContainment(const Plasma::Containment *containment) const override; int screenForContainment(const Plasma::Containment *containment) const override;

@ -124,6 +124,7 @@ DockView::DockView(Plasma::Corona *corona, QScreen *targetScreen, bool dockWindo
if (dockCorona) { if (dockCorona) {
connect(dockCorona, &DockCorona::docksCountChanged, this, &DockView::docksCountChanged); connect(dockCorona, &DockCorona::docksCountChanged, this, &DockView::docksCountChanged);
connect(this, &DockView::docksCountChanged, this, &DockView::totalDocksCountChanged);
connect(dockCorona, &DockCorona::dockLocationChanged, this, &DockView::dockLocationChanged); connect(dockCorona, &DockCorona::dockLocationChanged, this, &DockView::dockLocationChanged);
connect(dockCorona, &DockCorona::dockLocationChanged, this, [&]() { connect(dockCorona, &DockCorona::dockLocationChanged, this, [&]() {
//! check if an edge has been freed for a primary dock //! check if an edge has been freed for a primary dock
@ -788,7 +789,17 @@ int DockView::docksCount() const
{ {
auto dockCorona = qobject_cast<DockCorona *>(corona()); auto dockCorona = qobject_cast<DockCorona *>(corona());
if (!dockCorona || !this->containment()) if (!dockCorona)
return 0;
return dockCorona->docksCount(screen());
}
int DockView::totalDocksCount() const
{
auto dockCorona = qobject_cast<DockCorona *>(corona());
if (!dockCorona)
return 0; return 0;
return dockCorona->docksCount(); return dockCorona->docksCount();
@ -1247,12 +1258,14 @@ bool DockView::event(QEvent *e)
QList<int> DockView::freeEdges() const QList<int> DockView::freeEdges() const
{ {
if (!this->corona() || !this->containment()) { DockCorona *dockCorona = qobject_cast<DockCorona *>(this->corona());
if (!dockCorona) {
const QList<int> emptyEdges; const QList<int> emptyEdges;
return emptyEdges; return emptyEdges;
} }
const auto edges = corona()->freeEdges(this->containment()->screen()); const auto edges = dockCorona->freeEdges(screen());
QList<int> edgesInt; QList<int> edgesInt;
foreach (Plasma::Types::Location edge, edges) { foreach (Plasma::Types::Location edge, edges) {

@ -60,6 +60,7 @@ class DockView : public PlasmaQuick::ContainmentView {
Q_PROPERTY(int alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged) Q_PROPERTY(int alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
Q_PROPERTY(int docksCount READ docksCount NOTIFY docksCountChanged) Q_PROPERTY(int docksCount READ docksCount NOTIFY docksCountChanged)
Q_PROPERTY(int totalDocksCount READ totalDocksCount NOTIFY totalDocksCountChanged)
Q_PROPERTY(int x READ x NOTIFY xChanged) Q_PROPERTY(int x READ x NOTIFY xChanged)
Q_PROPERTY(int y READ y NOTIFY yChanged) Q_PROPERTY(int y READ y NOTIFY yChanged)
Q_PROPERTY(int width READ width NOTIFY widthChanged) Q_PROPERTY(int width READ width NOTIFY widthChanged)
@ -102,6 +103,7 @@ public:
int currentThickness() const; int currentThickness() const;
int docksCount() const; int docksCount() const;
int totalDocksCount() const;
bool behaveAsPlasmaPanel() const; bool behaveAsPlasmaPanel() const;
void setBehaveAsPlasmaPanel(bool behavior); void setBehaveAsPlasmaPanel(bool behavior);
@ -218,6 +220,7 @@ signals:
void screenGeometryChanged(); void screenGeometryChanged();
void sessionChanged(); void sessionChanged();
void shadowChanged(); void shadowChanged();
void totalDocksCountChanged();
void xChanged(); void xChanged();
void yChanged(); void yChanged();

@ -277,11 +277,14 @@ PlasmaCore.FrameSvgItem {
spacing: units.largeSpacing spacing: units.largeSpacing
property int docksCount: dock.docksCount Connections{
target: dock
onDocksCountChanged: actionButtons.updateEnabled();
}
onDocksCountChanged: { function updateEnabled() {
addDock.enabled = docksCount < 4 && dock.freeEdges().length > 0 addDock.enabled = dock.docksCount < 4 && dock.freeEdges().length > 0
removeDock.enabled = (docksCount>1) && !(dock.docksWithTasks()===1 && dock.tasksPresent()) removeDock.enabled = dock.docksCount>1 && !(dock.docksWithTasks()===1 && dock.tasksPresent())
} }
PlasmaComponents.Button { PlasmaComponents.Button {
@ -291,17 +294,27 @@ PlasmaCore.FrameSvgItem {
PlasmaComponents.ComboBox { PlasmaComponents.ComboBox {
id: actionsCmb id: actionsCmb
anchors.fill: parent anchors.fill: parent
enabled: addDock.enabled
Component.onCompleted:{ function addModel() {
var actions = [] var actions = []
actions.push(" " + i18n("Copy Dock")); actions.push(" " + i18n("Copy Dock"));
actionsCmb.model = actions; actionsCmb.model = actions;
actionsCmb.currentIndex = -1; actionsCmb.currentIndex = -1;
} }
function emptyModel() {
var actions = []
actions.push(" ");
actionsCmb.model = actions;
actionsCmb.currentIndex = -1;
}
Component.onCompleted:{
addModel();
}
onActivated: { onActivated: {
if (index==0) { if (index==0) {
dock.copyDock(); dock.copyDock();
@ -309,6 +322,13 @@ PlasmaCore.FrameSvgItem {
actionsCmb.currentIndex = -1; actionsCmb.currentIndex = -1;
} }
onEnabledChanged: {
if (enabled)
addModel();
else
emptyModel();
}
} }
@ -338,8 +358,7 @@ PlasmaCore.FrameSvgItem {
text: i18n("Remove") text: i18n("Remove")
iconSource: "edit-delete" iconSource: "edit-delete"
opacity: enabled ? 1 : 0 opacity: dock.totalDocksCount > 1 ? 1 : 0
//enabled: dock.docksCount > 1
tooltip: i18n("Remove current dock") tooltip: i18n("Remove current dock")
onClicked: dock.removeDock() onClicked: dock.removeDock()

Loading…
Cancel
Save