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

List:       kde-devel
Subject:    Kicker/Taskbar: formatting task groups' menu items
From:       Stefan Nikolaus <stefan.nikolaus () kdemail ! net>
Date:       2005-04-10 20:22:13
Message-ID: 200504102222.13491.stefan.nikolaus () kdemail ! net
[Download RAW message or body]

Hi,

I formatted the popup menu entries of task groups. Affected are the active 
task (bold font), minimized tasks (grayed out font) and tasks that demands 
attention. The last are represented by a shifted font, which is a bit crappy. 
Any suggestions how to display these in a better way?
I tried to highlight them as the the task buttons, but failed to set the 
background color of the menu item without erasing the icon. Any hints are 
welcome.

Regards,
Stefan

["taskbar-taskmenu-1.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	10 Apr 2005 20:18:32 -0000
@@ -25,9 +25,79 @@ CONNECTION WITH THE SOFTWARE OR THE USE 
 #include "tasklmbmenu.h"
 #include "tasklmbmenu.moc"
 
+#include <qpainter.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)
+{
+}
+
+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);
+    }
+    else if (!highlighted)
+    {
+        if (m_isMinimized)
+        {
+            p->setPen(QPen(blendColors(cg.background(), cg.text())));
+        }
+        else if (m_demandsAttention)
+        {
+            p->setPen(cg.highlight());
+            p->drawText(x+1, y+1, w, h, AlignAuto|AlignVCenter|DontClip|ShowPrefix, m_text);
+            p->setPen(cg.highlightedText());
+        }
+    }
+    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 )
@@ -40,20 +110,24 @@ TaskLMBMenu::TaskLMBMenu( TaskList* task
 	connect( &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("&", "&&");
 
-		int id = insertItem( QIconSet( t->pixmap() ), text,
-				     t, SLOT( activateRaiseOrIconify() ) );
-		setItemChecked( id, t->isActive() );
-		
-	}
+        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());
+    }
 }
 
 void TaskLMBMenu::dragEnterEvent( QDragEnterEvent* 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	10 Apr 2005 20:18:32 -0000
@@ -30,6 +30,26 @@ 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);
+
+private:
+    QString m_text;
+    bool m_isActive;
+    bool m_isMinimized;
+    bool m_demandsAttention;
+};
+
+/*****************************************************************************/
+
 class KDE_EXPORT TaskLMBMenu : public QPopupMenu
 {
     Q_OBJECT


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