~ubuntu-branches/ubuntu/wily/qtbase-opensource-src/wily

« back to all changes in this revision

Viewing changes to src/widgets/widgets/qmdiarea_p.h

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 12:46:17 UTC
  • Revision ID: package-import@ubuntu.com-20130205124617-c8jouts182j002fx
Tags: upstream-5.0.1+dfsg
ImportĀ upstreamĀ versionĀ 5.0.1+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the QtGui module of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:LGPL$
 
9
** Commercial License Usage
 
10
** Licensees holding valid commercial Qt licenses may use this file in
 
11
** accordance with the commercial license agreement provided with the
 
12
** Software or, alternatively, in accordance with the terms contained in
 
13
** a written agreement between you and Digia.  For licensing terms and
 
14
** conditions see http://qt.digia.com/licensing.  For further information
 
15
** use the contact form at http://qt.digia.com/contact-us.
 
16
**
 
17
** GNU Lesser General Public License Usage
 
18
** Alternatively, this file may be used under the terms of the GNU Lesser
 
19
** General Public License version 2.1 as published by the Free Software
 
20
** Foundation and appearing in the file LICENSE.LGPL included in the
 
21
** packaging of this file.  Please review the following information to
 
22
** ensure the GNU Lesser General Public License version 2.1 requirements
 
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 
24
**
 
25
** In addition, as a special exception, Digia gives you certain additional
 
26
** rights.  These rights are described in the Digia Qt LGPL Exception
 
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
28
**
 
29
** GNU General Public License Usage
 
30
** Alternatively, this file may be used under the terms of the GNU
 
31
** General Public License version 3.0 as published by the Free Software
 
32
** Foundation and appearing in the file LICENSE.GPL included in the
 
33
** packaging of this file.  Please review the following information to
 
34
** ensure the GNU General Public License version 3.0 requirements will be
 
35
** met: http://www.gnu.org/copyleft/gpl.html.
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#ifndef QMDIAREA_P_H
 
43
#define QMDIAREA_P_H
 
44
 
 
45
//
 
46
//  W A R N I N G
 
47
//  -------------
 
48
//
 
49
// This file is not part of the Qt API.  It exists purely as an
 
50
// implementation detail.  This header file may change from version to
 
51
// version without notice, or even be removed.
 
52
//
 
53
// We mean it.
 
54
//
 
55
 
 
56
#include "qmdiarea.h"
 
57
#include "qmdisubwindow.h"
 
58
 
 
59
#ifndef QT_NO_MDIAREA
 
60
 
 
61
#include <QList>
 
62
#include <QRect>
 
63
#include <QPoint>
 
64
#include <QtWidgets/qapplication.h>
 
65
#include <private/qmdisubwindow_p.h>
 
66
#include <private/qabstractscrollarea_p.h>
 
67
 
 
68
QT_BEGIN_NAMESPACE
 
