| 1 |
/* Copyright (C) 2016 - 2017 Dan Chapman <[email protected]> |
| 2 |
|
| 3 |
This file is part of Dekko email client for Ubuntu devices |
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or |
| 6 |
modify it under the terms of the GNU General Public License as |
| 7 |
published by the Free Software Foundation; either version 2 of |
| 8 |
the License or (at your option) version 3 |
| 9 |
|
| 10 |
This program is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
GNU General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU General Public License |
| 16 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
import QtQuick 2.4 |
| 19 |
import QtQuick.Window 2.2 |
| 20 |
import Lomiri.Components 1.3 |
| 21 |
import Dekko.Components 1.0 |
| 22 |
import Dekko.Lomiri.Constants 1.0 |
| 23 |
|
| 24 |
Item { |
| 25 |
id: panel |
| 26 |
width: implicitWidth; |
| 27 |
height: implicitHeight; |
| 28 |
// visible: !detached; |
| 29 |
implicitWidth: (!d.shouldStretch ? size : -1); |
| 30 |
implicitHeight: (!d.shouldStretch ? size : -1); |
| 31 |
// Which edge should have the resizable mouse area etc |
| 32 |
// Defaults to right side as if it is docked to the left |
| 33 |
// of it's parent |
| 34 |
property int activeEdge: Item.Right |
| 35 |
property int size: units.gu(30) |
| 36 |
property int minSize: units.gu(10) |
| 37 |
property int maxSize: units.gu(50) |
| 38 |
property bool resizable: true |
| 39 |
// If true the panels implicit size hints will get set to -1 |
| 40 |
// which when used in a StretchRow/Column will fill all the available space. |
| 41 |
// This works the same was as using Stretcher{} |
| 42 |
// You only really want to set this to true if this panel is the main page container |
| 43 |
// for mobile / small form factor devices. |
| 44 |
property bool stretchOnSmallFF: false |
| 45 |
property var viewState: dekko ? dekko : undefined |
| 46 |
readonly property bool expanded: !d.collapsed |
| 47 |
default property alias content: internal.data |
| 48 |
property alias contentItem: internal |
| 49 |
property alias container: container |
| 50 |
|
| 51 |
Item { |
| 52 |
id: container; |
| 53 |
visible: expanded; |
| 54 |
anchors.fill: parent |
| 55 |
Item { |
| 56 |
id: internal; |
| 57 |
anchors.fill: parent; |
| 58 |
|
| 59 |
// CONTENT HERE |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
MouseArea { |
| 64 |
id: grabber; |
| 65 |
visible: (expanded && resizable); |
| 66 |
onPressed: { |
| 67 |
var tmp = mapToItem (panel.parent, mouse.x, mouse.y); |
| 68 |
originalPos = Qt.point (tmp.x, tmp.y); |
| 69 |
originalSize = size; |
| 70 |
} |
| 71 |
onPositionChanged: { |
| 72 |
var absCurrPos = mapToItem(panel.parent, mouse.x, mouse.y); |
| 73 |
var deltaX = (absCurrPos.x - originalPos.x); |
| 74 |
var deltaY = (absCurrPos.y - originalPos.y); |
| 75 |
var tmp = originalSize; |
| 76 |
switch(activeEdge) { |
| 77 |
case Item.Top: |
| 78 |
tmp -= deltaY; |
| 79 |
break; |
| 80 |
case Item.Left: |
| 81 |
tmp -= deltaX; |
| 82 |
break; |
| 83 |
case Item.Right: |
| 84 |
tmp += deltaX; |
| 85 |
break; |
| 86 |
case Item.Bottom: |
| 87 |
tmp += deltaY; |
| 88 |
break; |
| 89 |
} |
| 90 |
size = Math.max(minSize, Math.min (maxSize, tmp)); |
| 91 |
} |
| 92 |
|
| 93 |
property int originalSize : 0; |
| 94 |
property point originalPos : Qt.point(0,0); |
| 95 |
|
| 96 |
HorizontalGradiant { |
| 97 |
id: sideShadow |
| 98 |
visible: grabber.pressed |
| 99 |
anchors { |
| 100 |
right: parent.right |
| 101 |
} |
| 102 |
rightToLeft: true |
| 103 |
height: parent.height |
| 104 |
z: 1 |
| 105 |
opacity: 0.7 |
| 106 |
width: units.gu(0.5) |
| 107 |
gradient: Gradient { |
| 108 |
GradientStop { position: 0.0; color: LomiriColors.blue } |
| 109 |
GradientStop { position: 1.0; color: "transparent" } |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
Line { |
| 115 |
id: divider |
| 116 |
visible: grabber.visible |
| 117 |
} |
| 118 |
|
| 119 |
function detach () { |
| 120 |
if (d.subWindow === null) { |
| 121 |
var rootItem = Introspector.window (panel); |
| 122 |
var abspos = rootItem.contentItem.mapFromItem (panel, 0 , 0); |
| 123 |
d.subWindow = compoWindow.createObject(Introspector.window (panel), { |
| 124 |
"x" : (abspos.x + rootItem.x), |
| 125 |
"y" : (abspos.y + rootItem.y), |
| 126 |
}); |
| 127 |
panel.parent = d.subWindow.contentItem; |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
function attach () { |
| 132 |
if (d.subWindow !== null) { |
| 133 |
panel.parent = internal; |
| 134 |
d.subWindow.destroy (); |
| 135 |
} |
| 136 |
} |
| 137 |
Component { |
| 138 |
id: compoWindow; |
| 139 |
|
| 140 |
Window { |
| 141 |
// color: rect.color; |
| 142 |
title: "Dev Stuff" |
| 143 |
width: internal.width; |
| 144 |
height: internal.height; |
| 145 |
visible: true; |
| 146 |
onClosing: { attach (); } |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
QtObject { |
| 151 |
id: d |
| 152 |
property bool collapsed: false |
| 153 |
readonly property bool shouldStretch: viewState && viewState.isSmallFF && stretchOnSmallFF |
| 154 |
readonly property bool dockedLeft: activeEdge === Item.Right |
| 155 |
readonly property bool dockedRight: activeEdge === Item.Left |
| 156 |
readonly property bool dockedBottom: activeEdge === Item.Top |
| 157 |
readonly property bool dockedTop: activeEdge === Item.Bottom |
| 158 |
property Window subWindow : null |
| 159 |
} |
| 160 |
|
| 161 |
states: [ |
| 162 |
State { |
| 163 |
when: d.dockedLeft |
| 164 |
|
| 165 |
AnchorChanges { |
| 166 |
target: grabber; |
| 167 |
anchors { |
| 168 |
top: panel.top; |
| 169 |
left: undefined; |
| 170 |
right: panel.right; |
| 171 |
bottom: panel.bottom; |
| 172 |
} |
| 173 |
} |
| 174 |
PropertyChanges { |
| 175 |
target: grabber; |
| 176 |
width: units.gu(0.5); |
| 177 |
cursorShape: Qt.SizeHorCursor; |
| 178 |
} |
| 179 |
AnchorChanges { |
| 180 |
target: divider; |
| 181 |
anchors { |
| 182 |
top: panel.top; |
| 183 |
left: undefined; |
| 184 |
right: panel.right; |
| 185 |
bottom: panel.bottom; |
| 186 |
} |
| 187 |
} |
| 188 |
}, |
| 189 |
State { |
| 190 |
when: d.dockedRight |
| 191 |
|
| 192 |
AnchorChanges { |
| 193 |
target: grabber; |
| 194 |
anchors { |
| 195 |
top: panel.top; |
| 196 |
left: panel.left; |
| 197 |
right: undefined; |
| 198 |
bottom: panel.bottom; |
| 199 |
} |
| 200 |
} |
| 201 |
PropertyChanges { |
| 202 |
target: grabber; |
| 203 |
width: units.gu(0.5); |
| 204 |
cursorShape: Qt.SizeHorCursor; |
| 205 |
} |
| 206 |
AnchorChanges { |
| 207 |
target: divider; |
| 208 |
anchors { |
| 209 |
top: panel.top; |
| 210 |
left: panel.left; |
| 211 |
right: undefined; |
| 212 |
bottom: panel.bottom; |
| 213 |
} |
| 214 |
} |
| 215 |
}, |
| 216 |
State { |
| 217 |
when: d.dockedTop |
| 218 |
|
| 219 |
AnchorChanges { |
| 220 |
target: grabber; |
| 221 |
anchors { |
| 222 |
top: undefined; |
| 223 |
left: panel.left; |
| 224 |
right: panel.right; |
| 225 |
bottom: panel.bottom; |
| 226 |
} |
| 227 |
} |
| 228 |
PropertyChanges { |
| 229 |
target: grabber; |
| 230 |
height: units.gu(0.5); |
| 231 |
cursorShape: Qt.SizeVerCursor; |
| 232 |
} |
| 233 |
AnchorChanges { |
| 234 |
target: divider; |
| 235 |
anchors { |
| 236 |
top: undefined; |
| 237 |
left: panel.left; |
| 238 |
right: panel.right; |
| 239 |
bottom: panel.bottom; |
| 240 |
} |
| 241 |
} |
| 242 |
}, |
| 243 |
State { |
| 244 |
when: d.dockedBottom |
| 245 |
|
| 246 |
AnchorChanges { |
| 247 |
target: grabber; |
| 248 |
anchors { |
| 249 |
top: panel.top; |
| 250 |
left: panel.left; |
| 251 |
right: panel.right; |
| 252 |
bottom: undefined; |
| 253 |
} |
| 254 |
} |
| 255 |
PropertyChanges { |
| 256 |
target: grabber; |
| 257 |
height: units.gu(0.5); |
| 258 |
cursorShape: Qt.SizeVerCursor; |
| 259 |
} |
| 260 |
AnchorChanges { |
| 261 |
target: divider; |
| 262 |
anchors { |
| 263 |
top: panel.top; |
| 264 |
left: panel.left; |
| 265 |
right: panel.right; |
| 266 |
bottom: undefined; |
| 267 |
} |
| 268 |
} |
| 269 |
} |
| 270 |
] |
| 271 |
} |
| 272 |
|