sync panel position to containment location

This commit is contained in:
Marco Martin 2013-02-21 17:49:52 +01:00
parent 99d49220df
commit f4a4bb55de
6 changed files with 91 additions and 2 deletions

View File

@ -357,6 +357,7 @@ void Containment::setFormFactor(FormFactor formFactor)
KConfigGroup c = config();
c.writeEntry("formfactor", (int)formFactor);
emit configNeedsSaving();
emit formFactorChanged(formFactor);
}
void Containment::setLocation(Location location)
@ -376,6 +377,7 @@ void Containment::setLocation(Location location)
KConfigGroup c = config();
c.writeEntry("location", (int)location);
emit configNeedsSaving();
emit locationChanged(location);
}
Applet *Containment::addApplet(const QString &name, const QVariantList &args)

View File

@ -270,6 +270,18 @@ Q_SIGNALS:
*/
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:
/**
* Informs the Corona as to what position it is in. This is informational

View File

@ -19,6 +19,7 @@
#include "panelview.h"
#include <QDebug>
#include <QScreen>
#include <KWindowSystem>
#include <kwindoweffects.h>
@ -38,7 +39,12 @@ PanelView::PanelView(Plasma::Corona *corona, QWindow *parent)
//TODO: how to take the shape from the framesvg?
KWindowEffects::enableBlurBehind(winId(), true);
//Screen management
connect(screen(), &QScreen::virtualGeometryChanged,
this, &PanelView::positionPanel);
connect(this, &View::locationChanged,
this, &PanelView::positionPanel);
}
PanelView::~PanelView()
@ -56,5 +62,32 @@ void PanelView::init()
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"

View File

@ -32,6 +32,10 @@ public:
virtual ~PanelView();
virtual void init();
private Q_SLOTS:
void positionPanel();
private:
};

View File

@ -57,6 +57,9 @@ void View::init()
void View::setContainment(Plasma::Containment *cont)
{
Plasma::Location oldLoc = location();
Plasma::FormFactor oldForm = formFactor();
if (m_containment) {
disconnect(m_containment.data(), 0, this, 0);
QObject *oldGraphicObject = m_containment.data()->property("graphicObject").value<QObject *>();
@ -68,7 +71,19 @@ void View::setContainment(Plasma::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;
}
@ -92,4 +107,20 @@ Plasma::Containment *View::containment() const
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"

View File

@ -42,6 +42,13 @@ public:
void setContainment(Plasma::Containment *cont);
Plasma::Containment *containment() const;
Plasma::Location location();
Plasma::FormFactor formFactor();
Q_SIGNALS:
void locationChanged(Plasma::Location location);
void formFactorChanged(Plasma::FormFactor formFactor);
private:
Plasma::Corona *m_corona;
QWeakPointer<Plasma::Containment> m_containment;