Warning, /frameworks/kirigami/examples/simpleexamples/dragPageWidth.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  *  SPDX-FileCopyrightText: 2017 Eike Hein <hein@kde.org>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 import QtQuick
0008 import org.kde.kirigami as Kirigami
0009 
0010 Kirigami.ApplicationWindow {
0011     id: root
0012 
0013     property int defaultColumnWidth: Kirigami.Units.gridUnit * 13
0014     property int columnWidth: defaultColumnWidth
0015 
0016     pageStack.defaultColumnWidth: columnWidth
0017     pageStack.initialPage: [firstPageComponent, secondPageComponent]
0018 
0019     MouseArea {
0020         id: dragHandle
0021 
0022         visible: pageStack.wideMode
0023 
0024         anchors.top: parent.top
0025         anchors.bottom: parent.bottom
0026 
0027         x: columnWidth - (width / 2)
0028         width: 2
0029 
0030         property int dragRange: (Kirigami.Units.gridUnit * 5)
0031         property int _lastX: -1
0032 
0033         cursorShape: Qt.SplitHCursor
0034 
0035         onPressed: mouse => {
0036             _lastX = mouse.x;
0037         }
0038 
0039         onPositionChanged: mouse => {
0040             if (mouse.x > _lastX) {
0041                 columnWidth = Math.min((defaultColumnWidth + dragRange),
0042                     columnWidth + (mouse.x - _lastX));
0043             } else if (mouse.x < _lastX) {
0044                 columnWidth = Math.max((defaultColumnWidth - dragRange),
0045                     columnWidth - (_lastX - mouse.x));
0046             }
0047         }
0048 
0049         Rectangle {
0050             anchors.fill: parent
0051 
0052             color: "blue"
0053         }
0054     }
0055 
0056     Component {
0057         id: firstPageComponent
0058 
0059         Kirigami.Page {
0060             id: firstPage
0061 
0062             background: Rectangle { color: "red" }
0063         }
0064     }
0065 
0066     Component {
0067         id: secondPageComponent
0068 
0069         Kirigami.Page {
0070             id: secondPage
0071 
0072             background: Rectangle { color: "green" }
0073         }
0074     }
0075 }