From 3028076db2c2bfa275c708ead8ef94be4520e92a Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Wed, 26 Jul 2017 09:25:56 +0300 Subject: [PATCH] add a special Latte info window / view --it is used mainly for presenting a Latte specific info window when changing dynamically layouts --- app/CMakeLists.txt | 1 + app/dockconfigview.h | 4 +- app/infoview.cpp | 226 +++++++++++++++++++++++++++++++++++++++++++ app/infoview.h | 68 +++++++++++++ 4 files changed, 297 insertions(+), 2 deletions(-) create mode 100644 app/infoview.cpp create mode 100644 app/infoview.h diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 175bf85e1..5ecc22aaa 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -23,6 +23,7 @@ set(lattedock-app_SRCS layoutsDelegates/colorcmbboxdelegate.cpp layoutsDelegates/colorcmbboxitemdelegate.cpp layoutsDelegates/activitycmbboxdelegate.cpp + infoview.cpp main.cpp ) diff --git a/app/dockconfigview.h b/app/dockconfigview.h index 2fafb04d9..6758b93e6 100644 --- a/app/dockconfigview.h +++ b/app/dockconfigview.h @@ -18,8 +18,8 @@ * along with this program. If not, see . */ -#ifndef NOWDOCKCONFIGVIEW_H -#define NOWDOCKCONFIGVIEW_H +#ifndef DOCKCONFIGVIEW_H +#define DOCKCONFIGVIEW_H #include "plasmaquick/configview.h" #include "../liblattedock/dock.h" diff --git a/app/infoview.cpp b/app/infoview.cpp new file mode 100644 index 000000000..18ffb9e68 --- /dev/null +++ b/app/infoview.cpp @@ -0,0 +1,226 @@ +/* +* Copyright 2016 Smith AR +* Michail Vourlakos +* +* This file is part of Latte-Dock +* +* Latte-Dock 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. +* +* Latte-Dock 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, see . +*/ + +#include "infoview.h" +#include "panelshadows_p.h" +#include "abstractwindowinterface.h" + +#include +#include +#include +#include + +#include +#include + +#include + +#include +#include + +namespace Latte { + +InfoView::InfoView(DockCorona *corona, QString message, QScreen *screen, QWindow *parent) + : QQuickView(parent), + m_corona(corona), + m_message(message), + m_screen(screen) +{ + setupWaylandIntegration(); + + setResizeMode(QQuickView::SizeViewToRootObject); + setColor(QColor(Qt::transparent)); + setIcon(qGuiApp->windowIcon()); + + setScreen(screen); + setFlags(wFlags()); + syncGeometry(); + + init(); +} + +InfoView::~InfoView() +{ + qDebug() << "InfoView deleting ..."; + + if (m_shellSurface) { + delete m_shellSurface; + m_shellSurface = nullptr; + } + +} + +void InfoView::init() +{ + setDefaultAlphaBuffer(true); + setColor(Qt::transparent); + PanelShadows::self()->addWindow(this); + + KDeclarative::KDeclarative kdeclarative; + kdeclarative.setDeclarativeEngine(engine()); + kdeclarative.setTranslationDomain(QStringLiteral("latte-dock")); + kdeclarative.setupBindings(); + auto source = QUrl::fromLocalFile(m_corona->kPackage().filePath("infoviewui")); + setSource(source); + rootObject()->setProperty("message", m_message); + + syncGeometry(); +} + +inline Qt::WindowFlags InfoView::wFlags() const +{ + return (flags() | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint) & ~Qt::WindowDoesNotAcceptFocus; +} + +void InfoView::syncGeometry() +{ + /*if (!m_dockView->containment() || !rootObject()) + return; + + const auto location = m_dockView->containment()->location(); + const auto sGeometry = screen()->geometry(); + + int clearThickness = m_dockView->normalThickness(); + + QPoint position{0, 0}; + + switch (m_dockView->containment()->formFactor()) { + case Plasma::Types::Horizontal: { + const QSize size(rootObject()->width(), rootObject()->height()); + setMaximumSize(size); + setMinimumSize(size); + resize(size); + + if (location == Plasma::Types::TopEdge) { + position = {sGeometry.center().x() - size.width() / 2 + , sGeometry.y() + clearThickness + }; + } else if (location == Plasma::Types::BottomEdge) { + position = {sGeometry.center().x() - size.width() / 2 + , sGeometry.y() + sGeometry.height() - clearThickness - size.height() + }; + } + } + break; + + case Plasma::Types::Vertical: { + const QSize size(rootObject()->width(), rootObject()->height()); + setMaximumSize(size); + setMinimumSize(size); + resize(size); + + if (location == Plasma::Types::LeftEdge) { + position = {sGeometry.x() + clearThickness + , sGeometry.center().y() - size.height() / 2 + }; + } else if (location == Plasma::Types::RightEdge) { + position = {sGeometry.x() + sGeometry.width() - clearThickness - size.width() + , sGeometry.center().y() - size.height() / 2 + }; + } + } + break; + + default: + qWarning() << "no sync geometry, wrong formFactor"; + break; + } + + setPosition(position); + + if (m_shellSurface) { + m_shellSurface->setPosition(position); + }*/ +} + +void InfoView::showEvent(QShowEvent *ev) +{ + QQuickWindow::showEvent(ev); + + WindowSystem::self().setDockExtraFlags(*this); + setFlags(wFlags()); + + WindowSystem::self().enableBlurBehind(*this); + + syncGeometry(); + + QTimer::singleShot(400, this, &InfoView::syncGeometry); +} + +void InfoView::setupWaylandIntegration() +{ + if (m_shellSurface) { + // already setup + return; + } + + if (m_corona) { + using namespace KWayland::Client; + PlasmaShell *interface = m_corona->waylandDockCoronaInterface(); + + if (!interface) { + return; + } + + Surface *s = Surface::fromWindow(this); + + if (!s) { + return; + } + + qDebug() << "wayland dock window surface was created..."; + + m_shellSurface = interface->createSurface(s, this); + + syncGeometry(); + } +} + +bool InfoView::event(QEvent *e) +{ + if (e->type() == QEvent::PlatformSurface) { + if (auto pe = dynamic_cast(e)) { + switch (pe->surfaceEventType()) { + case QPlatformSurfaceEvent::SurfaceCreated: + + if (m_shellSurface) { + break; + } + + setupWaylandIntegration(); + break; + + case QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed: + if (m_shellSurface) { + delete m_shellSurface; + m_shellSurface = nullptr; + } + + PanelShadows::self()->removeWindow(this); + break; + } + } + } + + return InfoView::event(e); +} + +} +// kate: indent-mode cstyle; indent-width 4; replace-tabs on; diff --git a/app/infoview.h b/app/infoview.h new file mode 100644 index 000000000..c68996266 --- /dev/null +++ b/app/infoview.h @@ -0,0 +1,68 @@ +/* +* Copyright 2016 Smith AR +* Michail Vourlakos +* +* This file is part of Latte-Dock +* +* Latte-Dock 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. +* +* Latte-Dock 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, see . +*/ + +#ifndef INFOVIEW_H +#define INFOVIEW_H + +#include "dockcorona.h" + +#include +#include + +namespace KWayland { +namespace Client { +class PlasmaShellSurface; +} +} + +namespace Latte { + +class InfoView : public QQuickView { + Q_OBJECT + +public: + InfoView(DockCorona *corona, QString message, QScreen *screen = qGuiApp->primaryScreen(), QWindow *parent = nullptr); + ~InfoView() override; + + void init(); + Qt::WindowFlags wFlags() const; + +public slots: + Q_INVOKABLE void syncGeometry(); + +protected: + void showEvent(QShowEvent *ev) override; + bool event(QEvent *e) override; + +private: + void setupWaylandIntegration(); + +private: + QString m_message; + + QScreen *m_screen; + KWayland::Client::PlasmaShellSurface *m_shellSurface{nullptr}; + + DockCorona *m_corona; +}; + +} +#endif //DOCKCONFIGVIEW_H +// kate: indent-mode cstyle; indent-width 4; replace-tabs on;