shift-shell/shell/contents/explorer/WidgetExplorer.qml

307 lines
12 KiB
QML
Raw Normal View History

/*
* Copyright 2011 Marco Martin <mart@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 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 Library 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.2
2015-09-23 10:22:39 +00:00
import QtGraphicalEffects 1.0
import QtQuick.Controls 1.1
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.kquickcontrolsaddons 2.0
2017-11-10 15:21:20 +00:00
import org.kde.kirigami 2.2 as Kirigami
import QtQuick.Window 2.1
import QtQuick.Layouts 1.1
import org.kde.plasma.private.shell 2.0
Rectangle {
id: root
color: Qt.rgba(0, 0, 0, (1 - Math.abs(main.x / (main.width/2))) * 0.8)
signal closed()
2015-10-07 13:28:56 +00:00
property alias containment: widgetExplorer.containment
2017-11-10 15:21:20 +00:00
Component.onCompleted: splitDrawer.contentX = typeSelector.width
MouseArea {
anchors.fill: parent
2015-09-23 09:54:26 +00:00
drag.filterChildren: true
drag.target: splitDrawer.open ? null : main
drag.axis: Drag.XAxis
drag.maximumX: 0
onReleased: {
if (main.x < -main.width/3) {
removeAnim.running = true;
} else {
openAnim.running = true;
}
}
onClicked: {
if (mouse.x > main.width) {
removeAnim.running = true;
}
}
NumberAnimation {
2015-09-23 09:54:26 +00:00
id: openAnim
running: true
target: main
properties: "x"
duration: units.longDuration
easing.type: Easing.InOutQuad
2015-09-23 09:54:26 +00:00
to: 0
}
2015-09-23 09:54:26 +00:00
SequentialAnimation {
id: removeAnim
NumberAnimation {
target: main
properties: "x"
duration: units.longDuration
easing.type: Easing.InOutQuad
to: -main.width
}
ScriptAction {
script: root.closed();
}
}
2015-09-23 09:54:26 +00:00
Rectangle {
id: main
2015-09-23 09:54:26 +00:00
x: -width
width: parent.width - parent.width/6
height: parent.height
color: theme.backgroundColor
2015-09-23 09:54:26 +00:00
//external drop events can cause a raise event causing us to lose focus and
//therefore get deleted whilst we are still in a drag exec()
//this is a clue to the owning dialog that hideOnWindowDeactivate should be deleted
//See https://bugs.kde.org/show_bug.cgi?id=332733
property bool preventWindowHide: false
2015-09-23 09:54:26 +00:00
property Item getWidgetsButton
property Item categoryButton
2015-09-23 09:54:26 +00:00
function addCurrentApplet() {
var pluginName = list.currentItem ? list.currentItem.pluginName : ""
if (pluginName) {
widgetExplorer.addApplet(pluginName)
}
}
2015-09-23 10:22:39 +00:00
LinearGradient {
width: units.gridUnit/2
anchors {
left: parent.right
top: parent.top
bottom: parent.bottom
rightMargin: -1
}
start: Qt.point(0, 0)
end: Qt.point(units.gridUnit/2, 0)
gradient: Gradient {
GradientStop {
position: 0.0
color: Qt.rgba(0, 0, 0, 0.3)
}
GradientStop {
position: 0.3
color: Qt.rgba(0, 0, 0, 0.15)
}
GradientStop {
position: 1.0
color: "transparent"
}
}
}
2015-09-23 09:54:26 +00:00
WidgetExplorer {
id: widgetExplorer
//view: desktop
onShouldClose: removeAnim.running = true;
}
2017-11-10 15:21:20 +00:00
Flickable {
2015-09-23 09:54:26 +00:00
id: splitDrawer
visible: true
anchors.fill: parent
2017-11-10 15:21:20 +00:00
clip: true
contentWidth: mainRow.width
contentHeight: height
Row {
id: mainRow
height: splitDrawer.height
PlasmaExtras.ScrollArea {
id: typeSelector
anchors {
top: parent.top
bottom: parent.bottom
}
width: units.gridUnit * 10
ListView {
model: widgetExplorer.filterModel
delegate: PlasmaComponents.ListItem {
enabled: true
visible: !model.separator
height: model.separator ? 0 : implicitHeight
PlasmaComponents.Label {
text: model.display
}
onClicked: {
list.contentX = 0
list.contentY = 0
heading.text = model.display
widgetExplorer.widgetsModel.filterQuery = model.filterData
widgetExplorer.widgetsModel.filterType = model.filterType
}
2015-09-23 09:54:26 +00:00
}
}
}
2017-11-10 15:21:20 +00:00
ColumnLayout {
anchors {
top: parent.top
bottom: parent.bottom
}
width: splitDrawer.width
2017-11-10 15:21:20 +00:00
spacing: units.smallSpacing
2017-11-10 15:21:20 +00:00
PlasmaExtras.Title {
id: heading
text: i18nd("plasma_shell_org.kde.plasma.desktop", "Widgets")
Layout.fillWidth: true
PlasmaComponents.ToolButton {
id: closeButton
anchors {
right: parent.right
verticalCenter: heading.verticalCenter
}
iconSource: "window-close"
onClicked: removeAnim.running = true;
}
}
2017-11-10 15:21:20 +00:00
PlasmaComponents.TextField {
id: searchInput
clearButtonShown: true
placeholderText: i18nd("plasma_shell_org.kde.plasma.desktop", "Search...")
onTextChanged: {
list.positionViewAtBeginning()
list.currentIndex = -1
widgetExplorer.widgetsModel.searchTerm = text
}
2015-09-23 10:01:13 +00:00
2017-11-10 15:21:20 +00:00
Component.onCompleted: forceActiveFocus()
Layout.fillWidth: true
}
2015-09-23 10:01:13 +00:00
2017-11-10 15:21:20 +00:00
PlasmaExtras.ScrollArea {
Layout.fillHeight: true
Layout.fillWidth: true
GridView {
id: list
2017-11-10 15:21:20 +00:00
model: widgetExplorer.widgetsModel
activeFocusOnTab: true
currentIndex: -1
keyNavigationWraps: true
cellWidth: units.iconSizes.huge + units.smallSpacing * 2
cellHeight: cellWidth + units.gridUnit * 4 + units.smallSpacing * 2
2017-11-10 15:21:20 +00:00
delegate: AppletDelegate {}
2017-11-10 15:21:20 +00:00
//slide in to view from the left
add: Transition {
NumberAnimation {
properties: "x"
from: -list.width
to: 0
duration: units.shortDuration * 3
2017-11-10 15:21:20 +00:00
}
}
2017-11-10 15:21:20 +00:00
//slide out of view to the right
remove: Transition {
NumberAnimation {
properties: "x"
to: list.width
duration: units.shortDuration * 3
}
}
2017-11-10 15:21:20 +00:00
//if we are adding other items into the view use the same animation as normal adding
//this makes everything slide in together
//if we make it move everything ends up weird
addDisplaced: list.add
//moved due to filtering
displaced: Transition {
NumberAnimation {
properties: "y"
duration: units.shortDuration * 3
}
}
}
}
2017-11-10 15:21:20 +00:00
Column {
id: bottomBar
anchors {
left: parent.left
right: parent.right
bottom: parent.bottom
leftMargin: units.smallSpacing
rightMargin: units.smallSpacing
bottomMargin: units.smallSpacing
}
2017-11-10 15:21:20 +00:00
spacing: units.smallSpacing
Repeater {
model: widgetExplorer.extraActions.length
PlasmaComponents.Button {
anchors {
left: parent.left
right: parent.right
}
iconSource: widgetExplorer.extraActions[modelData].icon
text: widgetExplorer.extraActions[modelData].text
onClicked: {
widgetExplorer.extraActions[modelData].trigger()
}
}
}
}
2017-11-10 15:21:20 +00:00
}
}
2015-09-23 09:54:26 +00:00
}
Component.onCompleted: {
main.getWidgetsButton = getWidgetsButton
main.categoryButton = categoryButton
}
}
}
}