~zsombi/ubuntu-ui-toolkit/listitemSelectModeBugs

« back to all changes in this revision

Viewing changes to src/Ubuntu/Components/plugin/ucslotslayout.h

  • Committer: Zsombor Egri
  • Date: 2015-11-16 06:35:05 UTC
  • mfrom: (1664.1.1 listitemSelectModeBugs)
  • Revision ID: zsombor.egri@canonical.com-20151116063505-cwn2qfks7qzk10g9
re-sync

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2015 Canonical Ltd.
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 *
 
16
 * Author: Andrea Bernabei <andrea.bernabei@canonical.com>
 
17
 */
 
18
 
 
19
#ifndef UCSLOTSLAYOUT_H
 
20
#define UCSLOTSLAYOUT_H
 
21
 
 
22
#include <QtQuick/QQuickItem>
 
23
 
 
24
class UCSlotsAttached;
 
25
class UCSlotsLayoutPadding;
 
26
class UCSlotsLayoutPrivate;
 
27
class UCSlotsLayout : public QQuickItem
 
28
{
 
29
    Q_OBJECT
 
30
 
 
31
    Q_PROPERTY(QQuickItem *mainSlot READ mainSlot WRITE setMainSlot NOTIFY mainSlotChanged)
 
32
    Q_PROPERTY(UCSlotsLayoutPadding *padding READ padding CONSTANT FINAL)
 
33
 
 
34
    Q_ENUMS(UCSlotPosition)
 
35
 
 
36
public:
 
37
    explicit UCSlotsLayout(QQuickItem *parent = 0);
 
38
 
 
39
    virtual QQuickItem *mainSlot();
 
40
    virtual QQuickItem *mainSlot() const;
 
41
    virtual void setMainSlot(QQuickItem *item, bool fireSignal = true);
 
42
 
 
43
    UCSlotsLayoutPadding *padding();
 
44
 
 
45
    enum UCSlotPosition {
 
46
        First = INT_MIN/2,
 
47
        Leading = INT_MIN/4,
 
48
        Trailing = INT_MAX/4,
 
49
        Last = INT_MAX/2
 
50
    };
 
51
 
 
52
    static UCSlotsAttached *qmlAttachedProperties(QObject *object);
 
53
 
 
54
Q_SIGNALS:
 
55
    void mainSlotChanged();
 
56
 
 
57
protected:
 
58
    Q_DECLARE_PRIVATE(UCSlotsLayout)
 
59
    void componentComplete();
 
60
    void itemChange(ItemChange change, const ItemChangeData &data);
 
61
 
 
62
private:
 
63
    Q_PRIVATE_SLOT(d_func(), void _q_onGuValueChanged())
 
64
    Q_PRIVATE_SLOT(d_func(), void _q_updateCachedHeight())
 
65
    Q_PRIVATE_SLOT(d_func(), void _q_updateGuValues())
 
66
    Q_PRIVATE_SLOT(d_func(), void _q_updateCachedMainSlotHeight())
 
67
    Q_PRIVATE_SLOT(d_func(), void _q_updateSlotsBBoxHeight())
 
68
    Q_PRIVATE_SLOT(d_func(), void _q_updateSize())
 
69
    Q_PRIVATE_SLOT(d_func(), void _q_onSlotWidthChanged())
 
70
    Q_PRIVATE_SLOT(d_func(), void _q_onSlotOverrideVerticalPositioningChanged())
 
71
    Q_PRIVATE_SLOT(d_func(), void _q_onSlotPositionChanged())
 
72
    Q_PRIVATE_SLOT(d_func(), void _q_relayout())
 
73
};
 
74
QML_DECLARE_TYPEINFO(UCSlotsLayout, QML_HAS_ATTACHED_PROPERTIES)
 
75
 
 
76
class UCSlotsAttachedPrivate;
 
77
class UCSlotsAttached : public QObject
 
78
{
 
79
    Q_OBJECT
 
80
    Q_PROPERTY(UCSlotsLayout::UCSlotPosition position READ position WRITE setPosition NOTIFY positionChanged)
 
81
    Q_PROPERTY(UCSlotsLayoutPadding *padding READ padding CONSTANT FINAL)
 
82
    Q_PROPERTY(bool overrideVerticalPositioning READ overrideVerticalPositioning WRITE setOverrideVerticalPositioning NOTIFY overrideVerticalPositioningChanged)
 
83
 
 
84
public:
 
85
    UCSlotsAttached(QObject *object = 0);
 
86
 
 
87
    UCSlotsLayout::UCSlotPosition position() const;
 
88
    void setPosition(UCSlotsLayout::UCSlotPosition pos);
 
89
 
 
90
    UCSlotsLayoutPadding *padding();
 
91
 
 
92
    bool overrideVerticalPositioning() const;
 
93
    void setOverrideVerticalPositioning(bool val);
 
94
 
 
95
Q_SIGNALS:
 
96
    void positionChanged();
 
97
    void overrideVerticalPositioningChanged();
 
98
 
 
99
protected:
 
100
    Q_DECLARE_PRIVATE(UCSlotsAttached)
 
101
 
 
102
private:
 
103
    Q_PRIVATE_SLOT(d_func(), void _q_onGuValueChanged())
 
104
};
 
105
 
 
106
class UCSlotsLayoutPadding : public QObject
 
107
{
 
108
    Q_OBJECT
 
109
    Q_PROPERTY(qreal leading READ leading WRITE setLeadingQml NOTIFY leadingChanged FINAL)
 
110
    Q_PROPERTY(qreal trailing READ trailing WRITE setTrailingQml NOTIFY trailingChanged FINAL)
 
111
    Q_PROPERTY(qreal top READ top WRITE setTopQml NOTIFY topChanged FINAL)
 
112
    Q_PROPERTY(qreal bottom READ bottom WRITE setBottomQml NOTIFY bottomChanged FINAL)
 
113
 
 
114
public:
 
115
    explicit UCSlotsLayoutPadding(QObject *parent = 0);
 
116
 
 
117
    qreal leading() const;
 
118
    void setLeading(qreal val);
 
119
    void setLeadingQml(qreal val);
 
120
 
 
121
    qreal trailing() const;
 
122
    void setTrailing(qreal val);
 
123
    void setTrailingQml(qreal val);
 
124
 
 
125
    qreal top() const;
 
126
    void setTop(qreal val);
 
127
    void setTopQml(qreal val);
 
128
 
 
129
    qreal bottom() const;
 
130
    void setBottom(qreal val);
 
131
    void setBottomQml(qreal val);
 
132
 
 
133
    //once the dev tries to change the offsets (and he does so via QML) we'll stop
 
134
    //updating offset's value, for instance when gu value changes or when the
 
135
    //positioning mode changes
 
136
    bool leadingWasSetFromQml : 1;
 
137
    bool trailingWasSetFromQml : 1;
 
138
    bool topWasSetFromQml : 1;
 
139
    bool bottomWasSetFromQml : 1;
 
140
 
 
141
Q_SIGNALS:
 
142
    void leadingChanged();
 
143
    void trailingChanged();
 
144
    void topChanged();
 
145
    void bottomChanged();
 
146
 
 
147
private:
 
148
    //similar to anchors.margins, but we don't use a contentItem so we handle this ourselves
 
149
    qreal m_leading;
 
150
    qreal m_trailing;
 
151
    qreal m_top;
 
152
    qreal m_bottom;
 
153
};
 
154
 
 
155
#endif // UCSLOTSLAYOUT_H