qt/qwidget/smoke_qwidget.cpp
branchSymbian3
changeset 43 14fcccfb4c0c
equal deleted inserted replaced
42:4f2786c97bf4 43:14fcccfb4c0c
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 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 ** 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 #if defined(QT3_SUPPORT)
       
    44 #include <q3hbox.h>
       
    45 #include <q3textedit.h>
       
    46 #endif
       
    47 #include <qboxlayout.h>
       
    48 #include <qapplication.h>
       
    49 #include <qbitmap.h>
       
    50 #include <qdebug.h>
       
    51 #include <qeventloop.h>
       
    52 #include <qlabel.h>
       
    53 #include <qlayout.h>
       
    54 #include <qlineedit.h>
       
    55 #include <qlistview.h>
       
    56 #include <qmessagebox.h>
       
    57 #include <qpainter.h>
       
    58 #include <qpoint.h>
       
    59 #include <qpushbutton.h>
       
    60 #include <qstyle.h>
       
    61 #include <qwidget.h>
       
    62 #include <qwindowsstyle.h>
       
    63 #include <qinputcontext.h>
       
    64 #include <qdesktopwidget.h>
       
    65 #include <private/qwidget_p.h>
       
    66 #include <private/qapplication_p.h>
       
    67 #include <qcalendarwidget.h>
       
    68 #include <qmainwindow.h>
       
    69 #include <qdockwidget.h>
       
    70 #include <qtoolbar.h>
       
    71 #include <QtGui/qpaintengine.h>
       
    72 #include <private/qbackingstore_p.h>
       
    73 
       
    74 #include <QtGui/QGraphicsView>
       
    75 #include <QtGui/QGraphicsProxyWidget>
       
    76 
       
    77 #include "../shared/util.h"
       
    78 
       
    79 
       
    80 #ifdef Q_WS_S60
       
    81 #include <avkon.hrh>                // EEikStatusPaneUidTitle
       
    82 #include <akntitle.h>               // CAknTitlePane
       
    83 #include <akncontext.h>             // CAknContextPane
       
    84 #include <eikspane.h>               // CEikStatusPane
       
    85 #include <eikbtgpc.h>               // CEikButtonGroupContainer
       
    86 #endif
       
    87 
       
    88 #ifdef Q_WS_QWS
       
    89 # include <qscreen_qws.h>
       
    90 #endif
       
    91 
       
    92 // I *MUST* have QtTest afterwards or this test won't work with newer headers
       
    93 #if defined(Q_WS_MAC)
       
    94 # include <private/qt_mac_p.h>
       
    95 #undef verify
       
    96 #include "tst_qwidget_mac_helpers.h"  // Abstract the ObjC stuff out so not everyone must run an ObjC++ compile.
       
    97 #endif
       
    98 
       
    99 #include <QtTest/QtTest>
       
   100 
       
   101 #if defined(Q_WS_WIN)
       
   102 #  include <qt_windows.h>
       
   103 #  if !defined(Q_OS_WINCE)
       
   104 #define Q_CHECK_PAINTEVENTS \
       
   105     if (::SwitchDesktop(::GetThreadDesktop(::GetCurrentThreadId())) == 0) \
       
   106         QSKIP("desktop is not visible, this test would fail", SkipSingle);
       
   107 #  else
       
   108 #    define Q_CHECK_PAINTEVENTS
       
   109 #  endif
       
   110 #elif defined(Q_WS_X11)
       
   111 #  include <private/qt_x11_p.h>
       
   112 #  include <qx11info_x11.h>
       
   113 #elif defined(Q_WS_QWS)
       
   114 # include <qwindowsystem_qws.h>
       
   115 #endif
       
   116 
       
   117 #if !defined(Q_WS_WIN)
       
   118 #define Q_CHECK_PAINTEVENTS
       
   119 #endif
       
   120 
       
   121 #if defined(Bool)
       
   122 #undef Bool
       
   123 #endif
       
   124 
       
   125 // Will try to wait for the condition while allowing event processing
       
   126 // for a maximum of 2 seconds.
       
   127 #define WAIT_FOR_CONDITION(expr, expected) \
       
   128     do { \
       
   129         const int step = 100; \
       
   130         for (int i = 0; i < 2000 && expr != expected; i+=step) { \
       
   131             QTest::qWait(step); \
       
   132         } \
       
   133     } while(0)
       
   134 
       
   135 //TESTED_CLASS=
       
   136 //TESTED_FILES=
       
   137 
       
   138 class tst_QWidget : public QObject
       
   139 {
       
   140     Q_OBJECT
       
   141 
       
   142 public:
       
   143     tst_QWidget();
       
   144     virtual ~tst_QWidget();
       
   145 
       
   146 
       
   147 public slots:
       
   148     void initTestCase();
       
   149     void cleanupTestCase();
       
   150     void init();
       
   151     void cleanup();
       
   152 private slots:
       
   153     void showFullScreen();
       
   154 	
       
   155 private:
       
   156     bool ensureScreenSize(int width, int height);
       
   157     QWidget *testWidget;
       
   158 };
       
   159 
       
   160 tst_QWidget::tst_QWidget()
       
   161 {
       
   162     QFont font;
       
   163     font.setBold(true);
       
   164     font.setPointSize(42);
       
   165     qApp->setFont(font, "QPropagationTestWidget");
       
   166 
       
   167     QPalette palette;
       
   168     palette.setColor(QPalette::ToolTipBase, QColor(12, 13, 14));
       
   169     palette.setColor(QPalette::Text, QColor(21, 22, 23));
       
   170     qApp->setPalette(palette, "QPropagationTestWidget");
       
   171 
       
   172     testWidget = 0;
       
   173 }
       
   174 
       
   175 tst_QWidget::~tst_QWidget()
       
   176 {
       
   177 }
       
   178 
       
   179 class BezierViewer : public QWidget {
       
   180 public:
       
   181     BezierViewer( QWidget* parent=0, const char* name=0 );
       
   182     void paintEvent( QPaintEvent* );
       
   183     void setPoints( const QPolygonF& poly );
       
   184 private:
       
   185     QPolygonF points;
       
   186 
       
   187 };
       
   188 
       
   189 void tst_QWidget::initTestCase()
       
   190 {
       
   191   // Create the test class
       
   192     testWidget = new BezierViewer( 0, "testObject");
       
   193     testWidget->resize(200,200);
       
   194 #ifdef QT3_SUPPORT
       
   195     qApp->setMainWidget(testWidget);
       
   196 #endif
       
   197     testWidget->show();
       
   198     QTest::qWaitForWindowShown(testWidget);
       
   199     QTest::qWait(50);
       
   200 }
       
   201 
       
   202 void tst_QWidget::cleanupTestCase()
       
   203 {
       
   204     delete testWidget;
       
   205     testWidget = 0;
       
   206 }
       
   207 
       
   208 
       
   209 void tst_QWidget::init()
       
   210 {
       
   211 // TODO: Add initialization code here.
       
   212 // This will be executed immediately before each test is run.
       
   213     testWidget->setFont(QFont());
       
   214     testWidget->setPalette(QPalette());
       
   215 }
       
   216 
       
   217 void tst_QWidget::cleanup()
       
   218 {
       
   219 }
       
   220 
       
   221 
       
   222 
       
   223 // Helper class...
       
   224 
       
   225 BezierViewer::BezierViewer( QWidget* parent, const char* name )
       
   226 	: QWidget( parent )
       
   227 {
       
   228     setObjectName(name);
       
   229     QPalette pal;
       
   230     pal.setColor(backgroundRole(), Qt::white);
       
   231     setPalette(pal);
       
   232 }
       
   233 
       
   234 
       
   235 void BezierViewer::setPoints( const QPolygonF& a )
       
   236 {
       
   237     points = a;
       
   238 }
       
   239 
       
   240 #include "private/qbezier_p.h"
       
   241 void BezierViewer::paintEvent( QPaintEvent* )
       
   242 {
       
   243     if ( points.size() != 4 ) {
       
   244 #if defined(QT_CHECK_RANGE)
       
   245 	qWarning( "QPolygon::bezier: The array must have 4 control points" );
       
   246 #endif
       
   247 	return;
       
   248     }
       
   249 
       
   250     // Calculate Bezier curve
       
   251     QPolygonF bezier = QBezier::fromPoints(points.at(0),points.at(1),points.at(2),points.at(3)).toPolygon();
       
   252 
       
   253     QPainter painter( this );
       
   254 
       
   255     // Calculate scale to fit in window
       
   256     QRectF br = bezier.boundingRect() | points.boundingRect();
       
   257     QRectF pr = rect();
       
   258     int scl = qMax( qMin(pr.width()/br.width(), pr.height()/br.height()), qreal(1.) );
       
   259     int border = scl-1;
       
   260 
       
   261     // Scale Bezier curve vertices
       
   262     for ( QPolygonF::Iterator it = bezier.begin(); it != bezier.end(); ++it ) {
       
   263 	it->setX( (it->x()-br.x()) * scl + border );
       
   264 	it->setY( (it->y()-br.y()) * scl + border );
       
   265     }
       
   266 
       
   267     // Draw grid
       
   268     painter.setPen( Qt::lightGray );
       
   269 	int i;
       
   270 	for ( i = border; i <= pr.width(); i += scl ) {
       
   271 		painter.drawLine( i, 0, i, pr.height() );
       
   272     }
       
   273     for ( int j = border; j <= pr.height(); j += scl ) {
       
   274 	painter.drawLine( 0, j, pr.width(), j );
       
   275     }
       
   276 
       
   277     // Write number of vertices
       
   278     painter.setPen( Qt::red );
       
   279     painter.setFont( QFont("Helvetica", 14, QFont::DemiBold, TRUE ) );
       
   280     QString caption;
       
   281     caption.setNum( bezier.size() );
       
   282     caption += QString::fromLatin1( " vertices" );
       
   283     painter.drawText( 10, pr.height()-10, caption );
       
   284 
       
   285     // Draw Bezier curve
       
   286     painter.setPen( Qt::black );
       
   287     painter.drawPolyline( bezier );
       
   288 
       
   289     // Scale and draw control points
       
   290     painter.setPen( Qt::darkGreen );
       
   291     for ( QPolygonF::Iterator p1 = points.begin(); p1 != points.end(); ++p1 ) {
       
   292 	int x = (p1->x()-br.x()) * scl + border;
       
   293 	int y = (p1->y()-br.y()) * scl + border;
       
   294 	painter.drawLine( x-4, y-4, x+4, y+4 );
       
   295 	painter.drawLine( x+4, y-4, x-4, y+4 );
       
   296     }
       
   297 
       
   298     // Draw vertices
       
   299     painter.setPen( Qt::red );
       
   300     painter.setBrush( Qt::red );
       
   301     for ( QPolygonF::Iterator p2 = bezier.begin(); p2 != bezier.end(); ++p2 )
       
   302 	painter.drawEllipse( p2->x()-1, p2->y()-1, 3, 3 );
       
   303 }
       
   304 
       
   305 void tst_QWidget::showFullScreen()
       
   306 {
       
   307     QWidget plain;
       
   308     QHBoxLayout *layout;
       
   309     QWidget layouted;
       
   310     QLineEdit le;
       
   311     QLineEdit le2;
       
   312     QLineEdit le3;
       
   313     layout = new QHBoxLayout;
       
   314 
       
   315     layout->addWidget(&le);
       
   316     layout->addWidget(&le2);
       
   317     layout->addWidget(&le3);
       
   318 
       
   319     layouted.setLayout(layout);
       
   320 
       
   321     plain.showFullScreen();
       
   322     QVERIFY(plain.windowState() & Qt::WindowFullScreen);
       
   323 
       
   324     plain.showNormal();
       
   325     QVERIFY(!(plain.windowState() & Qt::WindowFullScreen));
       
   326 
       
   327     layouted.showFullScreen();
       
   328     QVERIFY(layouted.windowState() & Qt::WindowFullScreen);
       
   329 
       
   330     layouted.showNormal();
       
   331     QVERIFY(!(layouted.windowState() & Qt::WindowFullScreen));
       
   332 
       
   333 #if !defined(Q_WS_QWS) && !defined(Q_OS_WINCE) && !defined (Q_WS_S60)
       
   334 //embedded may choose a different size to fit on the screen.
       
   335     QCOMPARE(layouted.size(), layouted.sizeHint());
       
   336 #endif
       
   337 
       
   338     layouted.showFullScreen();
       
   339     QVERIFY(layouted.isFullScreen());
       
   340     QVERIFY(layouted.isVisible());
       
   341 
       
   342     layouted.hide();
       
   343     QVERIFY(layouted.isFullScreen());
       
   344     QVERIFY(!layouted.isVisible());
       
   345 
       
   346     layouted.showFullScreen();
       
   347     QVERIFY(layouted.isFullScreen());
       
   348     QVERIFY(layouted.isVisible());
       
   349 
       
   350     layouted.showMinimized();
       
   351     QVERIFY(layouted.isMinimized());
       
   352     QVERIFY(layouted.isFullScreen());
       
   353 
       
   354     layouted.showFullScreen();
       
   355     QVERIFY(!layouted.isMinimized());
       
   356     QVERIFY(layouted.isFullScreen());
       
   357     QVERIFY(layouted.isVisible());
       
   358 
       
   359     layouted.showMinimized();
       
   360     QVERIFY(layouted.isMinimized());
       
   361     QVERIFY(layouted.isFullScreen());
       
   362 
       
   363     layouted.showFullScreen();
       
   364     QVERIFY(!layouted.isMinimized());
       
   365     QVERIFY(layouted.isFullScreen());
       
   366     QVERIFY(layouted.isVisible());
       
   367 
       
   368     {
       
   369         QWidget frame;
       
   370         QWidget widget(&frame);
       
   371         widget.showFullScreen();
       
   372         QVERIFY(widget.isFullScreen());
       
   373     }
       
   374 
       
   375 #ifdef QT3_SUPPORT
       
   376 #if !defined(Q_WS_QWS)
       
   377 //embedded respects max/min sizes by design -- maybe wrong design, but that's the way it is now.
       
   378     {
       
   379         Q3HBox box;
       
   380         QWidget widget(&box);
       
   381         widget.setMinimumSize(500, 500);
       
   382         box.showFullScreen();
       
   383         QVERIFY(box.isFullScreen());
       
   384     }
       
   385 
       
   386     {
       
   387         Q3HBox box;
       
   388         QWidget widget(&box);
       
   389         widget.setMaximumSize(500, 500);
       
   390 
       
   391         box.showFullScreen();
       
   392         QVERIFY(box.isFullScreen());
       
   393     }
       
   394 #endif
       
   395 #endif // QT3_SUPPORT
       
   396 }
       
   397 
       
   398 QTEST_MAIN(tst_QWidget)
       
   399 #include "smoke_qwidget.moc"