From 245f84d835394a7c46eed58553de65bb9f95d408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Sun, 27 Nov 2011 15:00:09 +0100 Subject: [PATCH] Close windows from TabBox QML Model exposes a method to close a window by index which is invoked by the window strip QML. --- tabbox/clientmodel.cpp | 9 +++++++++ tabbox/clientmodel.h | 4 ++++ tabbox/qml/window_strip.qml | 8 +------- tabbox/tabbox.cpp | 4 ++++ tabbox/tabbox.h | 1 + tabbox/tabboxhandler.h | 1 + 6 files changed, 20 insertions(+), 7 deletions(-) diff --git a/tabbox/clientmodel.cpp b/tabbox/clientmodel.cpp index 361d3d20ff..541d957b0d 100644 --- a/tabbox/clientmodel.cpp +++ b/tabbox/clientmodel.cpp @@ -235,5 +235,14 @@ void ClientModel::createClientList(int desktop, bool partialReset) reset(); } +void ClientModel::close(int i) +{ + QModelIndex ind = index(i, 0); + if (!ind.isValid()) { + return; + } + m_clientList.at(i)->close(); +} + } // namespace Tabbox } // namespace KWin diff --git a/tabbox/clientmodel.h b/tabbox/clientmodel.h index fb53ae371e..c091c7c096 100644 --- a/tabbox/clientmodel.h +++ b/tabbox/clientmodel.h @@ -46,6 +46,7 @@ namespace TabBox class ClientModel : public QAbstractItemModel { + Q_OBJECT public: enum { ClientRole = Qt::UserRole, ///< The TabBoxClient @@ -95,6 +96,9 @@ public: return m_clientList; } +public Q_SLOTS: + void close(int index); + private: TabBoxClientList m_clientList; }; diff --git a/tabbox/qml/window_strip.qml b/tabbox/qml/window_strip.qml index 8abe7609ab..f735061db4 100644 --- a/tabbox/qml/window_strip.qml +++ b/tabbox/qml/window_strip.qml @@ -135,13 +135,7 @@ Item { rightMargin: parent.margins.right } - onClicked: { - console.log("Close button clicked") - /*var service = tasksSource.serviceForSource(winId) - var operation = service.operationDescription("close") - - service.startOperationCall(operation)*/ - } + onClicked: thumbnailListView.model.close(index) } } } diff --git a/tabbox/tabbox.cpp b/tabbox/tabbox.cpp index 09e98b3a97..31080f8ac8 100644 --- a/tabbox/tabbox.cpp +++ b/tabbox/tabbox.cpp @@ -275,6 +275,10 @@ bool TabBoxClientImpl::isCloseable() const return m_client->isCloseable(); } +void TabBoxClientImpl::close() +{ + m_client->closeWindow(); +} /********************************************************* * TabBox diff --git a/tabbox/tabbox.h b/tabbox/tabbox.h index 27e3d908dd..41b9243453 100644 --- a/tabbox/tabbox.h +++ b/tabbox/tabbox.h @@ -81,6 +81,7 @@ public: virtual int width() const; virtual int height() const; virtual bool isCloseable() const; + virtual void close(); Client* client() const { return m_client; diff --git a/tabbox/tabboxhandler.h b/tabbox/tabboxhandler.h index ed4bb9a366..6b67f497c1 100644 --- a/tabbox/tabboxhandler.h +++ b/tabbox/tabboxhandler.h @@ -385,6 +385,7 @@ public: virtual int width() const = 0; virtual int height() const = 0; virtual bool isCloseable() const = 0; + virtual void close() = 0; }; /**