sync panel position to containment location
This commit is contained in:
parent
99d49220df
commit
f4a4bb55de
@ -357,6 +357,7 @@ void Containment::setFormFactor(FormFactor formFactor)
|
|||||||
KConfigGroup c = config();
|
KConfigGroup c = config();
|
||||||
c.writeEntry("formfactor", (int)formFactor);
|
c.writeEntry("formfactor", (int)formFactor);
|
||||||
emit configNeedsSaving();
|
emit configNeedsSaving();
|
||||||
|
emit formFactorChanged(formFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Containment::setLocation(Location location)
|
void Containment::setLocation(Location location)
|
||||||
@ -376,6 +377,7 @@ void Containment::setLocation(Location location)
|
|||||||
KConfigGroup c = config();
|
KConfigGroup c = config();
|
||||||
c.writeEntry("location", (int)location);
|
c.writeEntry("location", (int)location);
|
||||||
emit configNeedsSaving();
|
emit configNeedsSaving();
|
||||||
|
emit locationChanged(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
Applet *Containment::addApplet(const QString &name, const QVariantList &args)
|
Applet *Containment::addApplet(const QString &name, const QVariantList &args)
|
||||||
|
@ -270,6 +270,18 @@ Q_SIGNALS:
|
|||||||
*/
|
*/
|
||||||
void wallpaperChanged();
|
void wallpaperChanged();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted when the location has changed
|
||||||
|
* @since 5.0
|
||||||
|
*/
|
||||||
|
void locationChanged(Plasma::Location location);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emitted when the formFactor has changed
|
||||||
|
* @since 5.0
|
||||||
|
*/
|
||||||
|
void formFactorChanged(Plasma::FormFactor formFactor);
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
/**
|
/**
|
||||||
* Informs the Corona as to what position it is in. This is informational
|
* Informs the Corona as to what position it is in. This is informational
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "panelview.h"
|
#include "panelview.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QScreen>
|
||||||
|
|
||||||
#include <KWindowSystem>
|
#include <KWindowSystem>
|
||||||
#include <kwindoweffects.h>
|
#include <kwindoweffects.h>
|
||||||
@ -39,6 +40,11 @@ PanelView::PanelView(Plasma::Corona *corona, QWindow *parent)
|
|||||||
//TODO: how to take the shape from the framesvg?
|
//TODO: how to take the shape from the framesvg?
|
||||||
KWindowEffects::enableBlurBehind(winId(), true);
|
KWindowEffects::enableBlurBehind(winId(), true);
|
||||||
|
|
||||||
|
//Screen management
|
||||||
|
connect(screen(), &QScreen::virtualGeometryChanged,
|
||||||
|
this, &PanelView::positionPanel);
|
||||||
|
connect(this, &View::locationChanged,
|
||||||
|
this, &PanelView::positionPanel);
|
||||||
}
|
}
|
||||||
|
|
||||||
PanelView::~PanelView()
|
PanelView::~PanelView()
|
||||||
@ -56,5 +62,32 @@ void PanelView::init()
|
|||||||
setSource(QUrl::fromLocalFile(corona()->package().filePath("ui", "PanelView.qml")));
|
setSource(QUrl::fromLocalFile(corona()->package().filePath("ui", "PanelView.qml")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PanelView::positionPanel()
|
||||||
|
{
|
||||||
|
if (!containment()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QScreen *s = screen();
|
||||||
|
|
||||||
|
switch (containment()->location()) {
|
||||||
|
case Plasma::TopEdge:
|
||||||
|
containment()->setFormFactor(Plasma::Horizontal);
|
||||||
|
setPosition(s->virtualGeometry().topLeft());
|
||||||
|
break;
|
||||||
|
case Plasma::LeftEdge:
|
||||||
|
containment()->setFormFactor(Plasma::Vertical);
|
||||||
|
setPosition(s->virtualGeometry().topLeft());
|
||||||
|
break;
|
||||||
|
case Plasma::RightEdge:
|
||||||
|
containment()->setFormFactor(Plasma::Vertical);
|
||||||
|
setPosition(s->virtualGeometry().topRight() - QPoint(width(), 0));
|
||||||
|
break;
|
||||||
|
case Plasma::BottomEdge:
|
||||||
|
default:
|
||||||
|
containment()->setFormFactor(Plasma::Horizontal);
|
||||||
|
setPosition(s->virtualGeometry().bottomLeft() - QPoint(0, height()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#include "moc_panelview.cpp"
|
#include "moc_panelview.cpp"
|
||||||
|
@ -32,6 +32,10 @@ public:
|
|||||||
virtual ~PanelView();
|
virtual ~PanelView();
|
||||||
|
|
||||||
virtual void init();
|
virtual void init();
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void positionPanel();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -57,6 +57,9 @@ void View::init()
|
|||||||
|
|
||||||
void View::setContainment(Plasma::Containment *cont)
|
void View::setContainment(Plasma::Containment *cont)
|
||||||
{
|
{
|
||||||
|
Plasma::Location oldLoc = location();
|
||||||
|
Plasma::FormFactor oldForm = formFactor();
|
||||||
|
|
||||||
if (m_containment) {
|
if (m_containment) {
|
||||||
disconnect(m_containment.data(), 0, this, 0);
|
disconnect(m_containment.data(), 0, this, 0);
|
||||||
QObject *oldGraphicObject = m_containment.data()->property("graphicObject").value<QObject *>();
|
QObject *oldGraphicObject = m_containment.data()->property("graphicObject").value<QObject *>();
|
||||||
@ -68,7 +71,19 @@ void View::setContainment(Plasma::Containment *cont)
|
|||||||
|
|
||||||
m_containment = cont;
|
m_containment = cont;
|
||||||
|
|
||||||
if (!cont) {
|
if (oldLoc != location()) {
|
||||||
|
emit locationChanged(location());
|
||||||
|
}
|
||||||
|
if (oldForm != formFactor()) {
|
||||||
|
emit formFactorChanged(formFactor());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cont) {
|
||||||
|
connect(cont, &Plasma::Containment::locationChanged,
|
||||||
|
this, &View::locationChanged);
|
||||||
|
connect(cont, &Plasma::Containment::formFactorChanged,
|
||||||
|
this, &View::formFactorChanged);
|
||||||
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,4 +107,20 @@ Plasma::Containment *View::containment() const
|
|||||||
return m_containment.data();
|
return m_containment.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Plasma::Location View::location()
|
||||||
|
{
|
||||||
|
if (!m_containment) {
|
||||||
|
return Plasma::Desktop;
|
||||||
|
}
|
||||||
|
return m_containment.data()->location();
|
||||||
|
}
|
||||||
|
|
||||||
|
Plasma::FormFactor View::formFactor()
|
||||||
|
{
|
||||||
|
if (!m_containment) {
|
||||||
|
return Plasma::Planar;
|
||||||
|
}
|
||||||
|
return m_containment.data()->formFactor();
|
||||||
|
}
|
||||||
|
|
||||||
#include "moc_view.cpp"
|
#include "moc_view.cpp"
|
||||||
|
@ -42,6 +42,13 @@ public:
|
|||||||
void setContainment(Plasma::Containment *cont);
|
void setContainment(Plasma::Containment *cont);
|
||||||
Plasma::Containment *containment() const;
|
Plasma::Containment *containment() const;
|
||||||
|
|
||||||
|
Plasma::Location location();
|
||||||
|
Plasma::FormFactor formFactor();
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void locationChanged(Plasma::Location location);
|
||||||
|
void formFactorChanged(Plasma::FormFactor formFactor);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Plasma::Corona *m_corona;
|
Plasma::Corona *m_corona;
|
||||||
QWeakPointer<Plasma::Containment> m_containment;
|
QWeakPointer<Plasma::Containment> m_containment;
|
||||||
|
Loading…
Reference in New Issue
Block a user