[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdebase/workspace/plasma/applets/tasks
From:       MichaƂ Dutkiewicz <emdeck () gmail ! com>
Date:       2009-08-31 16:14:51
Message-ID: 1251735291.271259.28647.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1017829 by mdutkiewicz:

Keyboard navigation [Shift + ] Tab for Tasks applet (Enter / Return to activate task).
To make real use of it there is need to fix panel focus issue too.

 M  +25 -0     abstracttaskitem.cpp  
 M  +3 -0      abstracttaskitem.h  
 M  +59 -26    taskgroupitem.cpp  
 M  +2 -0      taskgroupitem.h  
 M  +13 -1     windowtaskitem.cpp  
 M  +1 -0      windowtaskitem.h  


--- trunk/KDE/kdebase/workspace/plasma/applets/tasks/abstracttaskitem.cpp #1017828:1017829
@@ -81,6 +81,9 @@
     setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding));
     setAcceptsHoverEvents(true);
     setAcceptDrops(true);
+    setFocusPolicy(Qt::StrongFocus);
+    setFlag(QGraphicsItem::ItemIsFocusable);
+
 //    setPreferredSize(basicPreferredSize());
 
     Plasma::ToolTipManager::self()->registerWidget(this);
@@ -286,6 +289,28 @@
     m_lastUpdate.restart();
 }
 
+void AbstractTaskItem::focusInEvent(QFocusEvent *event)
+{
+    Q_UNUSED(event)
+
+    m_flags |= TaskHasFocus;
+
+    setTaskFlags(m_flags);
+
+    update();
+}
+
+void AbstractTaskItem::focusOutEvent(QFocusEvent *event)
+{
+    Q_UNUSED(event)
+
+    m_flags &= ~TaskHasFocus;
+
+    setTaskFlags(m_flags);
+
+    update();
+}
+
 void AbstractTaskItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
 {
     Q_UNUSED(event)
--- trunk/KDE/kdebase/workspace/plasma/applets/tasks/abstracttaskitem.h #1017828:1017829
@@ -31,6 +31,7 @@
 // Qt
 #include <QTime>
 #include <QIcon>
+#include <QFocusEvent>
 #include <QGraphicsWidget>
 
 class QTextOption;
@@ -143,6 +144,8 @@
     void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
 
     // reimplemented
+    void focusInEvent(QFocusEvent *event);
+    void focusOutEvent(QFocusEvent *event);
     void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
     void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
     void mousePressEvent(QGraphicsSceneMouseEvent *event);
--- trunk/KDE/kdebase/workspace/plasma/applets/tasks/taskgroupitem.cpp #1017828:1017829
@@ -693,6 +693,64 @@
     return QGraphicsWidget::eventFilter(watched, event);
 }
 
+bool TaskGroupItem::focusNextPrevChild(bool next)
+{
+    return focusSubTask(next, false);
+}
+
+bool TaskGroupItem::focusSubTask(bool next, bool activate)
+{
+    const int subTasks = totalSubTasks();
+
+    if (subTasks > 0) {
+        int index = -1;
+
+        if (focusWidget() && subTasks > 1) {
+            for (int i = 0; i < subTasks; ++i) {
+                if (focusWidget() == selectSubTask(i)) {
+                    index = i;
+
+                    break;
+                }
+            }
+        }
+
+        if (next) {
+            ++index;
+
+            if (index >= subTasks) {
+                index = 0;
+            }
+        }
+        else {
+            --index;
+
+            if (index < 0) {
+                index = (subTasks - 1);
+            }
+        }
+
+        AbstractTaskItem *taskItem = selectSubTask(index);
+
+        if (taskItem) {
+            taskItem->setFocus();
+
+            m_activeTaskIndex = index;
+        }
+
+        if (activate && taskItem) {
+            stopWindowHoverEffect();
+
+            taskItem->activate();
+        }
+
+        return true;
+    }
+    else {
+        return false;
+    }
+}
+
 void TaskGroupItem::clearPopupLostFocus()
 {
     m_popupLostFocus = false;
@@ -1206,32 +1264,7 @@
 
 void TaskGroupItem::wheelEvent(QGraphicsSceneWheelEvent *event)
 {
-    int subTasks = totalSubTasks();
-    //zero or one tasks don't cycle
-    if (subTasks < 1) {
-        return;
-    }
-
-    //mouse wheel down
-    if (event->delta() < 0) {
-        m_activeTaskIndex++;
-        if (m_activeTaskIndex >= subTasks) {
-            m_activeTaskIndex = 0; // last item is spacer
-        }
-    } else {
-        //mouse wheel up
-        m_activeTaskIndex--;
-        if (m_activeTaskIndex < 0) {
-            m_activeTaskIndex = subTasks - 1; //last item is a spacer
-        }
-    }
-
-    //kDebug() << "Wheel event m_activeTaskIndex: " << m_activeTaskIndex << " of " << subTasks;
-    AbstractTaskItem *taskItem = selectSubTask(m_activeTaskIndex);
-    if (taskItem) {
-        stopWindowHoverEffect();
-        taskItem->activate();
-    }
+    focusSubTask((event->delta() > 0), true);
 }
 
 int TaskGroupItem::maxRows()
--- trunk/KDE/kdebase/workspace/plasma/applets/tasks/taskgroupitem.h #1017828:1017829
@@ -140,6 +140,7 @@
     virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
     virtual void dropEvent(QGraphicsSceneDragDropEvent *event);
     bool eventFilter(QObject *watched, QEvent *event);
+    bool focusNextPrevChild(bool next);
 
     void handleDroppedId(WId id, AbstractTaskItem *targetTask, QGraphicsSceneDragDropEvent *event);
 
@@ -185,6 +186,7 @@
     void setSplitIndex(int position);
 
     int totalSubTasks();
+    bool focusSubTask(bool next, bool activate);
     AbstractTaskItem * selectSubTask(int index);
 
     GroupPtr m_group;
--- trunk/KDE/kdebase/workspace/plasma/applets/tasks/windowtaskitem.cpp #1017828:1017829
@@ -96,6 +96,18 @@
     event->accept();
 }
 
+void WindowTaskItem::keyPressEvent(QKeyEvent *event)
+{
+    if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)
+    {
+        activate();
+    }
+    else
+    {
+        QGraphicsWidget::keyPressEvent(event);
+    }
+}
+
 //destroy this item
 void WindowTaskItem::close()
 {
@@ -240,7 +252,7 @@
     if (!m_busyWidget) {
         m_busyWidget = new Plasma::BusyWidget(this);
         m_busyWidget->hide();
-    }        
+    }
 }
 
 void WindowTaskItem::gotTaskPointer()
--- trunk/KDE/kdebase/workspace/plasma/applets/tasks/windowtaskitem.h #1017828:1017829
@@ -68,6 +68,7 @@
 protected:
     void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
     void mousePressEvent(QGraphicsSceneMouseEvent *event);
+    void keyPressEvent(QKeyEvent *event);
     void updateToolTip();
 
 private slots:
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic