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 length against drag distance to get a decent | ||||
438 | // pointer motion vector. If we're below, we're done for this | ||||
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 | // event: The timer has either already been started (oldPos was | ||||
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 | // null) or we're still waiting for more motion to make a decision | ||||
441 | // on it. | ||||
442 | if ((Math.abs(dx) + Math.abs(dy)) < Qt.styleHints.startDragDistance) { | ||||
443 | return; | ||||
444 | } | ||||
445 | | ||||
446 | // If we're still above the same tab, we only reset oldPos to | ||||
447 | // up the next pointer motion vector. | ||||
448 | if (tabBar.currentTab == button) { | ||||
449 | oldPos = Qt.point(mouse.x, mouse.y); | ||||
450 | | ||||
451 | return; | ||||
452 | } | ||||
453 | | ||||
454 | var tabBarPos = mapToItem(tabBar, oldPos.x, oldPos.y); | ||||
455 | oldPos = Qt.point(mouse.x, mouse.y); | ||||
456 | | ||||
457 | var angleMouseMove = Math.atan2(dy, dx) * 180 / Math.PI; | ||||
458 | var angleToCornerA = 0; | ||||
459 | var angleToCornerB = 0; | ||||
460 | | ||||
461 | switch (plasmoid.location) { | ||||
462 | case PlasmaCore.Types.TopEdge: { | ||||
463 | angleToCornerA = Math.atan2(tabBar.height - tabBarPos.y, 0 - tabBarPos.x); | ||||
464 | angleToCornerB = Math.atan2(tabBar.height - tabBarPos.y, tabBar.width - tabBarPos.x); | ||||
465 | | ||||
466 | break; | ||||
467 | } | ||||
468 | case PlasmaCore.Types.LeftEdge: { | ||||
469 | angleToCornerA = Math.atan2(0 - tabBarPos.y, tabBar.width - tabBarPos.x); | ||||
470 | angleToCornerB = Math.atan2(tabBar.height - tabBarPos.y, tabBar.width - tabBarPos.x); | ||||
471 | | ||||
472 | break; | ||||
473 | } | ||||
474 | case PlasmaCore.Types.RightEdge: { | ||||
475 | angleToCornerA = Math.atan2(0 - tabBarPos.y, 0 - tabBarPos.x); | ||||
476 | angleToCornerB = Math.atan2(tabBar.height - tabBarPos.y, 0 - tabBarPos.x); | ||||
477 | | ||||
478 | break; | ||||
479 | } | ||||
480 | // PlasmaCore.Types.BottomEdge | ||||
481 | default: { | ||||
482 | angleToCornerA = Math.atan2(0 - tabBarPos.y, 0 - tabBarPos.x); | ||||
483 | angleToCornerB = Math.atan2(0 - tabBarPos.y, tabBar.width - tabBarPos.x); | ||||
484 | } | ||||
485 | } | ||||
486 | | ||||
487 | // Degrees are nicer to debug than radians. | ||||
488 | angleToCornerA = angleToCornerA * 180 / Math.PI; | ||||
489 | angleToCornerB = angleToCornerB * 180 / Math.PI; | ||||
490 | | ||||
491 | var lower = Math.min(angleToCornerA, angleToCornerB); | ||||
492 | var upper = Math.max(angleToCornerA, angleToCornerB); | ||||
493 | | ||||
broulik: No `else` since you `return` in the `if` branch
```
if (...) {
...
return;
}
...
``` | |||||
494 | // If the motion vector is outside the angle range from oldPos to the | ||||
495 | // relevant tab bar corners, switch immediately. Otherwise start the | ||||
496 | // timer, which gets aborted should the pointer exit the the tab bar | ||||
497 | // early. | ||||
498 | var inRange = (lower < angleMouseMove == angleMouseMove < upper); | ||||
499 | | ||||
500 | // Mirror-flip. | ||||
501 | if (plasmoid.location == PlasmaCore.Types.RightEdge ? inRange : !inRange) { | ||||
502 | // Abort timer and activate button immediately. | ||||
503 | clickTimer.stop(); | ||||
504 | button.clicked(); | ||||
505 | | ||||
506 | return; | ||||
507 | } | ||||
508 | | ||||
509 | // Start timer for button activation. | ||||
510 | clickTimer.pendingButton = button; | ||||
511 | clickTimer.start(); | ||||
512 | } | ||||
513 | | ||||
514 | onClicked: { | ||||
515 | clickTimer.stop(); | ||||
516 | | ||||
517 | var button = tabBar.layout.childAt(mouse.x, mouse.y); | ||||
518 | | ||||
519 | if (!button || button.objectName != "KickoffButton") { | ||||
520 | return; | ||||
521 | } | ||||
522 | | ||||
523 | button.clicked(); | ||||
524 | } | ||||
525 | | ||||
526 | Timer { | ||||
527 | id: clickTimer | ||||
528 | | ||||
529 | property Item pendingButton: null | ||||
530 | | ||||
531 | interval: 250 | ||||
532 | | ||||
533 | onTriggered: { | ||||
534 | if (pendingButton) { | ||||
535 | pendingButton.clicked(); | ||||
536 | } | ||||
537 | } | ||||
538 | } | ||||
539 | } | ||||
540 | | ||||
409 | Keys.forwardTo: [tabBar.layout] | 541 | Keys.forwardTo: [tabBar.layout] | ||
410 | 542 | | |||
411 | Keys.onPressed: { | 543 | Keys.onPressed: { | ||
412 | 544 | | |||
413 | if (mainTabGroup.currentTab == applicationsPage) { | 545 | if (mainTabGroup.currentTab == applicationsPage) { | ||
414 | if (event.key != Qt.Key_Tab) { | 546 | if (event.key != Qt.Key_Tab) { | ||
415 | root.state = "Applications"; | 547 | root.state = "Applications"; | ||
416 | } | 548 | } | ||
▲ 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?