aboutsummaryrefslogtreecommitdiff
path: root/src/corelib/layout/mlayout_p.h
blob: 04e325d8b75d4ee61e09e8da4bce30848503f822 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (directui@nokia.com)
**
** This file is part of libmeegotouch.
**
** If you have questions regarding the use of this file, please contact
** Nokia at directui@nokia.com.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#ifndef MLAYOUT_P_H
#define MLAYOUT_P_H

#include "mlayout.h"
#include "mlayoutanimation.h"

#include <QtCore/QList>
#include <QtCore/QPointer>
#include <mnamespace.h>

class QGraphicsLayoutItem;
class MLayoutAnimation;

/** Private Layout class.
 */
class MLayoutPrivate
{
public:

    /** Constructor */
    explicit MLayoutPrivate(MLayout *l);

    /*!
     * \brief Method to register a policy with this layout.
     *
     * This is called by MAbstractLayoutPolicy when an instance is created.
     * If there are no other registered policies, this will become the active (current) policy.
     *
     * @param policy  The policy to register.
     */
    void registerPolicy(MAbstractLayoutPolicy *policy);

    /*!
     * \brief Method to unregister a policy with this layout.
     *
     * This is called by MAbstractLayoutPolicy when an instance is destroyed.
     *
     * If this policy was currently active, the most recently created policy will become automatically
     * active.  If there are no policies left, the current policy will become NULL.
     *
     * @param policy  The policy to deregister.
     */
    void unregisterPolicy(MAbstractLayoutPolicy *policy);

    /*! \brief Set the target geometry of the given item to the given geometry.
     *
     *  This is called by MAbstractLayoutPolicy::setGeometry() to set the target
     *  geometry of the item.
     *
     *  Note that this causes the item to be shown, if it's being hidden.
     */
    void setItemGeometry(int index, const QRectF &geometry);

    /*! \brief Return the target geometry of the item at the given index.
     */
    QRectF itemGeometry(int index) const;

    /*! \brief Hide the given item.
     *
     *  Items can be hidden by the policies and are automatically hidden when
     *  switching to a policy not visible.  Items become visible again with a
     *  subsequent call to setItemGeometry().
     *
     *  To hide items as a user of MLayout, see \ref visibility
     */
    void hideItem(int index);

    /** This is called by the animator to trigger cleanup tasks. */
    void animationFinished();
    /** This is called when an item's animation has finished, to delete
     *  the item if it needs deleting */
    void itemAnimationFinished(int index);

    /** Go up the parents and return the first parent that is not a layout */
    QGraphicsItem *parentItem() const;

    /** Hide the given item, setting a flag in MWidget to indicate that the layout hid it */
    void hideItemNow(QGraphicsItem *layoutItem) const;
    /** Show the given item if it was hidden by the layout, clearing the flag in MWidget to indicate that the layout unhid it */
    void showItemNow(QGraphicsItem *layoutItem) const;
    /** Only clear the flag in MWidget */
    void removeHiddenFlag(QGraphicsItem *layoutItem) const;
    /** This is called when the widget's orientation has changed (probably because the device has been rotated) */
    void setOrientation(M::Orientation orientation);
    /** Check the closest parent widget's scene to find out what orientation we are in */
    void recheckOrientation(bool fallbackToActiveWindow = true);
    /** Return the current orientation of the layout */
    M::Orientation orientation() const;

protected:
    Q_DECLARE_PUBLIC(MLayout)
    // Shared d_ptr related code:
    MLayout *q_ptr;
    MAbstractLayoutPolicy *portraitPolicy;
    MAbstractLayoutPolicy *landscapePolicy;

    /** The policy object governing layout. */
    MAbstractLayoutPolicy *current_policy;

    /** The layout animation for this policy */
    MLayoutAnimation *animation;

    /** Policies that are associated with this layout. */
    QList<MAbstractLayoutPolicy *> policies;

    /** The current orientation of the widget that this layout is in */
    M::Orientation m_orientation;

    struct LayoutItem {
        QGraphicsLayoutItem *item;
        QRectF geometry;
        bool toBeDeleted;
    };
    /** List of items */
    QList<LayoutItem> items;
};

#endif // Header Guard