Changeset View
Changeset View
Standalone View
Standalone View
components/containmentlayoutmanager/appletslayout.cpp
Show First 20 Lines • Show All 86 Lines • ▼ Show 20 Line(s) | 80 | connect(m_sizeSyncTimer, &QTimer::timeout, this, [this]() { | |||
---|---|---|---|---|---|
87 | } else if (!m_geometryBeforeResolutionChange.isEmpty()) { | 87 | } else if (!m_geometryBeforeResolutionChange.isEmpty()) { | ||
88 | m_layoutManager->layoutGeometryChanged(newGeom, m_geometryBeforeResolutionChange); | 88 | m_layoutManager->layoutGeometryChanged(newGeom, m_geometryBeforeResolutionChange); | ||
89 | m_geometryBeforeResolutionChange = QRectF(); | 89 | m_geometryBeforeResolutionChange = QRectF(); | ||
90 | 90 | | |||
91 | // Heuristically relayout items only when the plasma startup is fully completed | 91 | // Heuristically relayout items only when the plasma startup is fully completed | ||
92 | } else { | 92 | } else { | ||
93 | polish(); | 93 | polish(); | ||
94 | } | 94 | } | ||
95 | }); | 95 | }); | ||
96 | | ||||
97 | m_window = window(); | | |||
98 | if (m_window) { | | |||
99 | connect(m_window, &QWindow::activeChanged, this, [this]() { | | |||
100 | if (!m_window->isActive()) { | | |||
101 | setEditMode(false); | | |||
102 | } | | |||
103 | }); | | |||
104 | } | | |||
105 | connect(this, &QQuickItem::windowChanged, this, [this]() { | | |||
106 | if (m_window) { | | |||
107 | disconnect(m_window, &QWindow::activeChanged, this, nullptr); | | |||
108 | } | | |||
109 | m_window = window(); | | |||
110 | if (m_window) { | | |||
111 | connect(m_window, &QWindow::activeChanged, this, [this]() { | | |||
112 | if (!m_window->isActive()) { | | |||
113 | setEditMode(false); | | |||
114 | } | | |||
115 | }); | | |||
116 | } | | |||
117 | }); | | |||
118 | } | 96 | } | ||
davidedmundson: But we only evaluate this when this window changes - doesn't that mean we could when any other… | |||||
right.. it wouldn't notice if the edit mode was initiated when its window not in focus, i-.e. dbus from systemsettings case. mart: right.. it wouldn't notice if the edit mode was initiated when its window not in focus, i-.e. | |||||
mart: different approach in current version | |||||
119 | 97 | | |||
120 | AppletsLayout::~AppletsLayout() | 98 | AppletsLayout::~AppletsLayout() | ||
121 | { | 99 | { | ||
122 | } | 100 | } | ||
123 | 101 | | |||
124 | PlasmaQuick::AppletQuickItem *AppletsLayout::containment() const | 102 | PlasmaQuick::AppletQuickItem *AppletsLayout::containment() const | ||
125 | { | 103 | { | ||
126 | return m_containmentItem; | 104 | return m_containmentItem; | ||
▲ Show 20 Lines • Show All 235 Lines • ▼ Show 20 Line(s) | 335 | { | |||
362 | m_placeHolder = placeHolder; | 340 | m_placeHolder = placeHolder; | ||
363 | m_placeHolder->setParentItem(this); | 341 | m_placeHolder->setParentItem(this); | ||
364 | m_placeHolder->setZ(9999); | 342 | m_placeHolder->setZ(9999); | ||
365 | m_placeHolder->setOpacity(false); | 343 | m_placeHolder->setOpacity(false); | ||
366 | 344 | | |||
367 | emit placeHolderChanged(); | 345 | emit placeHolderChanged(); | ||
368 | } | 346 | } | ||
369 | 347 | | |||
348 | QQuickItem *AppletsLayout::eventManagerToFilter() const | ||||
349 | { | ||||
350 | return m_eventManagerToFilter; | ||||
351 | } | ||||
352 | | ||||
353 | void AppletsLayout::setEventManagerToFilter(QQuickItem *item) | ||||
354 | { | ||||
355 | if (m_eventManagerToFilter == item) { | ||||
356 | return; | ||||
357 | } | ||||
358 | | ||||
359 | m_eventManagerToFilter = item; | ||||
360 | setFiltersChildMouseEvents(m_eventManagerToFilter); | ||||
361 | emit eventManagerToFilterChanged(); | ||||
362 | } | ||||
363 | | ||||
364 | | ||||
370 | void AppletsLayout::save() | 365 | void AppletsLayout::save() | ||
371 | { | 366 | { | ||
372 | m_saveLayoutTimer->start(); | 367 | m_saveLayoutTimer->start(); | ||
373 | } | 368 | } | ||
374 | 369 | | |||
375 | void AppletsLayout::showPlaceHolderAt(const QRectF &geom) | 370 | void AppletsLayout::showPlaceHolderAt(const QRectF &geom) | ||
376 | { | 371 | { | ||
377 | if (!m_placeHolder) { | 372 | if (!m_placeHolder) { | ||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Line(s) | 516 | if (m_containment->screen() == id) { | |||
522 | m_geometryBeforeResolutionChange = QRectF(x(), y(), width(), height()); | 517 | m_geometryBeforeResolutionChange = QRectF(x(), y(), width(), height()); | ||
523 | } | 518 | } | ||
524 | }); | 519 | }); | ||
525 | } | 520 | } | ||
526 | QQuickItem::componentComplete(); | 521 | QQuickItem::componentComplete(); | ||
527 | } | 522 | } | ||
528 | 523 | | |||
529 | 524 | | |||
525 | bool AppletsLayout::childMouseEventFilter(QQuickItem *item, QEvent *event) | ||||
526 | { | ||||
527 | if (item != m_eventManagerToFilter) { | ||||
528 | return QQuickItem::childMouseEventFilter(item, event); | ||||
529 | } | ||||
530 | | ||||
531 | switch (event->type()) { | ||||
532 | case QEvent::MouseButtonPress: { | ||||
533 | QMouseEvent *me = static_cast<QMouseEvent *>(event); | ||||
534 | if (me->buttons() & Qt::LeftButton) { | ||||
davidedmundson: the first clause seems redundant | |||||
535 | mousePressEvent(me); | ||||
536 | } | ||||
537 | break; | ||||
538 | } | ||||
539 | case QEvent::MouseMove: { | ||||
540 | QMouseEvent *me = static_cast<QMouseEvent *>(event); | ||||
541 | mouseMoveEvent(me); | ||||
542 | break; | ||||
543 | } | ||||
544 | case QEvent::MouseButtonRelease: { | ||||
545 | QMouseEvent *me = static_cast<QMouseEvent *>(event); | ||||
546 | mouseReleaseEvent(me); | ||||
547 | break; | ||||
548 | } | ||||
549 | case QEvent::UngrabMouse: | ||||
550 | mouseUngrabEvent(); | ||||
551 | break; | ||||
552 | default: | ||||
553 | break; | ||||
554 | } | ||||
555 | | ||||
556 | return QQuickItem::childMouseEventFilter(item, event); | ||||
557 | } | ||||
530 | 558 | | |||
531 | void AppletsLayout::mousePressEvent(QMouseEvent *event) | 559 | void AppletsLayout::mousePressEvent(QMouseEvent *event) | ||
532 | { | 560 | { | ||
533 | forceActiveFocus(Qt::MouseFocusReason); | 561 | forceActiveFocus(Qt::MouseFocusReason); | ||
534 | 562 | | |||
535 | if (!m_editMode && m_editModeCondition == AppletsLayout::Manual) { | 563 | if (!m_editMode && m_editModeCondition == AppletsLayout::Manual) { | ||
536 | return; | 564 | return; | ||
537 | } | 565 | } | ||
Show All 19 Lines | 583 | if (!m_editMode | |||
557 | m_pressAndHoldTimer->stop(); | 585 | m_pressAndHoldTimer->stop(); | ||
558 | } | 586 | } | ||
559 | } | 587 | } | ||
560 | 588 | | |||
561 | void AppletsLayout::mouseReleaseEvent(QMouseEvent *event) | 589 | void AppletsLayout::mouseReleaseEvent(QMouseEvent *event) | ||
562 | { | 590 | { | ||
563 | if (m_editMode | 591 | if (m_editMode | ||
564 | && m_mouseDownWasEditMode | 592 | && m_mouseDownWasEditMode | ||
593 | // By only accepting synthetyzed events, this makes the | ||||
Please comment what this is doing.
davidedmundson: Please comment what this is doing.
> want with normal mouse the edit mode not being dismissed… | |||||
594 | // close by tapping in any empty area only work with real | ||||
595 | // touch events, as we want a different behavior between desktop | ||||
596 | // and tablet mode | ||||
597 | && (event->source() == Qt::MouseEventSynthesizedBySystem | ||||
598 | || event->source() == Qt::MouseEventSynthesizedByQt) | ||||
565 | && QPointF(event->windowPos() - m_mouseDownPosition).manhattanLength() < QGuiApplication::styleHints()->startDragDistance()) { | 599 | && QPointF(event->windowPos() - m_mouseDownPosition).manhattanLength() < QGuiApplication::styleHints()->startDragDistance()) { | ||
566 | setEditMode(false); | 600 | setEditMode(false); | ||
567 | } | 601 | } | ||
568 | 602 | | |||
569 | m_pressAndHoldTimer->stop(); | 603 | m_pressAndHoldTimer->stop(); | ||
570 | 604 | | |||
571 | if (!m_editMode) { | 605 | if (!m_editMode) { | ||
572 | for (auto *child : childItems()) { | 606 | for (auto *child : childItems()) { | ||
573 | ItemContainer *item = qobject_cast<ItemContainer *>(child); | 607 | ItemContainer *item = qobject_cast<ItemContainer *>(child); | ||
574 | if (item && item != m_placeHolder) { | 608 | if (item && item != m_placeHolder) { | ||
575 | item->setEditMode(false); | 609 | item->setEditMode(false); | ||
576 | } | 610 | } | ||
577 | } | 611 | } | ||
578 | } | 612 | } | ||
579 | } | 613 | } | ||
580 | 614 | | |||
615 | void AppletsLayout::mouseUngrabEvent() | ||||
616 | { | ||||
617 | m_pressAndHoldTimer->stop(); | ||||
618 | } | ||||
619 | | ||||
581 | void AppletsLayout::appletAdded(QObject *applet, int x, int y) | 620 | void AppletsLayout::appletAdded(QObject *applet, int x, int y) | ||
582 | { | 621 | { | ||
583 | PlasmaQuick::AppletQuickItem *appletItem = qobject_cast<PlasmaQuick::AppletQuickItem *>(applet); | 622 | PlasmaQuick::AppletQuickItem *appletItem = qobject_cast<PlasmaQuick::AppletQuickItem *>(applet); | ||
584 | 623 | | |||
585 | //maybe even an assert? | 624 | //maybe even an assert? | ||
586 | if (!appletItem) { | 625 | if (!appletItem) { | ||
587 | return; | 626 | return; | ||
588 | } | 627 | } | ||
▲ Show 20 Lines • Show All 115 Lines • Show Last 20 Lines |
But we only evaluate this when this window changes - doesn't that mean we could when any other plasma window had focus and then loses it?