1
/****************************************************************************
2
**
3
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
5
** Contact: Nokia Corporation (qt-info@nokia.com)
6
**
7
** This file is part of the test suite of the Qt Toolkit.
8
**
9
** $QT_BEGIN_LICENSE:LGPL$
10
** GNU Lesser General Public License Usage
11
** This file may be used under the terms of the GNU Lesser General Public
12
** License version 2.1 as published by the Free Software Foundation and
13
** appearing in the file LICENSE.LGPL included in the packaging of this
14
** file. Please review the following information to ensure the GNU Lesser
15
** General Public License version 2.1 requirements will be met:
16
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17
**
18
** In addition, as a special exception, Nokia gives you certain additional
19
** rights. These rights are described in the Nokia Qt LGPL Exception
20
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21
**
22
** GNU General Public License Usage
23
** Alternatively, this file may be used under the terms of the GNU General
24
** Public License version 3.0 as published by the Free Software Foundation
25
** and appearing in the file LICENSE.GPL included in the packaging of this
26
** file. Please review the following information to ensure the GNU General
27
** Public License version 3.0 requirements will be met:
28
** http://www.gnu.org/copyleft/gpl.html.
29
**
30
** Other Usage
31
** Alternatively, this file may be used in accordance with the terms and
32
** conditions contained in a signed written agreement between you and Nokia.
33
**
34
**
35
**
36
**
37
**
38
** $QT_END_LICENSE$
39
**
40
****************************************************************************/
41
42
43
#include <QtTest/QtTest>
44
45
#include <q3dockarea.h>
46
#include <q3dockwindow.h>
47
#include <q3mainwindow.h>
48
#include <qapplication.h>
49
#include <qframe.h>
50
#include <qlabel.h>
51
#include <qlayout.h>
52
#include <qmessagebox.h>
53
#include <qpushbutton.h>
54
55
//TESTED_CLASS=
56
//TESTED_FILES=
57
58
class tst_Q3DockWindow : public QObject
59
{
60
    Q_OBJECT
61
public:
62
    tst_Q3DockWindow();
63
    virtual ~tst_Q3DockWindow();
64
65
66
public slots:
67
    void initTestCase();
68
    void cleanupTestCase();
69
private slots:
70
    void parents();
71
    void showChild();
72
};
73
74
QFrame *makeFrame( const char *text, QWidget *parent )
75
{
76
    QFrame* frame = new QFrame(parent);
77
    QVBoxLayout* layout = new QVBoxLayout(frame);
78
    layout->setAutoAdd(true);
79
    new QLabel(text, frame);
80
    frame->setMinimumSize(200, 200);
81
    return frame;
82
}
83
84
Q3DockWindow* makeDock( const char* text, QWidget* parent )
85
{
86
    Q3DockWindow* dock = new Q3DockWindow(Q3DockWindow::InDock, parent, text);
87
    dock->setResizeEnabled(true);
88
    dock->setCloseMode(Q3DockWindow::Always);
89
    dock->setCaption(text);
90
    dock->setWidget(makeFrame(text, dock));
91
    dock->show();
92
93
    return dock;
94
}
95
96
97
tst_Q3DockWindow::tst_Q3DockWindow()
98
99
{
100
}
101
102
tst_Q3DockWindow::~tst_Q3DockWindow()
103
{
104
}
105
106
void tst_Q3DockWindow::initTestCase()
107
{
108
    // create a default mainwindow
109
    // If you run a widget test, this will be replaced in the testcase by the
110
    // widget under test
111
    QWidget *w = new QWidget(0,"mainWidget");
112
    w->setFixedSize( 200, 200 );
113
    qApp->setMainWidget( w );
114
    w->show();
115
}
116
117
void tst_Q3DockWindow::cleanupTestCase()
118
{
119
    delete qApp->mainWidget();
120
}
121
122
void tst_Q3DockWindow::parents()
123
{
124
    // create 5 dock windows, one for each dock area
125
    // and one for the mainwindow, in the end they should
126
    // all except the one with the mainwindow as parent should
127
    // have the same dock() and parent() pointer.
128
    Q3MainWindow mw;
129
    QFrame *central = makeFrame( "Central", &mw );
130
    mw.setCentralWidget( central );
131
132
    Q3DockWindow *topDock = makeDock( "Top", mw.topDock() );
133
    QVERIFY( topDock->area() == topDock->parent() );
134
135
    Q3DockWindow *leftDock = makeDock( "Left", mw.leftDock() );
136
    QVERIFY( leftDock->area() == leftDock->parent() );
137
138
    Q3DockWindow *rightDock= makeDock( "Right", mw.rightDock() );
139
    QVERIFY( rightDock->area() == rightDock->parent() );
140
141
    Q3DockWindow *bottomDock = makeDock( "Bottom", mw.bottomDock() );
142
    QVERIFY( bottomDock->area() == mw.bottomDock() );
143
144
    Q3DockWindow *mainDock = makeDock( "MainWindow as parent", &mw );
145
    QVERIFY( mainDock->parent() == mw.topDock() );
146
}
147
148
149
void tst_Q3DockWindow::showChild()
150
{
151
    // task 26225
152
    // calling show dose not propergate to child widgets if
153
    // main window is already showing
154
155
    Q3MainWindow mw;
156
    mw.show();
157
    Q3DockWindow * dock = new Q3DockWindow(&mw);
158
    QPushButton  * qpb = new QPushButton("hi", dock);
159
    dock->setWidget(qpb);
160
    dock->show();
161
    QVERIFY( mw.isVisible() );
162
    QVERIFY( dock->isVisible() );
163
    QVERIFY( qpb->isVisible() );
164
}
165
166
167
168
QTEST_MAIN(tst_Q3DockWindow)
169
#include "tst_q3dockwindow.moc"