diff --git a/fullscreenwindow.cpp b/fullscreenwindow.cpp index b8ddf80e1..a47da9139 100644 --- a/fullscreenwindow.cpp +++ b/fullscreenwindow.cpp @@ -1,113 +1,146 @@ /*************************************************************************** * Copyright (C) 2015 by Eike Hein * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include "fullscreenwindow.h" #include #include #include #include FullScreenWindow::FullScreenWindow(QQuickItem *parent) : QQuickWindow(parent ? parent->window() : 0) , m_mainItem(0) +, m_visualParentItem(0) +, m_visualParentWindow(0) { setClearBeforeRendering(true); setColor(QColor(0, 0, 0, 188)); setFlags(Qt::FramelessWindowHint); setIcon(QIcon::fromTheme("plasma")); connect(&m_theme, &Plasma::Theme::themeChanged, this, &FullScreenWindow::updateTheme); - - if (parent && parent->window()) { - connect(parent->window(), &QWindow::screenChanged, this, &FullScreenWindow::parentScreenChanged); - } } FullScreenWindow::~FullScreenWindow() { } QQuickItem *FullScreenWindow::mainItem() const { return m_mainItem; } -void FullScreenWindow::setMainItem(QQuickItem *mainItem) +void FullScreenWindow::setMainItem(QQuickItem *item) { - if (m_mainItem != mainItem) { + if (m_mainItem != item) { if (m_mainItem) { m_mainItem->setVisible(false); } - m_mainItem = mainItem; + m_mainItem = item; - if (mainItem) { + if (m_mainItem) { m_mainItem->setVisible(isVisible()); m_mainItem->setParentItem(contentItem()); } emit mainItemChanged(); } } +QQuickItem *FullScreenWindow::visualParent() const +{ + return m_visualParentItem; +} + +void FullScreenWindow::setVisualParent(QQuickItem *item) +{ + if (m_visualParentItem != item) { + if (m_visualParentItem) { + disconnect(m_mainItem, &QQuickItem::windowChanged, this, &FullScreenWindow::visualParentWindowChanged); + } + + m_visualParentItem = item; + + if (m_visualParentItem) { + connect(m_mainItem, &QQuickItem::windowChanged, this, &FullScreenWindow::visualParentWindowChanged); + } + + emit visualParentChanged(); + } +} + void FullScreenWindow::toggle() { if (isVisible()) { close(); } else { resize(screen()->size()); showFullScreen(); } } void FullScreenWindow::showEvent(QShowEvent *event) { updateTheme(); if (m_mainItem) { m_mainItem->setVisible(true); } QQuickWindow::showEvent(event); KWindowSystem::setState(winId(), NET::SkipTaskbar | NET::SkipPager); } void FullScreenWindow::hideEvent(QHideEvent *event) { if (m_mainItem) { m_mainItem->setVisible(false); } QQuickWindow::hideEvent(event); } void FullScreenWindow::updateTheme() { KWindowEffects::enableBlurBehind(winId(), true); } -void FullScreenWindow::parentScreenChanged(const QScreen *screen) +void FullScreenWindow::visualParentWindowChanged(QQuickWindow *window) +{ + if (m_visualParentWindow) { + disconnect(m_visualParentWindow, &QQuickWindow::screenChanged, this, &FullScreenWindow::visualParentScreenChanged); + } + + m_visualParentWindow = window; + + if (m_visualParentWindow) { + connect(m_visualParentWindow, &QQuickWindow::screenChanged, this, &FullScreenWindow::visualParentScreenChanged); + } +} + +void FullScreenWindow::visualParentScreenChanged(QScreen *screen) { if (screen) { setScreen(parent()->screen()); resize(screen->size()); } } diff --git a/fullscreenwindow.h b/fullscreenwindow.h index 01ea92f49..c10c19d7d 100644 --- a/fullscreenwindow.h +++ b/fullscreenwindow.h @@ -1,61 +1,69 @@ /*************************************************************************** * Copyright (C) 2015 by Eike Hein * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #ifndef FULLSCREENWINDOW_H #define FULLSCREENWINDOW_H #include #include #include class FullScreenWindow : public QQuickWindow { Q_OBJECT Q_PROPERTY(QQuickItem* mainItem READ mainItem WRITE setMainItem NOTIFY mainItemChanged) + Q_PROPERTY(QQuickItem* visualParent READ visualParent WRITE setVisualParent NOTIFY visualParentChanged) Q_CLASSINFO("DefaultProperty", "mainItem") public: FullScreenWindow(QQuickItem *parent = 0); ~FullScreenWindow(); QQuickItem *mainItem() const; - void setMainItem(QQuickItem *mainItem); + void setMainItem(QQuickItem *item); + + QQuickItem *visualParent() const; + void setVisualParent(QQuickItem *item); Q_INVOKABLE void toggle(); Q_SIGNALS: void mainItemChanged() const; + void visualParentChanged() const; private Q_SLOTS: void updateTheme(); - void parentScreenChanged(const QScreen *screen); + void visualParentWindowChanged(QQuickWindow *window); + void visualParentScreenChanged(QScreen *screen); protected: void showEvent(QShowEvent *event) Q_DECL_OVERRIDE; void hideEvent(QHideEvent *event) Q_DECL_OVERRIDE; private: QQuickItem *m_mainItem; + QPointer m_visualParentItem; + QPointer m_visualParentWindow; Plasma::Theme m_theme; }; #endif