diff --git a/fullscreenwindow.cpp b/dashboardwindow.cpp similarity index 63% rename from fullscreenwindow.cpp rename to dashboardwindow.cpp index 715ddd3ee..1b0f9b5b5 100644 --- a/fullscreenwindow.cpp +++ b/dashboardwindow.cpp @@ -1,155 +1,200 @@ /*************************************************************************** * 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 "dashboardwindow.h" +#include #include #include #include #include -FullScreenWindow::FullScreenWindow(QQuickItem *parent) : QQuickWindow(parent ? parent->window() : 0) +DashboardWindow::DashboardWindow(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); + connect(&m_theme, &Plasma::Theme::themeChanged, this, &DashboardWindow::updateTheme); } -FullScreenWindow::~FullScreenWindow() +DashboardWindow::~DashboardWindow() { } -QQuickItem *FullScreenWindow::mainItem() const +QQuickItem *DashboardWindow::mainItem() const { return m_mainItem; } -void FullScreenWindow::setMainItem(QQuickItem *item) +void DashboardWindow::setMainItem(QQuickItem *item) { if (m_mainItem != item) { if (m_mainItem) { m_mainItem->setVisible(false); } m_mainItem = item; if (m_mainItem) { m_mainItem->setVisible(isVisible()); m_mainItem->setParentItem(contentItem()); } emit mainItemChanged(); } } -QQuickItem *FullScreenWindow::visualParent() const +QQuickItem *DashboardWindow::visualParent() const { return m_visualParentItem; } -void FullScreenWindow::setVisualParent(QQuickItem *item) +void DashboardWindow::setVisualParent(QQuickItem *item) { if (m_visualParentItem != item) { if (m_visualParentItem) { - disconnect(m_visualParentItem.data(), &QQuickItem::windowChanged, this, &FullScreenWindow::visualParentWindowChanged); + disconnect(m_visualParentItem.data(), &QQuickItem::windowChanged, this, &DashboardWindow::visualParentWindowChanged); } m_visualParentItem = item; if (m_visualParentItem) { if (m_visualParentItem->window()) { visualParentWindowChanged(m_visualParentItem->window()); } - connect(m_visualParentItem.data(), &QQuickItem::windowChanged, this, &FullScreenWindow::visualParentWindowChanged); + connect(m_visualParentItem.data(), &QQuickItem::windowChanged, this, &DashboardWindow::visualParentWindowChanged); } emit visualParentChanged(); } } -void FullScreenWindow::toggle() { +QQuickItem *DashboardWindow::keyEventProxy() const +{ + return m_keyEventProxy; +} + +void DashboardWindow::setKeyEventProxy(QQuickItem *item) +{ + if (m_keyEventProxy != item) { + m_keyEventProxy = item; + + emit keyEventProxyChanged(); + } +} + +void DashboardWindow::toggle() { if (isVisible()) { close(); } else { resize(screen()->size()); showFullScreen(); KWindowSystem::forceActiveWindow(winId()); } } -bool FullScreenWindow::event(QEvent *event) +bool DashboardWindow::event(QEvent *event) { if (event->type() == QEvent::Expose) { KWindowSystem::setState(winId(), NET::SkipTaskbar | NET::SkipPager); } else if (event->type() == QEvent::Show) { updateTheme(); if (m_mainItem) { m_mainItem->setVisible(true); } } else if (event->type() == QEvent::Hide) { if (m_mainItem) { m_mainItem->setVisible(false); } } else if (event->type() == QEvent::FocusOut) { if (isVisible()) { KWindowSystem::raiseWindow(winId()); KWindowSystem::forceActiveWindow(winId()); } } return QQuickWindow::event(event); } -void FullScreenWindow::updateTheme() +void DashboardWindow::keyPressEvent(QKeyEvent *e) +{ + if (e->key() == Qt::Key_Escape) { + toggle(); + + return; + } else if (m_keyEventProxy && !m_keyEventProxy->hasActiveFocus() + && !(e->key() == Qt::Key_Home) + && !(e->key() == Qt::Key_End) + && !(e->key() == Qt::Key_Left) + && !(e->key() == Qt::Key_Up) + && !(e->key() == Qt::Key_Right) + && !(e->key() == Qt::Key_Down) + && !(e->key() == Qt::Key_PageUp) + && !(e->key() == Qt::Key_PageDown) + && !(e->key() == Qt::Key_Enter) + && !(e->key() == Qt::Key_Return) + && !(e->key() == Qt::Key_Menu)) { + m_keyEventProxy->forceActiveFocus(); + QEvent* eventCopy = new QKeyEvent(e->type(), e->key(), e->modifiers(), + e->nativeScanCode(), e->nativeVirtualKey(), e->nativeModifiers(), + e->text(), e->isAutoRepeat(), e->count()); + QCoreApplication::postEvent(this, eventCopy); + + return; + } + + QQuickWindow::keyPressEvent(e); +} + +void DashboardWindow::updateTheme() { KWindowEffects::enableBlurBehind(winId(), true); } -void FullScreenWindow::visualParentWindowChanged(QQuickWindow *window) +void DashboardWindow::visualParentWindowChanged(QQuickWindow *window) { if (m_visualParentWindow) { - disconnect(m_visualParentWindow.data(), &QQuickWindow::screenChanged, this, &FullScreenWindow::visualParentScreenChanged); + disconnect(m_visualParentWindow.data(), &QQuickWindow::screenChanged, this, &DashboardWindow::visualParentScreenChanged); } m_visualParentWindow = window; if (m_visualParentWindow) { visualParentScreenChanged(m_visualParentWindow->screen()); - connect(m_visualParentWindow.data(), &QQuickWindow::screenChanged, this, &FullScreenWindow::visualParentScreenChanged); + connect(m_visualParentWindow.data(), &QQuickWindow::screenChanged, this, &DashboardWindow::visualParentScreenChanged); } } -void FullScreenWindow::visualParentScreenChanged(QScreen *screen) +void DashboardWindow::visualParentScreenChanged(QScreen *screen) { if (screen) { setScreen(screen); setGeometry(screen->geometry()); } } diff --git a/fullscreenwindow.h b/dashboardwindow.h similarity index 82% rename from fullscreenwindow.h rename to dashboardwindow.h index 52e248f94..c6eb3d9be 100644 --- a/fullscreenwindow.h +++ b/dashboardwindow.h @@ -1,68 +1,75 @@ /*************************************************************************** * 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 +#ifndef DASHBOARDWINDOW_H +#define DASHBOARDWINDOW_H #include #include #include -class FullScreenWindow : public QQuickWindow +class DashboardWindow : 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_PROPERTY(QQuickItem* keyEventProxy READ keyEventProxy WRITE setKeyEventProxy NOTIFY keyEventProxyChanged) Q_CLASSINFO("DefaultProperty", "mainItem") public: - FullScreenWindow(QQuickItem *parent = 0); - ~FullScreenWindow(); + DashboardWindow(QQuickItem *parent = 0); + ~DashboardWindow(); QQuickItem *mainItem() const; void setMainItem(QQuickItem *item); QQuickItem *visualParent() const; void setVisualParent(QQuickItem *item); + QQuickItem *keyEventProxy() const; + void setKeyEventProxy(QQuickItem *item); + Q_INVOKABLE void toggle(); Q_SIGNALS: void mainItemChanged() const; void visualParentChanged() const; + void keyEventProxyChanged() const; private Q_SLOTS: void updateTheme(); void visualParentWindowChanged(QQuickWindow *window); void visualParentScreenChanged(QScreen *screen); protected: bool event(QEvent *event) Q_DECL_OVERRIDE; + void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE; private: QQuickItem *m_mainItem; QPointer m_visualParentItem; QPointer m_visualParentWindow; + QPointer m_keyEventProxy; Plasma::Theme m_theme; }; #endif diff --git a/kickerplugin.cpp b/kickerplugin.cpp index d8084fecb..96872e62c 100644 --- a/kickerplugin.cpp +++ b/kickerplugin.cpp @@ -1,61 +1,61 @@ /*************************************************************************** * Copyright (C) 2014 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 "kickerplugin.h" #include "abstractmodel.h" #include "appsmodel.h" #include "computermodel.h" #include "draghelper.h" #include "favoritesmodel.h" -#include "fullscreenwindow.h" +#include "dashboardwindow.h" #include "funnelmodel.h" #include "processrunner.h" #include "recentusagemodel.h" #include "rootmodel.h" #include "runnermodel.h" #include "submenu.h" #include "systemmodel.h" #include "systemsettings.h" #include "wheelinterceptor.h" #include "windowsystem.h" #include void KickerPlugin::registerTypes(const char *uri) { Q_ASSERT(uri == QLatin1String("org.kde.plasma.private.kicker")); qmlRegisterType(); qmlRegisterType(uri, 0, 1, "AppsModel"); qmlRegisterType(uri, 0, 1, "ComputerModel"); qmlRegisterType(uri, 0, 1, "DragHelper"); qmlRegisterType(uri, 0, 1, "FavoritesModel"); - qmlRegisterType(uri, 0, 1, "FullScreenWindow"); + qmlRegisterType(uri, 0, 1, "DashboardWindow"); qmlRegisterType(uri, 0, 1, "FunnelModel"); qmlRegisterType(uri, 0, 1, "ProcessRunner"); qmlRegisterType(uri, 0, 1, "RecentUsageModel"); qmlRegisterType(uri, 0, 1, "RootModel"); qmlRegisterType(uri, 0, 1, "RunnerModel"); qmlRegisterType(uri, 0, 1, "SubMenu"); qmlRegisterType(uri, 0, 1, "SystemModel"); qmlRegisterType(uri, 0, 1, "SystemSettings"); qmlRegisterType(uri, 0, 1, "WheelInterceptor"); qmlRegisterType(uri, 0, 1, "WindowSystem"); }