QtMvvm  1.1.0
A mvvm oriented library for Qt, to create Projects for Widgets and Quick in parallel
RoundMenuButton.qml
1 import QtQuick 2.10
2 import QtQuick.Controls 2.3
3 import de.skycoder42.QtMvvm.Quick 1.1
4 
33 Item {
34  id: _roundMenuButton
35 
45  property alias text: _rootButton.text
55  property alias icon: _rootButton.icon
68  property alias checked: _rootButton.checked
69 
79  property real buttonSpacing: 16
94  property real expansionAngle: 0
104  property size subButtonSize: Qt.size(40, 40)
120  property bool stickyToolTips: false
136  property bool invertToolTipDirection: Qt.application.layoutDirection == Qt.RightToLeft
137 
147  readonly property alias rootButton: _rootButton
148 
158  default property list<Action> actions
159 
160  implicitWidth: _rootButton.implicitWidth
161  implicitHeight: _rootButton.implicitHeight
162 
164  id: _rootButton
165  z: 10
166  anchors.fill: parent
167  checkable: true
168  }
169 
170  QtObject {
171  id: _p
172 
173  function toRadians(angle) {
174  return angle * (Math.PI/180);
175  }
176 
177  readonly property real vOffset: -1 * Math.cos(toRadians(_roundMenuButton.expansionAngle))
178  readonly property real hOffset: Math.sin(toRadians(_roundMenuButton.expansionAngle))
179  }
180 
181  Repeater {
182  model: actions
183 
184  delegate: RoundActionButton {
185  id: _subButton
186 
187  highlighted: false
188  anchors.horizontalCenter: _rootButton.horizontalCenter
189  anchors.verticalCenter: _rootButton.verticalCenter
190  implicitHeight: _roundMenuButton.subButtonSize.height + padding
191  implicitWidth: _roundMenuButton.subButtonSize.width + padding
192  state: _rootButton.checked ? "expanded" : "collapsed"
193 
194  toolTip: _roundMenuButton.stickyToolTips ? "" : _subButton.text
195 
196  onClicked: _rootButton.checked = false
197 
198  /* calc offsets as:
199  * - one subbutton (from center to center) + spacing between buttons
200  * - that times the number of buttons before this one + +1
201  * - that plus the extra height delta from the root button
202  * - that times the factor from the angle
203  */
204  readonly property real maxVOffset: _p.vOffset * ((1 + index) * (_subButton.height + _roundMenuButton.buttonSpacing) + (_rootButton.height - _subButton.height)/2)
205  readonly property real maxHOffset: _p.hOffset * ((1 + index) * (_subButton.width + _roundMenuButton.buttonSpacing) + (_rootButton.width - _subButton.width)/2)
206 
207  action: modelData
208 
209  ToolTip {
210  id: _permaToolTip
211  visible: _roundMenuButton.stickyToolTips && _subButton.text != "" && _subButton.visible
212  text: _subButton.text
213  x: invertToolTipDirection ?
214  _subButton.width + _roundMenuButton.buttonSpacing :
215  -(_permaToolTip.width + _roundMenuButton.buttonSpacing)
216  y: (_subButton.height - height)/2
217  }
218 
219  states: [
220  State {
221  name: "collapsed"
222  PropertyChanges {
223  target: _subButton
224  anchors.verticalCenterOffset: 0
225  anchors.horizontalCenterOffset: 0
226  visible: false
227  }
228  },
229  State {
230  name: "expanded"
231  PropertyChanges {
232  target: _subButton
233  anchors.verticalCenterOffset: maxVOffset
234  anchors.horizontalCenterOffset: maxHOffset
235  visible: true
236  }
237  }
238  ]
239 
240  transitions: [
241  Transition {
242  from: "collapsed"
243  to: "expanded"
244  SequentialAnimation {
245  PropertyAnimation {
246  target: _subButton
247  property: "visible"
248  duration: 0
249  }
250  ParallelAnimation {
251  PropertyAnimation {
252  target: _subButton
253  property: "anchors.verticalCenterOffset"
254  duration: 250
255  easing.type: Easing.OutCubic
256  }
257  PropertyAnimation {
258  target: _subButton
259  property: "anchors.horizontalCenterOffset"
260  duration: 250
261  easing.type: Easing.OutCubic
262  }
263  }
264  }
265  },
266  Transition {
267  from: "expanded"
268  to: "collapsed"
269  SequentialAnimation {
270  ParallelAnimation {
271  PropertyAnimation {
272  target: _subButton
273  property: "anchors.verticalCenterOffset"
274  duration: 250
275  easing.type: Easing.InCubic
276  }
277  PropertyAnimation {
278  target: _subButton
279  property: "anchors.horizontalCenterOffset"
280  duration: 250
281  easing.type: Easing.InCubic
282  }
283  }
284  PropertyAnimation {
285  target: _subButton
286  property: "visible"
287  duration: 0
288  }
289  }
290  }
291  ]
292  }
293  }
294 }
An extension of the RoundButton for better appearance.
The QML import for the QtMvvmQuick QML module.
Definition: ActionButton.qml:4