From 36d5f25371248612221f353b13d82bb51c683cb9 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 21 Feb 2013 20:35:21 +0100 Subject: [PATCH] restore some values from config panelviews can restore offset, minimum, maximum and size from the config still needed alignment and resize will need a bit of work since should be containment-controlled --- src/shell/panelview.cpp | 67 ++++++++++++++++++++++++++++++++++++----- src/shell/panelview.h | 5 ++- src/shell/view.cpp | 2 ++ src/shell/view.h | 1 + 4 files changed, 67 insertions(+), 8 deletions(-) diff --git a/src/shell/panelview.cpp b/src/shell/panelview.cpp index ef876a0b6..8ae75194b 100644 --- a/src/shell/panelview.cpp +++ b/src/shell/panelview.cpp @@ -28,7 +28,10 @@ #include PanelView::PanelView(Plasma::Corona *corona, QWindow *parent) - : View(corona, parent) + : View(corona, parent), + m_offset(0), + m_maxLength(0), + m_minLength(0) { QSurfaceFormat format; format.setAlphaBufferSize(8); @@ -46,11 +49,19 @@ PanelView::PanelView(Plasma::Corona *corona, QWindow *parent) this, &PanelView::positionPanel); connect(this, &View::locationChanged, this, &PanelView::positionPanel); + connect(this, &View::containmentChanged, + this, &PanelView::restore); } PanelView::~PanelView() { - + if (containment()) { + config().writeEntry("offset", m_offset); + config().writeEntry("max", m_maxLength); + config().writeEntry("min", m_minLength); + config().writeEntry("size", size()); + containment()->corona()->requestConfigSync(); + } } KConfigGroup PanelView::config() const @@ -59,7 +70,14 @@ KConfigGroup PanelView::config() const return KConfigGroup(); } KConfigGroup views(KGlobal::config(), "PlasmaViews"); - return KConfigGroup(&views, QString("Panel %1").arg(containment()->id())); + views = KConfigGroup(&views, QString("Panel %1").arg(containment()->id())); + + if (containment()->formFactor() == Plasma::Vertical) { + return KConfigGroup(&views, "Vertical" + QString::number(screen()->size().height())); + //treat everything else as horizontal + } else { + return KConfigGroup(&views, "Horizontal" + QString::number(screen()->size().width())); + } } void PanelView::init() @@ -83,21 +101,56 @@ void PanelView::positionPanel() switch (containment()->location()) { case Plasma::TopEdge: containment()->setFormFactor(Plasma::Horizontal); - setPosition(s->virtualGeometry().topLeft()); + setPosition(s->virtualGeometry().topLeft() + QPoint(m_offset, 0)); break; case Plasma::LeftEdge: containment()->setFormFactor(Plasma::Vertical); - setPosition(s->virtualGeometry().topLeft()); + setPosition(s->virtualGeometry().topLeft() + QPoint(0, m_offset)); break; case Plasma::RightEdge: containment()->setFormFactor(Plasma::Vertical); - setPosition(s->virtualGeometry().topRight() - QPoint(width(), 0)); + setPosition(s->virtualGeometry().topRight() - QPoint(width(), 0) + QPoint(0, m_offset)); break; case Plasma::BottomEdge: default: containment()->setFormFactor(Plasma::Horizontal); - setPosition(s->virtualGeometry().bottomLeft() - QPoint(0, height())); + setPosition(s->virtualGeometry().bottomLeft() - QPoint(0, height()) + QPoint(m_offset, 0)); } } +void PanelView::restore() +{ + if (!containment()) { + return; + } + + m_offset = config().readEntry("offset", 0); + m_maxLength = config().readEntry("max", -1); + m_minLength = config().readEntry("min", -1); + + setMinimumSize(QSize(-1, -1)); + //FIXME: an invalid size doesn't work with QWindows + setMaximumSize(QSize(10000, 10000)); + + if (containment()->formFactor() == Plasma::Vertical) { + if (m_minLength > 0) { + setMinimumHeight(m_minLength); + } + if (m_maxLength > 0) { + setMaximumHeight(m_maxLength); + } + resize(config().readEntry("size", QSize(32, screen()->size().width()))); + } else { + if (m_minLength > 0) { + setMinimumWidth(m_minLength); + } + if (m_maxLength > 0) { + setMaximumWidth(m_maxLength); + } + resize(config().readEntry("size", QSize(screen()->size().height(), 32))); + } + + positionPanel(); +} + #include "moc_panelview.cpp" diff --git a/src/shell/panelview.h b/src/shell/panelview.h index cfcceb1e3..82b8c8f87 100644 --- a/src/shell/panelview.h +++ b/src/shell/panelview.h @@ -37,9 +37,12 @@ public: private Q_SLOTS: void positionPanel(); + void restore(); private: - + int m_offset; + int m_maxLength; + int m_minLength; }; #endif // PANELVIEW_H diff --git a/src/shell/view.cpp b/src/shell/view.cpp index 93eb340c9..515fe2c21 100644 --- a/src/shell/view.cpp +++ b/src/shell/view.cpp @@ -89,6 +89,8 @@ void View::setContainment(Plasma::Containment *cont) emit formFactorChanged(formFactor()); } + emit containmentChanged(); + if (cont) { connect(cont, &Plasma::Containment::locationChanged, this, &View::locationChanged); diff --git a/src/shell/view.h b/src/shell/view.h index 880c07e73..4970d3d4a 100644 --- a/src/shell/view.h +++ b/src/shell/view.h @@ -50,6 +50,7 @@ public: Q_SIGNALS: void locationChanged(Plasma::Location location); void formFactorChanged(Plasma::FormFactor formFactor); + void containmentChanged(); private: Plasma::Corona *m_corona;