• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Applets

windowtaskitem.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by Robert Knight <robertknight@gmail.com>          *
00003  *   Copyright (C) 2008 by Alexis Ménard <darktears31@gmail.com>           *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
00019  ***************************************************************************/
00020 
00021 // Own
00022 #include "windowtaskitem.h"
00023 #include "taskgroupitem.h"
00024 
00025 // Qt
00026 #include <QGraphicsSceneContextMenuEvent>
00027 #include <QStyleOptionGraphicsItem>
00028 #include <QGraphicsView>
00029 #include <QTimer>
00030 #include <QApplication>
00031 
00032 // KDE
00033 #include <KAuthorized>
00034 #include <KDebug>
00035 #include <KIcon>
00036 #include <KLocalizedString>
00037 #include <KGlobalSettings>
00038 #include <KIconLoader>
00039 
00040 #include <taskmanager/taskactions.h>
00041 #include <taskmanager/task.h>
00042 #include <taskmanager/taskmanager.h>
00043 #include <taskmanager/taskgroup.h>
00044 
00045 #include <Plasma/Theme>
00046 #include <Plasma/FrameSvg>
00047 #include <Plasma/ToolTipManager>
00048 #include <Plasma/Corona>
00049 #include <Plasma/Containment>
00050 
00051 #include "tasks.h"
00052 
00053 WindowTaskItem::WindowTaskItem(QGraphicsWidget *parent, Tasks *applet, const bool showTooltip)
00054     : AbstractTaskItem(parent, applet, showTooltip),
00055       m_task(0)
00056 {
00057 }
00058 
00059 
00060 void WindowTaskItem::activate()
00061 {
00062     // the Task class has a method called activateRaiseOrIconify() which
00063     // should perform the required action here.
00064     //
00065     // however it currently does not minimize the task's window if the item
00066     // is clicked whilst the window is active probably because the active window by
00067     // the time the mouse is released over the window task button is not the
00068     // task's window but instead the desktop window
00069     //
00070     // TODO: the Kicker panel in KDE 3.x has a feature whereby clicking on it
00071     // does not take away the focus from the active window (unless clicking
00072     // in a widget such as a line edit which does accept the focus)
00073     // this needs to be implemented for Plasma's own panels.
00074     //kDebug();
00075     if (m_task) {
00076         m_task->task()->activateRaiseOrIconify();
00077        // emit windowSelected(this);
00078     }
00079 }
00080 
00081 void WindowTaskItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
00082 {
00083     if (event->buttons() & Qt::MidButton) {
00084         if (isGrouped()) {
00085             parentGroup()->collapse();
00086         }
00087     } else {
00088         AbstractTaskItem::mousePressEvent(event);
00089     }
00090 
00091     event->accept();
00092 }
00093 
00094 //destroy this item
00095 void WindowTaskItem::close()
00096 {
00097     //kDebug();
00098     m_task = 0;
00099 }
00100 
00101 void WindowTaskItem::publishIconGeometry() const
00102 {
00103     if (!m_task) {
00104         return;
00105     }
00106 
00107     QRect rect = iconGeometry();
00108     m_task->task()->publishIconGeometry(rect);
00109 }
00110 
00111 void WindowTaskItem::publishIconGeometry(const QRect &rect) const
00112 {
00113     if (m_task) {
00114         m_task->task()->publishIconGeometry(rect);
00115     }
00116 }
00117 
00118 void WindowTaskItem::updateTask(::TaskManager::TaskChanges changes)
00119 {
00120     if (!m_task) {
00121         return;
00122     }
00123 
00124     // task flags
00125     bool needsUpdate = false;
00126     TaskFlags flags = m_flags;
00127     if (m_task->isActive()) {
00128         flags |= TaskHasFocus;
00129         emit activated(this);
00130     } else {
00131         flags &= ~TaskHasFocus;
00132     }
00133 
00134     if (m_task->demandsAttention()) {
00135         flags |= TaskWantsAttention;
00136     } else {
00137         flags &= ~TaskWantsAttention;
00138     }
00139 
00140     if (m_task->isMinimized()) {
00141         flags |= TaskIsMinimized;
00142     } else {
00143         flags &= ~TaskIsMinimized;
00144     }
00145 
00146     if (m_flags != flags) {
00147         needsUpdate = true;
00148         setTaskFlags(flags);
00149     }
00150 
00151     // basic title and icon
00152     if (changes & TaskManager::IconChanged) {
00153         needsUpdate = true;
00154         setIcon(m_task->icon());
00155     }
00156 
00157     if (changes & TaskManager::NameChanged) {
00158         needsUpdate = true;
00159         setText(m_task->name());
00160     }
00161 
00162     if (m_showingTooltip &&
00163         (changes & TaskManager::IconChanged ||
00164          changes & TaskManager::NameChanged ||
00165          changes & TaskManager::DesktopChanged)) {
00166         updateToolTip();
00167     }
00168 
00169     if (needsUpdate) {
00170         //redraw
00171         //kDebug() << m_task->name();
00172         queueUpdate();
00173     }
00174 }
00175 
00176 void WindowTaskItem::updateToolTip()
00177 {
00178     if (!m_task) {
00179         return;
00180     }
00181 
00182     Plasma::ToolTipContent data(m_task->name(),
00183                                 i18nc("Which virtual desktop a window is currently on", "On %1",
00184                                       KWindowSystem::desktopName(m_task->desktop())),
00185                                 m_task->task()->icon(KIconLoader::SizeSmall, KIconLoader::SizeSmall, false));
00186     data.setWindowToPreview(m_task->task()->window());
00187 
00188     Plasma::ToolTipManager::self()->setContent(this, data);
00189 }
00190 
00191 void WindowTaskItem::setStartupTask(TaskItem *task)
00192 {
00193     //kDebug();
00194     if (!task->startup()) {
00195         kDebug() << "Error";
00196         return;
00197     }
00198     m_abstractItem = qobject_cast<TaskManager::AbstractGroupableItem *>(task);
00199     if (!m_abstractItem) {
00200         kDebug() << "error";
00201     }
00202     connect(task, SIGNAL(gotTaskPointer()), this, SLOT(gotTaskPointer()));
00203     setText(task->startup()->text());
00204     setIcon(KIcon(task->startup()->icon()));
00205 }
00206 
00207 void WindowTaskItem::gotTaskPointer()
00208 {
00209     //kDebug();
00210     TaskManager::TaskItem *item = qobject_cast<TaskManager::TaskItem*>(sender());
00211     if (item) {
00212         setWindowTask(item);
00213     }
00214 }
00215 
00216 
00217 void WindowTaskItem::setWindowTask(TaskManager::TaskItem* taskItem)
00218 {
00219     if (m_task) {
00220         disconnect(m_task->task().constData(), 0, this, 0);
00221     }
00222     m_task = taskItem;
00223     m_abstractItem = qobject_cast<TaskManager::AbstractGroupableItem *>(taskItem);
00224     if (!m_abstractItem) {
00225         kDebug() << "error";
00226     }
00227 
00228     connect(m_task, SIGNAL(changed(::TaskManager::TaskChanges)),
00229             this, SLOT(updateTask(::TaskManager::TaskChanges)));
00230 
00231     updateTask(::TaskManager::EverythingChanged);
00232     publishIconGeometry();
00233 
00234     //kDebug() << "Task added, isActive = " << task->isActive();
00235 }
00236 
00237 void WindowTaskItem::setTask(TaskManager::TaskItem* taskItem)
00238 {
00239     if (!taskItem->startup() && !taskItem->task()) {
00240         kDebug() << "Error";
00241         return;
00242     }
00243 
00244     if (!taskItem->task()) {
00245         setStartupTask(taskItem);
00246     } else {
00247         setWindowTask(taskItem);
00248     }
00249 }
00250 
00251 
00252 TaskManager::TaskPtr WindowTaskItem::windowTask() const
00253 {
00254     return m_task->task();
00255 }
00256 
00257 void WindowTaskItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *e)
00258 {
00259     if (!KAuthorized::authorizeKAction("kwin_rmb") || !m_task) {
00260         QGraphicsWidget::contextMenuEvent(e);
00261         return;
00262     }
00263 
00264     QList <QAction*> actionList;
00265     QAction *a(0);
00266     if (m_task->isGrouped()) {
00267         a = new QAction(i18n("Collapse Parent Group"), this);
00268         actionList.append(a);
00269         //connect(a, SIGNAL(triggered()), m_applet->groupItem(m_task->parentGroup()), SLOT(collapse())); FIXME
00270     }
00271 
00272     TaskManager::BasicMenu menu(0, m_task, &m_applet->groupManager(), actionList);
00273     menu.adjustSize();
00274     Q_ASSERT(m_applet->containment());
00275     Q_ASSERT(m_applet->containment()->corona());
00276     menu.exec(m_applet->containment()->corona()->popupPosition(this, menu.size()));
00277     delete a;
00278 }
00279 
00280 
00281 
00282 bool WindowTaskItem::isWindowItem() const
00283 {
00284     return true;
00285 }
00286 
00287 bool WindowTaskItem::isActive() const
00288 {
00289     if (!m_task) {
00290         //kDebug() << "no task set";
00291         return false;
00292     }
00293     return m_task->isActive();
00294 }
00295 
00296 void WindowTaskItem::setAdditionalMimeData(QMimeData* mimeData)
00297 {
00298     m_task->addMimeData(mimeData);
00299 }
00300 
00301 #include "windowtaskitem.moc"
00302 

Applets

Skip menu "Applets"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal