shift-shell/containments/panel/package/contents/ui/main.qml

403 lines
14 KiB
QML
Raw Normal View History

/*
* Copyright 2015 Marco Martin <mart@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 2.010-1301, USA.
*/
import QtQuick 2.12
import QtQuick.Layouts 1.3
2019-10-08 15:15:17 +00:00
import QtQml.Models 2.12
2020-02-05 19:25:52 +00:00
import QtGraphicalEffects 1.12
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
2019-10-08 15:15:17 +00:00
import org.kde.plasma.components 3.0 as PlasmaComponents
import org.kde.plasma.workspace.components 2.0 as PlasmaWorkspace
2019-10-04 10:59:58 +00:00
import org.kde.taskmanager 0.1 as TaskManager
import org.kde.plasma.private.nanoshell 2.0 as NanoShell
2020-07-22 15:17:10 +00:00
import org.kde.plasma.private.mobileshell 1.0 as MobileShell
import "LayoutManager.js" as LayoutManager
import "quicksettings"
import "indicators" as Indicators
2020-07-22 15:17:10 +00:00
2020-02-05 19:25:52 +00:00
Item {
id: root
width: 480
2019-10-04 10:59:58 +00:00
height: 30
2019-10-04 10:59:58 +00:00
Plasmoid.backgroundHints: showingApp ? PlasmaCore.Types.StandardBackground : PlasmaCore.Types.NoBackground
property Item toolBox
property int buttonHeight: width/4
property bool reorderingApps: false
property var layoutManager: LayoutManager
readonly property color backgroundColor: NanoShell.StartupFeedback.visible ? NanoShell.StartupFeedback.backgroundColor : icons.backgroundColor
readonly property bool showingApp: !MobileShell.HomeScreenControls.homeScreenVisible
readonly property bool hasTasks: tasksModel.count > 0
2019-10-04 10:59:58 +00:00
Containment.onAppletAdded: {
addApplet(applet, x, y);
LayoutManager.save();
}
function addApplet(applet, x, y) {
var compactContainer = compactContainerComponent.createObject(appletIconsRow)
print("Applet added: " + applet + " " + applet.title)
applet.parent = compactContainer;
compactContainer.applet = applet;
applet.anchors.fill = compactContainer;
applet.visible = true;
//FIXME: make a way to instantiate fullRepresentationItem without the open/close dance
applet.expanded = true
applet.expanded = false
var fullContainer = null;
if (applet.pluginName == "org.kde.plasma.notifications") {
fullContainer = fullNotificationsContainerComponent.createObject(fullRepresentationView.contentItem, {"fullRepresentationModel": fullRepresentationModel, "fullRepresentationView": fullRepresentationView});
} else {
fullContainer = fullContainerComponent.createObject(fullRepresentationView.contentItem, {"fullRepresentationModel": fullRepresentationModel, "fullRepresentationView": fullRepresentationView});
}
2019-10-22 11:38:07 +00:00
applet.fullRepresentationItem.parent = fullContainer;
fullContainer.applet = applet;
2019-10-08 16:21:39 +00:00
fullContainer.contentItem = applet.fullRepresentationItem;
//applet.fullRepresentationItem.anchors.fill = fullContainer;
}
Component.onCompleted: {
LayoutManager.plasmoid = plasmoid;
LayoutManager.root = root;
2015-06-04 03:34:43 +00:00
LayoutManager.layout = appletsLayout;
LayoutManager.restore();
}
2019-10-04 10:59:58 +00:00
TaskManager.TasksModel {
id: tasksModel
sortMode: TaskManager.TasksModel.SortVirtualDesktop
groupMode: TaskManager.TasksModel.GroupDisabled
screenGeometry: plasmoid.screenGeometry
filterByScreen: plasmoid.configuration.showForCurrentScreenOnly
//FIXME: workaround
Component.onCompleted: tasksModel.countChanged();
2019-10-04 10:59:58 +00:00
}
2015-05-12 16:59:55 +00:00
PlasmaCore.DataSource {
id: statusNotifierSource
engine: "statusnotifieritem"
interval: 0
onSourceAdded: {
connectSource(source)
}
Component.onCompleted: {
connectedSources = sources
}
}
RowLayout {
id: appletsLayout
Layout.minimumHeight: Math.max(root.height, Math.round(Layout.preferredHeight / root.height) * root.height)
}
//todo: REMOVE?
Component {
id: compactContainerComponent
2015-04-25 15:30:08 +00:00
Item {
property Item applet
visible: applet && (applet.status != PlasmaCore.Types.HiddenStatus && applet.status != PlasmaCore.Types.PassiveStatus)
2015-06-04 03:34:43 +00:00
Layout.fillHeight: true
Layout.minimumWidth: applet && applet.compactRepresentationItem ? Math.max(applet.compactRepresentationItem.Layout.minimumWidth, appletIconsRow.height) : appletIconsRow.height
Layout.maximumWidth: Layout.minimumWidth
}
}
2019-10-08 15:15:17 +00:00
Component {
id: fullContainerComponent
FullContainer {
}
}
Component {
id: fullNotificationsContainerComponent
FullNotificationsContainer {
}
}
PlasmaCore.DataSource {
id: timeSource
engine: "time"
connectedSources: ["Local"]
interval: 60 * 1000
}
2020-02-05 19:25:52 +00:00
DropShadow {
anchors.fill: icons
2020-06-26 21:59:07 +00:00
visible: !showingApp
2020-02-12 08:57:40 +00:00
cached: true
2020-02-05 19:25:52 +00:00
horizontalOffset: 0
verticalOffset: 1
radius: 4.0
samples: 17
color: Qt.rgba(0,0,0,0.8)
source: icons
}
// screen top panel
2020-02-05 19:25:52 +00:00
PlasmaCore.ColorScope {
id: icons
2015-06-03 19:52:02 +00:00
z: 1
2020-02-05 19:25:52 +00:00
colorGroup: showingApp ? PlasmaCore.Theme.NormalColorGroup : PlasmaCore.Theme.ComplementaryColorGroup
2019-10-04 10:01:56 +00:00
//parent: slidingPanel.visible && !slidingPanel.wideScreen ? panelContents : root
anchors {
left: parent.left
right: parent.right
bottom: parent.bottom
}
height: root.height
2019-10-04 10:59:58 +00:00
Rectangle {
anchors.fill: parent
2020-02-06 14:39:25 +00:00
gradient: Gradient {
GradientStop {
position: 1.0
color: showingApp ? root.backgroundColor : "transparent"
2020-02-06 14:39:25 +00:00
}
GradientStop {
position: 0.0
color: showingApp ? root.backgroundColor : Qt.rgba(0, 0, 0, 0.1)
2020-02-06 14:39:25 +00:00
}
}
2019-10-04 10:59:58 +00:00
}
Loader {
2015-06-05 04:14:18 +00:00
id: strengthLoader
height: parent.height
2015-06-05 04:14:18 +00:00
width: item ? item.width : 0
2019-10-07 11:16:50 +00:00
source: Qt.resolvedUrl("indicators/SignalStrength.qml")
}
2015-05-12 16:59:55 +00:00
Row {
2015-06-05 04:14:18 +00:00
id: sniRow
anchors.left: strengthLoader.right
2015-05-12 16:59:55 +00:00
height: parent.height
Repeater {
id: statusNotifierRepeater
model: PlasmaCore.SortFilterModel {
id: filteredStatusNotifiers
filterRole: "Title"
sourceModel: PlasmaCore.DataModel {
dataSource: statusNotifierSource
}
}
2015-05-12 16:59:55 +00:00
delegate: TaskWidget {
}
}
}
2015-06-05 04:14:18 +00:00
PlasmaComponents.Label {
id: clock
property bool is24HourTime: Qt.locale().timeFormat(Locale.ShortFormat).toLowerCase().indexOf("ap") === -1
2015-06-05 04:14:18 +00:00
anchors.fill: parent
text: Qt.formatTime(timeSource.data.Local.DateTime, is24HourTime ? "h:mm" : "h:mm ap")
2015-06-05 04:14:18 +00:00
color: PlasmaCore.ColorScope.textColor
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter
font.pixelSize: height / 2
}
RowLayout {
id: appletIconsRow
2015-05-12 16:59:55 +00:00
anchors {
2015-06-05 04:14:18 +00:00
bottom: parent.bottom
right: simpleIndicatorsLayout.left
2015-05-12 16:59:55 +00:00
}
2017-08-30 18:39:43 +00:00
height: parent.height
2015-05-12 16:59:55 +00:00
}
//TODO: pluggable
RowLayout {
id: simpleIndicatorsLayout
anchors {
top: parent.top
bottom: parent.bottom
right: parent.right
rightMargin: units.smallSpacing
}
Indicators.Bluetooth {}
Indicators.Wifi {}
Indicators.Volume {}
Indicators.Battery {}
}
2015-05-12 16:59:55 +00:00
}
// screen top panel background (background for the rest of the screen in SlidingPanel.qml)
Rectangle {
anchors.fill: parent
color: "black"
opacity: 0.6 * Math.min(1, slidingPanel.offset/panelContents.height)
}
2015-05-12 16:59:55 +00:00
MouseArea {
2015-06-03 19:52:02 +00:00
z: 99
2015-05-12 16:59:55 +00:00
property int oldMouseY: 0
2015-05-12 16:59:55 +00:00
anchors.fill: parent
onPressed: {
slidingPanel.cancelAnimations();
2019-09-18 14:42:33 +00:00
slidingPanel.drawerX = Math.min(Math.max(0, mouse.x - slidingPanel.drawerWidth/2), slidingPanel.width - slidingPanel.drawerWidth)
2017-09-05 11:59:20 +00:00
slidingPanel.userInteracting = true;
2015-05-12 16:59:55 +00:00
oldMouseY = mouse.y;
2019-10-04 14:27:29 +00:00
slidingPanel.offset = 0//units.gridUnit * 2;
2019-09-18 14:42:33 +00:00
slidingPanel.showFullScreen();
2015-05-12 16:59:55 +00:00
}
onPositionChanged: {
2019-10-11 13:21:24 +00:00
slidingPanel.offset = Math.min(slidingPanel.contentItem.height, slidingPanel.offset + (mouse.y - oldMouseY));
2020-08-20 09:44:56 +00:00
2015-05-12 16:59:55 +00:00
oldMouseY = mouse.y;
}
2017-09-05 11:59:20 +00:00
onReleased: {
slidingPanel.userInteracting = false;
slidingPanel.updateState();
}
2015-05-12 16:59:55 +00:00
}
2015-05-12 16:59:55 +00:00
SlidingPanel {
id: slidingPanel
width: plasmoid.availableScreenRect.width
height: plasmoid.availableScreenRect.height
2020-08-20 09:44:56 +00:00
openThreshold: units.gridUnit * 2
2017-09-05 11:14:15 +00:00
headerHeight: root.height
2019-10-04 14:02:26 +00:00
offset: quickSettingsParent.height
2020-02-04 20:26:26 +00:00
onClosed: quickSettings.closed()
contentItem: Item {
2019-10-04 14:37:51 +00:00
implicitWidth: quickSettingsParent.implicitWidth
2020-09-01 15:42:53 +00:00
implicitHeight: Math.min(slidingPanel.height, quickSettingsParent.implicitHeight)
GridLayout {
id: panelContents
anchors.fill: parent
implicitWidth: quickSettingsParent.implicitWidth
implicitHeight: Math.min(slidingPanel.height, quickSettingsParent.implicitHeight)
columns: slidingPanel.wideScreen ? 2 : 1
rows: slidingPanel.wideScreen ? 1 : 2
2019-10-08 16:21:39 +00:00
DrawerBackground {
id: quickSettingsParent
//anchors.fill: parent
Layout.alignment: Qt.AlignTop
Layout.preferredWidth: slidingPanel.wideScreen ? Math.min(slidingPanel.width/2, units.gridUnit * 25) : panelContents.width
z: 4
contentItem: QuickSettings {
id: quickSettings
onCloseRequested: {
slidingPanel.hide()
}
}
2019-10-08 16:21:39 +00:00
}
ListView {
id: fullRepresentationView
z: 1
interactive: width < contentWidth
//parent: slidingPanel.wideScreen ? slidingPanel.flickable.contentItem : panelContents
Layout.preferredWidth: slidingPanel.wideScreen ? Math.min(slidingPanel.width/2, quickSettingsParent.width*fullRepresentationModel.count) : panelContents.width
//Layout.fillWidth: true
clip: slidingPanel.wideScreen
y: slidingPanel.wideScreen ? 0 : quickSettingsParent.height - height * (1-opacity)
opacity: slidingPanel.wideScreen ? 1 : fullRepresentationModel.count > 0 && slidingPanel.offset/panelContents.height
height: Math.min(plasmoid.screenGeometry.height - slidingPanel.headerHeight - quickSettingsParent.height - bottomBar.height, implicitHeight)
//leftMargin: slidingPanel.drawerX
preferredHighlightBegin: slidingPanel.drawerX
2019-10-08 16:21:39 +00:00
implicitHeight: units.gridUnit * 20
cacheBuffer: width * 100
highlightFollowsCurrentItem: true
highlightRangeMode: ListView.StrictlyEnforceRange
highlightMoveDuration: units.longDuration
snapMode: slidingPanel.wideScreen ? ListView.NoSnap : ListView.SnapOneItem
model: ObjectModel {
id: fullRepresentationModel
}
orientation: ListView.Horizontal
2019-10-08 15:15:17 +00:00
MouseArea {
parent: fullRepresentationView.contentItem
anchors.fill: parent
z: -1
onClicked: slidingPanel.close()
}
//implicitHeight: fullRepresentationLayout.implicitHeight
//clip: true
}
2019-10-08 15:15:17 +00:00
}
}
2019-10-08 16:21:39 +00:00
DrawerBackground {
2019-10-08 15:15:17 +00:00
id: bottomBar
anchors {
left: parent.left
right: parent.right
bottom: parent.bottom
}
2019-10-08 16:21:39 +00:00
parent: slidingPanel.fixedArea
opacity: fullRepresentationView.opacity
visible: !slidingPanel.wideScreen && fullRepresentationModel.count > 1
2019-10-08 15:15:17 +00:00
//height: 40
z: 100
contentItem: RowLayout {
PlasmaComponents.TabBar {
Layout.fillWidth: true
Layout.fillHeight: true
position: PlasmaComponents.TabBar.Footer
2019-10-08 16:21:39 +00:00
Text {
text:fullRepresentationModel.count
}
2019-10-08 15:15:17 +00:00
Repeater {
model: fullRepresentationView.count
delegate: PlasmaComponents.TabButton {
implicitHeight: parent.height
text: fullRepresentationModel.get(index).applet.title
checked: fullRepresentationView.currentIndex === index
onClicked: fullRepresentationView.currentIndex = index
}
}
}
2019-10-08 15:15:17 +00:00
PlasmaComponents.ToolButton {
Layout.fillHeight: true
Layout.preferredWidth: height
icon.name: "paint-none"
onClicked: slidingPanel.close();
}
}
}
2015-05-12 16:59:55 +00:00
}
}