From 8b9e7f56cf2798db848f52687ba71c5e213aadca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 31 Oct 2011 14:34:37 +0100 Subject: [PATCH] Pass mouse events to declarative Tabbox The ListViews have therefore to emit a signal when the item changed due to a mouse click event. --- events.cpp | 3 +-- tabbox/declarative.cpp | 6 +++++ tabbox/declarative.h | 1 + tabbox/qml/IconTabBox.qml | 6 ++++- tabbox/qml/compact.qml | 6 ++++- tabbox/qml/informative.qml | 6 ++++- tabbox/qml/text.qml | 6 ++++- tabbox/tabbox.cpp | 47 +++++++++++++++++++++++--------------- tabbox/tabbox.h | 3 +-- tabbox/tabboxhandler.cpp | 8 +++++++ tabbox/tabboxhandler.h | 4 ++++ 11 files changed, 69 insertions(+), 27 deletions(-) diff --git a/events.cpp b/events.cpp index 4001347332..b18e2caa04 100644 --- a/events.cpp +++ b/events.cpp @@ -242,8 +242,7 @@ bool Workspace::workspaceEvent(XEvent * e) case MotionNotify: #ifdef KWIN_BUILD_TABBOX if (tabBox()->isGrabbed()) { - tab_box->handleMouseEvent(e); - return true; + return tab_box->handleMouseEvent(e); } #endif if (effects && static_cast(effects)->checkInputWindowEvent(e)) diff --git a/tabbox/declarative.cpp b/tabbox/declarative.cpp index 1567497137..1567964d99 100644 --- a/tabbox/declarative.cpp +++ b/tabbox/declarative.cpp @@ -126,6 +126,7 @@ void DeclarativeView::showEvent(QShowEvent *event) if (QObject *item = rootObject()->findChild("listView")) { item->setProperty("currentIndex", tabBox->first().row()); + connect(item, SIGNAL(currentIndexChanged(int)), SLOT(currentIndexChanged(int))); } slotUpdateGeometry(); QGraphicsView::showEvent(event); @@ -176,6 +177,11 @@ QModelIndex DeclarativeView::indexAt(const QPoint &pos) const return QModelIndex(); } +void DeclarativeView::currentIndexChanged(int row) +{ + tabBox->setCurrentIndex(m_model->index(row, 0)); +} + void DeclarativeView::updateQmlSource() { if (tabBox->config().layoutName() == m_currentLayout) { diff --git a/tabbox/declarative.h b/tabbox/declarative.h index b9befb5883..56740549e4 100644 --- a/tabbox/declarative.h +++ b/tabbox/declarative.h @@ -62,6 +62,7 @@ public Q_SLOTS: void slotUpdateGeometry(); private Q_SLOTS: void updateQmlSource(); + void currentIndexChanged(int row); private: QAbstractItemModel *m_model; QRect m_currentScreenGeometry; diff --git a/tabbox/qml/IconTabBox.qml b/tabbox/qml/IconTabBox.qml index 9f5a2c85e8..298068f3ca 100644 --- a/tabbox/qml/IconTabBox.qml +++ b/tabbox/qml/IconTabBox.qml @@ -81,6 +81,7 @@ Item { function indexAtMousePos(pos) { return iconsListView.indexAt(pos.x, pos.y); } + signal currentIndexChanged(int index) id: iconsListView objectName: "listView" orientation: ListView.Horizontal @@ -100,7 +101,10 @@ Item { } MouseArea { anchors.fill: parent - onClicked: iconsListView.currentIndex = iconsListView.indexAt(mouse.x, mouse.y) + onClicked: { + iconsListView.currentIndex = iconsListView.indexAt(mouse.x, mouse.y); + iconsListView.currentIndexChanged(iconsListView.currentIndex); + } } } } diff --git a/tabbox/qml/compact.qml b/tabbox/qml/compact.qml index 3e57c7e183..0d8469d362 100644 --- a/tabbox/qml/compact.qml +++ b/tabbox/qml/compact.qml @@ -165,6 +165,7 @@ Item { function indexAtMousePos(pos) { return compactListView.indexAt(pos.x, pos.y); } + signal currentIndexChanged(int index) id: compactListView objectName: "listView" // the maximum text width + icon item width (32 + 4 margin) + margins for hover item + margins for background @@ -189,7 +190,10 @@ Item { } MouseArea { anchors.fill: parent - onClicked: compactListView.currentIndex = compactListView.indexAt(mouse.x, mouse.y) + onClicked: { + compactListView.currentIndex = compactListView.indexAt(mouse.x, mouse.y); + compactListView.currentIndexChanged(compactListView.currentIndex); + } } } } diff --git a/tabbox/qml/informative.qml b/tabbox/qml/informative.qml index e65d0e33fb..b2a9f5eb96 100644 --- a/tabbox/qml/informative.qml +++ b/tabbox/qml/informative.qml @@ -181,6 +181,7 @@ Item { function indexAtMousePos(pos) { return listView.indexAt(pos.x, pos.y); } + signal currentIndexChanged(int index) id: listView objectName: "listView" // the maximum text width + icon item width (32 + 4 margin) + margins for hover item + margins for background @@ -205,7 +206,10 @@ Item { } MouseArea { anchors.fill: parent - onClicked: listView.currentIndex = listView.indexAt(mouse.x, mouse.y) + onClicked: { + listView.currentIndex = listView.indexAt(mouse.x, mouse.y); + listView.currentIndexChanged(listView.currentIndex); + } } } } diff --git a/tabbox/qml/text.qml b/tabbox/qml/text.qml index 7c5ed64342..1539f6cf7b 100644 --- a/tabbox/qml/text.qml +++ b/tabbox/qml/text.qml @@ -130,6 +130,7 @@ Item { function indexAtMousePos(pos) { return textListView.indexAt(pos.x, pos.y); } + signal currentIndexChanged(int index) id: textListView objectName: "listView" // the maximum text width + icon item width (32 + 4 margin) + margins for hover item + margins for background @@ -154,7 +155,10 @@ Item { } MouseArea { anchors.fill: parent - onClicked: textListView.currentIndex = textListView.indexAt(mouse.x, mouse.y) + onClicked: { + textListView.currentIndex = textListView.indexAt(mouse.x, mouse.y); + textListView.currentIndexChanged(textListView.currentIndex); + } } } } diff --git a/tabbox/tabbox.cpp b/tabbox/tabbox.cpp index f75f81fa28..3aa4ab08d3 100644 --- a/tabbox/tabbox.cpp +++ b/tabbox/tabbox.cpp @@ -392,10 +392,10 @@ void TabBox::reset(bool partial_reset) setCurrentClient(Workspace::self()->activeClient()); // it's possible that the active client is not part of the model // in that case the index is invalid - if (!m_index.isValid()) + if (!m_tabBox->currentIndex().isValid()) setCurrentIndex(m_tabBox->first()); } else { - if (!m_index.isValid() || !m_tabBox->client(m_index)) + if (!m_tabBox->currentIndex().isValid() || !m_tabBox->client(m_tabBox->currentIndex())) setCurrentIndex(m_tabBox->first()); } break; @@ -425,7 +425,7 @@ void TabBox::nextPrev(bool next) */ Client* TabBox::currentClient() { - if (TabBoxClientImpl* client = static_cast< TabBoxClientImpl* >(m_tabBox->client(m_index))) { + if (TabBoxClientImpl* client = static_cast< TabBoxClientImpl* >(m_tabBox->client(m_tabBox->currentIndex()))) { if (!Workspace::self()->hasClient(client->client())) return NULL; return client->client(); @@ -456,7 +456,7 @@ ClientList TabBox::currentClientList() */ int TabBox::currentDesktop() { - return m_tabBox->desktop(m_index); + return m_tabBox->desktop(m_tabBox->currentIndex()); } /*! @@ -493,7 +493,6 @@ void TabBox::setCurrentIndex(QModelIndex index, bool notifyEffects) { if (!index.isValid()) return; - m_index = index; m_tabBox->setCurrentIndex(index); if (notifyEffects) { emit tabBoxUpdated(); @@ -529,7 +528,6 @@ void TabBox::hide(bool abort) emit tabBoxClosed(); if (isDisplayed()) kDebug(1212) << "Tab box was not properly closed by an effect"; - m_index = QModelIndex(); m_tabBox->hide(abort); QApplication::syncX(); XEvent otherEvent; @@ -614,25 +612,35 @@ void TabBox::delayedShow() } -void TabBox::handleMouseEvent(XEvent* e) +bool TabBox::handleMouseEvent(XEvent* e) { XAllowEvents(display(), AsyncPointer, xTime()); if (!m_isShown && isDisplayed()) { // tabbox has been replaced, check effects if (effects && static_cast(effects)->checkInputWindowEvent(e)) - return; + return true; + } + if (e->type == ButtonPress) { + // press outside Tabbox? + QPoint pos(e->xbutton.x_root, e->xbutton.y_root); + + if ((!m_isShown && isDisplayed()) + || (!m_tabBox->containsPos(pos) && + (e->xbutton.button == Button1 || e->xbutton.button == Button2 || e->xbutton.button == Button3))) { + close(); // click outside closes tab + return true; + } + } + if (m_tabBoxMode == TabBoxWindowsMode || m_tabBoxMode == TabBoxWindowsAlternativeMode) { + // pass to declarative view + return false; + } + + // not declarative view + if (e->type != ButtonPress) { + return true; } - if (e->type != ButtonPress) - return; QPoint pos(e->xbutton.x_root, e->xbutton.y_root); - - if ((!m_isShown && isDisplayed()) - || (!m_tabBox->containsPos(pos) && - (e->xbutton.button == Button1 || e->xbutton.button == Button2 || e->xbutton.button == Button3))) { - close(); // click outside closes tab - return; - } - QModelIndex index; if (e->xbutton.button == Button1 || e->xbutton.button == Button2 || e->xbutton.button == Button3) { index = m_tabBox->indexAt(pos); @@ -640,7 +648,7 @@ void TabBox::handleMouseEvent(XEvent* e) if (TabBoxClientImpl* client = static_cast< TabBoxClientImpl* >(m_tabBox->client(index))) { if (Workspace::self()->hasClient(client->client())) { client->client()->closeWindow(); - return; + return true; } } } @@ -651,6 +659,7 @@ void TabBox::handleMouseEvent(XEvent* e) if (index.isValid()) setCurrentIndex(index); + return true; } void TabBox::grabbedKeyEvent(QKeyEvent* event) diff --git a/tabbox/tabbox.h b/tabbox/tabbox.h index 498d9e82b6..6ab07d69d3 100644 --- a/tabbox/tabbox.h +++ b/tabbox/tabbox.h @@ -143,7 +143,7 @@ public: return m_displayRefcount > 0; }; - void handleMouseEvent(XEvent*); + bool handleMouseEvent(XEvent* e); void grabbedKeyEvent(QKeyEvent* event); bool isGrabbed() const { @@ -219,7 +219,6 @@ private Q_SLOTS: private: TabBoxMode m_tabBoxMode; - QModelIndex m_index; TabBoxHandlerImpl* m_tabBox; bool m_delayShow; int m_delayShowTime; diff --git a/tabbox/tabboxhandler.cpp b/tabbox/tabboxhandler.cpp index 3e22dffe5e..57b6dafb81 100644 --- a/tabbox/tabboxhandler.cpp +++ b/tabbox/tabboxhandler.cpp @@ -531,6 +531,9 @@ int TabBoxHandler::currentSelectedDesktop() const void TabBoxHandler::setCurrentIndex(const QModelIndex& index) { + if (d->index == index) { + return; + } if (d->view) { d->view->setCurrentIndex(index); } @@ -548,6 +551,11 @@ void TabBoxHandler::setCurrentIndex(const QModelIndex& index) } } +const QModelIndex& TabBoxHandler::currentIndex() const +{ + return d->index; +} + QModelIndex TabBoxHandler::grabbedKeyEvent(QKeyEvent* event) const { QModelIndex ret; diff --git a/tabbox/tabboxhandler.h b/tabbox/tabboxhandler.h index cefec5f587..bf9fecdee9 100644 --- a/tabbox/tabboxhandler.h +++ b/tabbox/tabboxhandler.h @@ -211,6 +211,10 @@ public: * @param index The current Model index */ void setCurrentIndex(const QModelIndex& index); + /** + * @returns the current index + **/ + const QModelIndex ¤tIndex() const; /** * Retrieves the next or previous item of the current item.