Changeset View
Changeset View
Standalone View
Standalone View
applets/kickoff/package/contents/ui/FullRepresentation.qml
Show First 20 Lines • Show All 106 Lines • ▼ Show 20 Line(s) | 32 | Item { | |||
---|---|---|---|---|---|
107 | 107 | | |||
108 | PlasmaCore.Svg { | 108 | PlasmaCore.Svg { | ||
109 | id: arrowsSvg | 109 | id: arrowsSvg | ||
110 | 110 | | |||
111 | imagePath: "widgets/arrows" | 111 | imagePath: "widgets/arrows" | ||
112 | size: "16x16" | 112 | size: "16x16" | ||
113 | } | 113 | } | ||
114 | 114 | | |||
115 | Timer { | | |||
116 | id: clickTimer | | |||
117 | | ||||
118 | property Item pendingButton | | |||
119 | | ||||
120 | interval: 250 | | |||
121 | | ||||
122 | onTriggered: pendingButton.clicked() | | |||
123 | } | | |||
124 | | ||||
125 | Header { | 115 | Header { | ||
126 | id: header | 116 | id: header | ||
127 | } | 117 | } | ||
128 | 118 | | |||
129 | Item { | 119 | Item { | ||
130 | id: mainArea | 120 | id: mainArea | ||
131 | anchors.topMargin: mainTabGroup.state == "top" ? units.smallSpacing : 0 | 121 | anchors.topMargin: mainTabGroup.state == "top" ? units.smallSpacing : 0 | ||
132 | 122 | | |||
▲ Show 20 Lines • Show All 268 Lines • ▼ Show 20 Line(s) | 388 | onExpandedChanged: { | |||
401 | } | 391 | } | ||
402 | if (!expanded) { | 392 | if (!expanded) { | ||
403 | switchToInitial(); | 393 | switchToInitial(); | ||
404 | } | 394 | } | ||
405 | } | 395 | } | ||
406 | } | 396 | } | ||
407 | } // tabBar | 397 | } // tabBar | ||
408 | 398 | | |||
399 | MouseArea { | ||||
400 | anchors.fill: tabBar | ||||
401 | | ||||
402 | property var oldPos: null | ||||
broulik: `property point` or is that on purpose so you can set it to `null` instead to avoid ambiguity… | |||||
403 | | ||||
404 | hoverEnabled: root.switchTabsOnHover | ||||
405 | | ||||
406 | onExited: { | ||||
407 | // Reset so we switch immediately when MouseArea is entered | ||||
408 | // freshly, e.g. from the panel. | ||||
409 | oldPos = null; | ||||
410 | | ||||
411 | clickTimer.stop(); | ||||
412 | } | ||||
413 | | ||||
414 | onPositionChanged: { | ||||
415 | var button = tabBar.layout.childAt(mouse.x, mouse.y); | ||||
416 | | ||||
417 | if (!button || button.objectName != "KickoffButton") { | ||||
418 | clickTimer.stop(); | ||||
419 | | ||||
420 | return; | ||||
421 | } | ||||
422 | | ||||
423 | // Switch immediately when MouseArea was freshly entered, e.g. | ||||
424 | // from the panel. | ||||
425 | if (oldPos === null) { | ||||
426 | oldPos = Qt.point(mouse.x, mouse.y); | ||||
427 | | ||||
428 | clickTimer.stop(); | ||||
429 | button.clicked(); | ||||
430 | | ||||
431 | return; | ||||
432 | } | ||||
433 | | ||||
434 | var dx = (mouse.x - oldPos.x); | ||||
broulik: Coding style, one space before `=` | |||||
435 | var dy = (mouse.y - oldPos.y); | ||||
436 | | ||||
437 | // Check Manhattan langth against drag distance to get a decent | ||||
438 | // pointer motion vector. | ||||
that's normal length. Manhattan would be dx+dy As in the distance to walk to another place in the city using only roads in a block shaped city such as Manhattan. davidedmundson: that's normal length.
Manhattan would be dx+dy
As in the distance to walk to another place in… | |||||
davidedmundson: abs(dx) + abs(dy)
| |||||
439 | if (Math.abs(dx + dy) > Qt.styleHints.startDragDistance) { | ||||
I believe it's possible to reduce indentation. E.g. if ((Math.abs(dx) + Math.abs(dy)) <= Qt.styleHints.startDragDistance) { return; } if (tabBar.currentTab == button) { oldPos = Qt.point(mouse.x, mouse.y); return; } var tabBarPos = mapToItem(tabBar, oldPos.x, oldPos.y); // ... zzag: I believe it's possible to reduce indentation. E.g.
```lang=js
if ((Math.abs(dx) + Math.abs… | |||||
440 | if (tabBar.currentTab != button) { | ||||
441 | var tabBarPos = mapToItem(tabBar, oldPos.x, oldPos.y); | ||||
442 | oldPos = Qt.point(mouse.x, mouse.y); | ||||
443 | | ||||
444 | var angleMouseMove = Math.atan2(dy, dx) * 180 / Math.PI; | ||||
445 | var angleToCornerA = 0; | ||||
446 | var angleToCornerB = 0; | ||||
447 | | ||||
448 | switch (plasmoid.location) { | ||||
449 | case PlasmaCore.Types.TopEdge: { | ||||
450 | angleToCornerA = Math.atan2(tabBar.height - tabBarPos.y, 0 - tabBarPos.x); | ||||
451 | angleToCornerB = Math.atan2(tabBar.height - tabBarPos.y, tabBar.width - tabBarPos.x); | ||||
452 | | ||||
453 | break; | ||||
454 | } | ||||
455 | case PlasmaCore.Types.LeftEdge: { | ||||
456 | angleToCornerA = Math.atan2(0 - tabBarPos.y, tabBar.width - tabBarPos.x); | ||||
457 | angleToCornerB = Math.atan2(tabBar.height - tabBarPos.y, tabBar.width - tabBarPos.x); | ||||
458 | | ||||
459 | break; | ||||
460 | } | ||||
461 | case PlasmaCore.Types.RightEdge: { | ||||
462 | angleToCornerA = Math.atan2(0 - tabBarPos.y, 0 - tabBarPos.x); | ||||
463 | angleToCornerB = Math.atan2(tabBar.height - tabBarPos.y, 0 - tabBarPos.x); | ||||
464 | | ||||
465 | break; | ||||
466 | } | ||||
467 | // PlasmaCore.Types.BottomEdge | ||||
468 | default: { | ||||
469 | angleToCornerA = Math.atan2(0 - tabBarPos.y, 0 - tabBarPos.x); | ||||
470 | angleToCornerB = Math.atan2(0 - tabBarPos.y, tabBar.width - tabBarPos.x); | ||||
471 | } | ||||
472 | } | ||||
473 | | ||||
474 | // Degrees are nicer to debug than radians. | ||||
475 | angleToCornerA = angleToCornerA * 180 / Math.PI; | ||||
476 | angleToCornerB = angleToCornerB * 180 / Math.PI; | ||||
477 | | ||||
478 | var lower = Math.min(angleToCornerA, angleToCornerB); | ||||
479 | var upper = Math.max(angleToCornerA, angleToCornerB); | ||||
480 | | ||||
481 | // If the motion vector is outside the angle range from oldPos to the | ||||
482 | // relevant tab bar corners, switch immediately. Otherwise start the | ||||
483 | // timer, which gets aborted should the pointer exit the the tab bar | ||||
484 | // early. | ||||
485 | var inRange = (lower < angleMouseMove == angleMouseMove < upper); | ||||
486 | | ||||
487 | // Mirror-flip. | ||||
488 | if (plasmoid.location == PlasmaCore.Types.RightEdge ? inRange : !inRange) { | ||||
489 | clickTimer.stop(); | ||||
490 | button.clicked(); | ||||
491 | | ||||
492 | return; | ||||
493 | } else { | ||||
broulik: No `else` since you `return` in the `if` branch
```
if (...) {
...
return;
}
...
``` | |||||
494 | clickTimer.pendingButton = button; | ||||
495 | clickTimer.start(); | ||||
496 | } | ||||
497 | } else { | ||||
498 | oldPos = Qt.point(mouse.x, mouse.y); | ||||
499 | } | ||||
500 | } | ||||
501 | } | ||||
502 | | ||||
503 | onClicked: { | ||||
504 | clickTimer.stop(); | ||||
505 | | ||||
506 | var button = tabBar.layout.childAt(mouse.x, mouse.y); | ||||
507 | | ||||
508 | if (!button || button.objectName != "KickoffButton") { | ||||
509 | return; | ||||
510 | } | ||||
511 | | ||||
512 | button.clicked(); | ||||
513 | } | ||||
514 | | ||||
515 | Timer { | ||||
516 | id: clickTimer | ||||
517 | | ||||
518 | property Item pendingButton: null | ||||
519 | | ||||
520 | interval: 250 | ||||
521 | | ||||
522 | onTriggered: { | ||||
523 | if (pendingButton) { | ||||
524 | pendingButton.clicked(); | ||||
525 | } | ||||
526 | } | ||||
527 | } | ||||
528 | } | ||||
529 | | ||||
409 | Keys.forwardTo: [tabBar.layout] | 530 | Keys.forwardTo: [tabBar.layout] | ||
410 | 531 | | |||
411 | Keys.onPressed: { | 532 | Keys.onPressed: { | ||
412 | 533 | | |||
413 | if (mainTabGroup.currentTab == applicationsPage) { | 534 | if (mainTabGroup.currentTab == applicationsPage) { | ||
414 | if (event.key != Qt.Key_Tab) { | 535 | if (event.key != Qt.Key_Tab) { | ||
415 | root.state = "Applications"; | 536 | root.state = "Applications"; | ||
416 | } | 537 | } | ||
▲ Show 20 Lines • Show All 188 Lines • Show Last 20 Lines |
property point or is that on purpose so you can set it to null instead to avoid ambiguity with e.g. -1,-1?