/**************************************************************************** Copyright (C) 2012-2013 by Eike Hein <hein@kde.org> ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation; either version 2 of the License, or ** (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the ** Free Software Foundation, Inc., ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . ****************************************************************************/import QtQuick 2.0import org.kde.plasma.core 2.0 as PlasmaCoreimport org.kde.plasma.components 2.0 as PlasmaComponentsimport org.kde.draganddrop 2.0import org.kde.plasma.private.taskmanager 0.1 as TaskManagerAppletimport "../code/layout.js" as LayoutManagerimport "../code/tools.js" as TaskToolsMouseArea {id: taskwidth: groupDialog.mainItem.widthheight: Math.max(theme.mSize(theme.defaultFont).height, units.iconSizes.small) + LayoutManager.verticalMargins()visible: falseLayoutMirroring.enabled: (Qt.application.layoutDirection == Qt.RightToLeft)LayoutMirroring.childrenInherit: (Qt.application.layoutDirection == Qt.RightToLeft)property int itemIndex: indexproperty bool inPopup: falseproperty bool initialGeometryExported: falseproperty bool isGroupParent: model.IsGroupParent === trueproperty bool isActive: model.IsActive === trueproperty bool isWindow: model.IsWindow === trueproperty bool isLauncher: model.IsLauncher === trueproperty bool isStartup: model.IsStartup === trueproperty bool isGroupable: model.IsGroupable === trueproperty bool demandsAttention: model.IsDemandingAttention === trueproperty int textWidth: label.implicitWidthproperty bool pressed: falseproperty int pressX: -1property int pressY: -1property Item busyIndicatorproperty QtObject contextMenu: nullproperty int wheelDelta: 0// FIXME Clean up all these props.property variant launcherUrl: model.LauncherUrl != undefined ? model.LauncherUrl : falseproperty bool isClosable: model.IsClosable === trueproperty bool isMovable: model.IsMovable === trueproperty bool isResizable: model.IsResizable === trueproperty bool isMaximizable: model.IsMaximizable === trueproperty bool isMaximized: model.IsMaximized === trueproperty bool isMinimizable: model.IsMinimizable === trueproperty bool isMinimized: model.IsMinimized === trueproperty bool isKeepAbove: model.IsKeepAbove === trueproperty bool isKeepBelow: model.IsKeepBelow === trueproperty bool isFullScreenable: model.IsFullScreenable === trueproperty bool isFullScreen: model.IsFullScreen === trueproperty bool isShadeable: model.IsShadeable === trueproperty bool isShaded: model.IsShaded === trueproperty bool isVirtualDesktopChangeable: model.IsVirtualDesktopChangeable === trueproperty int virtualDesktop: model.VirtualDesktop != undefined ? model.VirtualDesktop : -1property int isOnAllVirtualDesktops: model.IsOnAllVirtualDesktops === truereadonly property bool smartLauncherEnabled: plasmoid.configuration.smartLaunchersEnabled && !inPopup && !isStartupproperty QtObject smartLauncherItem: nullacceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MidButtonhoverEnabled: trueonVisibleChanged: {if (visible && isWindow && itemIndex == 0) {tasksModel.requestPublishDelegateGeometry(modelIndex(), backend.globalRect(task), task);initialGeometryExported = true;}}onXChanged: {if (!initialGeometryExported) {tasksModel.requestPublishDelegateGeometry(modelIndex(), backend.globalRect(task), task);initialGeometryExported = true;}}onItemIndexChanged: {if (!inPopup && !tasks.vertical&& (LayoutManager.calculateStripes() > 1 || !plasmoid.configuration.separateLaunchers)) {tasks.requestLayout();}}onIsLauncherChanged: {if (!plasmoid.configuration.separateLaunchers) {tasks.requestLayout();}}onContainsMouseChanged: {if (!containsMouse) {pressed = false;}tasks.windowsHovered(model.LegacyWinIdList, containsMouse);}onPressed: {if (mouse.button == Qt.LeftButton || mouse.button == Qt.MidButton) {pressed = true;pressX = mouse.x;pressY = mouse.y;} else if (mouse.button == Qt.RightButton) {if (plasmoid.configuration.showToolTips) {toolTip.hideToolTip();}contextMenu = tasks.contextMenuComponent.createObject(task);contextMenu.visualParent = task;contextMenu.show();}}onReleased: {if (pressed) {if (mouse.button == Qt.MidButton) {if (plasmoid.configuration.middleClickAction == TaskManagerApplet.Backend.NewInstance) {tasksModel.requestNewInstance(modelIndex());} else if (plasmoid.configuration.middleClickAction == TaskManagerApplet.Backend.Close) {tasksModel.requestClose(modelIndex());} else if (plasmoid.configuration.middleClickAction == TaskManagerApplet.Backend.ToggleMinimized) {tasksModel.requestToggleMinimized(modelIndex());}} else if (mouse.button == Qt.LeftButton) {if (mouse.modifiers & Qt.ShiftModifier) {tasksModel.requestNewInstance(index);} else if (isGroupParent) {if ((iconsOnly || mouse.modifiers == Qt.ControlModifier) && backend.canPresentWindows()) {toolTip.hideToolTip();tasks.presentWindows(model.LegacyWinIdList);} else if (groupDialog.visible) {groupDialog.visible = false;} else {groupDialog.visualParent = task;groupDialog.visible = true;}} else {if (model.IsMinimized) {var i = modelIndex();tasksModel.requestToggleMinimized(i);tasksModel.requestActivate(i);} else if (model.IsActive) {tasksModel.requestToggleMinimized(modelIndex());} else {tasksModel.requestActivate(modelIndex());}}}}pressed = false;pressX = -1;pressY = -1;}onPositionChanged: {// mouse.button is always 0 here, hence checking with mouse.buttonsif (pressX != -1 && mouse.buttons == Qt.LeftButton && dragHelper.isDrag(pressX, pressY, mouse.x, mouse.y)) {tasks.dragSource = task;dragHelper.startDrag(task, model.MimeType, model.MimeData,model.LauncherUrl, model.decoration);pressX = -1;pressY = -1;return;}}onWheel: {if (plasmoid.configuration.wheelEnabled) {wheelDelta = TaskTools.wheelActivateNextPrevTask(wheelDelta, wheel.angleDelta.y);}}onSmartLauncherEnabledChanged: {if (smartLauncherEnabled && !smartLauncherItem) {var smartLauncher = Qt.createQmlObject("import org.kde.plasma.private.taskmanager 0.1 as TaskManagerApplet;TaskManagerApplet.SmartLauncherItem { }", task);smartLauncher.launcherUrl = Qt.binding(function() { return model.LauncherUrl; });smartLauncherItem = smartLauncher;}}function modelIndex() {return (inPopup ? tasksModel.makeModelIndex(groupDialog.visualParent.itemIndex, index): tasksModel.makeModelIndex(index));}PlasmaCore.FrameSvgItem {id: frameanchors {fill: parenttopMargin: (!tasks.vertical && taskList.rows > 1) ? units.smallSpacing / 4 : 0bottomMargin: (!tasks.vertical && taskList.rows > 1) ? units.smallSpacing / 4 : 0leftMargin: ((inPopup || tasks.vertical) && taskList.columns > 1) ? units.smallSpacing / 4 : 0rightMargin: ((inPopup || tasks.vertical) && taskList.columns > 1) ? units.smallSpacing / 4 : 0}imagePath: "widgets/tasks"property string basePrefix: "normal"prefix: TaskTools.taskPrefix("normal")onRepaintNeeded: prefix = TaskTools.taskPrefix(basePrefix);onBasePrefixChanged: prefix = TaskTools.taskPrefix(basePrefix);PlasmaCore.ToolTipArea {id: toolTipanchors.fill: parentactive: !inPopup && !groupDialog.visible && plasmoid.configuration.showToolTipsinteractive: truelocation: plasmoid.locationmainItem: toolTipDelegateonContainsMouseChanged: {if (containsMouse) {toolTipDelegate.parentIndex = itemIndex;toolTipDelegate.windows = Qt.binding(function() {return model.LegacyWinIdList;});toolTipDelegate.mainText = Qt.binding(function() {return model.display;});toolTipDelegate.icon = Qt.binding(function() {return model.decoration;});toolTipDelegate.subText = Qt.binding(function() {return model.IsLauncher ? model.GenericName : toolTip.generateSubText(model);});toolTipDelegate.launcherUrl = Qt.binding(function() {return model.LauncherUrl;});}}function generateSubText(task) {var subTextEntries = new Array();if (!plasmoid.configuration.showOnlyCurrentDesktop&& virtualDesktopInfo.numberOfDesktops > 1&& !model.IsOnAllVirtualDesktops&& model.VirtualDesktop != -1&& model.VirtualDesktop != undefined) {subTextEntries.push(i18n("On %1", virtualDesktopInfo.desktopNames[model.VirtualDesktop - 1]));}if (model.Activities == undefined) {return subTextEntries.join("\n");}if (model.Activities.length == 0 && activityInfo.numberOfRunningActivities > 1) {subTextEntries.push(i18nc("Which virtual desktop a window is currently on","Available on all activities"));} else if (model.Activities.length > 0) {var activityNames = new Array();for (var i = 0; i < model.Activities.length; i++) {var activity = model.Activities[i];if (plasmoid.configuration.showOnlyCurrentActivity) {if (activity != activityInfo.currentActivity) {activityNames.push(activityInfo.activityName(model.Activities[i]));}} else if (activity != activityInfo.currentActivity) {activityNames.push(activityInfo.activityName(model.Activities[i]));}}if (plasmoid.configuration.showOnlyCurrentActivity) {if (activityNames.length > 0) {subTextEntries.push(i18nc("Activities a window is currently on (apart from the current one)","Also available on %1", activityNames.join(", ")));}} else if (activityNames.length > 0) {subTextEntries.push(i18nc("Which activities a window is currently on","Available on %1", activityNames.join(", ")));}}return subTextEntries.join("\n");}}}Loader {anchors.fill: frameasynchronous: truesource: "TaskProgressOverlay.qml"active: plasmoid.configuration.smartLaunchersEnabled && task.smartLauncherItem && task.smartLauncherItem.progressVisible}Item {id: iconBoxanchors {left: parent.leftleftMargin: tasks.vertical && !label.visible ? adjustMargin(true, parent.width, taskFrame.margins.left) : taskFrame.margins.lefttop: parent.toptopMargin: adjustMargin(false, parent.height, taskFrame.margins.top);bottom: parent.bottombottomMargin: adjustMargin(false, parent.height, taskFrame.margins.bottom);right: (tasks.vertical && !label.visible && !inPopup) ? parent.right : undefinedrightMargin: tasks.vertical && !label.visible ? adjustMargin(true, parent.width, taskFrame.margins.right) : undefined}function adjustMargin(vert, size, margin) {if (!size) {return margin;}var margins = vert ? LayoutManager.horizontalMargins() : LayoutManager.verticalMargins();if ((size - margins) < units.iconSizes.small) {return Math.ceil((margin * (units.iconSizes.small / size)) / 2);}return margin;}width: inPopup ? units.iconSizes.small : Math.min(height, parent.width - LayoutManager.horizontalMargins())PlasmaCore.IconItem {id: iconanchors.fill: parentactive: task.containsMouse || (task.contextMenu && task.contextMenu.status == PlasmaComponents.DialogStatus.Open)enabled: trueusesPlasmaTheme: falsesource: model.decoration}Loader {anchors.fill: iconasynchronous: truesource: "TaskBadgeOverlay.qml"active: plasmoid.configuration.smartLaunchersEnabled && height >= units.iconSizes.small&& icon.visible && task.smartLauncherItem && task.smartLauncherItem.countVisible}PlasmaComponents.BusyIndicator {id: busyIndicatoranchors.fill: parentvisible: model.IsStartup === truerunning: model.IsStartup === true}states: [// Using a state transition avoids a binding loop between label.visible and// the text label margin, which derives from the icon width.State {name: "standalone"when: !label.visibleAnchorChanges {target: iconBoxanchors.left: undefinedanchors.horizontalCenter: parent.horizontalCenter}PropertyChanges {target: iconBoxanchors.leftMargin: 0}}]}TaskManagerApplet.TextLabel {id: labelanchors {fill: parentleftMargin: taskFrame.margins.left + iconBox.width + units.smallSpacingtopMargin: taskFrame.margins.toprightMargin: taskFrame.margins.rightbottomMargin: taskFrame.margins.bottom}visible: (inPopup || !iconsOnly && !model.IsLauncher && (parent.width - LayoutManager.horizontalMargins()) >= (theme.mSize(theme.defaultFont).width * 7))enabled: truetext: (!inPopup && iconsOnly) ? "" : model.displaycolor: theme.textColorelide: !inPopup}states: [State {name: "launcher"when: model.IsLauncherPropertyChanges {target: framebasePrefix: ""}},State {name: "hovered"when: containsMouse || (contextMenu.status == PlasmaComponents.DialogStatus.Open && contextMenu.visualParent == task)PropertyChanges {target: framebasePrefix: "hover"}},State {name: "attention"when: model.IsDemandingAttention || (task.smartLauncherItem && task.smartLauncherItem.urgent)PropertyChanges {target: framebasePrefix: "attention"}},State {name: "minimized"when: model.IsMinimized && !(groupDialog.visible && groupDialog.target == task)PropertyChanges {target: framebasePrefix: "minimized"}},State {name: "active"when: model.IsActive || groupDialog.visible && groupDialog.target == taskPropertyChanges {target: framebasePrefix: "focus"}}]Component.onCompleted: {if (!inPopup) {var component = Qt.createComponent("GroupExpanderOverlay.qml");component.createObject(task);}}}