Changeset View
Changeset View
Standalone View
Standalone View
components/containmentlayoutmanager/configoverlay.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2019 by Marco Martin <mart@kde.org> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU Library General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2, or | ||||
7 | * (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | * GNU Library General Public License for more details | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU Library General Public | ||||
15 | * License along with this program; if not, write to the | ||||
16 | * Free Software Foundation, Inc., | ||||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
18 | * | ||||
19 | */ | ||||
20 | | ||||
21 | #include "configoverlay.h" | ||||
22 | | ||||
23 | #include <cmath> | ||||
24 | | ||||
25 | ConfigOverlay::ConfigOverlay(QQuickItem *parent) | ||||
26 | : QQuickItem(parent) | ||||
27 | { | ||||
28 | setItemContainer(qobject_cast<ItemContainer *>(parent)); | ||||
29 | connect(this, &QQuickItem::parentChanged, this, [this]() { | ||||
30 | setItemContainer(qobject_cast<ItemContainer *>(parentItem())); | ||||
31 | }); | ||||
32 | | ||||
33 | m_hideTimer = new QTimer(this); | ||||
34 | m_hideTimer->setSingleShot(true); | ||||
35 | m_hideTimer->setInterval(600); | ||||
36 | connect(m_hideTimer, &QTimer::timeout, this, [this] () { | ||||
37 | setVisible(false); | ||||
38 | }); | ||||
39 | } | ||||
40 | | ||||
41 | ConfigOverlay::~ConfigOverlay() | ||||
42 | { | ||||
43 | } | ||||
44 | | ||||
45 | bool ConfigOverlay::open() const | ||||
46 | { | ||||
47 | return m_open; | ||||
48 | } | ||||
49 | | ||||
50 | void ConfigOverlay::setOpen(bool open) | ||||
51 | { | ||||
52 | if (open == m_open) { | ||||
53 | return; | ||||
54 | } | ||||
55 | | ||||
56 | m_open = open; | ||||
57 | | ||||
58 | if (open) { | ||||
59 | m_hideTimer->stop(); | ||||
60 | setVisible(true); | ||||
61 | } else { | ||||
62 | m_hideTimer->start(); | ||||
63 | } | ||||
64 | | ||||
65 | emit openChanged(); | ||||
66 | } | ||||
67 | | ||||
68 | bool ConfigOverlay::touchInteraction() const | ||||
69 | { | ||||
70 | return m_touchInteraction; | ||||
71 | } | ||||
72 | void ConfigOverlay::setTouchInteraction(bool touch) | ||||
73 | { | ||||
74 | if (touch == m_touchInteraction) { | ||||
75 | return; | ||||
76 | } | ||||
77 | | ||||
78 | m_touchInteraction = touch; | ||||
79 | emit touchInteractionChanged(); | ||||
80 | } | ||||
81 | | ||||
82 | ItemContainer *ConfigOverlay::itemContainer() const | ||||
83 | { | ||||
84 | return m_itemContainer; | ||||
85 | } | ||||
86 | | ||||
87 | void ConfigOverlay::setItemContainer(ItemContainer *container) | ||||
88 | { | ||||
89 | if (container == m_itemContainer) { | ||||
90 | return; | ||||
91 | } | ||||
92 | | ||||
93 | if (m_itemContainer) { | ||||
94 | disconnect(m_itemContainer, nullptr, this, nullptr); | ||||
95 | } | ||||
96 | | ||||
97 | m_itemContainer = container; | ||||
98 | | ||||
99 | if (!m_itemContainer || !m_itemContainer->layout()) { | ||||
100 | return; | ||||
101 | } | ||||
102 | | ||||
103 | m_leftAvailableSpace = qMax(0.0, m_itemContainer->x()); | ||||
104 | m_rightAvailableSpace = qMax(0.0, m_itemContainer->layout()->width() - (m_itemContainer->x() + m_itemContainer->width())); | ||||
105 | m_topAvailableSpace = qMax(0.0, m_itemContainer->y()); | ||||
106 | m_bottomAvailableSpace = qMax(0.0, m_itemContainer->layout()->height() - (m_itemContainer->y() + m_itemContainer->height())); | ||||
107 | emit leftAvailableSpaceChanged(); | ||||
108 | emit rightAvailableSpaceChanged(); | ||||
109 | emit topAvailableSpaceChanged(); | ||||
110 | emit bottomAvailableSpaceChanged(); | ||||
111 | | ||||
112 | connect(m_itemContainer.data(), &ItemContainer::xChanged, this, [this] () { | ||||
113 | m_leftAvailableSpace = qMax(0.0, m_itemContainer->x()); | ||||
114 | m_rightAvailableSpace = qMax(0.0, m_itemContainer->layout()->width() - (m_itemContainer->x() + m_itemContainer->width())); | ||||
115 | emit leftAvailableSpaceChanged(); | ||||
116 | emit rightAvailableSpaceChanged(); | ||||
117 | }); | ||||
118 | | ||||
119 | connect(m_itemContainer.data(), &ItemContainer::yChanged, this, [this] () { | ||||
120 | m_topAvailableSpace = qMax(0.0, m_itemContainer->y()); | ||||
121 | m_bottomAvailableSpace = qMax(0.0, m_itemContainer->layout()->height() - (m_itemContainer->y() + m_itemContainer->height())); | ||||
122 | emit topAvailableSpaceChanged(); | ||||
123 | emit bottomAvailableSpaceChanged(); | ||||
124 | }); | ||||
125 | | ||||
126 | connect(m_itemContainer.data(), &ItemContainer::widthChanged, this, [this] () { | ||||
127 | m_rightAvailableSpace = qMax(0.0, m_itemContainer->layout()->width() - (m_itemContainer->x() + m_itemContainer->width())); | ||||
128 | emit rightAvailableSpaceChanged(); | ||||
129 | }); | ||||
130 | | ||||
131 | connect(m_itemContainer.data(), &ItemContainer::heightChanged, this, [this] () { | ||||
132 | m_bottomAvailableSpace = qMax(0.0, m_itemContainer->layout()->height() - (m_itemContainer->y() + m_itemContainer->height())); | ||||
133 | emit bottomAvailableSpaceChanged(); | ||||
134 | }); | ||||
135 | emit itemContainerChanged(); | ||||
136 | } | ||||
137 | | ||||
138 | #include "moc_configoverlay.cpp" |