diff --git a/shell/panelview.cpp b/shell/panelview.cpp index 4dec906b6..553dc7da3 100644 --- a/shell/panelview.cpp +++ b/shell/panelview.cpp @@ -123,22 +123,27 @@ PanelView::~PanelView() PanelShadows::self()->removeWindow(this); } -KConfigGroup PanelView::config() const +KConfigGroup PanelView::panelConfig(ShellCorona *corona, Plasma::Containment *containment, QScreen *screen) { - if (!containment()) { + if (!containment || !screen) { return KConfigGroup(); } - KConfigGroup views(m_corona->applicationConfig(), "PlasmaViews"); - views = KConfigGroup(&views, QStringLiteral("Panel %1").arg(containment()->id())); + KConfigGroup views(corona->applicationConfig(), "PlasmaViews"); + views = KConfigGroup(&views, QStringLiteral("Panel %1").arg(containment->id())); - if (formFactor() == Plasma::Types::Vertical) { - return KConfigGroup(&views, "Vertical" + QString::number(screen()->size().height())); + if (containment->formFactor() == Plasma::Types::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())); + return KConfigGroup(&views, "Horizontal" + QString::number(screen->size().width())); } } +KConfigGroup PanelView::config() const +{ + return panelConfig(m_corona, containment(), screen()); +} + void PanelView::maximize() { int length; @@ -491,26 +496,12 @@ void PanelView::restore() int defaultMaxLength = 0; int defaultMinLength = 0; int defaultAlignment = Qt::AlignLeft; - - QQuickItem *containmentItem = containment()->property("_plasma_graphicObject").value(); - - if (containmentItem && containmentItem->property("_plasma_desktopscripting_alignment").canConvert()) { - defaultAlignment = containmentItem->property("_plasma_desktopscripting_alignment").toInt(); - } setAlignment((Qt::Alignment)config().readEntry("alignment", defaultAlignment)); - - - if (containmentItem && containmentItem->property("_plasma_desktopscripting_offset").canConvert()) { - defaultOffset = containmentItem->property("_plasma_desktopscripting_offset").toInt(); - } m_offset = config().readEntry("offset", defaultOffset); if (m_alignment != Qt::AlignCenter) { m_offset = qMax(0, m_offset); } - if (containmentItem && containmentItem->property("_plasma_desktopscripting_thickness").canConvert()) { - defaultThickness = qMax(16, containmentItem->property("_plasma_desktopscripting_thickness").toInt()); - } setThickness(config().readEntry("thickness", defaultThickness)); setMinimumSize(QSize(-1, -1)); @@ -521,13 +512,6 @@ void PanelView::restore() defaultMaxLength = screen()->size().height(); defaultMinLength = screen()->size().height(); - if (containmentItem && containmentItem->property("_plasma_desktopscripting_maxLength").canConvert()) { - defaultMaxLength = containmentItem->property("_plasma_desktopscripting_maxLength").toInt(); - } - if (containmentItem && containmentItem->property("_plasma_desktopscripting_minLength").canConvert()) { - defaultMinLength = containmentItem->property("_plasma_desktopscripting_minLength").toInt(); - } - m_maxLength = config().readEntry("maxLength", defaultMaxLength); m_minLength = config().readEntry("minLength", defaultMinLength); @@ -545,13 +529,6 @@ void PanelView::restore() defaultMaxLength = screen()->size().width(); defaultMinLength = screen()->size().width(); - if (containmentItem && containmentItem->property("_plasma_desktopscripting_maxLength").canConvert()) { - defaultMaxLength = containmentItem->property("_plasma_desktopscripting_maxLength").toInt(); - } - if (containmentItem && containmentItem->property("_plasma_desktopscripting_minLength").canConvert()) { - defaultMinLength = containmentItem->property("_plasma_desktopscripting_minLength").toInt(); - } - m_maxLength = config().readEntry("maxLength", defaultMaxLength); m_minLength = config().readEntry("minLength", defaultMinLength); diff --git a/shell/panelview.h b/shell/panelview.h index 9f8d4ce9c..c671f14f9 100644 --- a/shell/panelview.h +++ b/shell/panelview.h @@ -133,6 +133,9 @@ public: */ QRect geometryByDistance(int distance) const; + /* Shared with script/panel.cpp */ + static KConfigGroup panelConfig(ShellCorona *corona, Plasma::Containment *containment, QScreen *screen); + protected: void resizeEvent(QResizeEvent *ev); void showEvent(QShowEvent *event); diff --git a/shell/scripting/panel.cpp b/shell/scripting/panel.cpp index fb0ff2119..b9383dfb8 100644 --- a/shell/scripting/panel.cpp +++ b/shell/scripting/panel.cpp @@ -48,34 +48,34 @@ QString Panel::location() const { Plasma::Containment *c = containment(); if (!c) { - return QStringLiteral("floating"); + return "floating"; } switch (c->location()) { case Plasma::Types::Floating: - return QStringLiteral("floating"); + return "floating"; break; case Plasma::Types::Desktop: - return QStringLiteral("desktop"); + return "desktop"; break; case Plasma::Types::FullScreen: - return QStringLiteral("fullscreen"); + return "fullscreen"; break; case Plasma::Types::TopEdge: - return QStringLiteral("top"); + return "top"; break; case Plasma::Types::BottomEdge: - return QStringLiteral("bottom"); + return "bottom"; break; case Plasma::Types::LeftEdge: - return QStringLiteral("left"); + return "left"; break; case Plasma::Types::RightEdge: - return QStringLiteral("right"); + return "right"; break; } - return QStringLiteral("floating"); + return "floating"; } void Panel::setLocation(const QString &locationString) @@ -88,20 +88,20 @@ void Panel::setLocation(const QString &locationString) const QString lower = locationString.toLower(); Plasma::Types::Location loc = Plasma::Types::Floating; Plasma::Types::FormFactor ff = Plasma::Types::Planar; - if (lower == QLatin1String("desktop")) { + if (lower == "desktop") { loc = Plasma::Types::Desktop; - } else if (lower == QLatin1String("fullscreen")) { + } else if (lower == "fullscreen") { loc = Plasma::Types::FullScreen; - } else if (lower == QLatin1String("top")) { + } else if (lower == "top") { loc = Plasma::Types::TopEdge; ff = Plasma::Types::Horizontal; - } else if (lower == QLatin1String("bottom")) { + } else if (lower == "bottom") { loc = Plasma::Types::BottomEdge; ff = Plasma::Types::Horizontal; - } else if (lower == QLatin1String("left")) { + } else if (lower == "left") { loc = Plasma::Types::LeftEdge; ff = Plasma::Types::Vertical; - } else if (lower == QLatin1String("right")) { + } else if (lower == "right") { loc = Plasma::Types::RightEdge; ff = Plasma::Types::Vertical; } @@ -120,336 +120,148 @@ PanelView *Panel::panel() const return m_corona->panelView(c); } -QString Panel::alignment() const + +KConfigGroup Panel::panelConfig() const { - PanelView *v = panel(); - if (!v) { - return QStringLiteral("left"); + int screenNum = qMax(screen(), 0); //if we don't have a screen (-1) we'll be put on screen 0 + + if (QGuiApplication::screens().size() < screenNum) { + return KConfigGroup(); } + QScreen *s = QGuiApplication::screens().at(screenNum); + return PanelView::panelConfig(m_corona, containment(), s); +} - switch (v->alignment()) { +QString Panel::alignment() const +{ + switch (panelConfig().readEntry("alignment", 0)) { case Qt::AlignRight: - return QStringLiteral("right"); + return "right"; break; case Qt::AlignCenter: - return QStringLiteral("center"); + return "center"; break; default: - return QStringLiteral("left"); + return "left"; break; } - return QStringLiteral("left"); + return "left"; } void Panel::setAlignment(const QString &alignment) { - Qt::Alignment alignmentValue = Qt::AlignLeft; - - bool success = false; - - if (alignment.compare(QLatin1String("left"), Qt::CaseInsensitive) == 0) { - success = true; - alignmentValue = Qt::AlignLeft; - } else if (alignment.compare(QLatin1String("right"), Qt::CaseInsensitive) == 0) { - success = true; - alignmentValue = Qt::AlignRight; - } else if (alignment.compare(QLatin1String("center"), Qt::CaseInsensitive) == 0) { - success = true; - alignmentValue = Qt::AlignCenter; + int a = Qt::AlignLeft; + if (alignment.compare("right", Qt::CaseInsensitive) == 0) { + a = Qt::AlignRight; + } else if (alignment.compare("center", Qt::CaseInsensitive) == 0) { + a = Qt::AlignCenter; } - if (!success) { - return; - } - - PanelView *v = panel(); - if (v) { - v->setOffset(0); - v->setAlignment(alignmentValue); - } else { - QQuickItem *graphicObject = qobject_cast(containment()->property("_plasma_graphicObject").value()); - - if (!graphicObject) { - return; - } - graphicObject->setProperty("_plasma_desktopscripting_alignment", (int)alignmentValue); + panelConfig().writeEntry("alignment", a); + if (panel()) { + QMetaObject::invokeMethod(panel(), "restore"); } } int Panel::offset() const { - PanelView *v = panel(); - if (v) { - return v->offset(); - } - - return 0; + return panelConfig().readEntry("offset", 0); } void Panel::setOffset(int pixels) { - Plasma::Containment *c = containment(); - if (pixels < 0 || !c) { - return; - } - - QQuickItem *graphicObject = qobject_cast(c->property("_plasma_graphicObject").value()); - - if (!graphicObject) { - return; - } - - PanelView *v = panel(); - if (v) { - QRectF screen = v->screen()->geometry(); - QSizeF size(graphicObject->width(), graphicObject->height()); - - if (c->formFactor() == Plasma::Types::Vertical) { - if (pixels > screen.height()) { - return; - } - - if (size.height() + pixels > screen.height()) { - graphicObject->setWidth(size.width()); - graphicObject->setHeight(screen.height() - pixels); - } - } else if (pixels > screen.width()) { - return; - } else if (size.width() + pixels > screen.width()) { - size.setWidth(screen.width() - pixels); - graphicObject->setWidth(size.width()); - graphicObject->setHeight(size.height()); - v->setMinimumSize(size.toSize()); - v->setMaximumSize(size.toSize()); - } - - v->setOffset(pixels); - } + panelConfig().writeEntry("offset", pixels); + if (panel()) { + QMetaObject::invokeMethod(panel(), "restore"); + } } int Panel::length() const { - Plasma::Containment *c = containment(); - if (!c) { - return 0; - } - QQuickItem *graphicObject = qobject_cast(c->property("_plasma_graphicObject").value()); - - if (!graphicObject) { - return 0; - } - - if (c->formFactor() == Plasma::Types::Vertical) { - return graphicObject->height(); - } else { - return graphicObject->width(); - } + return panelConfig().readEntry("length", 0); } void Panel::setLength(int pixels) { - PanelView *v = panel(); - Plasma::Containment *c = containment(); - - if (!v || !c || pixels < 0 || pixels > v->maximumLength() || pixels < v->minimumLength()) { - return; - } - - QRectF screen = v->screen()->geometry(); - - if (c->formFactor() == Plasma::Types::Vertical - && pixels > screen.height() - v->offset()) { - return; - } else if (pixels > screen.width() - v->offset()) { - return; - } - - v->setLength(pixels); + panelConfig().writeEntry("length", pixels); + if (panel()) { + QMetaObject::invokeMethod(panel(), "restore"); + } } int Panel::minimumLength() const { - PanelView *v = panel(); - - if (v) { - return v->minimumLength(); - } - - return 0; + return panelConfig().readEntry("minLength", 0); } void Panel::setMinimumLength(int pixels) { - PanelView *v = panel(); - Plasma::Containment *c = containment(); - - if (!c || pixels < 0) { - return; - } - - //NOTE: due to dependency of class creation at startup, we can't in any way have - //the panel views already instantiated, so put the property in a placeholder dynamic property - if (!v) { - QQuickItem *graphicObject = qobject_cast(c->property("_plasma_graphicObject").value()); - - if (!graphicObject) { - return; - } - graphicObject->setProperty("_plasma_desktopscripting_minLength", pixels); - return; - } - - QRectF screen = v->screen()->geometry(); - - if (c->formFactor() == Plasma::Types::Vertical - && pixels > screen.height() - v->offset()) { - return; - } else if (pixels > screen.width() - v->offset()) { - return; - } - - v->setMinimumLength(pixels); - - if (v->maximumLength() < pixels) { - v->setMaximumLength(pixels); - } + panelConfig().writeEntry("minLength", pixels); + if (panel()) { + QMetaObject::invokeMethod(panel(), "restore"); + } } int Panel::maximumLength() const { - PanelView *v = panel(); - - if (v) { - return v->maximumLength(); - } - - return 0; + return panelConfig().readEntry("maxLength", 0); } void Panel::setMaximumLength(int pixels) { - PanelView *v = panel(); - Plasma::Containment *c = containment(); - - if (!c || pixels < 0) { - return; - } - - //NOTE: due to dependency of class creation at startup, we can't in any way have - //the panel views already instantiated, so put the property in a placeholder dynamic property - if (!v) { - QQuickItem *graphicObject = qobject_cast(c->property("_plasma_graphicObject").value()); - - if (!graphicObject) { - return; - } - graphicObject->setProperty("_plasma_desktopscripting_maxLength", pixels); - return; - } - - QRectF screen = v->screen()->geometry(); - - if (c->formFactor() == Plasma::Types::Vertical - && pixels > screen.height() - v->offset()) { - return; - } else if (pixels > screen.width() - v->offset()) { - return; - } - - v->setMaximumLength(pixels); - - if (v->minimumLength() > pixels) { - v->setMinimumLength(pixels); - } + panelConfig().writeEntry("maxLength", pixels); + if (panel()) { + QMetaObject::invokeMethod(panel(), "restore"); + } } int Panel::height() const { - Plasma::Containment *c = containment(); - if (!c) { - return 0; - } - - QQuickItem *graphicObject = qobject_cast(c->property("_plasma_graphicObject").value()); - - if (!graphicObject) { - return 0; - } - - return c->formFactor() == Plasma::Types::Vertical ? graphicObject->width() - : graphicObject->height(); + return panelConfig().readEntry("thickness", 0); } void Panel::setHeight(int height) { - Plasma::Containment *c = containment(); - if (height < 16 || !c) { - return; - } - - QQuickItem *graphicObject = qobject_cast(c->property("_plasma_graphicObject").value()); - - if (!graphicObject) { - return; - } - - PanelView *v = panel(); - if (v) { - QRect screen = v->screen()->geometry(); - QSizeF size(graphicObject->width(), graphicObject->height()); - const int max = (c->formFactor() == Plasma::Types::Vertical ? screen.width() : screen.height()) / 3; - height = qBound(16, height, max); - - v->setThickness(height); - } else { - //NOTE: due to dependency of class creation at startup, we can't in any way have - //the panel views already instantiated, so put the property in a placeholder dynamic property - QQuickItem *graphicObject = qobject_cast(c->property("_plasma_graphicObject").value()); - - if (!graphicObject) { - return; - } - graphicObject->setProperty("_plasma_desktopscripting_thickness", height); + panelConfig().writeEntry("thickness", height); + if (panel()) { + QMetaObject::invokeMethod(panel(), "restore"); } } QString Panel::hiding() const { - PanelView *v = panel(); - if (v) { - switch (v->visibilityMode()) { - case PanelView::NormalPanel: - return QStringLiteral("none"); - break; - case PanelView::AutoHide: - return QStringLiteral("autohide"); - break; - case PanelView::LetWindowsCover: - return QStringLiteral("windowscover"); - break; - case PanelView::WindowsGoBelow: - return QStringLiteral("windowsbelow"); - break; - } + switch (panelConfig().readEntry("panelVisibility", 0)) { + case PanelView::NormalPanel: + return "none"; + break; + case PanelView::AutoHide: + return "autohide"; + break; + case PanelView::LetWindowsCover: + return "windowscover"; + break; + case PanelView::WindowsGoBelow: + return "windowsbelow"; + break; } - - return QStringLiteral("none"); + return "none"; } void Panel::setHiding(const QString &mode) { - PanelView *v = panel(); - if (v) { - if (mode.compare(QLatin1String("autohide"), Qt::CaseInsensitive) == 0) { - v->setVisibilityMode(PanelView::AutoHide); - } else if (mode.compare(QLatin1String("windowscover"), Qt::CaseInsensitive) == 0) { - v->setVisibilityMode(PanelView::LetWindowsCover); - } else if (mode.compare(QLatin1String("windowsbelow"), Qt::CaseInsensitive) == 0) { - v->setVisibilityMode(PanelView::WindowsGoBelow); - } else { - v->setVisibilityMode(PanelView::NormalPanel); - } + PanelView::VisibilityMode visibilityMode = PanelView::NormalPanel; + if (mode.compare("autohide", Qt::CaseInsensitive) == 0) { + visibilityMode = PanelView::AutoHide; + } else if (mode.compare("windowscover", Qt::CaseInsensitive) == 0) { + visibilityMode = PanelView::LetWindowsCover; + } else if (mode.compare("windowsbelow", Qt::CaseInsensitive) == 0) { + visibilityMode = PanelView::WindowsGoBelow; + } + + panelConfig().writeEntry("panelVisibility", (int)visibilityMode); + if (panel()) { + QMetaObject::invokeMethod(panel(), "restore"); } } diff --git a/shell/scripting/panel.h b/shell/scripting/panel.h index f7279100a..32368ea83 100644 --- a/shell/scripting/panel.h +++ b/shell/scripting/panel.h @@ -100,6 +100,7 @@ public Q_SLOTS: private: PanelView *panel() const; + KConfigGroup panelConfig() const; ShellCorona *m_corona; };