| 1 | /****************************************************************************
|
|---|
| 2 | ** $Id: main.cpp 2 2005-11-16 15:49:26Z dmik $
|
|---|
| 3 | **
|
|---|
| 4 | ** Main for custom layout example
|
|---|
| 5 | **
|
|---|
| 6 | ** Copyright (C) 1996 by Trolltech AS. All rights reserved.
|
|---|
| 7 | **
|
|---|
| 8 | ** This file is part of an example program for Qt. This example
|
|---|
| 9 | ** program may be used, distributed and modified without limitation.
|
|---|
| 10 | **
|
|---|
| 11 | *****************************************************************************/
|
|---|
| 12 |
|
|---|
| 13 | #include "flow.h"
|
|---|
| 14 | #include "border.h"
|
|---|
| 15 | #include "card.h"
|
|---|
| 16 |
|
|---|
| 17 | #include <qapplication.h>
|
|---|
| 18 | #include <qlabel.h>
|
|---|
| 19 | #include <qcolor.h>
|
|---|
| 20 | #include <qgroupbox.h>
|
|---|
| 21 | #include <qpushbutton.h>
|
|---|
| 22 | #include <qmultilineedit.h>
|
|---|
| 23 | #include <qcolor.h>
|
|---|
| 24 |
|
|---|
| 25 | int main( int argc, char **argv )
|
|---|
| 26 | {
|
|---|
| 27 | QApplication a( argc, argv );
|
|---|
| 28 |
|
|---|
| 29 | QWidget *f = new QWidget;
|
|---|
| 30 | QBoxLayout *gm = new QVBoxLayout( f, 5 );
|
|---|
| 31 |
|
|---|
| 32 | SimpleFlow *b1 = new SimpleFlow( gm );
|
|---|
| 33 |
|
|---|
| 34 | b1->add( new QPushButton( "Short", f ) );
|
|---|
| 35 | b1->add( new QPushButton( "Longer", f ) );
|
|---|
| 36 | b1->add( new QPushButton( "Different text", f ) );
|
|---|
| 37 | b1->add( new QPushButton( "More text", f ) );
|
|---|
| 38 | b1->add( new QPushButton( "Even longer button text", f ) );
|
|---|
| 39 | QPushButton* qb = new QPushButton( "Quit", f );
|
|---|
| 40 | a.connect( qb, SIGNAL( clicked() ), SLOT( quit() ) );
|
|---|
| 41 | b1->add( qb );
|
|---|
| 42 |
|
|---|
| 43 | QWidget *wid = new QWidget( f );
|
|---|
| 44 |
|
|---|
| 45 | BorderLayout *large = new BorderLayout( wid );
|
|---|
| 46 | large->setSpacing( 5 );
|
|---|
| 47 | large->addWidget( new QPushButton( "North", wid ), BorderLayout::North );
|
|---|
| 48 | large->addWidget( new QPushButton( "West", wid ), BorderLayout::West );
|
|---|
| 49 | QMultiLineEdit* m = new QMultiLineEdit( wid );
|
|---|
| 50 | m->setText( "Central\nWidget" );
|
|---|
| 51 | large->addWidget( m, BorderLayout::Center );
|
|---|
| 52 | QWidget *east1 = new QPushButton( "East", wid );
|
|---|
| 53 | large->addWidget( east1, BorderLayout::East );
|
|---|
| 54 | QWidget *east2 = new QPushButton( "East 2", wid );
|
|---|
| 55 | large->addWidget( east2 , BorderLayout::East );
|
|---|
| 56 | large->addWidget( new QPushButton( "South", wid ), BorderLayout::South );
|
|---|
| 57 | //Left-to-right tab order looks better:
|
|---|
| 58 | QWidget::setTabOrder( east2, east1 );
|
|---|
| 59 | gm->addWidget( wid );
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 | wid = new QWidget( f );
|
|---|
| 63 | CardLayout *card = new CardLayout( wid, 10 );
|
|---|
| 64 |
|
|---|
| 65 | QWidget *crd = new QWidget( wid );
|
|---|
| 66 | crd->setBackgroundColor( Qt::red );
|
|---|
| 67 | card->add( crd );
|
|---|
| 68 | crd = new QWidget( wid );
|
|---|
| 69 | crd->setBackgroundColor( Qt::green );
|
|---|
| 70 | card->add( crd );
|
|---|
| 71 | crd = new QWidget( wid );
|
|---|
| 72 | crd->setBackgroundColor( Qt::blue );
|
|---|
| 73 | card->add( crd );
|
|---|
| 74 | crd = new QWidget( wid );
|
|---|
| 75 | crd->setBackgroundColor( Qt::white );
|
|---|
| 76 | card->add( crd );
|
|---|
| 77 | crd = new QWidget( wid );
|
|---|
| 78 | crd->setBackgroundColor( Qt::black );
|
|---|
| 79 | card->add( crd );
|
|---|
| 80 | crd = new QWidget( wid );
|
|---|
| 81 | crd->setBackgroundColor( Qt::yellow );
|
|---|
| 82 | card->add( crd );
|
|---|
| 83 |
|
|---|
| 84 | gm->addWidget( wid );
|
|---|
| 85 |
|
|---|
| 86 | QLabel* s = new QLabel( f );
|
|---|
| 87 | s->setText( "outermost box" );
|
|---|
| 88 | s->setFrameStyle( QFrame::Panel | QFrame::Sunken );
|
|---|
| 89 | s->setAlignment( Qt::AlignVCenter | Qt::AlignHCenter );
|
|---|
| 90 | gm->addWidget( s );
|
|---|
| 91 | a.setMainWidget( f );
|
|---|
| 92 | f->setCaption("Qt Example - Custom Layout");
|
|---|
| 93 | f->show();
|
|---|
| 94 |
|
|---|
| 95 | int result = a.exec();
|
|---|
| 96 | delete f;
|
|---|
| 97 | return result;
|
|---|
| 98 | }
|
|---|