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

List:       kde-devel
Subject:    Re: Kicker/Taskbar: formatting task groups' menu items
From:       Stefan Nikolaus <stefan.nikolaus () kdemail ! net>
Date:       2005-04-11 21:19:49
Message-ID: 200504112319.49335.stefan.nikolaus () kdemail ! net
[Download RAW message or body]

On Monday, 11. April 2005 00:19, Aaron J. Seigo wrote:
> how about making it blink, like it does in the taskbar? i don't know how

Patch attached...

[...]
> then put the text back. combined with being painted in the highlight colour
> this should hopefully be clear .. or maybe it would just be annoying =P

...without the highlighting color, just blinking. Not perfect, but clear 
enough for me. What do you think?

Bye,
Stefan

["taskbar-taskmenu-2.patch" (text/x-diff)]

Index: tasklmbmenu.cpp
===================================================================
RCS file: /home/kde/kdebase/kicker/taskmanager/tasklmbmenu.cpp,v
retrieving revision 1.11
diff -u -p -r1.11 tasklmbmenu.cpp
--- tasklmbmenu.cpp	9 Apr 2005 02:24:30 -0000	1.11
+++ tasklmbmenu.cpp	11 Apr 2005 21:05:34 -0000
@@ -25,35 +25,149 @@ CONNECTION WITH THE SOFTWARE OR THE USE 
 #include "tasklmbmenu.h"
 #include "tasklmbmenu.moc"
 
+#include <qpainter.h>
+#include "qstyle.h"
+
 #include <kdebug.h>
 #include <kglobalsettings.h>
 
+TaskMenuItem::TaskMenuItem(const QString &text,
+                          bool active, bool minimized, bool attention)
+  : QCustomMenuItem(),
+    m_text(text),
+    m_isActive(active),
+    m_isMinimized(minimized),
+    m_demandsAttention(attention),
+    m_attentionState(true)
+{
+}
+
+TaskMenuItem::~TaskMenuItem()
+{
+}
+
+void TaskMenuItem::paint(QPainter *p, const QColorGroup &cg,
+                         bool highlighted, bool /*enabled*/,
+                         int x, int y, int w, int h )
+{
+    if (m_isActive)
+    {
+        QFont font = p->font();
+        font.setBold(true);
+        p->setFont(font);
+    }
+
+    if (highlighted)
+    {
+        p->setPen(cg.highlightedText());
+    }
+    else if (m_isMinimized)
+    {
+        p->setPen(QPen(blendColors(cg.background(), cg.text())));
+    }
+
+    if (!m_demandsAttention || m_attentionState)
+    {
+        p->drawText(x, y, w, h, AlignAuto|AlignVCenter|DontClip|ShowPrefix, m_text);
+    }
+}
+
+QSize TaskMenuItem::sizeHint()
+{
+    QFont font = QFont();
+    if (m_isActive)
+    {
+        font.setBold(true);
+    }
+    return QFontMetrics(font).size(AlignAuto|AlignVCenter|DontClip|ShowPrefix,
+                                   m_text);
+}
+
+QColor TaskMenuItem::blendColors( QColor c1, QColor c2 )
+{
+    int r1, g1, b1;
+    int r2, g2, b2;
+
+    c1.rgb( &r1, &g1, &b1 );
+    c2.rgb( &r2, &g2, &b2 );
+
+    r1 += (int) ( .5 * ( r2 - r1 ) );
+    g1 += (int) ( .5 * ( g2 - g1 ) );
+    b1 += (int) ( .5 * ( b2 - b1 ) );
+
+    return QColor( r1, g1, b1 );
+}
+
+/*****************************************************************************/
+
 TaskLMBMenu::TaskLMBMenu( TaskList* tasks, QWidget *parent, const char *name )
-	: QPopupMenu( parent, name )
-	, m_tasks( *tasks )
-	, m_lastDragId( -1 )
+  : QPopupMenu(parent, name),
+    m_tasks(*tasks),
+    m_lastDragId(-1),
+    m_attentionState(false)
 {
-	fillMenu( tasks );
-	
-	setAcceptDrops(true); // Always enabled to activate task during drag&drop.
-	
-	connect( &dragSwitchTimer, SIGNAL( timeout() ), SLOT( dragSwitch() ) );
+    fillMenu(tasks);
+
+    setAcceptDrops(true); // Always enabled to activate task during drag&drop.
+
+    m_dragSwitchTimer = new QTimer(this, "DragSwitchTimer");
+    connect(m_dragSwitchTimer, SIGNAL(timeout()), SLOT(dragSwitch()));
 }
 
