Warning, /maui/mauikit/src/controls.5/ToolActions.qml is written in an unsupported language. File is not indexed.
0001 import QtQuick 2.15
0002 import QtQuick.Controls 2.15
0003 import QtQuick.Layouts 1.3
0004 import QtQml 2.14
0005 import QtQuick.Templates 2.15 as T
0006
0007 import org.mauikit.controls 1.3 as Maui
0008
0009 import "private" as Private
0010
0011 /**
0012 * ToolActions
0013 * A global sidebar for the application window that can be collapsed.
0014 *
0015 *
0016 *
0017 *
0018 *
0019 *
0020 */
0021 T.Control
0022 {
0023 id: control
0024 implicitWidth: implicitContentWidth + leftPadding + rightPadding
0025 implicitHeight: implicitContentHeight + topPadding + bottomPadding
0026
0027 opacity: enabled ? 1 : 0.5
0028
0029 spacing: 2
0030 padding: 0
0031
0032 Maui.Theme.colorSet: Maui.Theme.Button
0033 Maui.Theme.inherit: false
0034 /**
0035 * actions : list<Action>
0036 */
0037 default property list<Action> actions
0038
0039 /**
0040 * autoExclusive : bool
0041 */
0042 property bool autoExclusive: true
0043
0044 /**
0045 * checkable : bool
0046 */
0047 property bool checkable: true
0048
0049 /**
0050 * display : int
0051 */
0052 property int display: ToolButton.TextBesideIcon
0053
0054 /**
0055 * cyclic : bool
0056 */
0057 property bool cyclic: false
0058
0059 readonly property bool canCyclic : control.cyclic && control.count === 2 && control.autoExclusive
0060
0061 /**
0062 * flat : bool
0063 */
0064 property bool flat : false
0065
0066 /**
0067 * count : int
0068 */
0069 readonly property int count : actions.length
0070
0071
0072 /**
0073 * expanded : bool
0074 */
0075 property bool expanded : true
0076
0077 /**
0078 * defaultIconName : string
0079 */
0080 property string defaultIconName: "application-menu"
0081 // border.color: control.flat ? "transparent" : Qt.tint(Maui.Theme.textColor, Qt.rgba(Maui.Theme.backgroundColor.r, Maui.Theme.backgroundColor.g, Maui.Theme.backgroundColor.b, 0.7))
0082
0083 //radius: Maui.Style.radiusV
0084 //color: !control.enabled || control.flat ? "transparent" : Maui.Theme.backgroundColor
0085
0086
0087 /**
0088 *
0089 */
0090 function uncheck(except)
0091 {
0092 for(var i in control.actions)
0093 {
0094 if(control.actions[i] === except)
0095 {
0096 continue
0097 }
0098
0099 control.actions[i].checked = false
0100 }
0101 }
0102
0103 contentItem: Loader
0104 {
0105 id: _loader
0106 asynchronous: true
0107 sourceComponent: control.expanded ? _rowComponent : _buttonComponent
0108 }
0109
0110 background: null
0111
0112 Component
0113 {
0114 id: _rowComponent
0115
0116 Row
0117 {
0118 id: _row
0119 property int biggerHeight : 0
0120 spacing: control.spacing
0121
0122 Behavior on width
0123 {
0124 enabled: Maui.Style.enableEffects
0125
0126 NumberAnimation
0127 {
0128 duration: Maui.Style.units.shortDuration
0129 easing.type: Easing.InOutQuad
0130 }
0131 }
0132
0133 function calculateBiggerHeight()
0134 {
0135 var value = 0
0136 for(var i in _row.children)
0137 {
0138 const height = _row.children[i].implicitHeight
0139 if(height > value)
0140 {
0141 value = height
0142 }
0143 }
0144
0145 return value
0146 }
0147
0148 Repeater
0149 {
0150 id: _repeater
0151 model: control.actions
0152
0153 ToolButton
0154 {
0155 id: _actionButton
0156 action : modelData
0157 checkable: control.checkable || action.checkable
0158
0159 height: Math.max(implicitHeight, _row.biggerHeight)
0160
0161 onImplicitHeightChanged: _row.biggerHeight = _row.calculateBiggerHeight()
0162
0163 autoExclusive: control.autoExclusive
0164 enabled: action.enabled
0165
0166 display: control.display
0167
0168 background: Maui.ShadowedRectangle
0169 {
0170 color: (checked || down ? Maui.Theme.highlightColor : ( hovered ? Maui.Theme.hoverColor : Maui.Theme.backgroundColor))
0171 corners
0172 {
0173 topLeftRadius: index === 0 ? Maui.Style.radiusV : 0
0174 topRightRadius: index === _repeater.count - 1 ? Maui.Style.radiusV : 0
0175 bottomLeftRadius: index === 0 ? Maui.Style.radiusV : 0
0176 bottomRightRadius: index === _repeater.count - 1 ? Maui.Style.radiusV : 0
0177 }
0178
0179 Behavior on color
0180 {
0181 Maui.ColorTransition{}
0182 }
0183 }
0184 }
0185 }
0186 }
0187 }
0188
0189 Component
0190 {
0191 id: _buttonComponent
0192
0193 ToolButton
0194 {
0195 id: _defaultButtonIcon
0196
0197 property Action m_action
0198
0199 Component.onCompleted: _defaultButtonIcon.m_action = _defaultButtonIcon.buttonAction()
0200
0201 function buttonAction()
0202 {
0203 if(control.autoExclusive)
0204 {
0205 var currentAction
0206 var actionIndex = -1
0207 for(var i in control.actions)
0208 {
0209 console.log("Checking current action", i)
0210 if(control.actions[i].checked)
0211 {
0212 actionIndex = i
0213 currentAction = control.actions[actionIndex]
0214 console.log("Found current action", i, actionIndex)
0215 }
0216 }
0217
0218 if(control.canCyclic)
0219 {
0220 actionIndex++
0221
0222 let m_index = actionIndex >= control.actions.length ? 0 : actionIndex
0223 //
0224 console.log("Setting current action at", m_index)
0225 if(control.actions[m_index].enabled)
0226 {
0227 return control.actions[m_index];
0228 }
0229 }
0230
0231 return currentAction
0232 }
0233
0234 return null
0235 }
0236
0237 Row
0238 {
0239 visible: false
0240 Repeater
0241 {
0242 model: control.actions
0243 delegate: Item
0244 {
0245 property bool checked : modelData.checked
0246 onCheckedChanged: _defaultButtonIcon.m_action = _defaultButtonIcon.buttonAction()
0247 }
0248 }
0249 }
0250
0251
0252 data: Maui.ContextualMenu
0253 {
0254 id: _menu
0255
0256 Repeater
0257 {
0258 model: control.autoExclusive && control.canCyclic ? undefined : control.actions
0259
0260 delegate: MenuItem
0261 {
0262 action: modelData
0263 enabled: modelData.enabled
0264 autoExclusive: control.autoExclusive
0265 checkable: control.checkable || action.checkable
0266 }
0267 }
0268 }
0269
0270 onClicked:
0271 {
0272 if(_defaultButtonIcon.m_action && control.canCyclic && control.autoExclusive)
0273 {
0274 console.log("Trigger next cyclic action", _defaultButtonIcon.m_action.icon.name)
0275 // var previousAction = _defaultButtonIcon.action
0276 _defaultButtonIcon.m_action.triggered()
0277 _defaultButtonIcon.m_action = _defaultButtonIcon.buttonAction()
0278
0279 }else
0280 {
0281 if(!_menu.visible)
0282 {
0283 _menu.show(0, control.height, control)
0284
0285 }else
0286 {
0287 _menu.close()
0288 }
0289 }
0290 }
0291
0292
0293
0294 icon.width: Maui.Style.iconSize
0295 icon.height: Maui.Style.iconSize
0296 icon.color: m_action ? (m_action.icon.color && m_action.icon.color.length ? m_action.icon.color : (pressed ? control.Maui.Theme.highlightColor : control.Maui.Theme.textColor)) : control.Maui.Theme.textColor
0297
0298 icon.name: m_action ? m_action.icon.name : control.defaultIconName
0299 text: m_action ? m_action.text: ""
0300
0301 enabled: m_action ? m_action.enabled : true
0302
0303 subMenu: !control.canCyclic
0304
0305 display: control.display
0306
0307 checkable: control.checkable && (action ? action.checkable : false)
0308
0309 background: Rectangle
0310 {
0311 color: Maui.Theme.backgroundColor
0312 radius: Maui.Style.radiusV
0313
0314 Behavior on color
0315 {
0316 Maui.ColorTransition{}
0317 }
0318 }
0319 }
0320
0321
0322 }
0323 }