| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> | 
|---|
| 2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/examples/tabdialog/tabdialog.doc:4 --> | 
|---|
| 3 | <html> | 
|---|
| 4 | <head> | 
|---|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | 
|---|
| 6 | <title>Tabdialog</title> | 
|---|
| 7 | <style type="text/css"><!-- | 
|---|
| 8 | fn { margin-left: 1cm; text-indent: -1cm; } | 
|---|
| 9 | a:link { color: #004faf; text-decoration: none } | 
|---|
| 10 | a:visited { color: #672967; text-decoration: none } | 
|---|
| 11 | body { background: #ffffff; color: black; } | 
|---|
| 12 | --></style> | 
|---|
| 13 | </head> | 
|---|
| 14 | <body> | 
|---|
| 15 |  | 
|---|
| 16 | <table border="0" cellpadding="0" cellspacing="0" width="100%"> | 
|---|
| 17 | <tr bgcolor="#E5E5E5"> | 
|---|
| 18 | <td valign=center> | 
|---|
| 19 | <a href="index.html"> | 
|---|
| 20 | <font color="#004faf">Home</font></a> | 
|---|
| 21 | | <a href="classes.html"> | 
|---|
| 22 | <font color="#004faf">All Classes</font></a> | 
|---|
| 23 | | <a href="mainclasses.html"> | 
|---|
| 24 | <font color="#004faf">Main Classes</font></a> | 
|---|
| 25 | | <a href="annotated.html"> | 
|---|
| 26 | <font color="#004faf">Annotated</font></a> | 
|---|
| 27 | | <a href="groups.html"> | 
|---|
| 28 | <font color="#004faf">Grouped Classes</font></a> | 
|---|
| 29 | | <a href="functions.html"> | 
|---|
| 30 | <font color="#004faf">Functions</font></a> | 
|---|
| 31 | </td> | 
|---|
| 32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Tabdialog</h1> | 
|---|
| 33 |  | 
|---|
| 34 |  | 
|---|
| 35 | <p> | 
|---|
| 36 | This example shows how to use a dialog with multiple tabs | 
|---|
| 37 | (pages). To start the program you have to specify a filename | 
|---|
| 38 | as the first argument. The dialog shows information about the | 
|---|
| 39 | file separated onto different tabs. | 
|---|
| 40 | <p> <hr> | 
|---|
| 41 | <p> Header file: | 
|---|
| 42 | <p> <pre>/**************************************************************************** | 
|---|
| 43 | ** $Id: tabdialog-example.html 2051 2007-02-21 10:04:20Z chehrlic $ | 
|---|
| 44 | ** | 
|---|
| 45 | ** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved. | 
|---|
| 46 | ** | 
|---|
| 47 | ** This file is part of an example program for Qt.  This example | 
|---|
| 48 | ** program may be used, distributed and modified without limitation. | 
|---|
| 49 | ** | 
|---|
| 50 | *****************************************************************************/ | 
|---|
| 51 |  | 
|---|
| 52 | #ifndef TABDIALOG_H | 
|---|
| 53 | #define TABDIALOG_H | 
|---|
| 54 |  | 
|---|
| 55 | #include <<a href="qtabdialog-h.html">qtabdialog.h</a>> | 
|---|
| 56 | #include <<a href="qstring-h.html">qstring.h</a>> | 
|---|
| 57 | #include <<a href="qfileinfo-h.html">qfileinfo.h</a>> | 
|---|
| 58 |  | 
|---|
| 59 | class TabDialog : public <a href="qtabdialog.html">QTabDialog</a> | 
|---|
| 60 | { | 
|---|
| 61 | <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a> | 
|---|
| 62 |  | 
|---|
| 63 | public: | 
|---|
| 64 | TabDialog( <a href="qwidget.html">QWidget</a> *parent, const char *name, const <a href="qstring.html">QString</a> &_filename ); | 
|---|
| 65 |  | 
|---|
| 66 | protected: | 
|---|
| 67 | <a href="qstring.html">QString</a> filename; | 
|---|
| 68 | <a href="qfileinfo.html">QFileInfo</a> fileinfo; | 
|---|
| 69 |  | 
|---|
| 70 | void setupTab1(); | 
|---|
| 71 | void setupTab2(); | 
|---|
| 72 | void setupTab3(); | 
|---|
| 73 |  | 
|---|
| 74 | }; | 
|---|
| 75 |  | 
|---|
| 76 | #endif | 
|---|
| 77 | </pre> | 
|---|
| 78 |  | 
|---|
| 79 | <p> <hr> | 
|---|
| 80 | <p> Implementation: | 
|---|
| 81 | <p> <pre>/**************************************************************************** | 
|---|
| 82 | ** $Id: tabdialog-example.html 2051 2007-02-21 10:04:20Z chehrlic $ | 
|---|
| 83 | ** | 
|---|
| 84 | ** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved. | 
|---|
| 85 | ** | 
|---|
| 86 | ** This file is part of an example program for Qt.  This example | 
|---|
| 87 | ** program may be used, distributed and modified without limitation. | 
|---|
| 88 | ** | 
|---|
| 89 | *****************************************************************************/ | 
|---|
| 90 |  | 
|---|
| 91 | #include "tabdialog.h" | 
|---|
| 92 |  | 
|---|
| 93 | #include <<a href="qvbox-h.html">qvbox.h</a>> | 
|---|
| 94 | #include <<a href="qlabel-h.html">qlabel.h</a>> | 
|---|
| 95 | #include <<a href="qlineedit-h.html">qlineedit.h</a>> | 
|---|
| 96 | #include <<a href="qdatetime-h.html">qdatetime.h</a>> | 
|---|
| 97 | #include <<a href="qbuttongroup-h.html">qbuttongroup.h</a>> | 
|---|
| 98 | #include <<a href="qcheckbox-h.html">qcheckbox.h</a>> | 
|---|
| 99 | #include <<a href="qlistbox-h.html">qlistbox.h</a>> | 
|---|
| 100 | #include <<a href="qapplication-h.html">qapplication.h</a>> | 
|---|
| 101 |  | 
|---|
| 102 | <a name="f200"></a>TabDialog::TabDialog( <a href="qwidget.html">QWidget</a> *parent, const char *name, const <a href="qstring.html">QString</a> &_filename ) | 
|---|
| 103 | : <a href="qtabdialog.html">QTabDialog</a>( parent, name ), filename( _filename ), fileinfo( filename ) | 
|---|
| 104 | { | 
|---|
| 105 | setupTab1(); | 
|---|
| 106 | setupTab2(); | 
|---|
| 107 | setupTab3(); | 
|---|
| 108 |  | 
|---|
| 109 | <a href="qobject.html#connect">connect</a>( this, SIGNAL( <a href="qtabdialog.html#applyButtonPressed">applyButtonPressed</a>() ), qApp, SLOT( <a href="qapplication.html#quit">quit</a>() ) ); | 
|---|
| 110 | } | 
|---|
| 111 |  | 
|---|
| 112 | void <a name="f201"></a>TabDialog::setupTab1() | 
|---|
| 113 | { | 
|---|
| 114 | <a href="qvbox.html">QVBox</a> *tab1 = new <a href="qvbox.html">QVBox</a>( this ); | 
|---|
| 115 | <a name="x53"></a>    tab1-><a href="qframe.html#setMargin">setMargin</a>( 5 ); | 
|---|
| 116 |  | 
|---|
| 117 | (void)new <a href="qlabel.html">QLabel</a>( "Filename:", tab1 ); | 
|---|
| 118 | <a href="qlineedit.html">QLineEdit</a> *fname = new <a href="qlineedit.html">QLineEdit</a>( filename, tab1 ); | 
|---|
| 119 | fname-><a href="qwidget.html#setFocus">setFocus</a>(); | 
|---|
| 120 |  | 
|---|
| 121 | (void)new <a href="qlabel.html">QLabel</a>( "Path:", tab1 ); | 
|---|
| 122 | <a href="qlabel.html">QLabel</a> *path = new <a href="qlabel.html">QLabel</a>( fileinfo.dirPath( TRUE ), tab1 ); | 
|---|
| 123 | <a name="x52"></a>    path-><a href="qframe.html#setFrameStyle">setFrameStyle</a>( QFrame::Panel | QFrame::Sunken ); | 
|---|
| 124 |  | 
|---|
| 125 | (void)new <a href="qlabel.html">QLabel</a>( "Size:", tab1 ); | 
|---|
| 126 | ulong kb = (ulong)(fileinfo.size()/1024); | 
|---|
| 127 | <a href="qlabel.html">QLabel</a> *size = new <a href="qlabel.html">QLabel</a>( QString( "%1 KB" ).arg( kb ), tab1 ); | 
|---|
| 128 | size-><a href="qframe.html#setFrameStyle">setFrameStyle</a>( QFrame::Panel | QFrame::Sunken ); | 
|---|
| 129 |  | 
|---|
| 130 | (void)new <a href="qlabel.html">QLabel</a>( "Last Read:", tab1 ); | 
|---|
| 131 | <a href="qlabel.html">QLabel</a> *lread = new <a href="qlabel.html">QLabel</a>( fileinfo.lastRead().toString(), tab1 ); | 
|---|
| 132 | lread-><a href="qframe.html#setFrameStyle">setFrameStyle</a>( QFrame::Panel | QFrame::Sunken ); | 
|---|
| 133 |  | 
|---|
| 134 | (void)new <a href="qlabel.html">QLabel</a>( "Last Modified:", tab1 ); | 
|---|
| 135 | <a href="qlabel.html">QLabel</a> *lmodif = new <a href="qlabel.html">QLabel</a>( fileinfo.lastModified().toString(), tab1 ); | 
|---|
| 136 | lmodif-><a href="qframe.html#setFrameStyle">setFrameStyle</a>( QFrame::Panel | QFrame::Sunken ); | 
|---|
| 137 |  | 
|---|
| 138 | <a href="qtabdialog.html#addTab">addTab</a>( tab1, "General" ); | 
|---|
| 139 | } | 
|---|
| 140 |  | 
|---|
| 141 | void <a name="f202"></a>TabDialog::setupTab2() | 
|---|
| 142 | { | 
|---|
| 143 | <a href="qvbox.html">QVBox</a> *tab2 = new <a href="qvbox.html">QVBox</a>( this ); | 
|---|
| 144 | tab2-><a href="qframe.html#setMargin">setMargin</a>( 5 ); | 
|---|
| 145 |  | 
|---|
| 146 | <a href="qbuttongroup.html">QButtonGroup</a> *bg = new <a href="qbuttongroup.html">QButtonGroup</a>( 1, QGroupBox::Horizontal, "Permissions", tab2 ); | 
|---|
| 147 |  | 
|---|
| 148 | <a href="qcheckbox.html">QCheckBox</a> *readable = new <a href="qcheckbox.html">QCheckBox</a>( "Readable", bg ); | 
|---|
| 149 | if ( fileinfo.isReadable() ) | 
|---|
| 150 | <a name="x51"></a>        readable-><a href="qcheckbox.html#setChecked">setChecked</a>( TRUE ); | 
|---|
| 151 |  | 
|---|
| 152 | <a href="qcheckbox.html">QCheckBox</a> *writable = new <a href="qcheckbox.html">QCheckBox</a>( "Writeable", bg ); | 
|---|
| 153 | if ( fileinfo.isWritable() ) | 
|---|
| 154 | writable-><a href="qcheckbox.html#setChecked">setChecked</a>( TRUE ); | 
|---|
| 155 |  | 
|---|
| 156 | <a href="qcheckbox.html">QCheckBox</a> *executable = new <a href="qcheckbox.html">QCheckBox</a>( "Executable", bg ); | 
|---|
| 157 | if ( fileinfo.isExecutable() ) | 
|---|
| 158 | executable-><a href="qcheckbox.html#setChecked">setChecked</a>( TRUE ); | 
|---|
| 159 |  | 
|---|
| 160 | <a href="qbuttongroup.html">QButtonGroup</a> *bg2 = new <a href="qbuttongroup.html">QButtonGroup</a>( 2, QGroupBox::Horizontal, "Owner", tab2 ); | 
|---|
| 161 |  | 
|---|
| 162 | (void)new <a href="qlabel.html">QLabel</a>( "Owner", bg2 ); | 
|---|
| 163 | <a href="qlabel.html">QLabel</a> *owner = new <a href="qlabel.html">QLabel</a>( fileinfo.owner(), bg2 ); | 
|---|
| 164 | owner-><a href="qframe.html#setFrameStyle">setFrameStyle</a>( QFrame::Panel | QFrame::Sunken ); | 
|---|
| 165 |  | 
|---|
| 166 | (void)new <a href="qlabel.html">QLabel</a>( "Group", bg2 ); | 
|---|
| 167 | <a href="qlabel.html">QLabel</a> *group = new <a href="qlabel.html">QLabel</a>( fileinfo.group(), bg2 ); | 
|---|
| 168 | group-><a href="qframe.html#setFrameStyle">setFrameStyle</a>( QFrame::Panel | QFrame::Sunken ); | 
|---|
| 169 |  | 
|---|
| 170 | <a href="qtabdialog.html#addTab">addTab</a>( tab2, "Permissions" ); | 
|---|
| 171 | } | 
|---|
| 172 |  | 
|---|
| 173 | void <a name="f203"></a>TabDialog::setupTab3() | 
|---|
| 174 | { | 
|---|
| 175 | <a href="qvbox.html">QVBox</a> *tab3 = new <a href="qvbox.html">QVBox</a>( this ); | 
|---|
| 176 | tab3-><a href="qframe.html#setMargin">setMargin</a>( 5 ); | 
|---|
| 177 | <a name="x54"></a>    tab3-><a href="qhbox.html#setSpacing">setSpacing</a>( 5 ); | 
|---|
| 178 |  | 
|---|
| 179 | (void)new <a href="qlabel.html">QLabel</a>( QString( "Open %1 with:" ).arg( filename ), tab3 ); | 
|---|
| 180 |  | 
|---|
| 181 | <a href="qlistbox.html">QListBox</a> *prgs = new <a href="qlistbox.html">QListBox</a>( tab3 ); | 
|---|
| 182 | for ( unsigned int i = 0; i < 30; i++ ) { | 
|---|
| 183 | <a href="qstring.html">QString</a> prg = QString( "Application %1" ).arg( i ); | 
|---|
| 184 | <a name="x55"></a>        prgs-><a href="qlistbox.html#insertItem">insertItem</a>( prg ); | 
|---|
| 185 | } | 
|---|
| 186 | <a name="x56"></a>    prgs-><a href="qlistbox.html#setCurrentItem">setCurrentItem</a>( 3 ); | 
|---|
| 187 |  | 
|---|
| 188 | (void)new <a href="qcheckbox.html">QCheckBox</a>( QString( "Open files with the extension '%1' always with this application" ).arg( fileinfo.extension() ), tab3 ); | 
|---|
| 189 |  | 
|---|
| 190 | <a href="qtabdialog.html#addTab">addTab</a>( tab3, "Applications" ); | 
|---|
| 191 | } | 
|---|
| 192 | </pre> | 
|---|
| 193 |  | 
|---|
| 194 | <p> <hr> | 
|---|
| 195 | <p> Main: | 
|---|
| 196 | <p> <pre>/**************************************************************************** | 
|---|
| 197 | ** $Id: tabdialog-example.html 2051 2007-02-21 10:04:20Z chehrlic $ | 
|---|
| 198 | ** | 
|---|
| 199 | ** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved. | 
|---|
| 200 | ** | 
|---|
| 201 | ** This file is part of an example program for Qt.  This example | 
|---|
| 202 | ** program may be used, distributed and modified without limitation. | 
|---|
| 203 | ** | 
|---|
| 204 | *****************************************************************************/ | 
|---|
| 205 |  | 
|---|
| 206 | #include "tabdialog.h" | 
|---|
| 207 | #include <<a href="qapplication-h.html">qapplication.h</a>> | 
|---|
| 208 | #include <<a href="qstring-h.html">qstring.h</a>> | 
|---|
| 209 |  | 
|---|
| 210 | int main( int argc, char **argv ) | 
|---|
| 211 | { | 
|---|
| 212 |  | 
|---|
| 213 | <a href="qapplication.html">QApplication</a> a( argc, argv ); | 
|---|
| 214 |  | 
|---|
| 215 | TabDialog tabdialog( 0, "tabdialog", QString( argc < 2 ? "." : argv[1] ) ); | 
|---|
| 216 | <a name="x60"></a>    tabdialog.<a href="qwidget.html#resize">resize</a>( 450, 350 ); | 
|---|
| 217 | tabdialog.<a href="qwidget.html#setCaption">setCaption</a>( "Qt Example - Tabbed Dialog" ); | 
|---|
| 218 | a.<a href="qapplication.html#setMainWidget">setMainWidget</a>( &tabdialog ); | 
|---|
| 219 | <a name="x61"></a>    tabdialog.<a href="qdialog.html#show">show</a>(); | 
|---|
| 220 |  | 
|---|
| 221 | return a.<a href="qapplication.html#exec">exec</a>(); | 
|---|
| 222 | } | 
|---|
| 223 | </pre> | 
|---|
| 224 |  | 
|---|
| 225 | <p>See also <a href="examples.html">Examples</a>. | 
|---|
| 226 |  | 
|---|
| 227 | <!-- eof --> | 
|---|
| 228 | <p><address><hr><div align=center> | 
|---|
| 229 | <table width=100% cellspacing=0 border=0><tr> | 
|---|
| 230 | <td>Copyright © 2007 | 
|---|
| 231 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a> | 
|---|
| 232 | <td align=right><div align=right>Qt 3.3.8</div> | 
|---|
| 233 | </table></div></address></body> | 
|---|
| 234 | </html> | 
|---|