1
/****************************************************************************
3
** Copyright (C) 2016 The Qt Company Ltd.
4
** Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
5
** Contact: https://www.qt.io/licensing/
7
** This file is part of the test suite of the Qt Toolkit.
9
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
10
** Commercial License Usage
11
** Licensees holding valid commercial Qt licenses may use this file in
12
** accordance with the commercial license agreement provided with the
13
** Software or, alternatively, in accordance with the terms contained in
14
** a written agreement between you and The Qt Company. For licensing terms
15
** and conditions see https://www.qt.io/terms-conditions. For further
16
** information use the contact form at https://www.qt.io/contact-us.
18
** GNU General Public License Usage
19
** Alternatively, this file may be used under the terms of the GNU
20
** General Public License version 3 as published by the Free Software
21
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
22
** included in the packaging of this file. Please review the following
23
** information to ensure the GNU General Public License requirements will
24
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
28
****************************************************************************/
32
#include <QStyleOptionFrame>
35
#include <QStyleFactory>
37
class tst_QFrame : public QObject
42
void testInitStyleOption_data();
43
void testInitStyleOption();
44
void testPainting_data();
48
Q_DECLARE_METATYPE(QFrame::Shape)
49
Q_DECLARE_METATYPE(QFrame::Shadow)
51
void tst_QFrame::testDefaults()
54
QCOMPARE(frame.frameStyle(), int(QFrame::NoFrame | QFrame::Plain));
55
frame.setFrameShape(QFrame::Box);
56
QCOMPARE(frame.frameStyle(), int(QFrame::Box | QFrame::Plain));
57
frame.setFrameStyle(QFrame::Box); // no shadow specified!
58
QCOMPARE(frame.frameStyle(), int(QFrame::Box));
61
static void provideFrameData()
63
QTest::addColumn<QString>("basename");
64
QTest::addColumn<int>("lineWidth");
65
QTest::addColumn<int>("midLineWidth");
66
QTest::addColumn<QFrame::Shape>("shape");
67
QTest::addColumn<QFrame::Shadow>("shadow");
69
for (int lineWidth = 0; lineWidth < 3; ++lineWidth) {
70
for (int midLineWidth = 0; midLineWidth < 3; ++midLineWidth) {
71
const QByteArray postFix = '_' + QByteArray::number(lineWidth) + '_'
72
+ QByteArray::number(midLineWidth);
73
QTest::newRow(("box_noshadow" + postFix).constData())
74
<< "box_noshadow" << lineWidth << midLineWidth << QFrame::Box << (QFrame::Shadow)0;
75
QTest::newRow(("box_plain" + postFix).constData())
76
<< "box_plain" << lineWidth << midLineWidth << QFrame::Box << QFrame::Plain;
77
QTest::newRow(("box_raised" + postFix).constData())
78
<< "box_raised" << lineWidth << midLineWidth << QFrame::Box << QFrame::Raised;
79
QTest::newRow(("box_sunken" + postFix).constData())
80
<< "box_sunken" << lineWidth << midLineWidth << QFrame::Box << QFrame::Sunken;
82
QTest::newRow(("winpanel_noshadow" + postFix).constData())
83
<< "winpanel_noshadow" << lineWidth << midLineWidth << QFrame::WinPanel << (QFrame::Shadow)0;
84
QTest::newRow(("winpanel_plain" + postFix).constData())
85
<< "winpanel_plain" << lineWidth << midLineWidth << QFrame::WinPanel << QFrame::Plain;
86
QTest::newRow(("winpanel_raised" + postFix).constData())
87
<< "winpanel_raised" << lineWidth << midLineWidth << QFrame::WinPanel << QFrame::Raised;
88
QTest::newRow(("winpanel_sunken" + postFix).constData())
89
<< "winpanel_sunken" << lineWidth << midLineWidth << QFrame::WinPanel << QFrame::Sunken;
94
class Frame : public QFrame
97
using QFrame::initStyleOption;
100
void tst_QFrame::testInitStyleOption_data()
105
void tst_QFrame::testInitStyleOption()
107
QFETCH(QString, basename);
108
QFETCH(int, lineWidth);
109
QFETCH(int, midLineWidth);
110
QFETCH(QFrame::Shape, shape);
111
QFETCH(QFrame::Shadow, shadow);
114
frame.setFrameStyle(shape | shadow);
115
frame.setLineWidth(lineWidth);
116
frame.setMidLineWidth(midLineWidth);
117
frame.resize(16, 16);
119
QStyleOptionFrame styleOption;
120
frame.initStyleOption(&styleOption);
125
case QFrame::StyledPanel:
128
QCOMPARE(styleOption.lineWidth, lineWidth);
129
QCOMPARE(styleOption.midLineWidth, midLineWidth);
132
case QFrame::NoFrame:
133
case QFrame::WinPanel:
134
QCOMPARE(styleOption.lineWidth, frame.frameWidth());
135
QCOMPARE(styleOption.midLineWidth, 0);
139
QCOMPARE(styleOption.features, QStyleOptionFrame::None);
140
QCOMPARE(styleOption.frameShape, shape);
141
if (shadow == QFrame::Sunken)
142
QVERIFY(styleOption.state & QStyle::State_Sunken);
143
else if (shadow == QFrame::Raised)
144
QVERIFY(styleOption.state & QStyle::State_Raised);
148
Q_GUI_EXPORT QPalette qt_fusionPalette();
151
void tst_QFrame::testPainting_data()
156
void tst_QFrame::testPainting()
158
QFETCH(QString, basename);
159
QFETCH(int, lineWidth);
160
QFETCH(int, midLineWidth);
161
QFETCH(QFrame::Shape, shape);
162
QFETCH(QFrame::Shadow, shadow);
165
frame.setStyle(QStyleFactory::create(QStringLiteral("fusion")));
166
frame.setPalette(qt_fusionPalette());
167
frame.setFrameStyle(shape | shadow);
168
frame.setLineWidth(lineWidth);
169
frame.setMidLineWidth(midLineWidth);
170
frame.resize(16, 16);
172
const QPixmap pixmap = frame.grab();
174
const QString fileName = QLatin1String("images/") + basename + QLatin1Char('_')
175
+ QString::number(lineWidth) + QLatin1Char('_') + QString::number(midLineWidth)
176
+ QLatin1String(".png");
177
const QString referenceFilePath = QFINDTESTDATA(fileName);
178
const QPixmap referencePixmap(referenceFilePath);
179
QVERIFY2(!referencePixmap.isNull(), qPrintable(QStringLiteral("Could not load reference pixmap %1").arg(referenceFilePath)));
180
QCOMPARE(pixmap, referencePixmap);
183
QTEST_MAIN(tst_QFrame)
185
#include "tst_qframe.moc"