source: trunk/examples/demo/main.cpp@ 203

Last change on this file since 203 was 160, checked in by dmik, 19 years ago

Imported table and iconview modules and a bunch of dependent examples from the official release 3.3.1 from Trolltech.

  • Property svn:keywords set to Id
File size: 9.4 KB
Line 
1/****************************************************************************
2** $Id: main.cpp 160 2006-12-11 20:15:57Z dmik $
3**
4** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
5**
6** This file is part of an example program for Qt. This example
7** program may be used, distributed and modified without limitation.
8**
9*****************************************************************************/
10
11#include "frame.h"
12#include "graph.h"
13#include "display.h"
14#include "icons.h"
15
16#include "textdrawing/textedit.h"
17#include "textdrawing/helpwindow.h"
18#include "dnd/dnd.h"
19#include "i18n/i18n.h"
20
21#include <qmodules.h>
22
23#if defined(QT_MODULE_OPENGL)
24#include "opengl/glworkspace.h"
25#include "opengl/gllandscapeviewer.h"
26#include "opengl/glinfotext.h"
27#endif
28
29#if defined(QT_MODULE_CANVAS)
30#include "qasteroids/toplevel.h"
31#endif
32
33#if defined(QT_MODULE_TABLE)
34#include "widgets/widgetsbase.h"
35#else
36#include "widgets/widgetsbase_pro.h"
37#endif
38
39#include <stdlib.h>
40
41#include <qapplication.h>
42#include <qimage.h>
43
44#include <qtabwidget.h>
45#include <qfont.h>
46#include <qworkspace.h>
47#include <qwidgetstack.h>
48
49#if defined(QT_MODULE_SQL)
50#include <qsqldatabase.h>
51#include "sql/sqlex.h"
52#endif
53
54#if defined(Q_OS_MACX)
55#include <stdlib.h>
56#include <qdir.h>
57#endif
58
59#include "categoryinterface.h"
60
61static void qdemo_set_caption( CategoryInterface *c, int i )
62{
63 QWidget *w = qApp->mainWidget();
64 if ( !w )
65 return;
66 QString title = Frame::tr( "Qt Demo Collection" );
67 title += " - " + c->categoryName( i - c->categoryOffset() );
68 w->setCaption( title );
69}
70
71class WidgetCategory : public CategoryInterface
72{
73public:
74 WidgetCategory( QWidgetStack *s ) : CategoryInterface( s ), created( FALSE ) {}
75
76 QString name() const { return "Widgets"; }
77 QIconSet icon() const { return QPixmap( widgeticon ); }
78 int numCategories() const { return 2; }
79 QString categoryName( int i ) const {
80 switch ( i ) {
81 case 0:
82 return Frame::tr( "Widgets" );
83 break;
84 case 1:
85 return Frame::tr( "Drag and Drop" );
86 break;
87 }
88 return QString::null;
89 }
90 QIconSet categoryIcon( int ) const { return QIconSet(); }
91 void setCurrentCategory( int i ) {
92 create();
93 stack->raiseWidget( i );
94 qdemo_set_caption( this, i );
95 }
96 void create() {
97 if ( created )
98 return;
99 created = TRUE;
100 stack->addWidget( new WidgetsBase( stack ), categoryOffset() + 0 );
101 stack->addWidget( new DnDDemo( stack ), categoryOffset() + 1 );
102 }
103
104 int categoryOffset() const { return 0; }
105
106private:
107 bool created;
108
109};
110
111#if defined(QT_MODULE_SQL)
112class DatabaseCategory : public CategoryInterface
113{
114public:
115 DatabaseCategory( QWidgetStack *s ) : CategoryInterface( s ), created( FALSE ) {}
116
117 QString name() const { return "Database"; }
118 QIconSet icon() const { return QPixmap( dbicon ); }
119 int numCategories() const { return 1; }
120 QString categoryName( int i ) const {
121 switch ( i ) {
122 case 0:
123 return Frame::tr( "SQL Explorer" );
124 break;
125 }
126 return QString::null;
127 }
128 QIconSet categoryIcon( int ) const { return QIconSet(); }
129 void setCurrentCategory( int i ) {
130 create();
131 stack->raiseWidget( i );
132 qdemo_set_caption( this, i );
133 }
134 void create() {
135 if ( created )
136 return;
137 created = TRUE;
138 stack->addWidget( new SqlEx( stack ), categoryOffset() + 0 );
139 }
140
141 int categoryOffset() const { return 10; }
142
143private:
144 bool created;
145
146};
147#endif
148
149#if defined(QT_MODULE_CANVAS)
150class CanvasCategory : public CategoryInterface
151{
152public:
153 CanvasCategory( QWidgetStack *s ) : CategoryInterface( s ), created( FALSE ) {}
154
155 QString name() const { return "2D Graphics"; }
156 QIconSet icon() const { return QPixmap( twodicon ); }
157 int numCategories() const { return 2; }
158 QString categoryName( int i ) const {
159 switch ( i ) {
160 case 0:
161 return Frame::tr( "Graph Drawing" );
162 break;
163 case 1:
164 return Frame::tr( "Display" );
165 break;
166 }
167 return QString::null;
168 }
169 QIconSet categoryIcon( int ) const { return QIconSet(); }
170 void setCurrentCategory( int i ) {
171 create();
172 stack->raiseWidget( i );
173 qdemo_set_caption( this, i );
174 }
175 void create() {
176 if ( created )
177 return;
178 created = TRUE;
179 stack->addWidget( new GraphWidget( stack ), categoryOffset() + 0 );
180 stack->addWidget( new DisplayWidget( stack ), categoryOffset() + 1 );
181 }
182
183 int categoryOffset() const { return 100; }
184
185private:
186 bool created;
187
188};
189#endif
190
191#if defined(QT_MODULE_OPENGL)
192class OpenGLCategory : public CategoryInterface
193{
194public:
195 OpenGLCategory( QWidgetStack *s ) : CategoryInterface( s ), created( FALSE ) {}
196
197 QString name() const { return "3D Graphics"; }
198 QIconSet icon() const { return QPixmap( threedicon ); }
199 int numCategories() const { return 3; }
200 QString categoryName( int i ) const {
201 switch ( i ) {
202 case 0:
203 return Frame::tr( "3D Demo" );
204 break;
205 case 1:
206 return Frame::tr( "Fractal landscape" );
207 break;
208 case 2:
209 return Frame::tr( "OpenGL info" );
210 break;
211 }
212 return QString::null;
213 }
214 QIconSet categoryIcon( int ) const { return QIconSet(); }
215 void setCurrentCategory( int i ) {
216 create();
217 stack->raiseWidget( i );
218 qdemo_set_caption( this, i );
219 }
220 void create() {
221 if ( created )
222 return;
223 created = TRUE;
224 stack->addWidget( new GLWorkspace( stack ), categoryOffset() + 0 );
225 stack->addWidget( new GLLandscapeViewer( stack ), categoryOffset() + 1 );
226 stack->addWidget( new GLInfoText( stack ), categoryOffset() + 2 );
227 }
228 int categoryOffset() const { return 1000; }
229
230private:
231 bool created;
232
233};
234#endif
235
236class TextCategory : public CategoryInterface
237{
238public:
239 TextCategory( QWidgetStack *s ) : CategoryInterface( s ), created( FALSE ) {}
240
241 QString name() const { return "Text Drawing/Editing"; }
242 QIconSet icon() const { return QPixmap( texticon ); }
243 int numCategories() const { return 2; }
244 QString categoryName( int i ) const {
245 switch ( i ) {
246 case 0:
247 return Frame::tr( "Richtext Editor" );
248 break;
249 case 1:
250 return Frame::tr( "Help Browser" );
251 break;
252 }
253 return QString::null;
254 }
255 QIconSet categoryIcon( int ) const { return QIconSet(); }
256 void setCurrentCategory( int i ) {
257 create();
258 stack->raiseWidget( i );
259 qdemo_set_caption( this, i );
260 }
261 void create() {
262 if ( created )
263 return;
264 created = TRUE;
265 TextEdit *te = new TextEdit( stack );
266 te->load( "textdrawing/example.html" );
267 stack->addWidget( te, categoryOffset() + 0 );
268 QString home = QDir( "../../doc/html/index.html" ).absPath();
269 HelpWindow *w = new HelpWindow( home, ".", stack, "helpviewer" );
270 stack->addWidget( w, categoryOffset() + 1 );
271 }
272 int categoryOffset() const { return 10000; }
273
274private:
275 bool created;
276
277};
278
279class I18NCategory : public CategoryInterface
280{
281public:
282 I18NCategory( QWidgetStack *s ) : CategoryInterface( s ), created( FALSE ) {}
283
284 QString name() const { return "Internationalization"; }
285 QIconSet icon() const { return QPixmap( internicon ); }
286 int numCategories() const { return 1; }
287 QString categoryName( int i ) const {
288 switch ( i ) {
289 case 0:
290 return Frame::tr( "Internationalization" );
291 break;
292 }
293 return QString::null;
294 }
295 QIconSet categoryIcon( int ) const { return QIconSet(); }
296 void setCurrentCategory( int i ) {
297 create();
298 stack->raiseWidget( i );
299 qdemo_set_caption( this, i );
300 }
301 void create() {
302 if ( created )
303 return;
304 created = TRUE;
305 stack->addWidget( new I18nDemo( stack ), categoryOffset() + 0 );
306 }
307 int categoryOffset() const { return 100000; }
308
309private:
310 bool created;
311
312};
313
314#if defined(QT_MODULE_CANVAS)
315class GameCategory : public CategoryInterface
316{
317public:
318 GameCategory( QWidgetStack *s ) : CategoryInterface( s ), created( FALSE ) {}
319
320 QString name() const { return "Game"; }
321 QIconSet icon() const { return QPixmap( joyicon ); }
322 int numCategories() const { return 1; }
323 QString categoryName( int i ) const {
324 switch ( i ) {
325 case 0:
326 return Frame::tr( "Asteroids" );
327 break;
328 }
329 return QString::null;
330 }
331 QIconSet categoryIcon( int ) const { return QIconSet(); }
332 void setCurrentCategory( int i ) {
333 create();
334 stack->raiseWidget( i );
335 qdemo_set_caption( this, i );
336 }
337 void create() {
338 if ( created )
339 return;
340 created = TRUE;
341 stack->addWidget( new KAstTopLevel( stack ), categoryOffset() + 0 );
342 }
343 int categoryOffset() const { return 1000000; }
344
345private:
346 bool created;
347
348};
349#endif
350
351int main( int argc, char **argv )
352{
353 QString category;
354 QApplication a( argc, argv );
355
356 Frame::updateTranslators();
357 Frame frame;
358 a.setMainWidget( &frame );
359
360 QPtrList<CategoryInterface> categories;
361 categories.append( new WidgetCategory( frame.widgetStack() ) );
362#if defined(QT_MODULE_SQL)
363 categories.append( new DatabaseCategory( frame.widgetStack() ) );
364#endif
365 categories.append( new CanvasCategory( frame.widgetStack() ) );
366#if defined(QT_MODULE_OPENGL)
367 categories.append( new OpenGLCategory( frame.widgetStack() ) );
368#endif
369 categories.append( new TextCategory( frame.widgetStack() ) );
370 categories.append( new I18NCategory( frame.widgetStack() ) );
371 categories.append( new GameCategory( frame.widgetStack() ) );
372 frame.setCategories( categories );
373
374 frame.resize( 1000, 700 );
375 frame.show();
376
377 return a.exec();
378}
Note: See TracBrowser for help on using the repository browser.