| 1 |
import QtQuick 2.0 |
| 2 |
|
| 3 |
Item { |
| 4 |
id: root |
| 5 |
property int activeTab: -1 |
| 6 |
property var tabs: [] |
| 7 |
property var titles: [] |
| 8 |
property int __panelWidth: 250 |
| 9 |
|
| 10 |
readonly property int panelWidth: __panelWidth |
| 11 |
|
| 12 |
Rectangle { |
| 13 |
id: contentBox |
| 14 |
x: parent.width - width // can't use an anchors, for dragability |
| 15 |
|
| 16 |
height: parent.height |
| 17 |
width: (activeTab >= 0) ? __panelWidth : 0 |
| 18 |
color: "#1f1f1f" |
| 19 |
Behavior on width { |
| 20 |
enabled: !splitterDrag.drag.active |
| 21 |
NumberAnimation { |
| 22 |
duration: 250 |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
clip: true |
| 27 |
|
| 28 |
Loader { |
| 29 |
id: loader |
| 30 |
anchors.fill: parent |
| 31 |
sourceComponent: (activeTab >= 0) ? tabs[activeTab] : null |
| 32 |
} |
| 33 |
|
| 34 |
Connections { |
| 35 |
target: loader.item |
| 36 |
function onRequestPanelClose() { root.activeTab = -1; } |
| 37 |
ignoreUnknownSignals: true |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
Rectangle { |
| 42 |
id: splitter |
| 43 |
width: 2 |
| 44 |
height: parent.height |
| 45 |
anchors.right: contentBox.left |
| 46 |
|
| 47 |
color: "orange" |
| 48 |
|
| 49 |
MouseArea { |
| 50 |
id: splitterDrag |
| 51 |
height: parent.height |
| 52 |
width: parent.width * 25 |
| 53 |
|
| 54 |
drag.target: contentBox |
| 55 |
drag.axis: Drag.XAxis |
| 56 |
drag.minimumX: 0 |
| 57 |
drag.maximumX: root.width |
| 58 |
|
| 59 |
onMouseXChanged: { |
| 60 |
__panelWidth = root.width - contentBox.x |
| 61 |
} |
| 62 |
|
| 63 |
// enabled when open? |
| 64 |
|
| 65 |
// click to toggle open / close |
| 66 |
|
| 67 |
cursorShape: Qt.SizeHorCursor |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
Column { |
| 72 |
anchors.right: splitter.left |
| 73 |
anchors.top: parent.top |
| 74 |
anchors.topMargin: 20 |
| 75 |
spacing: 1 |
| 76 |
|
| 77 |
Repeater { |
| 78 |
model: tabs |
| 79 |
Rectangle { |
| 80 |
readonly property bool tabIsActive: (model.index == activeTab) |
| 81 |
width: tabLabel.implicitHeight + 10 |
| 82 |
height: tabLabel.implicitWidth + 20 |
| 83 |
|
| 84 |
color: "#3f3f3f" |
| 85 |
border.width: 1 |
| 86 |
border.color: "#5f5f5f" |
| 87 |
|
| 88 |
Text { |
| 89 |
anchors.centerIn: parent |
| 90 |
id: tabLabel |
| 91 |
text: titles[model.index] |
| 92 |
rotation: 90 |
| 93 |
color: tabIsActive ? "orange" : tabMouse.containsMouse ? "#afafaf" : "#9f9f9f" |
| 94 |
transformOrigin: Item.Center |
| 95 |
} |
| 96 |
|
| 97 |
MouseArea { |
| 98 |
id: tabMouse |
| 99 |
hoverEnabled: true |
| 100 |
anchors.fill: parent |
| 101 |
onClicked: { |
| 102 |
if (parent.tabIsActive) { |
| 103 |
activeTab = -1 |
| 104 |
} else { |
| 105 |
activeTab = model.index |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
} // rectangle |
| 110 |
} // of repeater |
| 111 |
} |
| 112 |
} |