From f4a4bb55de1b52147e0b3922da7cc0d07036428a Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 21 Feb 2013 17:49:52 +0100 Subject: [PATCH] sync panel position to containment location --- src/plasma/containment.cpp | 2 ++ src/plasma/containment.h | 12 ++++++++++++ src/shell/panelview.cpp | 35 ++++++++++++++++++++++++++++++++++- src/shell/panelview.h | 4 ++++ src/shell/view.cpp | 33 ++++++++++++++++++++++++++++++++- src/shell/view.h | 7 +++++++ 6 files changed, 91 insertions(+), 2 deletions(-) diff --git a/src/plasma/containment.cpp b/src/plasma/containment.cpp index f04513e30..304e2c5ee 100644 --- a/src/plasma/containment.cpp +++ b/src/plasma/containment.cpp @@ -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) diff --git a/src/plasma/containment.h b/src/plasma/containment.h index 79c029450..8d668276d 100644 --- a/src/plasma/containment.h +++ b/src/plasma/containment.h @@ -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 diff --git a/src/shell/panelview.cpp b/src/shell/panelview.cpp index 37610ce2b..2c8596fb8 100644 --- a/src/shell/panelview.cpp +++ b/src/shell/panelview.cpp @@ -19,6 +19,7 @@ #include "panelview.h" #include +#include #include #include @@ -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" diff --git a/src/shell/panelview.h b/src/shell/panelview.h index 87b5fce6f..bf5a0f286 100644 --- a/src/shell/panelview.h +++ b/src/shell/panelview.h @@ -32,6 +32,10 @@ public: virtual ~PanelView(); virtual void init(); + +private Q_SLOTS: + void positionPanel(); + private: }; diff --git a/src/shell/view.cpp b/src/shell/view.cpp index 3ef49bed1..59353b72e 100644 --- a/src/shell/view.cpp +++ b/src/shell/view.cpp @@ -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(); @@ -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" diff --git a/src/shell/view.h b/src/shell/view.h index 25e0072e2..ba0cb7a15 100644 --- a/src/shell/view.h +++ b/src/shell/view.h @@ -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 m_containment;