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 | m_hideTimer = new QTimer(this); | ||||
29 | m_hideTimer->setSingleShot(true); | ||||
30 | m_hideTimer->setInterval(600); | ||||
31 | connect(m_hideTimer, &QTimer::timeout, this, [this] () { | ||||
32 | setVisible(false); | ||||
33 | }); | ||||
34 | } | ||||
35 | | ||||
36 | ConfigOverlay::~ConfigOverlay() | ||||
37 | { | ||||
38 | } | ||||
39 | | ||||
40 | bool ConfigOverlay::open() const | ||||
41 | { | ||||
42 | return m_open; | ||||
43 | } | ||||
44 | | ||||
45 | void ConfigOverlay::setOpen(bool open) | ||||
46 | { | ||||
47 | if (open == m_open) { | ||||
48 | return; | ||||
49 | } | ||||
50 | | ||||
51 | m_open = open; | ||||
52 | | ||||
53 | if (open) { | ||||
54 | m_hideTimer->stop(); | ||||
55 | setVisible(true); | ||||
56 | } else { | ||||
57 | m_hideTimer->start(); | ||||
58 | } | ||||
59 | | ||||
60 | emit openChanged(); | ||||
61 | } | ||||
62 | | ||||
63 | bool ConfigOverlay::touchInteraction() const | ||||
64 | { | ||||
65 | return m_touchInteraction; | ||||
66 | } | ||||
67 | void ConfigOverlay::setTouchInteraction(bool touch) | ||||
68 | { | ||||
69 | if (touch == m_touchInteraction) { | ||||
70 | return; | ||||
71 | } | ||||
72 | | ||||
73 | m_touchInteraction = touch; | ||||
74 | emit touchInteractionChanged(); | ||||
75 | } | ||||
76 | | ||||
77 | ItemContainer *ConfigOverlay::itemContainer() const | ||||
78 | { | ||||
79 | return m_itemContainer; | ||||
80 | } | ||||
81 | | ||||
82 | void ConfigOverlay::setItemContainer(ItemContainer *container) | ||||
83 | { | ||||
84 | if (container == m_itemContainer) { | ||||
85 | return; | ||||
86 | } | ||||
87 | | ||||
88 | if (m_itemContainer) { | ||||
89 | disconnect(m_itemContainer, nullptr, this, nullptr); | ||||
90 | } | ||||
91 | | ||||
92 | m_itemContainer = container; | ||||
93 | | ||||
94 | if (!m_itemContainer || !m_itemContainer->layout()) { | ||||
95 | return; | ||||
96 | } | ||||
97 | | ||||
98 | m_leftAvailableSpace = qMax(0.0, m_itemContainer->x()); | ||||
99 | m_rightAvailableSpace = qMax(0.0, m_itemContainer->layout()->width() - (m_itemContainer->x() + m_itemContainer->width())); | ||||
100 | m_topAvailableSpace = qMax(0.0, m_itemContainer->y()); | ||||
101 | m_bottomAvailableSpace = qMax(0.0, m_itemContainer->layout()->height() - (m_itemContainer->y() + m_itemContainer->height())); | ||||
102 | emit leftAvailableSpaceChanged(); | ||||
103 | emit rightAvailableSpaceChanged(); | ||||
104 | emit topAvailableSpaceChanged(); | ||||
105 | emit bottomAvailableSpaceChanged(); | ||||
106 | | ||||
107 | connect(m_itemContainer.data(), &ItemContainer::xChanged, this, [this] () { | ||||
108 | m_leftAvailableSpace = qMax(0.0, m_itemContainer->x()); | ||||
109 | m_rightAvailableSpace = qMax(0.0, m_itemContainer->layout()->width() - (m_itemContainer->x() + m_itemContainer->width())); | ||||
110 | emit leftAvailableSpaceChanged(); | ||||
111 | emit rightAvailableSpaceChanged(); | ||||
112 | }); | ||||
113 | | ||||
114 | connect(m_itemContainer.data(), &ItemContainer::yChanged, this, [this] () { | ||||
115 | m_topAvailableSpace = qMax(0.0, m_itemContainer->y()); | ||||
116 | m_bottomAvailableSpace = qMax(0.0, m_itemContainer->layout()->height() - (m_itemContainer->y() + m_itemContainer->height())); | ||||
117 | emit topAvailableSpaceChanged(); | ||||
118 | emit bottomAvailableSpaceChanged(); | ||||
119 | }); | ||||
120 | | ||||
121 | connect(m_itemContainer.data(), &ItemContainer::widthChanged, this, [this] () { | ||||
122 | m_rightAvailableSpace = qMax(0.0, m_itemContainer->layout()->width() - (m_itemContainer->x() + m_itemContainer->width())); | ||||
123 | emit rightAvailableSpaceChanged(); | ||||
124 | }); | ||||
125 | | ||||
126 | connect(m_itemContainer.data(), &ItemContainer::heightChanged, this, [this] () { | ||||
127 | m_bottomAvailableSpace = qMax(0.0, m_itemContainer->layout()->height() - (m_itemContainer->y() + m_itemContainer->height())); | ||||
128 | emit bottomAvailableSpaceChanged(); | ||||
129 | }); | ||||
130 | emit itemContainerChanged(); | ||||
131 | } | ||||
132 | | ||||
133 | #include "moc_configoverlay.cpp" |