-void TaskLMBMenu::fillMenu( TaskList* tasks )
+void TaskLMBMenu::fillMenu(TaskList* tasks)
 {
-	setCheckable( true );
+    setCheckable(true);
+
+    for (QPtrListIterator<Task> it(*tasks); *it; ++it)
+    {
+        Task* t = (*it);
 
-	for( QPtrListIterator<Task> it(*tasks); *it; ++it ) {
-		Task* t = (*it);
+        QString text = t->visibleNameWithState().replace("&", "&&");
 
-		QString text = t->visibleNameWithState().replace("&", "&&");
+        TaskMenuItem *menuItem = new TaskMenuItem(text,
+                                                  t->isActive(),
+                                                  t->isIconified(),
+                                                  t->demandsAttention());
+        int id = insertItem(QIconSet(t->pixmap()), menuItem);
+        connectItem(id, t, SLOT(activateRaiseOrIconify()));
+        setItemChecked(id, t->isActive());
 
-		int id = insertItem( QIconSet( t->pixmap() ), text,
-				     t, SLOT( activateRaiseOrIconify() ) );
-		setItemChecked( id, t->isActive() );
-		
-	}
+        if (t->demandsAttention())
+        {
+            m_attentionState = true;
+            m_attentionMap.append(menuItem);
+        }
+    }
+
+    if (m_attentionState)
+    {
+        m_attentionTimer = new QTimer(this, "AttentionTimer");
+        connect(m_attentionTimer, SIGNAL(timeout()),
+                this, SLOT(attentionTimeout()));
+        m_attentionTimer->start(750, true);
+    }
+}
+
+void TaskLMBMenu::attentionTimeout()
+{
+    m_attentionState = !m_attentionState;
+
+    TaskMenuItem *menuItem = m_attentionMap.first();
+    for (; menuItem; menuItem = m_attentionMap.next())
+    {
+        menuItem->setAttentionState(m_attentionState);
+    }
+
+    update();
+
+    if (m_attentionState)
+    {
+        m_attentionTimer->start(750, true);
+    }
+    else
+    {
+        m_attentionTimer->start(250, true);
+    }
 }
 
 void TaskLMBMenu::dragEnterEvent( QDragEnterEvent* e )
@@ -68,13 +182,13 @@ void TaskLMBMenu::dragEnterEvent( QDragE
 
     if (id == -1)
     {
-        dragSwitchTimer.stop();
+        m_dragSwitchTimer->stop();
         m_lastDragId = -1;
     }
     else if (id != m_lastDragId)
     {
         m_lastDragId = id;
-        dragSwitchTimer.start(1000, true);
+        m_dragSwitchTimer->start(1000, true);
     }
 
     QPopupMenu::dragEnterEvent( e );
@@ -82,7 +196,7 @@ void TaskLMBMenu::dragEnterEvent( QDragE
 
 void TaskLMBMenu::dragLeaveEvent( QDragLeaveEvent* e )
 {
-    dragSwitchTimer.stop();
+    m_dragSwitchTimer->stop();
     m_lastDragId = -1;
 
     QPopupMenu::dragLeaveEvent(e);
@@ -102,13 +216,13 @@ void TaskLMBMenu::dragMoveEvent( QDragMo
 
     if (id == -1)
     {
-        dragSwitchTimer.stop();
+        m_dragSwitchTimer->stop();
         m_lastDragId = -1;
     }
     else if (id != m_lastDragId)
     {
         m_lastDragId = id;
-        dragSwitchTimer.start(1000, true);
+        m_dragSwitchTimer->start(1000, true);
     }
 
     QPopupMenu::dragMoveEvent(e);
Index: tasklmbmenu.h
===================================================================
RCS file: /home/kde/kdebase/kicker/taskmanager/tasklmbmenu.h,v
retrieving revision 1.5
diff -u -p -r1.5 tasklmbmenu.h
--- tasklmbmenu.h	9 Apr 2005 02:24:30 -0000	1.5
+++ tasklmbmenu.h	11 Apr 2005 21:05:34 -0000
@@ -30,31 +30,57 @@ CONNECTION WITH THE SOFTWARE OR THE USE 
 
 #include "taskmanager.h"
 
+class TaskMenuItem : public QCustomMenuItem
+{
+public:
+    TaskMenuItem(const QString &text,
+                 bool active, bool minimized, bool attention);
+    ~TaskMenuItem();
+
+    void paint(QPainter*, const QColorGroup&, bool, bool, int, int, int, int);
+    QSize sizeHint();
+    QColor blendColors(QColor, QColor);
+    void setAttentionState(bool state) { m_attentionState = state; }
+
+private:
+    QString m_text;
+    bool m_isActive;
+    bool m_isMinimized;
+    bool m_demandsAttention;
+    bool m_attentionState;
+};
+
+/*****************************************************************************/
+
 class KDE_EXPORT TaskLMBMenu : public QPopupMenu
 {
     Q_OBJECT
 
-    public:
-        TaskLMBMenu(TaskList* list, QWidget *parent = 0, const char *name = 0);
-
-        protected slots:
-            void dragSwitch();
+public:
+    TaskLMBMenu(TaskList* list, QWidget *parent = 0, const char *name = 0);
 
-    protected:
-        void dragEnterEvent(QDragEnterEvent*);
-        void dragLeaveEvent(QDragLeaveEvent*);
-        void dragMoveEvent(QDragMoveEvent*);
-        void mousePressEvent(QMouseEvent*);
-        void mouseMoveEvent(QMouseEvent*);
-        void mouseReleaseEvent(QMouseEvent*);
-
-    private:
-        void fillMenu(TaskList* tasks);
-
-        TaskList&  m_tasks;
-        int        m_lastDragId;
-        QTimer     dragSwitchTimer;
-        QPoint     m_dragStartPos;
+protected slots:
+    void dragSwitch();
+    void attentionTimeout();
+
+protected:
+    void dragEnterEvent(QDragEnterEvent*);
+    void dragLeaveEvent(QDragLeaveEvent*);
+    void dragMoveEvent(QDragMoveEvent*);
+    void mousePressEvent(QMouseEvent*);
+    void mouseMoveEvent(QMouseEvent*);
+    void mouseReleaseEvent(QMouseEvent*);
+
+private:
+    void fillMenu(TaskList* tasks);
+
+    TaskList&  m_tasks;
+    int        m_lastDragId;
+    bool       m_attentionState;
+    QTimer*    m_attentionTimer;
+    QTimer*    m_dragSwitchTimer;
+    QPoint     m_dragStartPos;
+    QPtrList<TaskMenuItem> m_attentionMap;
 };
 
 #endif


>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


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

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