diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 90825e2392b2d70e43c7a25b8a3752299a933894 (patch) | |
tree | e33aa27f02b74604afbfd0ea4f1cfca8833d882a /kjsembed/docs/examples/qdocviewer/qdocviewer.js | |
download | tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.tar.gz tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebindings@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kjsembed/docs/examples/qdocviewer/qdocviewer.js')
-rw-r--r-- | kjsembed/docs/examples/qdocviewer/qdocviewer.js | 201 |
1 files changed, 201 insertions, 0 deletions
diff --git a/kjsembed/docs/examples/qdocviewer/qdocviewer.js b/kjsembed/docs/examples/qdocviewer/qdocviewer.js new file mode 100644 index 00000000..41ae2835 --- /dev/null +++ b/kjsembed/docs/examples/qdocviewer/qdocviewer.js @@ -0,0 +1,201 @@ +#!/usr/bin/env qjscmd +// Populates the sidebar listview +function setup_sidebar( special, qt, all ) +{ + var qobjects = Factory.constructors().sort(); + + for ( var i=0; i < qobjects.length ; i++ ) { + all.insertItem( qobjects[i] ); + + if ( /^Q/.test(qobjects[i]) ) + qt.insertItem( qobjects[i] ); + else + special.insertItem( qobjects[i] ); + } +} + +function documentStaticObject( type ) +{ + HelpPage.text ="<h1>" + type + "</h1><HR>"; + try{ + var obj = eval( type ); + HelpPage.text += dump(obj); + } + catch (error) + { + HelpPage.text += "This object is not supported by this version of KJSEmbed"; + } +} + +function documentConstructableObject( type ) +{ + HelpPage.text ="<h1>" + type + "</h1><HR>"; + if ( type!= 'TextStream' ) + { + try { + HelpPage.text += dump(Factory.createObject( type )); + } + catch(x) { + HelpPage.text +='Bindings for the ' + type + ' class.<br /> This class is understood by the interpreter, but cannot be created from scripts.' + } + } +} + +function populateStaticObjects() +{ + StaticObjectList.clear(); + var statics = [ 'Factory', 'System', 'Global', 'StdDialog', + 'StdAction', 'StdDirs', 'StdIcons', 'Qt' ]; + for ( var idx = 0; idx < statics.length; idx++ ) + { + StaticObjectList.insertItem(statics[idx]); + } +} + +function populateExceptions() +{ + var expts = [ 'ReferenceError', 'EvalError', 'RangeError', 'TypeError' ]; + for ( var idx = 0; idx < expts.length; idx++ ) + { + ExceptionTypeList.insertItem(expts[idx]); + } +} + +function populateObjects() +{ + var tps = Factory.types().sort(); + QtObjectList.clear(); + KJSEmbedObjectList.clear(); + KDEObjectList.clear(); + ObjectTypeList.clear(); + + cons = Factory.constructors().sort(); + cons += 'Part'; + + for ( var i=0; i < tps.length; i++ ) { + + if ( /^Q/.test(tps[i]) ) { + QtObjectList.insertItem( tps[i] ); + } + else if ( /^KJSEmbed::/.test(tps[i]) ) { + if ( tps[i] != 'KJSEmbed::Bindings::JSDCOPInterface' ) { + KJSEmbedObjectList.insertItem( tps[i] ); + } + } + else if ( /^K/.test(tps[i]) ) { + KDEObjectList.insertItem( tps[i] ); + } + else { + ObjectTypeList.insertItem( tps[i] ); + } + } +} +// +// Main +// + +// Create the UI +var mw = Factory.loadui("docviewer.ui"); +//mw.qt_central_widget.HelpPage.text = dump(mw.qt_central_widget.Navbar.StaticObjects.StaticObjectList); +var HelpPage = mw.qt_central_widget.HelpPage; +var StaticObjectList = mw.qt_central_widget.Navbar.StaticObjects.StaticObjectList; +var ExceptionTypeList = mw.qt_central_widget.Navbar.ExceptionTypes.ExceptionTypeList; +var KDEObjectList = mw.qt_central_widget.Navbar.KDEObjects.KDEObjectList; +var QtObjectList = mw.qt_central_widget.Navbar.QtObjects.QtObjectList; +var KJSEmbedObjectList = mw.qt_central_widget.Navbar.KJSEmbedObjects.KJSEmbedObjectList; +var ObjectTypeList = mw.qt_central_widget.Navbar.ObjectTypes.ObjectTypeList; + +populateStaticObjects(); +populateExceptions(); +populateObjects(); + +mw.connect( StaticObjectList, 'highlighted(const QString&)', this, 'documentStaticObject' ); +mw.connect( ExceptionTypeList, 'highlighted(const QString&)', this, 'documentStaticObject' ); +mw.connect( KDEObjectList, 'highlighted(const QString&)', this, 'documentConstructableObject' ); +mw.connect( QtObjectList, 'highlighted(const QString&)', this, 'documentConstructableObject' ); +mw.connect( KJSEmbedObjectList, 'highlighted(const QString&)', this, 'documentConstructableObject' ); +mw.connect( ObjectTypeList, 'highlighted(const QString&)', this, 'documentConstructableObject' ); + + +mw.show(); +application.exec(); +/* + +side = new QTabWidget( split, 'sidebar' ); +view = new QTabWidget( split, 'mainview' ); + +// Load the view +js = new QTextEdit( view, 'js' ); +js.setReadOnly( true ); + +view.addTab( js, '&Javascript' ); + +view.set_class = function( clazz ) +{ + clazz = clazz.replace( '^[^QK]*', '' ); + + // JS docs + var s = ''; + + s = s + '<html>'; + s = s + '<body>'; + s = s + '<h1>' + clazz + '</h1>'; + + try { + var obj = eval('new '+clazz+'()'); + s = s + dump(obj); + } + catch ( err ) { + s = s + '<font color="red">Error dumping object: ' + err + '</font>'; + } + + s = s + '</body>'; + s = s + '</html>'; + + js.text = s; +} + +view.setup = function() +{ + // JS docs + var s = ''; + s = s + '<html>'; + s = s + '<body>'; + s = s + '<h1>Script Reference</h1>'; + s = s + '</body>'; + s = s + '</html>'; + + js.text = s; +} + +// Setup the sidebar +specialside = new QListBox( side, 'specialsidebar' ); +qtside = new QListBox( side, 'qtsidebar' ); +allside = new QListBox( side, 'allsidebar' ); + +side.addTab( specialside, '&Special' ); +side.addTab( qtside, '&Qt' ); +side.addTab( allside, '&All' ); + +setup_sidebar( specialside, qtside, allside ); + +qtside.connect( qtside, 'highlighted(const QString&)', view, 'set_class' ); +specialside.connect( specialside, 'highlighted(const QString&)', view, 'set_class' ); +allside.connect( allside, 'highlighted(const QString&)', view, 'set_class' ); + +// +// Show the window +// + +side.maximumWidth = 250; +mw.resize( 800, 550 ); + +mw.show(); + +// +// Connect together +// +view.setup(); + +application.exec(); +*/ |