Pass mouse events to declarative Tabbox

The ListViews have therefore to emit a signal when the item changed
due to a mouse click event.
icc-effect-5.14.5
Martin Gräßlin 2011-10-31 14:34:37 +01:00
parent 918087e34f
commit 8b9e7f56cf
11 changed files with 69 additions and 27 deletions

View File

@ -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<EffectsHandlerImpl*>(effects)->checkInputWindowEvent(e))

View File

@ -126,6 +126,7 @@ void DeclarativeView::showEvent(QShowEvent *event)
if (QObject *item = rootObject()->findChild<QObject*>("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) {

View File

@ -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;

View File

@ -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);
}
}
}
}

View File

@ -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);
}
}
}
}

View File

@ -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);
}
}
}
}

View File

@ -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);
}
}
}
}

View File

@ -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<EffectsHandlerImpl*>(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)

View File

@ -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;

View File

@ -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;

View File

@ -211,6 +211,10 @@ public:
* @param index The current Model index
*/
void setCurrentIndex(const QModelIndex& index);
/**
* @returns the current index
**/
const QModelIndex &currentIndex() const;
/**
* Retrieves the next or previous item of the current item.