/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used 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. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#if defined(QT3_SUPPORT)
#include <q3hbox.h>
#include <q3textedit.h>
#endif
#include <qboxlayout.h>
#include <qapplication.h>
#include <qbitmap.h>
#include <qdebug.h>
#include <qeventloop.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qlistview.h>
#include <qmessagebox.h>
#include <qpainter.h>
#include <qpoint.h>
#include <qpushbutton.h>
#include <qstyle.h>
#include <qwidget.h>
#include <qwindowsstyle.h>
#include <qinputcontext.h>
#include <qdesktopwidget.h>
#include <private/qwidget_p.h>
#include <private/qapplication_p.h>
#include <qcalendarwidget.h>
#include <qmainwindow.h>
#include <qdockwidget.h>
#include <qtoolbar.h>
#include <QtGui/qpaintengine.h>
#include <private/qbackingstore_p.h>
#include <qmenubar.h>
#include <qtableview.h>
#include <QtGui/QGraphicsView>
#include <QtGui/QGraphicsProxyWidget>
#include "../../shared/util.h"
#ifdef Q_WS_S60
#include <avkon.hrh> // EEikStatusPaneUidTitle
#include <akntitle.h> // CAknTitlePane
#include <akncontext.h> // CAknContextPane
#endif
#ifdef Q_OS_SYMBIAN
#include <eikspane.h> // CEikStatusPane
#include <eikbtgpc.h> // CEikButtonGroupContainer
#include <eikenv.h> // CEikonEnv
#include <eikaufty.h> // MEikAppUiFactory
#include <eikmenub.h> // CEikMenuBar
#endif
#ifdef Q_WS_QWS
# include <qscreen_qws.h>
#endif
// I *MUST* have QtTest afterwards or this test won't work with newer headers
#if defined(Q_WS_MAC)
# include <private/qt_mac_p.h>
#undef verify
#include "tst_qwidget_mac_helpers.h" // Abstract the ObjC stuff out so not everyone must run an ObjC++ compile.
#endif
#include <QtTest/QtTest>
#if defined(Q_WS_WIN)
# include <qt_windows.h>
# if !defined(Q_OS_WINCE)
#define Q_CHECK_PAINTEVENTS \
if (::SwitchDesktop(::GetThreadDesktop(::GetCurrentThreadId())) == 0) \
QSKIP("desktop is not visible, this test would fail", SkipSingle);
# else
# define Q_CHECK_PAINTEVENTS
# endif
#elif defined(Q_WS_X11)
# include <private/qt_x11_p.h>
# include <qx11info_x11.h>
#elif defined(Q_WS_QWS)
# include <qwindowsystem_qws.h>
#endif
#if !defined(Q_WS_WIN)
#define Q_CHECK_PAINTEVENTS
#endif
#if defined(Q_OS_WINCE_WM)
#include <qguifunctions_wince.h>
// taken from qguifunctions_wce.cpp
#define SPI_GETPLATFORMTYPE 257
bool qt_wince_is_platform(const QString &platformString) {
wchar_t tszPlatform[64];
if (SystemParametersInfo(SPI_GETPLATFORMTYPE,
sizeof(tszPlatform)/sizeof(*tszPlatform),tszPlatform,0))
if (0 == _tcsicmp(reinterpret_cast<const wchar_t *> (platformString.utf16()), tszPlatform))
return true;
return false;
}
bool qt_wince_is_smartphone() {
return qt_wince_is_platform(QString::fromLatin1("Smartphone"));
}
#endif
#ifdef Q_WS_MAC
#include <Security/AuthSession.h>
bool macHasAccessToWindowsServer()
{
SecuritySessionId mySession;
SessionAttributeBits sessionInfo;
SessionGetInfo(callerSecuritySession, &mySession, &sessionInfo);
return (sessionInfo & sessionHasGraphicAccess);
}
#endif
#if defined(Bool)
#undef Bool
#endif
//TESTED_CLASS=
//TESTED_FILES=
class tst_QWidget : public QObject
{
Q_OBJECT
public:
tst_QWidget();
virtual ~tst_QWidget();
public slots:
void initTestCase();
void cleanupTestCase();
void init();
void cleanup();
private slots:
void getSetCheck();
void fontPropagation();
void fontPropagation2();
void palettePropagation();
void palettePropagation2();
void enabledPropagation();
void acceptDropsPropagation();
void isEnabledTo();
void visible();
void visible_setWindowOpacity();
void isVisibleTo();
void isHidden();
void fonts();
void mapToGlobal();
void mapFromAndTo_data();
void mapFromAndTo();
void checkFocus();
void focusChainOnHide();
void focusChainOnReparent();
void setTabOrder();
void activation();
void reparent();
void windowState();
void showMaximized();
void showFullScreen();
void showMinimized();
void showMinimizedKeepsFocus();
void icon();
void hideWhenFocusWidgetIsChild();
void normalGeometry();
void setGeometry();
void windowOpacity();
void raise();
void lower();
void stackUnder();
void testContentsPropagation();
void saveRestoreGeometry();
void restoreVersion1Geometry_data();
void restoreVersion1Geometry();
void windowTitle();
void windowModified();
void windowIconText();
void widgetAt();
#ifdef Q_WS_MAC
void retainHIView();
void sheetOpacity();
void setMask();
#endif
void optimizedResizeMove();
void optimizedResize_topLevel();
void resizeEvent();
void task110173();
void testDeletionInEventHandlers();
void childDeletesItsSibling();
void setMinimumSize();
void setMaximumSize();
void setFixedSize();
void ensureCreated();
void winIdChangeEvent();
#ifdef Q_OS_SYMBIAN
void reparentCausesChildWinIdChange();
#else
void persistentWinId();
#endif
void showNativeChild();
void qobject_castInDestroyedSlot();
void showHideEvent_data();
void showHideEvent();
void lostUpdatesOnHide();
void update();
void isOpaque();
#ifndef Q_WS_MAC
void scroll();
#endif
// tests QWidget::setGeometry() on windows only
void setWindowGeometry_data();
void setWindowGeometry();
// tests QWidget::move() and resize() on windows only
void windowMoveResize_data();
void windowMoveResize();
void moveChild_data();
void moveChild();
void showAndMoveChild();
void subtractOpaqueSiblings();
#ifdef Q_WS_WIN
void getDC();
#ifndef Q_OS_WINCE
void setGeometry_win();
#endif
#endif
void setLocale();
void deleteStyle();
void multipleToplevelFocusCheck();
void setFocus();
void setCursor();
void setToolTip();
void testWindowIconChangeEventPropagation();
#ifdef Q_WS_X11
void minAndMaxSizeWithX11BypassWindowManagerHint();
void showHideShow();
void clean_qt_x11_enforce_cursor();
#endif
void compatibilityChildInsertedEvents();
void render();
void renderInvisible();
void renderWithPainter();
void render_task188133();
void render_task211796();
void render_task217815();
void render_windowOpacity();
void render_systemClip();
void render_systemClip2_data();
void render_systemClip2();
void render_systemClip3_data();
void render_systemClip3();
void render_task252837();
void render_worldTransform();
void setContentsMargins();
void moveWindowInShowEvent_data();
void moveWindowInShowEvent();
void repaintWhenChildDeleted();
void hideOpaqueChildWhileHidden();
void updateWhileMinimized();
#if defined(Q_WS_WIN) || defined(Q_WS_X11)
void alienWidgets();
#endif
void adjustSize();
void adjustSize_data();
void updateGeometry();
void updateGeometry_data();
void sendUpdateRequestImmediately();
void painterRedirection();
void doubleRepaint();
#ifndef Q_WS_MAC
void resizeInPaintEvent();
void opaqueChildren();
#endif
void setMaskInResizeEvent();
void moveInResizeEvent();
#if defined(Q_WS_WIN) || defined(Q_WS_X11)
// We don't support immediate repaint right after show on
// other platforms. Must be compatible with Qt 4.3.
void immediateRepaintAfterShow();
void immediateRepaintAfterInvalidateBuffer();
#endif
void effectiveWinId();
void effectiveWinId2();
void customDpi();
void customDpiProperty();
void quitOnCloseAttribute();
void moveRect();
#if defined (Q_WS_WIN)
void gdiPainting();
void paintOnScreenPossible();
#endif
void reparentStaticWidget();
void QTBUG6883_reparentStaticWidget2();
#ifdef Q_WS_QWS
void updateOutsideSurfaceClip();
#endif
void translucentWidget();
void setClearAndResizeMask();
void maskedUpdate();
#if defined(Q_WS_WIN) || defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_WS_QPA)
void syntheticEnterLeave();
void taskQTBUG_4055_sendSyntheticEnterLeave();
#endif
void windowFlags();
void initialPosForDontShowOnScreenWidgets();
#ifdef Q_WS_X11
void paintOutsidePaintEvent();
#endif
void updateOnDestroyedSignal();
void toplevelLineEditFocus();
void inputFocus_task257832();
void focusWidget_task254563();
void rectOutsideCoordinatesLimit_task144779();
void setGraphicsEffect();
void destroyBackingStore();
void destroyBackingStoreWhenHidden();
void activateWindow();
void openModal_taskQTBUG_5804();
#ifdef Q_OS_SYMBIAN
void cbaVisibility();
void fullScreenWindowModeTransitions();
void maximizedWindowModeTransitions();
void minimizedWindowModeTransitions();
void normalWindowModeTransitions();
void focusSwitchClosesPopupMenu();
#endif
void focusProxyAndInputMethods();
void scrollWithoutBackingStore();
void taskQTBUG_7532_tabOrderWithFocusProxy();
void movedAndResizedAttributes();
void childAt();
#ifdef Q_WS_MAC
void childAt_unifiedToolBar();
void taskQTBUG_17333_ResizeInfiniteRecursion();
#ifdef QT_MAC_USE_COCOA
void taskQTBUG_11373();
#endif // QT_MAC_USE_COCOA
#endif
void nativeChildFocus();
private:
bool ensureScreenSize(int width, int height);
QWidget *testWidget;
};
bool tst_QWidget::ensureScreenSize(int width, int height)
{
QSize available;
#ifdef Q_WS_QWS
available = QDesktopWidget().availableGeometry().size();
if (available.width() < width || available.height() < height) {
QScreen *screen = QScreen::instance();
if (!screen)
return false;
screen->setMode(width, height, screen->depth());
}
#endif // Q_WS_QWS
available = QDesktopWidget().availableGeometry().size();
return (available.width() >= width && available.height() >= height);
}
class MyInputContext : public QInputContext
{
public:
MyInputContext() : QInputContext() {}
QString identifierName() { return QString("NoName"); }
QString language() { return QString("NoLanguage"); }
void reset() {}
bool isComposing() const { return false; }
};
// Testing get/set functions
void tst_QWidget::getSetCheck()
{
QWidget obj1;
QWidget child1(&obj1);
// QStyle * QWidget::style()
// void QWidget::setStyle(QStyle *)
QWindowsStyle *var1 = new QWindowsStyle;
obj1.setStyle(var1);
QCOMPARE(static_cast<QStyle *>(var1), obj1.style());
obj1.setStyle((QStyle *)0);
QVERIFY(var1 != obj1.style());
QVERIFY(0 != obj1.style()); // style can never be 0 for a widget
// int QWidget::minimumWidth()
// void QWidget::setMinimumWidth(int)
obj1.setMinimumWidth(0);
QCOMPARE(obj1.minimumWidth(), 0);
obj1.setMinimumWidth(INT_MIN);
QCOMPARE(obj1.minimumWidth(), 0); // A widgets width can never be less than 0
obj1.setMinimumWidth(INT_MAX);
#ifndef Q_WS_QWS //QWS doesn't allow toplevels to be bigger than the screen
QCOMPARE(obj1.minimumWidth(), QWIDGETSIZE_MAX); // The largest minimum size should only be as big as the maximium
#endif
child1.setMinimumWidth(0);
QCOMPARE(child1.minimumWidth(), 0);
child1.setMinimumWidth(INT_MIN);
QCOMPARE(child1.minimumWidth(), 0); // A widgets width can never be less than 0
child1.setMinimumWidth(INT_MAX);
QCOMPARE(child1.minimumWidth(), QWIDGETSIZE_MAX); // The largest minimum size should only be as big as the maximium
// int QWidget::minimumHeight()
// void QWidget::setMinimumHeight(int)
obj1.setMinimumHeight(0);
QCOMPARE(obj1.minimumHeight(), 0);
obj1.setMinimumHeight(INT_MIN);
QCOMPARE(obj1.minimumHeight(), 0); // A widgets height can never be less than 0
obj1.setMinimumHeight(INT_MAX);
#ifndef Q_WS_QWS //QWS doesn't allow toplevels to be bigger than the screen
QCOMPARE(obj1.minimumHeight(), QWIDGETSIZE_MAX); // The largest minimum size should only be as big as the maximium
#endif
child1.setMinimumHeight(0);
QCOMPARE(child1.minimumHeight(), 0);
child1.setMinimumHeight(INT_MIN);
QCOMPARE(child1.minimumHeight(), 0); // A widgets height can never be less than 0
child1.setMinimumHeight(INT_MAX);
QCOMPARE(child1.minimumHeight(), QWIDGETSIZE_MAX); // The largest minimum size should only be as big as the maximium
// int QWidget::maximumWidth()
// void QWidget::setMaximumWidth(int)
obj1.setMaximumWidth(0);
QCOMPARE(obj1.maximumWidth(), 0);
obj1.setMaximumWidth(INT_MIN);
QCOMPARE(obj1.maximumWidth(), 0); // A widgets width can never be less than 0
obj1.setMaximumWidth(INT_MAX);
QCOMPARE(obj1.maximumWidth(), QWIDGETSIZE_MAX); // QWIDGETSIZE_MAX is the abs max, not INT_MAX
// int QWidget::maximumHeight()
// void QWidget::setMaximumHeight(int)
obj1.setMaximumHeight(0);
QCOMPARE(obj1.maximumHeight(), 0);
obj1.setMaximumHeight(INT_MIN);
QCOMPARE(obj1.maximumHeight(), 0); // A widgets height can never be less than 0
obj1.setMaximumHeight(INT_MAX);
QCOMPARE(obj1.maximumHeight(), QWIDGETSIZE_MAX); // QWIDGETSIZE_MAX is the abs max, not INT_MAX
// back to normal
obj1.setMinimumWidth(0);
obj1.setMinimumHeight(0);
obj1.setMaximumWidth(QWIDGETSIZE_MAX);
obj1.setMaximumHeight(QWIDGETSIZE_MAX);
// const QPalette & QWidget::palette()
// void QWidget::setPalette(const QPalette &)
QPalette var6;
obj1.setPalette(var6);
QCOMPARE(var6, obj1.palette());
obj1.setPalette(QPalette());
QCOMPARE(QPalette(), obj1.palette());
// const QFont & QWidget::font()
// void QWidget::setFont(const QFont &)
QFont var7;
obj1.setFont(var7);
QCOMPARE(var7, obj1.font());
obj1.setFont(QFont());
QCOMPARE(QFont(), obj1.font());
// qreal QWidget::windowOpacity()
// void QWidget::setWindowOpacity(qreal)
obj1.setWindowOpacity(0.0);
QCOMPARE(0.0, obj1.windowOpacity());
obj1.setWindowOpacity(1.1f);
QCOMPARE(1.0, obj1.windowOpacity()); // 1.0 is the fullest opacity possible
// QWidget * QWidget::focusProxy()
// void QWidget::setFocusProxy(QWidget *)
QWidget *var9 = new QWidget();
obj1.setFocusProxy(var9);
QCOMPARE(var9, obj1.focusProxy());
obj1.setFocusProxy((QWidget *)0);
QCOMPARE((QWidget *)0, obj1.focusProxy());
delete var9;
// const QRect & QWidget::geometry()
// void QWidget::setGeometry(const QRect &)
qApp->processEvents();
QRect var10(10, 10, 100, 100);
obj1.setGeometry(var10);
qApp->processEvents();
qDebug() << obj1.geometry();
QCOMPARE(var10, obj1.geometry());
obj1.setGeometry(QRect(0,0,0,0));
qDebug() << obj1.geometry();
QCOMPARE(QRect(0,0,0,0), obj1.geometry());
// QLayout * QWidget::layout()
// void QWidget::setLayout(QLayout *)
QBoxLayout *var11 = new QBoxLayout(QBoxLayout::LeftToRight);
obj1.setLayout(var11);
QCOMPARE(static_cast<QLayout *>(var11), obj1.layout());
obj1.setLayout((QLayout *)0);
QCOMPARE(static_cast<QLayout *>(var11), obj1.layout()); // You cannot set a 0-pointer layout, that keeps the current
delete var11; // This will remove the layout from the widget
QCOMPARE((QLayout *)0, obj1.layout());
// bool QWidget::acceptDrops()
// void QWidget::setAcceptDrops(bool)
obj1.setAcceptDrops(false);
QCOMPARE(false, obj1.acceptDrops());
obj1.setAcceptDrops(true);
QCOMPARE(true, obj1.acceptDrops());
// QInputContext * QWidget::inputContext()
// void QWidget::setInputContext(QInputContext *)
MyInputContext *var13 = new MyInputContext;
obj1.setInputContext(var13);
QCOMPARE((QInputContext *)0, obj1.inputContext()); // The widget by default doesn't have the WA_InputMethodEnabled attribute
obj1.setAttribute(Qt::WA_InputMethodEnabled);
obj1.setInputContext(var13);
QCOMPARE(static_cast<QInputContext *>(var13), obj1.inputContext());
// QWidget takes ownership, so check parent
QCOMPARE(var13->parent(), static_cast<QObject *>(&obj1));
// Check self assignment
obj1.setInputContext(obj1.inputContext());
QCOMPARE(static_cast<QInputContext *>(var13), obj1.inputContext());
obj1.setInputContext((QInputContext *)0);
QCOMPARE(qApp->inputContext(), obj1.inputContext());
QVERIFY(qApp->inputContext() != var13);
// bool QWidget::autoFillBackground()
// void QWidget::setAutoFillBackground(bool)
obj1.setAutoFillBackground(false);
QCOMPARE(false, obj1.autoFillBackground());
obj1.setAutoFillBackground(true);
QCOMPARE(true, obj1.autoFillBackground());
delete var1;
#if defined (Q_WS_WIN) && !defined(Q_OS_WINCE)
obj1.setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint);
HWND handle = obj1.winId();
long flags = GetWindowLong(handle, GWL_STYLE);
QVERIFY(flags & WS_POPUP);
#endif
}
tst_QWidget::tst_QWidget()
{
QFont font;
font.setBold(true);
font.setPointSize(42);
qApp->setFont(font, "QPropagationTestWidget");
QPalette palette;
palette.setColor(QPalette::ToolTipBase, QColor(12, 13, 14));
palette.setColor(QPalette::Text, QColor(21, 22, 23));
qApp->setPalette(palette, "QPropagationTestWidget");
testWidget = 0;
}
tst_QWidget::~tst_QWidget()
{
}
class BezierViewer : public QWidget {
public:
BezierViewer( QWidget* parent=0, const char* name=0 );
void paintEvent( QPaintEvent* );
void setPoints( const QPolygonF& poly );
private:
QPolygonF points;
};
void tst_QWidget::initTestCase()
{
#ifdef Q_OS_WINCE //disable magic for WindowsCE
qApp->setAutoMaximizeThreshold(-1);
#endif
// Create the test class
testWidget = new BezierViewer( 0, "testObject");
testWidget->resize(200,200);
#ifdef QT3_SUPPORT
qApp->setMainWidget(testWidget);
#endif
testWidget->show();
QTest::qWaitForWindowShown(testWidget);
QTest::qWait(50);
}
void tst_QWidget::cleanupTestCase()
{
delete testWidget;
testWidget = 0;
}
void tst_QWidget::init()
{
// TODO: Add initialization code here.
// This will be executed immediately before each test is run.
testWidget->setFont(QFont());
testWidget->setPalette(QPalette());
}
void tst_QWidget::cleanup()
{
}
// Helper class...
BezierViewer::BezierViewer( QWidget* parent, const char* name )
: QWidget( parent )
{
setObjectName(name);
QPalette pal;
pal.setColor(backgroundRole(), Qt::white);
setPalette(pal);
}
void BezierViewer::setPoints( const QPolygonF& a )
{
points = a;
}
#include "private/qbezier_p.h"
void BezierViewer::paintEvent( QPaintEvent* )
{
if ( points.size() != 4 ) {
#if defined(QT_CHECK_RANGE)
qWarning( "QPolygon::bezier: The array must have 4 control points" );
#endif
return;
}
/* Calculate Bezier curve */
QPolygonF bezier = QBezier::fromPoints(points.at(0),points.at(1),points.at(2),points.at(3)).toPolygon();
QPainter painter( this );
/* Calculate scale to fit in window */
QRectF br = bezier.boundingRect() | points.boundingRect();
QRectF pr = rect();
int scl = qMax( qMin(pr.width()/br.width(), pr.height()/br.height()), qreal(1.) );
int border = scl-1;
/* Scale Bezier curve vertices */
for ( QPolygonF::Iterator it = bezier.begin(); it != bezier.end(); ++it ) {
it->setX( (it->x()-br.x()) * scl + border );
it->setY( (it->y()-br.y()) * scl + border );
}
/* Draw grid */
painter.setPen( Qt::lightGray );
int i;
for ( i = border; i <= pr.width(); i += scl ) {
painter.drawLine( i, 0, i, pr.height() );
}
for ( int j = border; j <= pr.height(); j += scl ) {
painter.drawLine( 0, j, pr.width(), j );
}
/* Write number of vertices */
painter.setPen( Qt::red );
painter.setFont( QFont("Helvetica", 14, QFont::DemiBold, TRUE ) );
QString caption;
caption.setNum( bezier.size() );
caption += QString::fromLatin1( " vertices" );
painter.drawText( 10, pr.height()-10, caption );
/* Draw Bezier curve */
painter.setPen( Qt::black );
painter.drawPolyline( bezier );
/* Scale and draw control points */
painter.setPen( Qt::darkGreen );
for ( QPolygonF::Iterator p1 = points.begin(); p1 != points.end(); ++p1 ) {
int x = (p1->x()-br.x()) * scl + border;
int y = (p1->y()-br.y()) * scl + border;
painter.drawLine( x-4, y-4, x+4, y+4 );
painter.drawLine( x+4, y-4, x-4, y+4 );
}
/* Draw vertices */
painter.setPen( Qt::red );
painter.setBrush( Qt::red );
for ( QPolygonF::Iterator p2 = bezier.begin(); p2 != bezier.end(); ++p2 )
painter.drawEllipse( p2->x()-1, p2->y()-1, 3, 3 );
}
void tst_QWidget::fontPropagation()
{
QFont font = testWidget->font();
QWidget* childWidget = new QWidget( testWidget );
childWidget->show();
QCOMPARE( font, childWidget->font() );
font.setBold( TRUE );
testWidget->setFont( font );
QCOMPARE( font, testWidget->font() );
QCOMPARE( font, childWidget->font() );
QFont newFont = font;
newFont.setItalic( TRUE );
childWidget->setFont( newFont );
QWidget* grandChildWidget = new QWidget( childWidget );
QCOMPARE( font, testWidget->font() );
QCOMPARE( newFont, grandChildWidget->font() );
font.setUnderline( TRUE );
testWidget->setFont( font );
// the child and grand child should now have merged bold and
// underline
newFont.setUnderline( TRUE );
QCOMPARE( newFont, childWidget->font() );
QCOMPARE( newFont, grandChildWidget->font() );
// make sure font propagation continues working after reparenting
font = testWidget->font();
font.setPointSize(font.pointSize() + 2);
testWidget->setFont(font);
QWidget *one = new QWidget(testWidget);
QWidget *two = new QWidget(one);
QWidget *three = new QWidget(two);
QWidget *four = new QWidget(two);
four->setParent(three);
four->move(QPoint(0,0));
font.setPointSize(font.pointSize() + 2);
testWidget->setFont(font);
QCOMPARE(testWidget->font(), one->font());
QCOMPARE(one->font(), two->font());
QCOMPARE(two->font(), three->font());
QCOMPARE(three->font(), four->font());
QVERIFY(testWidget->testAttribute(Qt::WA_SetFont));
QVERIFY(! one->testAttribute(Qt::WA_SetFont));
QVERIFY(! two->testAttribute(Qt::WA_SetFont));
QVERIFY(! three->testAttribute(Qt::WA_SetFont));
QVERIFY(! four->testAttribute(Qt::WA_SetFont));
font.setPointSize(font.pointSize() + 2);
one->setFont(font);
QCOMPARE(one->font(), two->font());
QCOMPARE(two->font(), three->font());
QCOMPARE(three->font(), four->font());
QVERIFY(one->testAttribute(Qt::WA_SetFont));
QVERIFY(! two->testAttribute(Qt::WA_SetFont));
QVERIFY(! three->testAttribute(Qt::WA_SetFont));
QVERIFY(! four->testAttribute(Qt::WA_SetFont));
font.setPointSize(font.pointSize() + 2);
two->setFont(font);
QCOMPARE(two->font(), three->font());
QCOMPARE(three->font(), four->font());
QVERIFY(two->testAttribute(Qt::WA_SetFont));
QVERIFY(! three->testAttribute(Qt::WA_SetFont));
QVERIFY(! four->testAttribute(Qt::WA_SetFont));
font.setPointSize(font.pointSize() + 2);
three->setFont(font);
QCOMPARE(three->font(), four->font());
QVERIFY(three->testAttribute(Qt::WA_SetFont));
QVERIFY(! four->testAttribute(Qt::WA_SetFont));
font.setPointSize(font.pointSize() + 2);
four->setFont(font);
QVERIFY(four->testAttribute(Qt::WA_SetFont));
}
class QPropagationTestWidget : public QWidget
{
Q_OBJECT
public:
QPropagationTestWidget(QWidget *parent = 0)
: QWidget(parent)
{ }
};
void tst_QWidget::fontPropagation2()
{
// ! Note, the code below is executed in tst_QWidget's constructor.
// QFont font;
// font.setBold(true);
// font.setPointSize(42);
// qApp->setFont(font, "QPropagationTestWidget");
QWidget *root = new QWidget;
QWidget *child0 = new QWidget(root);
QWidget *child1 = new QWidget(child0);
QWidget *child2 = new QPropagationTestWidget(child1);
QWidget *child3 = new QWidget(child2);
QWidget *child4 = new QWidget(child3);
QWidget *child5 = new QWidget(child4);
root->show();
// Check that only the application fonts apply.
QCOMPARE(root->font(), QApplication::font());
QCOMPARE(child0->font(), QApplication::font());
QCOMPARE(child1->font(), QApplication::font());
QCOMPARE(child2->font().pointSize(), 42);
QVERIFY(child2->font().bold());
QCOMPARE(child3->font().pointSize(), 42);
QVERIFY(child3->font().bold());
QCOMPARE(child4->font().pointSize(), 42);
QVERIFY(child4->font().bold());
QCOMPARE(child5->font().pointSize(), 42);
QVERIFY(child5->font().bold());
// Set child0's font size to 15, and remove bold on child4.
QFont font;
font.setPointSize(15);
child0->setFont(font);
QFont unboldFont;
unboldFont.setBold(false);
child4->setFont(unboldFont);
// Check that the above settings propagate correctly.
QCOMPARE(root->font(), QApplication::font());
QCOMPARE(child0->font().pointSize(), 15);
QVERIFY(!child0->font().bold());
QCOMPARE(child1->font().pointSize(), 15);
QVERIFY(!child1->font().bold());
QCOMPARE(child2->font().pointSize(), 15);
QVERIFY(child2->font().bold());
QCOMPARE(child3->font().pointSize(), 15);
QVERIFY(child3->font().bold());
QCOMPARE(child4->font().pointSize(), 15);
QVERIFY(!child4->font().bold());
QCOMPARE(child5->font().pointSize(), 15);
QVERIFY(!child5->font().bold());
// Replace the app font for child2. Italic should propagate
// but the size should still be ignored. The previous bold
// setting is gone.
QFont italicSizeFont;
italicSizeFont.setItalic(true);
italicSizeFont.setPointSize(33);
qApp->setFont(italicSizeFont, "QPropagationTestWidget");
// Check that this propagates correctly.
QCOMPARE(root->font(), QApplication::font());
QCOMPARE(child0->font().pointSize(), 15);
QVERIFY(!child0->font().bold());
QVERIFY(!child0->font().italic());
QCOMPARE(child1->font().pointSize(), 15);
QVERIFY(!child1->font().bold());
QVERIFY(!child1->font().italic());
QCOMPARE(child2->font().pointSize(), 15);
QVERIFY(!child2->font().bold());
QVERIFY(child2->font().italic());
QCOMPARE(child3->font().pointSize(), 15);
QVERIFY(!child3->font().bold());
QVERIFY(child3->font().italic());
QCOMPARE(child4->font().pointSize(), 15);
QVERIFY(!child4->font().bold());
QVERIFY(child4->font().italic());
QCOMPARE(child5->font().pointSize(), 15);
QVERIFY(!child5->font().bold());
QVERIFY(child5->font().italic());
}
void tst_QWidget::palettePropagation()
{
QPalette palette = testWidget->palette();
QWidget* childWidget = new QWidget( testWidget );
childWidget->show();
QCOMPARE( palette, childWidget->palette() );
palette.setColor( QPalette::Base, Qt::red );
testWidget->setPalette( palette );
QCOMPARE( palette, testWidget->palette() );
QCOMPARE( palette, childWidget->palette() );
QPalette newPalette = palette;
newPalette.setColor( QPalette::Highlight, Qt::green );
childWidget->setPalette( newPalette );
QWidget* grandChildWidget = new QWidget( childWidget );
QCOMPARE( palette, testWidget->palette() );
QCOMPARE( newPalette, grandChildWidget->palette() );
palette.setColor( QPalette::Text, Qt::blue );
testWidget->setPalette( palette );
// the child and grand child should now have merged green
// highlight and blue text
newPalette.setColor( QPalette::Text, Qt::blue);
QCOMPARE( newPalette, childWidget->palette() );
QCOMPARE( newPalette, grandChildWidget->palette() );
}
void tst_QWidget::palettePropagation2()
{
// ! Note, the code below is executed in tst_QWidget's constructor.
// QPalette palette;
// font.setColor(QPalette::ToolTipBase, QColor(12, 13, 14));
// font.setColor(QPalette::Text, QColor(21, 22, 23));
// qApp->setPalette(palette, "QPropagationTestWidget");
QWidget *root = new QWidget;
QWidget *child0 = new QWidget(root);
QWidget *child1 = new QWidget(child0);
QWidget *child2 = new QPropagationTestWidget(child1);
QWidget *child3 = new QWidget(child2);
QWidget *child4 = new QWidget(child3);
QWidget *child5 = new QWidget(child4);
root->show();
QTest::qWait(100);
// These colors are unlikely to be imposed on the default palette of
// QWidget ;-).
QColor sysPalText(21, 22, 23);
QColor sysPalToolTipBase(12, 13, 14);
QColor overridePalText(42, 43, 44);
QColor overridePalToolTipBase(45, 46, 47);
QColor sysPalButton(99, 98, 97);
// Check that only the application fonts apply.
QPalette appPal = QApplication::palette();
QCOMPARE(root->palette(), appPal);
QCOMPARE(child0->palette(), appPal);
QCOMPARE(child1->palette(), appPal);
QCOMPARE(child2->palette().color(QPalette::ToolTipBase), sysPalToolTipBase);
QCOMPARE(child2->palette().color(QPalette::Text), sysPalText);
QCOMPARE(child2->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText));
QCOMPARE(child3->palette().color(QPalette::ToolTipBase), sysPalToolTipBase);
QCOMPARE(child3->palette().color(QPalette::Text), sysPalText);
QCOMPARE(child3->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText));
QCOMPARE(child4->palette().color(QPalette::ToolTipBase), sysPalToolTipBase);
QCOMPARE(child4->palette().color(QPalette::Text), sysPalText);
QCOMPARE(child4->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText));
QCOMPARE(child5->palette().color(QPalette::ToolTipBase), sysPalToolTipBase);
QCOMPARE(child5->palette().color(QPalette::Text), sysPalText);
QCOMPARE(child5->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText));
// Set child0's Text, and set ToolTipBase on child4.
QPalette textPalette;
textPalette.setColor(QPalette::Text, overridePalText);
child0->setPalette(textPalette);
QPalette toolTipPalette;
toolTipPalette.setColor(QPalette::ToolTipBase, overridePalToolTipBase);
child4->setPalette(toolTipPalette);
// Check that the above settings propagate correctly.
QCOMPARE(root->palette(), appPal);
QCOMPARE(child0->palette().color(QPalette::Text), overridePalText);
QCOMPARE(child0->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase));
QCOMPARE(child0->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText));
QCOMPARE(child1->palette().color(QPalette::Text), overridePalText);
QCOMPARE(child1->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase));
QCOMPARE(child1->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText));
QCOMPARE(child2->palette().color(QPalette::Text), overridePalText);
QCOMPARE(child2->palette().color(QPalette::ToolTipBase), sysPalToolTipBase);
QCOMPARE(child2->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText));
QCOMPARE(child3->palette().color(QPalette::Text), overridePalText);
QCOMPARE(child3->palette().color(QPalette::ToolTipBase), sysPalToolTipBase);
QCOMPARE(child3->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText));
QCOMPARE(child4->palette().color(QPalette::Text), overridePalText);
QCOMPARE(child4->palette().color(QPalette::ToolTipBase), overridePalToolTipBase);
QCOMPARE(child4->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText));
QCOMPARE(child5->palette().color(QPalette::Text), overridePalText);
QCOMPARE(child5->palette().color(QPalette::ToolTipBase), overridePalToolTipBase);
QCOMPARE(child5->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText));
// Replace the app palette for child2. Button should propagate but Text
// should still be ignored. The previous ToolTipBase setting is gone.
QPalette buttonPalette;
buttonPalette.setColor(QPalette::ToolTipText, sysPalButton);
qApp->setPalette(buttonPalette, "QPropagationTestWidget");
// Check that the above settings propagate correctly.
QCOMPARE(root->palette(), appPal);
QCOMPARE(child0->palette().color(QPalette::Text), overridePalText);
QCOMPARE(child0->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase));
QCOMPARE(child0->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText));
QCOMPARE(child1->palette().color(QPalette::Text), overridePalText);
QCOMPARE(child1->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase));
QCOMPARE(child1->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText));
QCOMPARE(child2->palette().color(QPalette::Text), overridePalText);
QCOMPARE(child2->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase));
QCOMPARE(child2->palette().color(QPalette::ToolTipText), sysPalButton);
QCOMPARE(child3->palette().color(QPalette::Text), overridePalText);
QCOMPARE(child3->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase));
QCOMPARE(child3->palette().color(QPalette::ToolTipText), sysPalButton);
QCOMPARE(child4->palette().color(QPalette::Text), overridePalText);
QCOMPARE(child4->palette().color(QPalette::ToolTipBase), overridePalToolTipBase);
QCOMPARE(child4->palette().color(QPalette::ToolTipText), sysPalButton);
QCOMPARE(child5->palette().color(QPalette::Text), overridePalText);
QCOMPARE(child5->palette().color(QPalette::ToolTipBase), overridePalToolTipBase);
QCOMPARE(child5->palette().color(QPalette::ToolTipText), sysPalButton);
}
void tst_QWidget::enabledPropagation()
{
QWidget* childWidget = new QWidget( testWidget );
childWidget->show();
QVERIFY( testWidget->isEnabled() );
QVERIFY( childWidget->isEnabled() );
testWidget->setEnabled( FALSE );
QVERIFY( !testWidget->isEnabled() );
QVERIFY( !childWidget->isEnabled() );
testWidget->setDisabled( FALSE );
QVERIFY( testWidget->isEnabled() );
QVERIFY( childWidget->isEnabled() );
QWidget* grandChildWidget = new QWidget( childWidget );
QVERIFY( grandChildWidget->isEnabled() );
testWidget->setDisabled( TRUE );
QVERIFY( !testWidget->isEnabled() );
QVERIFY( !childWidget->isEnabled() );
QVERIFY( !grandChildWidget->isEnabled() );
grandChildWidget->setEnabled( FALSE );
testWidget->setEnabled( TRUE );
QVERIFY( testWidget->isEnabled() );
QVERIFY( childWidget->isEnabled() );
QVERIFY( !grandChildWidget->isEnabled() );
grandChildWidget->setEnabled( TRUE );
testWidget->setEnabled( FALSE );
childWidget->setDisabled( TRUE );
testWidget->setEnabled( TRUE );
QVERIFY( testWidget->isEnabled() );
QVERIFY( !childWidget->isEnabled() );
QVERIFY( !grandChildWidget->isEnabled() );
}
void tst_QWidget::acceptDropsPropagation()
{
#ifdef QT_NO_DRAGANDDROP
QSKIP("Drag'n drop disabled in this build", SkipAll);
#else
QWidget *childWidget = new QWidget(testWidget);
childWidget->show();
QVERIFY(!testWidget->acceptDrops());
QVERIFY(!childWidget->acceptDrops());
testWidget->setAcceptDrops(true);
QVERIFY(testWidget->acceptDrops());
QVERIFY(!childWidget->acceptDrops());
QVERIFY(childWidget->testAttribute(Qt::WA_DropSiteRegistered));
testWidget->setAcceptDrops(false);
QVERIFY(!testWidget->acceptDrops());
QVERIFY(!childWidget->acceptDrops());
QVERIFY(!childWidget->testAttribute(Qt::WA_DropSiteRegistered));
QWidget *grandChildWidget = new QWidget(childWidget);
QVERIFY(!grandChildWidget->acceptDrops());
QVERIFY(!grandChildWidget->testAttribute(Qt::WA_DropSiteRegistered));
testWidget->setAcceptDrops(true);
QVERIFY(testWidget->acceptDrops());
QVERIFY(!childWidget->acceptDrops());
QVERIFY(childWidget->testAttribute(Qt::WA_DropSiteRegistered));
QVERIFY(!grandChildWidget->acceptDrops());
QVERIFY(grandChildWidget->testAttribute(Qt::WA_DropSiteRegistered));
grandChildWidget->setAcceptDrops(true);
testWidget->setAcceptDrops(false);
QVERIFY(!testWidget->acceptDrops());
QVERIFY(!childWidget->acceptDrops());
QVERIFY(grandChildWidget->acceptDrops());
QVERIFY(grandChildWidget->testAttribute(Qt::WA_DropSiteRegistered));
grandChildWidget->setAcceptDrops(false);
QVERIFY(!grandChildWidget->testAttribute(Qt::WA_DropSiteRegistered));
testWidget->setAcceptDrops(true);
childWidget->setAcceptDrops(true);
testWidget->setAcceptDrops(false);
QVERIFY(!testWidget->acceptDrops());
QVERIFY(childWidget->acceptDrops());
QVERIFY(!grandChildWidget->acceptDrops());
QVERIFY(grandChildWidget->testAttribute(Qt::WA_DropSiteRegistered));
#endif
}
void tst_QWidget::isEnabledTo()
{
QWidget* childWidget = new QWidget( testWidget );
QWidget* grandChildWidget = new QWidget( childWidget );
QVERIFY( childWidget->isEnabledTo( testWidget ) );
QVERIFY( grandChildWidget->isEnabledTo( testWidget ) );
childWidget->setEnabled( FALSE );
QVERIFY( !childWidget->isEnabledTo( testWidget ) );
QVERIFY( grandChildWidget->isEnabledTo( childWidget ) );
QVERIFY( !grandChildWidget->isEnabledTo( testWidget ) );
}
void tst_QWidget::visible()
{
// Ensure that the testWidget is hidden for this test at the
// start
testWidget->hide();
QVERIFY( !testWidget->isVisible() );
QWidget* childWidget = new QWidget( testWidget );
QVERIFY( !childWidget->isVisible() );
testWidget->show();
QVERIFY( testWidget->isVisible() );
QVERIFY( childWidget->isVisible() );
QWidget* grandChildWidget = new QWidget( childWidget );
QVERIFY( !grandChildWidget->isVisible() );
grandChildWidget->show();
QVERIFY( grandChildWidget->isVisible() );
grandChildWidget->hide();
testWidget->hide();
testWidget->show();
QVERIFY( !grandChildWidget->isVisible() );
QVERIFY( testWidget->isVisible() );
QVERIFY( childWidget->isVisible() );
grandChildWidget->show();
childWidget->hide();
testWidget->hide();
testWidget->show();
QVERIFY( testWidget->isVisible() );
QVERIFY( !childWidget->isVisible() );
QVERIFY( !grandChildWidget->isVisible() );
grandChildWidget->show();
QVERIFY( !grandChildWidget->isVisible() );
}
void tst_QWidget::setLocale()
{
QWidget w;
QCOMPARE(w.locale(), QLocale());
w.setLocale(QLocale::Italian);
QCOMPARE(w.locale(), QLocale(QLocale::Italian));
QWidget child1(&w);
QCOMPARE(child1.locale(), QLocale(QLocale::Italian));
w.unsetLocale();
QCOMPARE(w.locale(), QLocale());
QCOMPARE(child1.locale(), QLocale());
w.setLocale(QLocale::French);
QCOMPARE(w.locale(), QLocale(QLocale::French));
QCOMPARE(child1.locale(), QLocale(QLocale::French));
child1.setLocale(QLocale::Italian);
QCOMPARE(w.locale(), QLocale(QLocale::French));
QCOMPARE(child1.locale(), QLocale(QLocale::Italian));
child1.unsetLocale();
QCOMPARE(w.locale(), QLocale(QLocale::French));
QCOMPARE(child1.locale(), QLocale(QLocale::French));
QWidget child2;
QCOMPARE(child2.locale(), QLocale());
child2.setParent(&w);
QCOMPARE(child2.locale(), QLocale(QLocale::French));
}
void tst_QWidget::visible_setWindowOpacity()
{
testWidget->hide();
QVERIFY( !testWidget->isVisible() );
testWidget->setWindowOpacity(0.5);
#ifdef Q_OS_WIN
QVERIFY(::IsWindowVisible(testWidget->winId()) == FALSE);
#endif
testWidget->setWindowOpacity(1.0);
}
void tst_QWidget::isVisibleTo()
{
// Ensure that the testWidget is hidden for this test at the
// start
testWidget->hide();
QWidget* childWidget = new QWidget( testWidget );
QVERIFY( childWidget->isVisibleTo( testWidget ) );
childWidget->hide();
QVERIFY( !childWidget->isVisibleTo( testWidget ) );
QWidget* grandChildWidget = new QWidget( childWidget );
QVERIFY( !grandChildWidget->isVisibleTo( testWidget ) );
QVERIFY( grandChildWidget->isVisibleTo( childWidget ) );
testWidget->show();
childWidget->show();
QVERIFY( childWidget->isVisibleTo( testWidget ) );
grandChildWidget->hide();
QVERIFY( !grandChildWidget->isVisibleTo( childWidget ) );
QVERIFY( !grandChildWidget->isVisibleTo( testWidget ) );
}
void tst_QWidget::isHidden()
{
// Ensure that the testWidget is hidden for this test at the
// start
testWidget->hide();
QVERIFY( testWidget->isHidden() );
QWidget* childWidget = new QWidget( testWidget );
QVERIFY( !childWidget->isHidden() );
testWidget->show();
QVERIFY( !testWidget->isHidden() );
QVERIFY( !childWidget->isHidden() );
QWidget* grandChildWidget = new QWidget( childWidget );
QVERIFY( grandChildWidget->isHidden() );
grandChildWidget->show();
QVERIFY( !grandChildWidget->isHidden() );
grandChildWidget->hide();
testWidget->hide();
testWidget->show();
QVERIFY( grandChildWidget->isHidden() );
QVERIFY( !testWidget->isHidden() );
QVERIFY( !childWidget->isHidden() );
grandChildWidget->show();
childWidget->hide();
testWidget->hide();
testWidget->show();
QVERIFY( !testWidget->isHidden() );
QVERIFY( childWidget->isHidden() );
QVERIFY( !grandChildWidget->isHidden() );
grandChildWidget->show();
QVERIFY( !grandChildWidget->isHidden() );
}
void tst_QWidget::fonts()
{
// Tests setFont(), ownFont() and unsetFont()
QWidget* cleanTestWidget = new QWidget( testWidget );
QFont originalFont = cleanTestWidget->font();
QVERIFY( !cleanTestWidget->testAttribute(Qt::WA_SetFont) );
cleanTestWidget->setFont(QFont());
QVERIFY( !cleanTestWidget->testAttribute(Qt::WA_SetFont) );
QFont newFont( "times", 18 );
cleanTestWidget->setFont( newFont );
newFont = newFont.resolve( testWidget->font() );
QVERIFY( cleanTestWidget->testAttribute(Qt::WA_SetFont) );
QVERIFY( cleanTestWidget->font() == newFont );
cleanTestWidget->setFont(QFont());
QVERIFY( !cleanTestWidget->testAttribute(Qt::WA_SetFont) );
QVERIFY( cleanTestWidget->font() == originalFont );
}
void tst_QWidget::mapToGlobal()
{
#if !defined(QT3_SUPPORT)
QSKIP("No Qt3 Support", SkipAll);
#else
QPoint vis = testWidget->mapToGlobal(QPoint(0,0));
testWidget->hide();
QCOMPARE(testWidget->mapToGlobal(QPoint(0,0)), vis);
testWidget->show();
// test in a layout and witha move
Q3HBox * qhb = new Q3HBox(testWidget);
QWidget * qw = new QWidget(qhb);
qw->move(6,12);
QPoint wVis = qw->mapToGlobal(QPoint(0,0));
qw->hide();
QCOMPARE(qw->mapToGlobal(QPoint(0,0)), wVis);
delete qhb;
#endif // QT3_SUPPORT
}
void tst_QWidget::mapFromAndTo_data()
{
QTest::addColumn<bool>("windowHidden");
QTest::addColumn<bool>("subWindow1Hidden");
QTest::addColumn<bool>("subWindow2Hidden");
QTest::addColumn<bool>("subSubWindowHidden");
QTest::addColumn<bool>("windowMinimized");
QTest::addColumn<bool>("subWindow1Minimized");
QTest::newRow("window 1 sub1 1 sub2 1 subsub 1") << false << false << false << false << false << false;
QTest::newRow("window 0 sub1 1 sub2 1 subsub 1") << true << false << false << false << false << false;
QTest::newRow("window 1 sub1 0 sub2 1 subsub 1") << false << true << false << false << false << false;
QTest::newRow("window 0 sub1 0 sub2 1 subsub 1") << true << true << false << false << false << false;
QTest::newRow("window 1 sub1 1 sub2 0 subsub 1") << false << false << true << false << false << false;
QTest::newRow("window 0 sub1 1 sub2 0 subsub 1") << true << false << true << false << false << false;
QTest::newRow("window 1 sub1 0 sub2 0 subsub 1") << false << true << true << false << false << false;
QTest::newRow("window 0 sub1 0 sub2 0 subsub 1") << true << true << true << false << false << false;
QTest::newRow("window 1 sub1 1 sub2 1 subsub 0") << false << false << false << true << false << false;
QTest::newRow("window 0 sub1 1 sub2 1 subsub 0") << true << false << false << true << false << false;
QTest::newRow("window 1 sub1 0 sub2 1 subsub 0") << false << true << false << true << false << false;
QTest::newRow("window 0 sub1 0 sub2 1 subsub 0") << true << true << false << true << false << false;
QTest::newRow("window 1 sub1 1 sub2 0 subsub 0") << false << false << true << true << false << false;
QTest::newRow("window 0 sub1 1 sub2 0 subsub 0") << true << false << true << true << false << false;
QTest::newRow("window 1 sub1 0 sub2 0 subsub 0") << false << true << true << true << false << false;
QTest::newRow("window 0 sub1 0 sub2 0 subsub 0") << true << true << true << true << false << false;
QTest::newRow("window 1 sub1 1 sub2 1 subsub 1 windowMinimized") << false << false << false << false << true << false;
QTest::newRow("window 0 sub1 1 sub2 1 subsub 1 windowMinimized") << true << false << false << false << true << false;
QTest::newRow("window 1 sub1 0 sub2 1 subsub 1 windowMinimized") << false << true << false << false << true << false;
QTest::newRow("window 0 sub1 0 sub2 1 subsub 1 windowMinimized") << true << true << false << false << true << false;
QTest::newRow("window 1 sub1 1 sub2 0 subsub 1 windowMinimized") << false << false << true << false << true << false;
QTest::newRow("window 0 sub1 1 sub2 0 subsub 1 windowMinimized") << true << false << true << false << true << false;
QTest::newRow("window 1 sub1 0 sub2 0 subsub 1 windowMinimized") << false << true << true << false << true << false;
QTest::newRow("window 0 sub1 0 sub2 0 subsub 1 windowMinimized") << true << true << true << false << true << false;
QTest::newRow("window 1 sub1 1 sub2 1 subsub 0 windowMinimized") << false << false << false << true << true << false;
QTest::newRow("window 0 sub1 1 sub2 1 subsub 0 windowMinimized") << true << false << false << true << true << false;
QTest::newRow("window 1 sub1 0 sub2 1 subsub 0 windowMinimized") << false << true << false << true << true << false;
QTest::newRow("window 0 sub1 0 sub2 1 subsub 0 windowMinimized") << true << true << false << true << true << false;
QTest::newRow("window 1 sub1 1 sub2 0 subsub 0 windowMinimized") << false << false << true << true << true << false;
QTest::newRow("window 0 sub1 1 sub2 0 subsub 0 windowMinimized") << true << false << true << true << true << false;
QTest::newRow("window 1 sub1 0 sub2 0 subsub 0 windowMinimized") << false << true << true << true << true << false;
QTest::newRow("window 0 sub1 0 sub2 0 subsub 0 windowMinimized") << true << true << true << true << true << false;
QTest::newRow("window 1 sub1 1 sub2 1 subsub 1 subWindow1Minimized") << false << false << false << false << false << true;
QTest::newRow("window 0 sub1 1 sub2 1 subsub 1 subWindow1Minimized") << true << false << false << false << false << true;
QTest::newRow("window 1 sub1 0 sub2 1 subsub 1 subWindow1Minimized") << false << true << false << false << false << true;
QTest::newRow("window 0 sub1 0 sub2 1 subsub 1 subWindow1Minimized") << true << true << false << false << false << true;
QTest::newRow("window 1 sub1 1 sub2 0 subsub 1 subWindow1Minimized") << false << false << true << false << false << true;
QTest::newRow("window 0 sub1 1 sub2 0 subsub 1 subWindow1Minimized") << true << false << true << false << false << true;
QTest::newRow("window 1 sub1 0 sub2 0 subsub 1 subWindow1Minimized") << false << true << true << false << false << true;
QTest::newRow("window 0 sub1 0 sub2 0 subsub 1 subWindow1Minimized") << true << true << true << false << false << true;
QTest::newRow("window 1 sub1 1 sub2 1 subsub 0 subWindow1Minimized") << false << false << false << true << false << true;
QTest::newRow("window 0 sub1 1 sub2 1 subsub 0 subWindow1Minimized") << true << false << false << true << false << true;
QTest::newRow("window 1 sub1 0 sub2 1 subsub 0 subWindow1Minimized") << false << true << false << true << false << true;
QTest::newRow("window 0 sub1 0 sub2 1 subsub 0 subWindow1Minimized") << true << true << false << true << false << true;
QTest::newRow("window 1 sub1 1 sub2 0 subsub 0 subWindow1Minimized") << false << false << true << true << false << true;
QTest::newRow("window 0 sub1 1 sub2 0 subsub 0 subWindow1Minimized") << true << false << true << true << false << true;
QTest::newRow("window 1 sub1 0 sub2 0 subsub 0 subWindow1Minimized") << false << true << true << true << false << true;
QTest::newRow("window 0 sub1 0 sub2 0 subsub 0 subWindow1Minimized") << true << true << true << true << false << true;
}
void tst_QWidget::mapFromAndTo()
{
QFETCH(bool, windowHidden);
QFETCH(bool, subWindow1Hidden);
QFETCH(bool, subWindow2Hidden);
QFETCH(bool, subSubWindowHidden);
QFETCH(bool, windowMinimized);
QFETCH(bool, subWindow1Minimized);
// create a toplevel and two overlapping siblings
QWidget window;
window.setWindowFlags(window.windowFlags() | Qt::X11BypassWindowManagerHint);
QWidget *subWindow1 = new QWidget(&window);
QWidget *subWindow2 = new QWidget(&window);
QWidget *subSubWindow = new QWidget(subWindow1);
// set their geometries
window.setGeometry(100, 100, 100, 100);
subWindow1->setGeometry(50, 50, 100, 100);
subWindow2->setGeometry(75, 75, 100, 100);
subSubWindow->setGeometry(10, 10, 10, 10);
#if !defined (Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) //still no proper minimizing
//update visibility
if (windowMinimized) {
if (!windowHidden) {
window.showMinimized();
QVERIFY(window.isMinimized());
}
} else {
window.setVisible(!windowHidden);
}
if (subWindow1Minimized) {
subWindow1->hide();
subWindow1->showMinimized();
QVERIFY(subWindow1->isMinimized());
} else {
subWindow1->setVisible(!subWindow1Hidden);
}
#else
Q_UNUSED(windowHidden);
Q_UNUSED(subWindow1Hidden);
Q_UNUSED(windowMinimized);
Q_UNUSED(subWindow1Minimized);
#endif
subWindow2->setVisible(!subWindow2Hidden);
subSubWindow->setVisible(!subSubWindowHidden);
// window
QCOMPARE(window.mapToGlobal(QPoint(0, 0)), QPoint(100, 100));
QCOMPARE(window.mapToGlobal(QPoint(10, 0)), QPoint(110, 100));
QCOMPARE(window.mapToGlobal(QPoint(0, 10)), QPoint(100, 110));
QCOMPARE(window.mapToGlobal(QPoint(-10, 0)), QPoint(90, 100));
QCOMPARE(window.mapToGlobal(QPoint(0, -10)), QPoint(100, 90));
QCOMPARE(window.mapToGlobal(QPoint(100, 100)), QPoint(200, 200));
QCOMPARE(window.mapToGlobal(QPoint(110, 100)), QPoint(210, 200));
QCOMPARE(window.mapToGlobal(QPoint(100, 110)), QPoint(200, 210));
QCOMPARE(window.mapFromGlobal(QPoint(100, 100)), QPoint(0, 0));
QCOMPARE(window.mapFromGlobal(QPoint(110, 100)), QPoint(10, 0));
QCOMPARE(window.mapFromGlobal(QPoint(100, 110)), QPoint(0, 10));
QCOMPARE(window.mapFromGlobal(QPoint(90, 100)), QPoint(-10, 0));
QCOMPARE(window.mapFromGlobal(QPoint(100, 90)), QPoint(0, -10));
QCOMPARE(window.mapFromGlobal(QPoint(200, 200)), QPoint(100, 100));
QCOMPARE(window.mapFromGlobal(QPoint(210, 200)), QPoint(110, 100));
QCOMPARE(window.mapFromGlobal(QPoint(200, 210)), QPoint(100, 110));
QCOMPARE(window.mapToParent(QPoint(0, 0)), QPoint(100, 100));
QCOMPARE(window.mapToParent(QPoint(10, 0)), QPoint(110, 100));
QCOMPARE(window.mapToParent(QPoint(0, 10)), QPoint(100, 110));
QCOMPARE(window.mapToParent(QPoint(-10, 0)), QPoint(90, 100));
QCOMPARE(window.mapToParent(QPoint(0, -10)), QPoint(100, 90));
QCOMPARE(window.mapToParent(QPoint(100, 100)), QPoint(200, 200));
QCOMPARE(window.mapToParent(QPoint(110, 100)), QPoint(210, 200));
QCOMPARE(window.mapToParent(QPoint(100, 110)), QPoint(200, 210));
QCOMPARE(window.mapFromParent(QPoint(100, 100)), QPoint(0, 0));
QCOMPARE(window.mapFromParent(QPoint(110, 100)), QPoint(10, 0));
QCOMPARE(window.mapFromParent(QPoint(100, 110)), QPoint(0, 10));
QCOMPARE(window.mapFromParent(QPoint(90, 100)), QPoint(-10, 0));
QCOMPARE(window.mapFromParent(QPoint(100, 90)), QPoint(0, -10));
QCOMPARE(window.mapFromParent(QPoint(200, 200)), QPoint(100, 100));
QCOMPARE(window.mapFromParent(QPoint(210, 200)), QPoint(110, 100));
QCOMPARE(window.mapFromParent(QPoint(200, 210)), QPoint(100, 110));
// first subwindow
QCOMPARE(subWindow1->mapToGlobal(QPoint(0, 0)), QPoint(150, 150));
QCOMPARE(subWindow1->mapToGlobal(QPoint(10, 0)), QPoint(160, 150));
QCOMPARE(subWindow1->mapToGlobal(QPoint(0, 10)), QPoint(150, 160));
QCOMPARE(subWindow1->mapToGlobal(QPoint(-10, 0)), QPoint(140, 150
QCOMPARE(subWindow1->mapToGlobal(QPoint(= true;
updateItem(i);
}
}
for (i = from; i; i = i->next()) {
if (!invert) {
if (!i->s && i->isSelectable()) {
i->s = true;
changed = true;
updateItem(i);
}
} else {
bool sel = !i->s;
if (((bool)i->s != sel && sel && i->isSelectable()) || !sel) {
i->s = sel;
changed = true;
updateItem(i);
}
}
if (i == to)
break;
}
if (changed) {
emit selectionChanged();
#ifndef QT_NO_ACCESSIBILITY
QAccessible::updateAccessibility(viewport(), 0, QAccessible::Selection);
#endif
}
}
/*! \reimp */
void Q3ListBox::changeEvent(QEvent *ev)
{
if (ev->type() == QEvent::ActivationChange) {
if (!isActiveWindow() && d->scrollTimer)
d->scrollTimer->stop();
if (!palette().isEqual(QPalette::Active, QPalette::Inactive))
viewport()->update();
}
Q3ScrollView::changeEvent(ev);
if (ev->type() == QEvent::ApplicationFontChange || ev->type() == QEvent::FontChange)
triggerUpdate(true);
}
/*!
Returns 0.
Make your derived classes return their own values for rtti(), and
you can distinguish between listbox items. You should use values
greater than 1000 preferably a large random number, to allow for
extensions to this class.
*/
int Q3ListBoxItem::rtti() const
{
return RTTI;
}
/*!
\fn bool Q3ListBox::dragSelect() const
Returns true. Dragging always selects.
*/
/*!
\fn void Q3ListBox::setDragSelect(bool b)
Does nothing. Dragging always selects. The \a b parameter is ignored.
*/
/*!
\fn bool Q3ListBox::autoScroll() const
Use dragAutoScroll() instead. This function always returns true.
*/
/*!
\fn void Q3ListBox::setAutoScroll(bool b)
Use setDragAutoScroll(\a b) instead.
*/
/*!
\fn bool Q3ListBox::autoScrollBar() const
Use vScrollBarMode() instead. Returns true if the vertical
scrollbar mode is \c Auto.
*/
/*!
\fn void Q3ListBox::setAutoScrollBar(bool enable)
Use setVScrollBarMode() instead.
If \a enable is true, pass \c Auto as the argument to
setVScrollBarMode(); otherwise, pass \c AlwaysOff.
*/
/*!
\fn bool Q3ListBox::scrollBar() const
Use vScrollBarMode() instead. Returns true if the vertical
scrollbar mode is not \c AlwaysOff.
*/
/*!
\fn void Q3ListBox::setScrollBar(bool enable)
Use setVScrollBarMode() instead.
If \a enable is true, pass \c AlwaysOn as the argument to
setVScrollBarMode(); otherwise, pass \c AlwaysOff.
*/
/*!
\fn bool Q3ListBox::autoBottomScrollBar() const
Use hScrollBarMode() instead. Returns true if the horizontal
scrollbar mode is set to \c Auto.
*/
/*!
\fn void Q3ListBox::setAutoBottomScrollBar(bool enable)
Use setHScrollBarMode() instead.
If \a enable is true, pass \c Auto as the argument to
setHScrollBarMode(); otherwise, pass \c AlwaysOff.
*/
/*!
\fn bool Q3ListBox::bottomScrollBar() const
Use hScrollBarMode() instead. Returns true if the horizontal
scrollbar mode is not \c AlwaysOff.
*/
/*!
\fn void Q3ListBox::setBottomScrollBar(bool enable)
Use setHScrollBarMode() instead.
If \a enable is true, pass \c AlwaysOn as the argument to
setHScrollBarMode(); otherwise, pass \c AlwaysOff.
*/
/*!
\fn bool Q3ListBox::smoothScrolling() const
Returns false. Qt always scrolls smoothly.
*/
/*!
\fn void Q3ListBox::setSmoothScrolling(bool b)
Does nothing. Qt always scrolls smoothly. The \a b parameter is
ignored.
*/
/*!
\fn bool Q3ListBox::autoUpdate() const
Returns true. Qt always updates automatically.
*/
/*!
\fn void Q3ListBox::setAutoUpdate(bool b)
Does nothing. Qt always updates automatically. The \a b parameter
is ignored.
*/
/*!
\fn void Q3ListBox::setFixedVisibleLines(int lines)
Use setRowMode(\a lines) instead.
*/
/*!
\fn int Q3ListBox::cellHeight(int i) const
Use itemHeight(\a i) instead.
*/
/*!
\fn int Q3ListBox::cellHeight() const
Use itemHeight() instead.
*/
/*!
\fn int Q3ListBox::cellWidth() const
Use maxItemWidth() instead.
*/
/*!
\fn int Q3ListBox::cellWidth(int i) const
Use maxItemWidth(\a i) instead.
*/
/*!
\fn int Q3ListBox::numCols() const
Use numColumns() instead.
*/
/*!
\fn void Q3ListBox::updateCellWidth()
Does nothing. Qt automatically updates.
*/
/*!
\fn int Q3ListBox::totalWidth() const
Use contentsWidth() instead.
*/
/*!
\fn int Q3ListBox::totalHeight() const
Use contentsHeight() instead.
*/
/*!
\fn int Q3ListBox::findItem(int yPos) const
Use index(itemAt(\a yPos)) instead.
*/
/*!
\fn bool Q3ListBoxItem::selected() const
Use isSelected() instead. Returns true if isSelected()
returns true.
*/
/*!
\fn bool Q3ListBoxItem::current() const
Use isCurrent() instead. Returns true if isCurrent()
returns true.
*/
/*!
\enum Q3ListBox::StringComparisonMode
This enum type is used to set the string comparison mode when
searching for an item. We'll refer to the string being searched
as the 'target' string.
\value CaseSensitive The strings must match case sensitively.
\value ExactMatch The target and search strings must match exactly.
\value BeginsWith The target string begins with the search string.
\value EndsWith The target string ends with the search string.
\value Contains The target string contains the search string.
If you OR these flags together (excluding \c CaseSensitive), the
search criteria be applied in the following order: \c ExactMatch,
\c BeginsWith, \c EndsWith, \c Contains.
Matching is case-insensitive unless \c CaseSensitive is set. \c
CaseSensitive can be OR-ed with any combination of the other
flags.
\sa ComparisonFlags
*/
/*!
\typedef Q3ListBox::ComparisonFlags
This typedef is used in Q3IconView's API for values that are OR'd
combinations of \l StringComparisonMode values.
\sa StringComparisonMode
*/
QT_END_NAMESPACE
#endif // QT_NO_LISTBOX
|