From 47cf35720fc73be59707bc520b7bdfbe93cb0c2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 5 Aug 2013 14:08:23 +0200 Subject: [PATCH] Present Window's close button ported to QtQuick 2 --- effects/CMakeLists.txt | 1 + effects/presentwindows/main.qml | 9 +++--- effects/presentwindows/presentwindows.cpp | 34 ++++++++--------------- effects/presentwindows/presentwindows.h | 8 +++--- 4 files changed, 21 insertions(+), 31 deletions(-) diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt index 4190d47f5d..7ab4ba1f34 100644 --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -13,6 +13,7 @@ set(kwin_effect_KDE_LIBS set(kwin_effect_QT_LIBS ${Qt5Declarative_LIBRARIES} + ${Qt5Quick_LIBRARIES} ${Qt5X11Extras_LIBRARIES} ${Qt5DBus_LIBRARIES} ) diff --git a/effects/presentwindows/main.qml b/effects/presentwindows/main.qml index e456a48a30..83af6c07c8 100644 --- a/effects/presentwindows/main.qml +++ b/effects/presentwindows/main.qml @@ -17,16 +17,17 @@ 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 . *********************************************************************/ -import QtQuick 1.1 -import org.kde.plasma.components 0.1 as Plasma +import QtQuick 2.0 +import org.kde.plasma.components 2.0 as Plasma Item { + width: 32 + height: 32 Plasma.Button { id: closeButton objectName: "closeButton" enabled: armed - width: 32 - height: 32 iconSource: "window-close" + anchors.fill: parent } } diff --git a/effects/presentwindows/presentwindows.cpp b/effects/presentwindows/presentwindows.cpp index c682b9a8cb..21e125e54e 100755 --- a/effects/presentwindows/presentwindows.cpp +++ b/effects/presentwindows/presentwindows.cpp @@ -41,8 +41,9 @@ along with this program. If not, see . #include #include #include -#include -#include +#include +#include +#include #include #include #include @@ -1478,7 +1479,7 @@ void PresentWindowsEffect::setActive(bool active) if (!m_doNotCloseWindows) { m_closeView = new CloseWindowView(); - connect(m_closeView, SIGNAL(close()), SLOT(closeWindow())); + connect(m_closeView, &CloseWindowView::requestClose, this, &PresentWindowsEffect::closeWindow); } // Add every single window to m_windowData (Just calling [w] creates it) @@ -1690,12 +1691,12 @@ void PresentWindowsEffect::updateCloseWindow() return; const QRectF rect(m_motionManager.targetGeometry(m_highlightedWindow)); - if (2*m_closeView->sceneRect().width() > rect.width() && 2*m_closeView->sceneRect().height() > rect.height()) { + if (2*m_closeView->width() > rect.width() && 2*m_closeView->height() > rect.height()) { // not for tiny windows (eg. with many windows) - they might become unselectable m_closeView->hide(); return; } - QRect cvr(QPoint(0,0), m_closeView->sceneRect().size().toSize()); + QRect cvr(QPoint(0,0), m_closeView->size()); switch (m_closeButtonCorner) { case Qt::TopLeftCorner: @@ -1938,31 +1939,18 @@ void PresentWindowsEffect::screenCountChanged() /************************************************ * CloseWindowView ************************************************/ -CloseWindowView::CloseWindowView(QWidget *parent) - : QDeclarativeView(parent) +CloseWindowView::CloseWindowView(QWindow *parent) + : QQuickView(parent) , m_armTimer(new QTimer(this)) { - setWindowFlags(Qt::X11BypassWindowManagerHint); - setAttribute(Qt::WA_TranslucentBackground); - QPalette pal = palette(); - pal.setColor(backgroundRole(), Qt::transparent); - setPalette(pal); - for (const QString &importPath : KGlobal::dirs()->findDirs("module", QStringLiteral("imports"))) { - engine()->addImportPath(importPath); - } -#warning Port declarative code to QtQuick2 -#if KWIN_QT5_PORTING - KDeclarative kdeclarative; - kdeclarative.setDeclarativeEngine(engine()); - kdeclarative.initialize(); - kdeclarative.setupBindings(); -#endif + setFlags(Qt::X11BypassWindowManagerHint); + setColor(Qt::transparent); rootContext()->setContextProperty(QStringLiteral("armed"), QVariant(false)); setSource(QUrl(KStandardDirs::locate("data", QStringLiteral("kwin/effects/presentwindows/main.qml")))); if (QObject *item = rootObject()->findChild(QStringLiteral("closeButton"))) { - connect(item, SIGNAL(clicked()), SIGNAL(close())); + connect(item, SIGNAL(clicked()), SIGNAL(requestClose())); } // setup the timer - attempt to prevent accidental clicks diff --git a/effects/presentwindows/presentwindows.h b/effects/presentwindows/presentwindows.h index dc319ffb91..1733d029d1 100644 --- a/effects/presentwindows/presentwindows.h +++ b/effects/presentwindows/presentwindows.h @@ -26,24 +26,24 @@ along with this program. If not, see . #include #include -#include +#include class QTimer; namespace KWin { -class CloseWindowView : public QDeclarativeView +class CloseWindowView : public QQuickView { Q_OBJECT public: - explicit CloseWindowView(QWidget *parent = 0); + explicit CloseWindowView(QWindow *parent = 0); void windowInputMouseEvent(QMouseEvent* e); void disarm(); public Q_SLOTS: void arm(); Q_SIGNALS: - void close(); + void requestClose(); private: QTimer* m_armTimer;