--- kdebase-3.4.0/kicker/taskmanager/tasklmbmenu.cpp-- 2005-04-22 08:38:13.633417553 +0200 +++ kdebase-3.4.0/kicker/taskmanager/tasklmbmenu.cpp 2005-04-22 08:46:01.270466623 +0200 @@ -24,33 +24,137 @@ CONNECTION WITH THE SOFTWARE OR THE USE #include "tasklmbmenu.h" #include "tasklmbmenu.moc" +#include <qpainter.h> +#include "qstyle.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->setPen(cg.mid()); + } + 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 ) + , m_attentionState(false) { fillMenu( tasks ); setAcceptDrops(true); // Always enabled to activate task during drag&drop. - - connect( &dragSwitchTimer, SIGNAL( timeout() ), SLOT( dragSwitch() ) ); + m_dragSwitchTimer = new QTimer(this, "DragSwitchTimer"); + connect( m_dragSwitchTimer, SIGNAL( timeout() ), SLOT( dragSwitch() ) ); } void TaskLMBMenu::fillMenu( TaskList* tasks ) { setCheckable( true ); + TaskList::iterator itEnd = (*tasks).end(); + for (TaskList::iterator it = (*tasks).begin(); it != itEnd; ++it) + { - for( TaskList::iterator it = tasks->begin(); it != tasks->end(); ++it ) { Task::Ptr t = (*it); + QString text = t->visibleName().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()); + + if (t->demandsAttention()) + { + m_attentionState = true; + m_attentionMap.append(menuItem); + } + } + + if (m_attentionState) + { + m_attentionTimer = new QTimer(this, "AttentionTimer"); + connect(m_attentionTimer, SIGNAL(timeout()), SLOT(attentionTimeout())); + m_attentionTimer->start(500, true); + } +} + +void TaskLMBMenu::attentionTimeout() +{ + m_attentionState = !m_attentionState; + + TaskMenuItem *menuItem = m_attentionMap.first(); + for (; menuItem; menuItem = m_attentionMap.next()) + { + menuItem->setAttentionState(m_attentionState); + } - int id = insertItem( QIconSet( t->pixmap() ), text, - t, SLOT( activateRaiseOrIconify() ) ); - setItemChecked( id, t->isActive() ); + update(); - } + m_attentionTimer->start(500, true); } void TaskLMBMenu::dragEnterEvent( QDragEnterEvent* e ) @@ -58,11 +162,11 @@ void TaskLMBMenu::dragEnterEvent( QDragE int id = idAt( e->pos() ); 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 ); @@ -70,7 +174,7 @@ void TaskLMBMenu::dragEnterEvent( QDragE void TaskLMBMenu::dragLeaveEvent( QDragLeaveEvent* e ) { - dragSwitchTimer.stop(); + m_dragSwitchTimer->stop(); m_lastDragId = -1; QPopupMenu::dragLeaveEvent( e ); @@ -83,11 +187,11 @@ void TaskLMBMenu::dragMoveEvent( QDragMo int id = idAt( e->pos() ); 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 ); --- kdebase-3.4.0/kicker/taskmanager/tasklmbmenu.h-- 2005-04-22 08:37:19.846720134 +0200 +++ kdebase-3.4.0/kicker/taskmanager/tasklmbmenu.h 2005-04-22 08:38:08.656353263 +0200 @@ -30,6 +30,27 @@ 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 @@ -39,7 +60,7 @@ public: protected slots: void dragSwitch(); - + void attentionTimeout(); protected: void dragEnterEvent( QDragEnterEvent* ); void dragLeaveEvent( QDragLeaveEvent* ); @@ -50,7 +71,10 @@ private: TaskList& m_tasks; int m_lastDragId; - QTimer dragSwitchTimer; + bool m_attentionState; + QTimer* m_attentionTimer; + QTimer* m_dragSwitchTimer; + QPtrList<TaskMenuItem> m_attentionMap; }; #endif