69
 
 
70
namespace QMdi {
 
71
class Rearranger
 
72
{
 
73
public:
 
74
    enum Type {
 
75
        RegularTiler,
 
76
        SimpleCascader,
 
77
        IconTiler
 
78
    };
 
79
 
 
80
    // Rearranges widgets relative to domain.
 
81
    virtual void rearrange(QList<QWidget *> &widgets, const QRect &domain) const = 0;
 
82
    virtual Type type() const = 0;
 
83
    virtual ~Rearranger() {}
 
84
};
 
85
 
 
86
class RegularTiler : public Rearranger
 
87
{
 
88
    // Rearranges widgets according to a regular tiling pattern
 
89
    // covering the entire domain.
 
90
    // Both positions and sizes may change.
 
91
    void rearrange(QList<QWidget *> &widgets, const QRect &domain) const;
 
92
    inline Type type() const { return Rearranger::RegularTiler; }
 
93
};
 
94
 
 
95
class SimpleCascader : public Rearranger
 
96
{
 
97
    // Rearranges widgets according to a simple, regular cascading pattern.
 
98
    // Widgets are resized to minimumSize.
 
99
    // Both positions and sizes may change.
 
100
    void rearrange(QList<QWidget *> &widgets, const QRect &domain) const;
 
101
    inline Type type() const { return Rearranger::SimpleCascader; }
 
102
};
 
103
 
 
104
class IconTiler : public Rearranger
 
105
{
 
106
    // Rearranges icons (assumed to be the same size) according to a regular
 
107
    // tiling pattern filling up the domain from the bottom.
 
108
    // Only positions may change.
 
109
    void rearrange(QList<QWidget *> &widgets, const QRect &domain) const;
 
110
    inline Type type() const { return Rearranger::IconTiler; }
 
111
};
 
112
 
 
113
class Placer
 
114
{
 
115
public:
 
116
    // Places the rectangle defined by 'size' relative to 'rects' and 'domain'.
 
117
    // Returns the position of the resulting rectangle.
 
118
    virtual QPoint place(
 
119
        const QSize &size, const QList<QRect> &rects, const QRect &domain) const = 0;
 
120
    virtual ~Placer() {}
 
121
};
 
122
 
 
123
class MinOverlapPlacer : public Placer
 
124
{
 
125
    QPoint place(const QSize &size, const QList<QRect> &rects, const QRect &domain) const;
 
126
    static int accumulatedOverlap(const QRect &source, const QList<QRect> &rects);
 
127
    static QRect findMinOverlapRect(const QList<QRect> &source, const QList<QRect> &rects);
 
128
    static void getCandidatePlacements(
 
129
        const QSize &size, const QList<QRect> &rects, const QRect &domain,
 
130
        QList<QRect> &candidates);
 
131
    static QPoint findBestPlacement(
 
132
        const QRect &domain, const QList<QRect> &rects, QList<QRect> &source);
 
133
    static void findNonInsiders(
 
134
        const QRect &domain, QList<QRect> &source, QList<QRect> &result);
 
135
    static void findMaxOverlappers(
 
136
        const QRect &domain, const QList<QRect> &source, QList<QRect> &result);
 
137
};
 
138
} // namespace QMdi
 
139
 
 
140
class QMdiAreaTabBar;
 
141
class QMdiAreaPrivate : public QAbstractScrollAreaPrivate
 
