summaryrefslogtreecommitdiffstats
path: root/examples/demo/main.cpp
blob: 7be7d248321837034464fd1ca7409f3e85c42a00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
/****************************************************************************
**
** Copyright (C) 1992-2008 Trolltech ASA.  All rights reserved.
**
** This file is part of an example program for TQt.  This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/

#include "frame.h"
#include "graph.h"
#include "display.h"
#include "icons.h"

#include "textdrawing/textedit.h"
#include "textdrawing/helpwindow.h"
#include "dnd/dnd.h"
#include "i18n/i18n.h"

#include <ntqmodules.h>

#if defined(TQT_MODULE_OPENGL)
#include "opengl/glworkspace.h"
#include "opengl/gllandscapeviewer.h"
#include "opengl/glinfotext.h"
#endif

#if defined(TQT_MODULE_CANVAS)
#include "qasteroids/toplevel.h"
#endif

#if defined(TQT_MODULE_TABLE)
#include "widgets/widgetsbase.h"
#else
#include "widgets/widgetsbase_pro.h"
#endif

#include <stdlib.h>

#include <ntqapplication.h>
#include <tqimage.h>

#include <tqtabwidget.h>
#include <tqfont.h>
#include <tqworkspace.h>
#include <tqwidgetstack.h>

#if defined(TQT_MODULE_SQL)
#include <tqsqldatabase.h>
#include "sql/sqlex.h"
#endif

#if defined(Q_OS_MACX)
#include <stdlib.h>
#include <tqdir.h>
#endif

#include "categoryinterface.h"

static void qdemo_set_caption( CategoryInterface *c, int i )
{
    TQWidget *w = tqApp->mainWidget();
    if ( !w )
	return;
    TQString title = Frame::tr( "TQt Demo Collection" );
    title += " - " + c->categoryName( i - c->categoryOffset() );
    w->setCaption( title );
}

class WidgetCategory : public CategoryInterface
{
public:
    WidgetCategory( TQWidgetStack *s ) : CategoryInterface( s ), created( FALSE ) {}

    TQString name() const { return "Widgets"; }
    TQIconSet icon() const { return TQPixmap( widgeticon ); }
    int numCategories() const { return 2; }
    TQString categoryName( int i ) const {
	switch ( i ) {
	case 0:
	    return Frame::tr( "Widgets" );
	    break;
	case 1:
	    return Frame::tr( "Drag and Drop" );
	    break;
	}
	return TQString::null;
    }
    TQIconSet categoryIcon( int ) const { return TQIconSet(); }
    void setCurrentCategory( int i ) {
	create();
	stack->raiseWidget( i );
	qdemo_set_caption( this, i );
    }
    void create() {
	if ( created )
	    return;
	created = TRUE;
	stack->addWidget( new WidgetsBase( stack ), categoryOffset() + 0 );
	stack->addWidget( new DnDDemo( stack ), categoryOffset() + 1 );
    }

    int categoryOffset() const { return 0; }

private:
    bool created;

};

#if defined(TQT_MODULE_SQL)
class DatabaseCategory : public CategoryInterface
{
public:
    DatabaseCategory( TQWidgetStack *s ) : CategoryInterface( s ), created( FALSE ) {}

    TQString name() const { return "Database"; }
    TQIconSet icon() const { return TQPixmap( dbicon ); }
    int numCategories() const { return 1; }
    TQString categoryName( int i ) const {
	switch ( i ) {
	case 0:
	    return Frame::tr( "SQL Explorer" );
	    break;
	}
	return TQString::null;
    }
    TQIconSet categoryIcon( int ) const { return TQIconSet(); }
    void setCurrentCategory( int i ) {
	create();
	stack->raiseWidget( i );
	qdemo_set_caption( this, i );
    }
    void create() {
	if ( created )
	    return;
	created = TRUE;
	stack->addWidget( new SqlEx( stack ), categoryOffset() + 0 );
    }

    int categoryOffset() const { return 10; }

private:
    bool created;

};
#endif

#if defined(TQT_MODULE_CANVAS)
class CanvasCategory : public CategoryInterface
{
public:
    CanvasCategory( TQWidgetStack *s ) : CategoryInterface( s ), created( FALSE ) {}

    TQString name() const { return "2D Graphics"; }
    TQIconSet icon() const { return TQPixmap( twodicon ); }
    int numCategories() const { return 2; }
    TQString categoryName( int i ) const {
	switch ( i ) {
	case 0:
	    return Frame::tr( "Graph Drawing" );
	    break;
	case 1:
	    return Frame::tr( "Display" );
	    break;
	}
	return TQString::null;
    }
    TQIconSet categoryIcon( int ) const { return TQIconSet(); }
    void setCurrentCategory( int i ) {
	create();
	stack->raiseWidget( i );
	qdemo_set_caption( this, i );
    }
    void create() {
	if ( created )
	    return;
	created = TRUE;
	stack->addWidget( new GraphWidget( stack ), categoryOffset() + 0 );
	stack->addWidget( new DisplayWidget( stack ), categoryOffset() + 1 );
    }

    int categoryOffset() const { return 100; }

private:
    bool created;

};
#endif

#if defined(TQT_MODULE_OPENGL)
class OpenGLCategory : public CategoryInterface
{
public:
    OpenGLCategory( TQWidgetStack *s ) : CategoryInterface( s ), created( FALSE ) {}

    TQString name() const { return "3D Graphics"; }
    TQIconSet icon() const { return TQPixmap( threedicon ); }
    int numCategories() const { return 3; }
    TQString categoryName( int i ) const {
	switch ( i ) {
	case 0:
	    return Frame::tr( "3D Demo" );
	    break;
	case 1:
	    return Frame::tr( "Fractal landscape" );
	    break;
	case 2:
	    return Frame::tr( "OpenGL info" );
	    break;
	}
	return TQString::null;
    }
    TQIconSet categoryIcon( int ) const { return TQIconSet(); }
    void setCurrentCategory( int i ) {
	create();
	stack->raiseWidget( i );
	qdemo_set_caption( this, i );
    }
    void create() {
	if ( created )
	    return;
	created = TRUE;
	stack->addWidget( new GLWorkspace( stack ), categoryOffset() + 0 );
	stack->addWidget( new GLLandscapeViewer( stack ), categoryOffset() + 1 );
	stack->addWidget( new GLInfoText( stack ), categoryOffset() + 2 );
    }
    int categoryOffset() const { return 1000; }

private:
    bool created;

};
#endif

class TextCategory : public CategoryInterface
{
public:
    TextCategory( TQWidgetStack *s ) : CategoryInterface( s ), created( FALSE ) {}

    TQString name() const { return "Text Drawing/Editing"; }
    TQIconSet icon() const { return TQPixmap( texticon ); }
    int numCategories() const { return 2; }
    TQString categoryName( int i ) const {
	switch ( i ) {
	case 0:
	    return Frame::tr( "Richtext Editor" );
	    break;
	case 1:
	    return Frame::tr( "Help Browser" );
	    break;
	}
	return TQString::null;
    }
    TQIconSet categoryIcon( int ) const { return TQIconSet(); }
    void setCurrentCategory( int i ) {
	create();
	stack->raiseWidget( i );
	qdemo_set_caption( this, i );
    }
    void create() {
	if ( created )
	    return;
	created = TRUE;
	TextEdit *te = new TextEdit( stack );
	te->load( "textdrawing/example.html" );
	stack->addWidget( te, categoryOffset() + 0 );
	TQString home = TQDir( "../../doc/html/index.html" ).absPath();
	HelpWindow *w = new HelpWindow( home, ".", stack, "helpviewer" );
	stack->addWidget( w, categoryOffset() + 1 );
    }
    int categoryOffset() const { return 10000; }

private:
    bool created;

};

class I18NCategory : public CategoryInterface
{
public:
    I18NCategory( TQWidgetStack *s ) : CategoryInterface( s ), created( FALSE ) {}

    TQString name() const { return "Internationalization"; }
    TQIconSet icon() const { return TQPixmap( internicon ); }
    int numCategories() const { return 1; }
    TQString categoryName( int i ) const {
	switch ( i ) {
	case 0:
	    return Frame::tr( "Internationalization" );
	    break;
	}
	return TQString::null;
    }
    TQIconSet categoryIcon( int ) const { return TQIconSet(); }
    void setCurrentCategory( int i ) {
	create();
	stack->raiseWidget( i );
	qdemo_set_caption( this, i );
    }
    void create() {
	if ( created )
	    return;
	created = TRUE;
	stack->addWidget( new I18nDemo( stack ), categoryOffset() + 0 );
    }
    int categoryOffset() const { return 100000; }

private:
    bool created;

};

#if defined(TQT_MODULE_CANVAS)
class GameCategory : public CategoryInterface
{
public:
    GameCategory( TQWidgetStack *s ) : CategoryInterface( s ), created( FALSE ) {}

    TQString name() const { return "Game"; }
    TQIconSet icon() const { return TQPixmap( joyicon ); }
    int numCategories() const { return 1; }
    TQString categoryName( int i ) const {
	switch ( i ) {
	case 0:
	    return Frame::tr( "Asteroids" );
	    break;
	}
	return TQString::null;
    }
    TQIconSet categoryIcon( int ) const { return TQIconSet(); }
    void setCurrentCategory( int i ) {
	create();
	stack->raiseWidget( i );
	qdemo_set_caption( this, i );
    }
    void create() {
	if ( created )
	    return;
	created = TRUE;
	stack->addWidget( new KAstTopLevel( stack ), categoryOffset() + 0 );
    }
    int categoryOffset() const { return 1000000; }

private:
    bool created;

};
#endif

int main( int argc, char **argv )
{
    TQString category;
    TQApplication a( argc, argv );

    Frame::updateTranslators();
    Frame frame;
    a.setMainWidget( &frame );

    TQPtrList<CategoryInterface> categories;
    categories.append( new WidgetCategory( frame.widgetStack() ) );
#if defined(TQT_MODULE_SQL)
    categories.append( new DatabaseCategory( frame.widgetStack() ) );
#endif
    categories.append( new CanvasCategory( frame.widgetStack() ) );
#if defined(TQT_MODULE_OPENGL)
    categories.append( new OpenGLCategory( frame.widgetStack() ) );
#endif
    categories.append( new TextCategory( frame.widgetStack() ) );
    categories.append( new I18NCategory( frame.widgetStack() ) );
    categories.append( new GameCategory( frame.widgetStack() ) );
    frame.setCategories( categories );

    frame.resize( 1000, 700 );
    frame.show();

    return a.exec();
}