Warning, /maui/mauikit/src/controls.5/private/SideBar.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 * Copyright 2018 Camilo Higuita <milo.h@aol.com>
0003 *
0004 * This program is free software; you can redistribute it and/or modify
0005 * it under the terms of the GNU Library General Public License as
0006 * published by the Free Software Foundation; either version 2, or
0007 * (at your option) any later version.
0008 *
0009 * This program is distributed in the hope that it will be useful,
0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0012 * GNU General Public License for more details
0013 *
0014 * You should have received a copy of the GNU Library General Public
0015 * License along with this program; if not, write to the
0016 * Free Software Foundation, Inc.,
0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0018 */
0019
0020 import QtQuick 2.15
0021 import QtQuick.Controls 2.15
0022 import QtQml 2.15
0023 import org.mauikit.controls 1.3 as Maui
0024 import QtQuick.Templates 2.15 as T
0025 import QtQuick.Window 2.15
0026
0027 /**
0028 * SideBar
0029 * A global sidebar for the application window that can be collapsed.
0030 *
0031 *
0032 *
0033 *
0034 *
0035 *
0036 */
0037 T.Pane
0038 {
0039 id: control
0040
0041 Maui.Theme.colorSet: Maui.Theme.Window
0042 Maui.Theme.inherit: false
0043
0044 readonly property alias position : _private.position
0045 readonly property bool peeking : control.collapsed && control.position > 0
0046 readonly property bool resizing: _dragHandler.active
0047
0048 visible: position > 0
0049
0050 width: position * constrainedWidth
0051
0052 /*!
0053 * \qmlproperty Item AbstractSideBar::content
0054 *
0055 * The main content is added to an Item contents, it can anchored or sized normally.
0056 */
0057 default property alias content : _content.data
0058
0059
0060 /*!
0061 * If the sidebar should be collapsed or not, this property can be used to dynamically collapse
0062 * the sidebar on constrained spaces.
0063 */
0064 property bool collapsed: false
0065 property bool resizeable : !Maui.Handy.isMobile
0066 /*!
0067 * If when collapsed the sidebar should automatically hide or stay in place
0068 */
0069 property bool autoHide: false
0070 property bool autoShow: true
0071
0072 /*!
0073 * preferredWidth : int
0074 * The preferred width of the sidebar in the expanded state.
0075 */
0076 readonly property int constrainedWidth : Math.min(control.preferredWidth, control.Window.window.width*0.9)
0077 property int preferredWidth : Maui.Style.units.gridUnit * 12
0078 property int maximumWidth: Maui.Style.units.gridUnit * 20
0079 property int minimumWidth: Maui.Style.units.gridUnit * 4
0080 /*!
0081 * \qmlproperty MouseArea AbstractSideBar::overlay
0082 *
0083 * When the application has a constrained width to fit the sidebar and main contain,
0084 * the sidebar is in a constrained state, and the app main content gets dimmed by an overlay.
0085 * This property gives access to such ovelay element drawn on top of the app contents.
0086 */
0087 //readonly property alias overlay : _overlayLoader.item
0088
0089 clip: true
0090
0091 padding: 0
0092 topPadding: 0
0093 bottomPadding: 0
0094 leftPadding: 0
0095 rightPadding: 0
0096
0097 signal opened()
0098 signal closed()
0099
0100 background: Rectangle
0101 {
0102 opacity: Maui.Style.translucencyAvailable && Maui.Style.enableEffects ? 0.8 : 1
0103 color: Maui.Theme.backgroundColor
0104 Behavior on color
0105 {
0106 Maui.ColorTransition{}
0107 }
0108 }
0109
0110 // Component.onCompleted:
0111 // {
0112 // if(control.autoShow && control.collapsed)
0113 // control.open()
0114 // }
0115 //
0116 QtObject
0117 {
0118 id: _private
0119 property bool initial: true
0120 property double position
0121 property int resizeValue
0122 property int finalWidth : control.constrainedWidth + _dragHandler.centroid.position.x
0123
0124 // Binding on resizeValue
0125 // {
0126 // //delayed: true
0127 // // when: _dragHandler.active
0128 // value:
0129 // restoreMode: Binding.RestoreBindingOrValue
0130 // }
0131 //
0132 Binding on position
0133 {
0134 // when: control.autoHide
0135 value: control.enabled ? (!control.autoShow ? 0 : (control.collapsed && control.autoHide ? 0 : 1)) : 0
0136 restoreMode: Binding.RestoreBindingOrValue
0137 }
0138
0139 Behavior on position
0140 {
0141 enabled: Maui.Style.enableEffects
0142
0143 NumberAnimation
0144 {
0145 duration: Maui.Style.units.shortDuration
0146 easing.type: Easing.InOutQuad
0147 }
0148 }
0149 }
0150
0151 onCollapsedChanged:
0152 {
0153 if(control.collapsed || !control.enabled)
0154 {
0155 if(control.autoHide)
0156 {
0157 control.close()
0158 }
0159 }
0160 else
0161 {
0162
0163 if(control.autoShow)
0164 {
0165 control.open()
0166 }
0167
0168 }
0169 }
0170
0171 contentItem: Item
0172 {
0173
0174 Item
0175 {
0176 id: _content
0177 width: control.constrainedWidth
0178 anchors.top: parent.top
0179 anchors.bottom: parent.bottom
0180 anchors.right: parent.right
0181 }
0182
0183 Loader
0184 {
0185
0186 active: control.resizing
0187 sourceComponent: Item
0188 {
0189 Rectangle
0190 {
0191 parent: control.parent
0192 id: _resizeTarget
0193 width: Math.max(Math.min(_private.finalWidth, control.maximumWidth), control.minimumWidth)
0194 height: parent.height
0195 color: Maui.Theme.alternateBackgroundColor
0196
0197 HoverHandler
0198 {
0199 cursorShape: Qt.SizeHorCursor
0200 }
0201
0202 Maui.Separator
0203 {
0204 anchors.top: parent.top
0205 anchors.bottom: parent.bottom
0206 anchors.right: parent.right
0207 weight: Maui.Separator.Weight.Light
0208 opacity: 0.4
0209
0210 Behavior on color
0211 {
0212 Maui.ColorTransition{}
0213 }
0214 }
0215 }
0216
0217 Rectangle
0218 {
0219 parent: control.parent
0220 id: _resizeTarget2
0221 anchors.leftMargin: _resizeTarget.width
0222 width: parent.width
0223 height: parent.height
0224 color: Maui.Theme.backgroundColor
0225 }
0226 }
0227 }
0228
0229 Rectangle
0230 {
0231 visible: control.resizeable
0232 height: parent.height
0233 width : 6
0234 anchors.right: parent.right
0235 color: _dragHandler.active ? Maui.Theme.highlightColor : "transparent"
0236
0237 HoverHandler
0238 {
0239 cursorShape: Qt.SizeHorCursor
0240 }
0241
0242 DragHandler
0243 {
0244 id: _dragHandler
0245 enabled: control.resizeable
0246 yAxis.enabled: false
0247 xAxis.enabled: true
0248 xAxis.minimum: control.minimumWidth - control.constrainedWidth
0249 xAxis.maximum: control.maximumWidth - control.constrainedWidth
0250 target: null
0251 cursorShape: Qt.SizeHorCursor
0252
0253 onActiveChanged:
0254 {
0255 let value = control.preferredWidth + _dragHandler.centroid.position.x
0256 if(!active)
0257 {
0258 if(value > control.maximumWidth)
0259 {
0260 control.preferredWidth = control.maximumWidth
0261 return
0262 }
0263
0264 if( value < control.minimumWidth)
0265 {
0266 control.preferredWidth = control.minimumWidth
0267 return
0268 }
0269 control.preferredWidth = value
0270 }
0271 }
0272 }
0273 }
0274
0275 Maui.Separator
0276 {
0277 anchors.top: parent.top
0278 anchors.bottom: parent.bottom
0279 anchors.right: parent.right
0280 weight: Maui.Separator.Weight.Light
0281
0282 Behavior on color
0283 {
0284 Maui.ColorTransition{}
0285 }
0286 }
0287 }
0288
0289 function open()
0290 {
0291 _private.position = 1
0292 }
0293
0294 function close()
0295 {
0296 _private.position = 0
0297 }
0298
0299 function toggle()
0300 {
0301 if(_private.position === 0)
0302 {
0303 control.open()
0304 }else
0305 {
0306 control.close()
0307 }
0308 }
0309 }
0310