142
{
 
143
    Q_DECLARE_PUBLIC(QMdiArea)
 
144
public:
 
145
    QMdiAreaPrivate();
 
146
 
 
147
    // Variables.
 
148
    QMdi::Rearranger *cascader;
 
149
    QMdi::Rearranger *regularTiler;
 
150
    QMdi::Rearranger *iconTiler;
 
151
    QMdi::Placer *placer;
 
152
#ifndef QT_NO_RUBBERBAND
 
153
    QRubberBand *rubberBand;
 
154
#endif
 
155
    QMdiAreaTabBar *tabBar;
 
156
    QList<QMdi::Rearranger *> pendingRearrangements;
 
157
    QList< QPointer<QMdiSubWindow> > pendingPlacements;
 
158
    QList< QPointer<QMdiSubWindow> > childWindows;
 
159
    QList<int> indicesToActivatedChildren;
 
160
    QPointer<QMdiSubWindow> active;
 
161
    QPointer<QMdiSubWindow> aboutToBecomeActive;
 
162
    QBrush background;
 
163
    QMdiArea::WindowOrder activationOrder;
 
164
    QMdiArea::AreaOptions options;
 
165
    QMdiArea::ViewMode viewMode;
 
166
#ifndef QT_NO_TABBAR
 
167
    bool documentMode;
 
168
    bool tabsClosable;
 
169
    bool tabsMovable;
 
170
#endif
 
171
#ifndef QT_NO_TABWIDGET
 
172
    QTabWidget::TabShape tabShape;
 
173
    QTabWidget::TabPosition tabPosition;
 
174
#endif
 
175
    bool ignoreGeometryChange;
 
176
    bool ignoreWindowStateChange;
 
177
    bool isActivated;
 
178
    bool isSubWindowsTiled;
 
179
    bool showActiveWindowMaximized;
 
180
    bool tileCalledFromResizeEvent;
 
181
    bool updatesDisabledByUs;
 
182
    bool inViewModeChange;
 
183
    int indexToNextWindow;
 
184
    int indexToPreviousWindow;
 
185
    int indexToHighlighted;
 
186
    int indexToLastActiveTab;
 
187
    int resizeTimerId;
 
188
    int tabToPreviousTimerId;
 
189
 
 
190
    // Slots.
 
191
    void _q_deactivateAllWindows(QMdiSubWindow *aboutToActivate = 0);
 
192
    void _q_processWindowStateChanged(Qt::WindowStates oldState, Qt::WindowStates newState);
 
193
    void _q_currentTabChanged(int index);
 
194
    void _q_closeTab(int index);
 
195
    void _q_moveTab(int from, int to);
 
196
 
 
197
    // Functions.
 
198
    void appendChild(QMdiSubWindow *child);
 
199
    void place(QMdi::Placer *placer, QMdiSubWindow *child);
 
200
    void rearrange(QMdi::Rearranger *rearranger);
 
201
    void arrangeMinimizedSubWindows();
 
202
    void activateWindow(QMdiSubWindow *child);
 
203
    void activateCurrentWindow();
 
204
    void activateHighlightedWindow();
 
205
    void emitWindowActivated(QMdiSubWindow *child);
 
206
    void resetActiveWindow(QMdiSubWindow *child = 0);
 
207
    void updateActiveWindow(int removedIndex, bool activeRemoved);
 
208
    void updateScrollBars();
 
209
    void internalRaise(QMdiSubWindow *child) const;
 
210
    bool scrollBarsEnabled() const;
 
211
    bool lastWindowAboutToBeDestroyed() const;
 
212
    void setChildActivationEnabled(bool enable = true, bool onlyNextActivationEvent = false) const;
 
213
    QRect resizeToMinimumTileSize(const QSize &minSubWindowSize, int subWindowCount);
 
214
    void scrollBarPolicyChanged(Qt::Orientation, Qt::ScrollBarPolicy); // reimp
 
215
    QMdiSubWindow *nextVisibleSubWindow(int increaseFactor, QMdiArea::WindowOrder,
 
216
                                        int removed = -1, int fromIndex = -1) const;
 
217
    void highlightNextSubWindow(int increaseFactor);
 
218
    QList<QMdiSubWindow *> subWindowList(QMdiArea::WindowOrder, bool reversed = false) const;
 
219
    void disconnectSubWindow(QObject *subWindow);
 
220
    void setViewMode(QMdiArea::ViewMode mode);
 
221
#ifndef QT_NO_TABBAR
 
222
    void updateTabBarGeometry();
 
223
    void refreshTabBar();
 
224
#endif
 
225
 
 
226
    inline void startResizeTimer()
 
227
    {
 
228
        Q_Q(QMdiArea);
 
229
        if (resizeTimerId > 0)
 
230
            q->killTimer(resizeTimerId);
 
231
        resizeTimerId = q->startTimer(200);
 
232
    }
 
233
 
 
234
    inline void startTabToPreviousTimer()
 
235
    {
 
236
        Q_Q(QMdiArea);
 
237
        if (tabToPreviousTimerId > 0)
 
238
            q->killTimer(tabToPreviousTimerId);
 
239
        tabToPreviousTimerId = q->startTimer(QApplication::keyboardInputInterval());
 
240
    }
 
241
 
 
242
    inline bool windowStaysOnTop(QMdiSubWindow *subWindow) const
 
243
    {
 
244
        if (!subWindow)
 
245
            return false;
 
246
        return subWindow->windowFlags() & Qt::WindowStaysOnTopHint;
 
247
    }
 
248
 
 
249
    inline bool isExplicitlyDeactivated(QMdiSubWindow *subWindow) const
 
250
    {
 
251
        if (!subWindow)
 
252
            return true;
 
253
        return subWindow->d_func()->isExplicitlyDeactivated;
 
254
    }
 
255
 
 
256
    inline void setActive(QMdiSubWindow *subWindow, bool active = true, bool changeFocus = true) const
 
257
    {
 
258
        if (subWindow)
 
259
            subWindow->d_func()->setActive(active, changeFocus);
 
260
    }
 
261
 
 
262
#ifndef QT_NO_RUBBERBAND
 
263
    inline void showRubberBandFor(QMdiSubWindow *subWindow)
 
264
    {
 
265
        if (!subWindow || !rubberBand)
 
266
            return;
 
267
        rubberBand->setGeometry(subWindow->geometry());
 
268
        rubberBand->raise();
 
269
        rubberBand->show();
 
270
    }
 
271
 
 
272
    inline void hideRubberBand()
 
273
    {
 
274
        if (rubberBand && rubberBand->isVisible())
 
275
            rubberBand->hide();
 
276
        indexToHighlighted = -1;
 
277
    }
 
278
#endif // QT_NO_RUBBERBAND
 
279
};
 
280
 
 
281
#endif // QT_NO_MDIAREA
 
282
 
 
283
QT_END_NAMESPACE
 
284
 
 
285
#endif // QMDIAREA_P_H