0
+ − 1
/****************************************************************************
+ − 2
**
4
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 3
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
0
+ − 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
** No Commercial Usage
+ − 11
** This file contains pre-release code and may not be distributed.
+ − 12
** You may use this file in accordance with the terms and conditions
+ − 13
** contained in the Technology Preview License Agreement accompanying
+ − 14
** this package.
+ − 15
**
+ − 16
** GNU Lesser General Public License Usage
+ − 17
** Alternatively, this file may be used under the terms of the GNU Lesser
+ − 18
** General Public License version 2.1 as published by the Free Software
+ − 19
** Foundation and appearing in the file LICENSE.LGPL included in the
+ − 20
** packaging of this file. Please review the following information to
+ − 21
** ensure the GNU Lesser General Public License version 2.1 requirements
+ − 22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+ − 23
**
+ − 24
** In addition, as a special exception, Nokia gives you certain additional
+ − 25
** rights. These rights are described in the Nokia Qt LGPL Exception
+ − 26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+ − 27
**
+ − 28
** If you have questions regarding the use of this file, please contact
+ − 29
** Nokia at qt-info@nokia.com.
+ − 30
**
+ − 31
**
+ − 32
**
+ − 33
**
+ − 34
**
+ − 35
**
+ − 36
**
+ − 37
**
+ − 38
** $QT_END_LICENSE$
+ − 39
**
+ − 40
****************************************************************************/
+ − 41
+ − 42
+ − 43
#include <QtTest/QtTest>
+ − 44
#include <QtGui>
+ − 45
+ − 46
//TESTED_CLASS=
+ − 47
//TESTED_FILES=
+ − 48
+ − 49
class tst_QBoxLayout : public QObject
+ − 50
{
+ − 51
Q_OBJECT
+ − 52
+ − 53
public:
+ − 54
tst_QBoxLayout();
+ − 55
virtual ~tst_QBoxLayout();
+ − 56
+ − 57
public slots:
+ − 58
void initTestCase();
+ − 59
void cleanupTestCase();
+ − 60
void init();
+ − 61
void cleanup();
+ − 62
+ − 63
private slots:
+ − 64
void insertSpacerItem();
+ − 65
void sizeHint();
+ − 66
void sizeConstraints();
+ − 67
void setGeometry();
+ − 68
void setStyleShouldChangeSpacing();
4
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 69
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 70
void taskQTBUG_7103_minMaxWidthNotRespected();
0
+ − 71
};
+ − 72
+ − 73
class CustomLayoutStyle : public QWindowsStyle
+ − 74
{
+ − 75
Q_OBJECT
+ − 76
public:
+ − 77
CustomLayoutStyle() : QWindowsStyle()
+ − 78
{
+ − 79
hspacing = 5;
+ − 80
vspacing = 10;
+ − 81
}
+ − 82
+ − 83
virtual int pixelMetric(PixelMetric metric, const QStyleOption * option = 0,
+ − 84
const QWidget * widget = 0 ) const;
+ − 85
+ − 86
int hspacing;
+ − 87
int vspacing;
+ − 88
};
+ − 89
+ − 90
int CustomLayoutStyle::pixelMetric(PixelMetric metric, const QStyleOption * option /*= 0*/,
+ − 91
const QWidget * widget /*= 0*/ ) const
+ − 92
{
+ − 93
switch (metric) {
+ − 94
case PM_LayoutLeftMargin:
+ − 95
return 0;
+ − 96
break;
+ − 97
case PM_LayoutTopMargin:
+ − 98
return 3;
+ − 99
break;
+ − 100
case PM_LayoutRightMargin:
+ − 101
return 6;
+ − 102
break;
+ − 103
case PM_LayoutBottomMargin:
+ − 104
return 9;
+ − 105
break;
+ − 106
case PM_LayoutHorizontalSpacing:
+ − 107
return hspacing;
+ − 108
case PM_LayoutVerticalSpacing:
+ − 109
return vspacing;
+ − 110
break;
+ − 111
default:
+ − 112
break;
+ − 113
}
+ − 114
return QWindowsStyle::pixelMetric(metric, option, widget);
+ − 115
}
+ − 116
+ − 117
+ − 118
tst_QBoxLayout::tst_QBoxLayout()
+ − 119
{
+ − 120
}
+ − 121
+ − 122
tst_QBoxLayout::~tst_QBoxLayout()
+ − 123
{
+ − 124
}
+ − 125
+ − 126
void tst_QBoxLayout::initTestCase()
+ − 127
{
+ − 128
}
+ − 129
+ − 130
void tst_QBoxLayout::cleanupTestCase()
+ − 131
{
+ − 132
}
+ − 133
+ − 134
void tst_QBoxLayout::init()
+ − 135
{
+ − 136
}
+ − 137
+ − 138
void tst_QBoxLayout::cleanup()
+ − 139
{
+ − 140
}
+ − 141
+ − 142
void tst_QBoxLayout::insertSpacerItem()
+ − 143
{
+ − 144
QWidget *window = new QWidget;
+ − 145
+ − 146
QSpacerItem *spacer1 = new QSpacerItem(20, 10, QSizePolicy::Expanding, QSizePolicy::Expanding);
+ − 147
QSpacerItem *spacer2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Expanding);
+ − 148
+ − 149
QBoxLayout *layout = new QHBoxLayout;
+ − 150
layout->addWidget(new QLineEdit("Foooooooooooooooooooooooooo"));
+ − 151
layout->addSpacerItem(spacer1);
+ − 152
layout->addWidget(new QLineEdit("Baaaaaaaaaaaaaaaaaaaaaaaaar"));
+ − 153
layout->insertSpacerItem(0, spacer2);
+ − 154
window->setLayout(layout);
+ − 155
+ − 156
QVERIFY(layout->itemAt(0) == spacer2);
+ − 157
QVERIFY(layout->itemAt(2) == spacer1);
+ − 158
+ − 159
window->show();
+ − 160
}
+ − 161
+ − 162
void tst_QBoxLayout::sizeHint()
+ − 163
{
+ − 164
QWidget *window = new QWidget;
+ − 165
QHBoxLayout *lay1 = new QHBoxLayout;
+ − 166
QHBoxLayout *lay2 = new QHBoxLayout;
+ − 167
QLabel *label = new QLabel("widget twooooooooooooooooooooooooooooooooooooooooooooooooooooooo");
+ − 168
lay2->addWidget(label);
+ − 169
lay1->addLayout(lay2);
+ − 170
window->setLayout(lay1);
+ − 171
window->show();
+ − 172
label->setText("foooooooo baaaaaaar");
+ − 173
QSize sh = lay1->sizeHint();
+ − 174
QApplication::processEvents();
+ − 175
// Note that this is not strictly required behaviour - actually
+ − 176
// the preferred behaviour would be that sizeHint returns
+ − 177
// the same value regardless of what's lying in the event queue.
+ − 178
// (i.e. we would check for equality here instead)
+ − 179
QVERIFY(lay1->sizeHint() != sh);
+ − 180
}
+ − 181
+ − 182
void tst_QBoxLayout::sizeConstraints()
+ − 183
{
+ − 184
QWidget *window = new QWidget;
+ − 185
QHBoxLayout *lay = new QHBoxLayout;
+ − 186
lay->addWidget(new QLabel("foooooooooooooooooooooooooooooooooooo"));
+ − 187
lay->addWidget(new QLabel("baaaaaaaaaaaaaaaaaaaaaaaaaaaaaar"));
+ − 188
lay->setSizeConstraint(QLayout::SetFixedSize);
+ − 189
window->setLayout(lay);
+ − 190
window->show();
+ − 191
QApplication::processEvents();
+ − 192
QSize sh = window->sizeHint();
+ − 193
lay->takeAt(1);
+ − 194
QVERIFY(sh.width() >= window->sizeHint().width() &&
+ − 195
sh.height() >= window->sizeHint().height());
+ − 196
+ − 197
}
+ − 198
+ − 199
void tst_QBoxLayout::setGeometry()
+ − 200
{
+ − 201
QWidget w;
+ − 202
QVBoxLayout *lay = new QVBoxLayout;
+ − 203
lay->setMargin(0);
+ − 204
lay->setSpacing(0);
+ − 205
QHBoxLayout *lay2 = new QHBoxLayout;
+ − 206
QDial *dial = new QDial;
+ − 207
lay2->addWidget(dial);
+ − 208
lay2->setAlignment(Qt::AlignTop);
+ − 209
lay2->setAlignment(Qt::AlignRight);
+ − 210
lay->addLayout(lay2);
+ − 211
w.setLayout(lay);
+ − 212
w.show();
+ − 213
+ − 214
QRect newGeom(0, 0, 70, 70);
+ − 215
lay2->setGeometry(newGeom);
+ − 216
QVERIFY2(newGeom.contains(dial->geometry()), "dial->geometry() should be smaller and within newGeom");
+ − 217
}
+ − 218
+ − 219
void tst_QBoxLayout::setStyleShouldChangeSpacing()
+ − 220
{
+ − 221
+ − 222
QWidget *window = new QWidget;
+ − 223
QHBoxLayout *hbox = new QHBoxLayout(window);
+ − 224
QPushButton *pb1 = new QPushButton(tr("The spacing between this"));
+ − 225
QPushButton *pb2 = new QPushButton(tr("and this button should depend on the style of the parent widget"));;
+ − 226
pb1->setAttribute(Qt::WA_LayoutUsesWidgetRect);
+ − 227
pb2->setAttribute(Qt::WA_LayoutUsesWidgetRect);
+ − 228
hbox->addWidget(pb1);
+ − 229
hbox->addWidget(pb2);
+ − 230
CustomLayoutStyle *style1 = new CustomLayoutStyle;
+ − 231
style1->hspacing = 6;
+ − 232
window->setStyle(style1);
+ − 233
window->show();
+ − 234
+ − 235
QTest::qWait(100);
+ − 236
int spacing = pb2->geometry().left() - pb1->geometry().right() - 1;
+ − 237
QCOMPARE(spacing, 6);
+ − 238
+ − 239
CustomLayoutStyle *style2 = new CustomLayoutStyle();
+ − 240
style2->hspacing = 10;
+ − 241
window->setStyle(style2);
+ − 242
QTest::qWait(100);
+ − 243
spacing = pb2->geometry().left() - pb1->geometry().right() - 1;
+ − 244
QCOMPARE(spacing, 10);
+ − 245
+ − 246
delete window;
+ − 247
delete style1;
+ − 248
delete style2;
+ − 249
}
+ − 250
4
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 251
void tst_QBoxLayout::taskQTBUG_7103_minMaxWidthNotRespected()
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 252
{
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 253
QLabel *label = new QLabel("Qt uses standard C++, but makes extensive use of the C pre-processor to enrich the language. Qt can also be used in several other programming languages via language bindings. It runs on all major platforms, and has extensive internationalization support. Non-GUI features include SQL database access, XML parsing, thread management, network support and a unified cross-platform API for file handling.");
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 254
label->setWordWrap(true);
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 255
label->setFixedWidth(200);
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 256
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 257
QVBoxLayout *layout = new QVBoxLayout;
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 258
layout->addWidget(label);
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 259
layout->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Fixed, QSizePolicy::Expanding));
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 260
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 261
QWidget widget;
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 262
widget.setLayout(layout);
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 263
widget.show();
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 264
QTest::qWaitForWindowShown(&widget);
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 265
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 266
int height = label->height();
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 267
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 268
QRect g = widget.geometry();
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 269
g.setWidth(600);
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 270
widget.setGeometry(g);
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 271
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 272
QTest::qWait(50);
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 273
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 274
QCOMPARE(label->height(), height);
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 275
}
0
+ − 276
+ − 277
QTEST_MAIN(tst_QBoxLayout)
+ − 278
#include "tst_qboxlayout.moc"