2
* Copyright 2015 Canonical Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation; version 3.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Author: Zsombor Egri <zsombor.egri@canonical.com>
19
#include "ucbottomedge.h"
20
#include "ucbottomedge_p.h"
21
#include "ucbottomedgeregion.h"
22
#include "propertychange_p.h"
23
#include <QtQml/private/qqmlproperty_p.h>
26
* \qmltype BottomEdgeRegion
27
* \instantiates UCBottomEdgeRegion
29
* \inmodule Ubuntu.Components 1.3
30
* \since Ubuntu.Components 1.3
32
* \brief Defines an active region within the BottomEdge component.
34
* Bottom edge regions are portions within the bottom edge area which can define
35
* different content or action whenever the drag enters in the area. The area is
36
* defined by \l from and \l to properties vertically, whereas horizontally is
37
* stretched across bottom edge width. Custom content can be defined through
38
* \l contentUrl or \l contentComponent properties, which will override the
39
* \l BottomEdge::contentUrl and \l BottomEdge::contentComponent properties for the
40
* time the gesture is in the section area.
43
* import Ubuntu.Components 1.3
47
* height: units.gu(70)
50
* header: PageHeader {
51
* title: "BottomEdge regions"
56
* height: parent.height - units.gu(20)
57
* hint: BottomEdgeHint {
58
* text: "My bottom edge"
60
* // a fake content till we reach the committable area
61
* contentComponent: Rectangle {
62
* width: bottomEdge.width
63
* height: bottomEdge.height
64
* color: UbuntuColors.green
66
* // override bottom edge sections to switch to real content
69
* contentComponent: Page {
70
* width: bottomEdge.width
71
* height: bottomEdge.height
72
* header: PageHeader {
73
* title: "BottomEdge Content"
82
* Entering into the section area is signalled by the \l entered signal and when
83
* drag leaves the area the \l exited signal is emitted. If the drag ends within
84
* the section area, the \l dragEnded signal is emitted. In case the section's
85
* \l to property is less than 1.0, the bottom edge content will only be exposed
86
* to that value, and the \l BottomEdge::status will get the \e Committed value.
87
* No further drag is possible after reaching \e Commited state.
89
* \note Whereas there is no restriction on making overlapping sections, beware that
90
* overlapping sections changing the content through the \l contentUrl or \l contentComponent
91
* properties will cause unpredictable results.
94
UCBottomEdgeRegion::UCBottomEdgeRegion(QObject *parent)
96
, m_bottomEdge(qobject_cast<UCBottomEdge*>(parent))
97
, m_component(Q_NULLPTR)
98
, m_urlBackup(Q_NULLPTR)
99
, m_componentBackup(Q_NULLPTR)
106
void UCBottomEdgeRegion::attachToBottomEdge(UCBottomEdge *bottomEdge)
108
QQml_setParent_noEvent(this, bottomEdge);
109
m_bottomEdge = bottomEdge;
110
// adjust to property value if not set yet
117
bool UCBottomEdgeRegion::contains(qreal dragRatio)
119
return (m_enabled && (m_from < m_to) && dragRatio >= m_from && dragRatio <= m_to);
122
void UCBottomEdgeRegion::enter()
126
if (m_url.isValid()) {
127
m_urlBackup = new PropertyChange(m_bottomEdge, "contentUrl");
128
QQmlProperty property(this, "contentUrl", qmlContext(this));
129
QQmlAbstractBinding *binding = QQmlPropertyPrivate::binding(property);
131
PropertyChange::setBinding(m_urlBackup, binding);
133
PropertyChange::setValue(m_urlBackup, m_url);
137
m_componentBackup = new PropertyChange(m_bottomEdge, "contentComponent");
138
QQmlProperty property(this, "contentComponent", qmlContext(this));
139
QQmlAbstractBinding *binding = QQmlPropertyPrivate::binding(property);
141
PropertyChange::setBinding(m_componentBackup, binding);
143
PropertyChange::setValue(m_componentBackup, QVariant::fromValue<QQmlComponent*>(m_component));
148
void UCBottomEdgeRegion::exit()
150
if (m_componentBackup) {
151
delete m_componentBackup;
152
m_componentBackup = Q_NULLPTR;
156
m_urlBackup = Q_NULLPTR;
161
const QRectF UCBottomEdgeRegion::rect(const QRectF &bottomEdgeRect)
164
bottomEdgeRect.topLeft() + QPointF(0, bottomEdgeRect.height() * (1.0 - m_to)),
165
QSizeF(bottomEdgeRect.width(), bottomEdgeRect.height() * (m_to - m_from)));
170
* \qmlproperty bool BottomEdgeRegion::enabled
171
* Enables the section. Disabled sections do not trigger nor change the BottomEdge
172
* content. Defaults to false.
174
void UCBottomEdgeRegion::setEnabled(bool enabled)
176
if (enabled == m_enabled) {
181
UCBottomEdgePrivate::get(m_bottomEdge)->validateRegion(this);
183
Q_EMIT enabledChanged();
187
* \qmlproperty real BottomEdgeRegion::from
188
* Specifies the starting ratio of the bottom erge area. The value must be bigger
189
* or equal to 0 but strictly smaller than \l to. Defaults to 0.0.
191
void UCBottomEdgeRegion::setFrom(qreal from)
193
if (from == m_from) {
198
UCBottomEdgePrivate::get(m_bottomEdge)->validateRegion(this);
200
Q_EMIT fromChanged();
204
* \qmlproperty real BottomEdgeRegion::to
205
* Specifies the ending ratio of the bottom edge area. The value must be bigger
206
* than \l from and smaller or equal to 1.0.
207
* \note If the end point is less than 1.0, ending the drag within the section
208
* will result in exposing the bottom edge content only till the ration specified
211
void UCBottomEdgeRegion::setTo(qreal to)
218
UCBottomEdgePrivate::get(m_bottomEdge)->validateRegion(this);
224
* \qmlproperty url BottomEdgeRegion::contentUrl
225
* Specifies the url to the document defining the section specific content. This
226
* propery will temporarily override the \l BottomEdge::contentUrl property value
227
* when the drag gesture enters the section area. The orginal value will be restored
228
* once the gesture leaves the section area.
232
* \qmlproperty Component BottomEdgeRegion::contentComponent
233
* Specifies the component defining the section specific content. This propery
234
* will temporarily override the \l BottomEdge::contentComponent property value
235
* when the drag gesture enters the section area. The orginal value will be restored
236
* once the gesture leaves the section area.
240
* \qmlsignal void BottomEdgeRegion::entered()
241
* Signal triggered when the drag enters into the area defined by the bottom edge
246
* \qmlsignal void BottomEdgeRegion::exited()
247
* Signal triggered when the drag leaves the area defined by the bottom edge section.
251
* \qmlsignal void BottomEdgeRegion::dragEnded()
252
* Signal triggered when the drag ends within the active bottom edge section area.