1 /*****************************************************************
3 Copyright 2008 Christian Mollekopf <chrigi_1@hotmail.com>
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 ******************************************************************/
24 #include "taskactions.h"
25 #include "taskactions_p.h"
29 #include "taskgroup.h"
32 #include "taskmanager.h"
33 #include "abstractgroupingstrategy.h"
44 QAction
*standardGroupableAction(GroupableAction action
, AbstractItemPtr item
, QObject
*parent
, int desktop
)
50 return new MaximizeActionImpl(parent
, item
);
53 return new MinimizeActionImpl(parent
, item
);
55 case ToCurrentDesktopAction
:
56 return new ToCurrentDesktopActionImpl(parent
, item
);
59 return new ToDesktopActionImpl(parent
, item
, desktop
);
62 return new ShadeActionImpl(parent
, item
);
65 return new CloseActionImpl(parent
, item
);
67 case ViewFullscreenAction
:
68 return new ViewFullscreenActionImpl(parent
, item
);
71 return new KeepBelowActionImpl(parent
, item
);
78 QAction
* standardTaskAction(TaskAction action
, TaskItem
*item
, QObject
*parent
)
84 return new ResizeActionImpl(parent
, item
);
87 return new MoveActionImpl(parent
, item
);
94 QAction
* standardGroupingAction(GroupingAction action
, AbstractItemPtr item
, GroupManager
*strategy
, QObject
*parent
)
100 case LeaveGroupAction
:
101 return new LeaveGroupActionImpl(parent
, item
, strategy
);
108 MinimizeActionImpl::MinimizeActionImpl(QObject
*parent
, AbstractItemPtr item
)
111 connect(this, SIGNAL(triggered()), item
, SLOT(toggleMinimized()));
112 setText(i18n("Mi&nimize"));
114 setChecked(item
->isMinimized());
115 setEnabled(item
->isActionSupported(NET::ActionMinimize
));
119 MaximizeActionImpl::MaximizeActionImpl(QObject
*parent
, AbstractItemPtr item
)
122 connect(this, SIGNAL(triggered()), item
, SLOT(toggleMaximized()));
123 setText(i18n("Ma&ximize"));
125 setChecked(item
->isMaximized());
126 setEnabled(item
->isActionSupported(NET::ActionMax
));
129 ShadeActionImpl::ShadeActionImpl(QObject
*parent
, AbstractItemPtr item
)
132 connect(this, SIGNAL(triggered()), item
, SLOT(toggleShaded()));
133 setText(i18n("&Shade"));
135 setChecked(item
->isShaded());
136 setEnabled(item
->isActionSupported(NET::ActionShade
));
139 ResizeActionImpl::ResizeActionImpl(QObject
*parent
, TaskItem
* item
)
142 TaskPtr task
= item
->task();
143 connect(this, SIGNAL(triggered()), task
.data(), SLOT(resize()));
144 setText(i18n("Re&size"));
145 setEnabled(item
->isActionSupported(NET::ActionResize
));
148 MoveActionImpl::MoveActionImpl(QObject
*parent
, TaskItem
* item
)
151 TaskPtr task
= item
->task();
152 connect(this, SIGNAL(triggered()), task
.data(), SLOT(move()));
153 setText(i18n("&Move"));
154 setIcon(KIcon("transform-move"));
155 setEnabled(item
->isActionSupported(NET::ActionMove
));
158 CloseActionImpl::CloseActionImpl(QObject
*parent
, AbstractItemPtr item
)
161 connect(this, SIGNAL(triggered()), item
, SLOT(close()));
162 setText(i18n("&Close"));
163 setIcon(KIcon("window-close"));
164 setEnabled(item
->isActionSupported(NET::ActionClose
));
168 ToCurrentDesktopActionImpl::ToCurrentDesktopActionImpl(QObject
*parent
, AbstractItemPtr item
)
172 connect(this, SIGNAL(triggered()), this, SLOT(slotToCurrentDesktop()));
173 setText(i18n("&To Current Desktop"));
174 setEnabled(!item
->isOnCurrentDesktop() && item
->isActionSupported(NET::ActionChangeDesktop
));
177 void ToCurrentDesktopActionImpl::slotToCurrentDesktop()
179 m_item
->toDesktop(KWindowSystem::currentDesktop());
184 ToDesktopActionImpl::ToDesktopActionImpl(QObject
*parent
, AbstractItemPtr item
, int desktop
)
189 connect(this, SIGNAL(triggered()), this, SLOT(slotToDesktop()));
191 if (!desktop
) { //to All Desktops
192 setText(i18n("&All Desktops"));
193 setChecked(item
->isOnAllDesktops());
195 QString name
= QString("&%1 %2").arg(desktop
).arg(TaskManager::self()->desktopName(desktop
).replace('&', "&&"));
197 setChecked(!item
->isOnAllDesktops() && item
->desktop() == desktop
);
202 void ToDesktopActionImpl::slotToDesktop()
204 m_item
->toDesktop(m_desktop
);
209 DesktopsMenu::DesktopsMenu(QWidget
*parent
, AbstractItemPtr item
)
212 setTitle( i18n("To &Desktop") );
213 addAction( new ToDesktopActionImpl(this,item
,0) ); //0 means all desktops
215 for (int i
= 1; i
<= TaskManager::self()->numberOfDesktops(); i
++) {
216 addAction( new ToDesktopActionImpl(this,item
,i
) );
218 setEnabled(item
->isActionSupported(NET::ActionChangeDesktop
));
221 KeepAboveActionImpl::KeepAboveActionImpl(QObject
*parent
, AbstractItemPtr item
)
224 connect(this, SIGNAL(triggered()), item
, SLOT(toggleAlwaysOnTop()));
225 setText(i18n("Keep &Above Others"));
226 setIcon(KIcon("go-up"));
228 setChecked(item
->isAlwaysOnTop());
231 KeepBelowActionImpl::KeepBelowActionImpl(QObject
*parent
, AbstractItemPtr item
)
234 connect(this, SIGNAL(triggered()), item
, SLOT(toggleKeptBelowOthers()));
235 setText(i18n("Keep &Below Others"));
236 setIcon(KIcon("go-down"));
238 setChecked(item
->isKeptBelowOthers());
241 ViewFullscreenActionImpl::ViewFullscreenActionImpl(QObject
*parent
, AbstractItemPtr item
)
244 connect(this, SIGNAL(triggered()), item
, SLOT(toggleFullScreen()));
245 setText(i18n("&Fullscreen"));
246 setIcon(KIcon("view-fullscreen"));
248 setChecked(item
->isFullScreen());
249 setEnabled(item
->isActionSupported(NET::ActionFullScreen
));
252 AdvancedMenu::AdvancedMenu(QWidget
*parent
, AbstractItemPtr item
)
255 setTitle(i18n("Ad&vanced"));
256 addAction(new KeepAboveActionImpl(this, item
));
257 addAction(new KeepBelowActionImpl(this, item
));
258 addAction(new ViewFullscreenActionImpl(this, item
));
261 LeaveGroupActionImpl::LeaveGroupActionImpl(QObject
*parent
, AbstractItemPtr item
, GroupManager
*strategy
)
262 : QAction(parent
), abstractItem(item
), groupingStrategy(strategy
)
265 connect(this, SIGNAL(triggered()), this, SLOT(leaveGroup()));
266 setText(i18n("&Leave Group"));
267 setIcon(KIcon("window-close"));
268 setEnabled(item
->isGrouped());
271 void LeaveGroupActionImpl::leaveGroup()
273 groupingStrategy
->manualGroupingRequest(abstractItem
,abstractItem
->parentGroup()->parentGroup());
276 EditGroupActionImpl::EditGroupActionImpl(QObject
*parent
, TaskGroup
*group
, GroupManager
*groupManager
)
279 Q_ASSERT(groupManager
);
280 connect(this, SIGNAL(triggered()), group
, SIGNAL(groupEditRequest()));
281 setText(i18n("&Edit Group"));
282 //setIcon(KIcon("window-close"));
283 if (groupManager
->groupingStrategy()) {
284 setEnabled(groupManager
->taskGrouper()->editableGroupProperties());
290 GroupingStrategyMenu::GroupingStrategyMenu(QWidget
*parent
, AbstractGroupableItem
* item
, GroupManager
*strategy
)
296 setTitle("Grouping strategy actions");
297 if (strategy
->taskGrouper()) {
298 QList
<QAction
*> groupingStrategyActions
= strategy
->taskGrouper()->strategyActions(this, item
);
299 if (!groupingStrategyActions
.empty()) {
301 foreach (QAction
*action
, groupingStrategyActions
) {
310 BasicMenu::BasicMenu(QWidget
*parent
, TaskItem
* item
, GroupManager
*strategy
, QList
<QAction
*> visualizationActions
)
316 setTitle(item
->name());
317 setIcon(item
->icon());
318 addMenu(new AdvancedMenu(this, item
));
320 if (TaskManager::self()->numberOfDesktops() > 1) {
321 addMenu(new DesktopsMenu(this, item
));
322 addAction(new ToCurrentDesktopActionImpl(this, item
));
325 addAction(new MoveActionImpl(this, item
));
326 addAction(new ResizeActionImpl(this, item
));
327 addAction(new MinimizeActionImpl(this, item
));
328 addAction(new MaximizeActionImpl(this, item
));
329 addAction(new ShadeActionImpl(this, item
));
331 if (strategy
->taskGrouper()) {
332 QList
<QAction
*> groupingStrategyActions
= strategy
->taskGrouper()->strategyActions(this, item
);
333 if (!groupingStrategyActions
.isEmpty()) {
335 foreach (QAction
*action
, groupingStrategyActions
) {
338 // delete groupingStrategyActions;
342 foreach (QAction
*action
, visualizationActions
) {
347 addAction(new CloseActionImpl(this, item
));
350 BasicMenu::BasicMenu(QWidget
*parent
, TaskGroup
* group
, GroupManager
*strategy
, QList
<QAction
*> visualizationActions
)
356 setTitle(group
->name());
357 setIcon(group
->icon());
358 foreach (AbstractGroupableItem
*item
, group
->members()) {
359 if (item
->isGroupItem()) {
360 addMenu(new BasicMenu(this, dynamic_cast<TaskGroup
*>(item
), strategy
));
362 addMenu(new BasicMenu(this, dynamic_cast<TaskItem
*>(item
), strategy
));
366 addMenu(new AdvancedMenu(this, group
));
368 if (TaskManager::self()->numberOfDesktops() > 1) {
369 addMenu(new DesktopsMenu(this, group
));
370 addAction(new ToCurrentDesktopActionImpl(this, group
));
373 addAction(new MinimizeActionImpl(this, group
));
374 addAction(new MaximizeActionImpl(this, group
));
375 addAction(new ShadeActionImpl(this, group
));
377 if (strategy
->taskGrouper()) {
378 QList
<QAction
*> groupingStrategyActions
= strategy
->taskGrouper()->strategyActions(this, group
);
379 if (!groupingStrategyActions
.isEmpty()) {
381 foreach (QAction
*action
, groupingStrategyActions
) {
386 addAction(new EditGroupActionImpl(this, group
, strategy
));
387 foreach(QAction
*action
, visualizationActions
) {
392 addAction(new CloseActionImpl(this, group
));
395 GroupPopupMenu::GroupPopupMenu(QWidget
*parent
, TaskGroup
*group
, GroupManager
*groupManager
)
398 setTitle(group
->name());
399 setIcon(group
->icon());
400 foreach (AbstractGroupableItem
*item
, group
->members()) {
402 kDebug() << "invalid Item";
406 if (item
->isGroupItem()) {
407 QMenu
* menu
= new GroupPopupMenu (this, qobject_cast
<TaskGroup
*>(item
), groupManager
);
410 QAction
* action
= new QAction(item
->icon(), item
->name(), this);
411 connect(action
, SIGNAL(triggered(bool)), (qobject_cast
<TaskItem
*>(item
))->task().data() , SLOT(activateRaiseOrIconify()));
417 } // TaskManager namespace
419 #include "taskactions.moc"
420 #include "taskactions_p.moc"