/* * SPL - The SPL Programming Language * Copyright (C) 2004, 2005 Clifford Wolf * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * qtdemo003.spl: A Tiny XML Viewer */ load "qt"; load "xml"; load "file"; var xd = xml_parse(file_read("qtdemo003.ui")); var item_to_node; var qapp = new qt.QApplication(); var win = qt_ui("qtdemo003.ui"); function set_tree(list, node, insertafter) { var item = new qt.QListViewItem(list, qt_as("QListViewItem*", insertafter), node["."].name, node["."].type, node["."].path); if (node["."].path =~ ,^/[^/]+(/[^/]+)?$,) item.setOpen(1); item_to_node[item.ptr] = node; var lastitem = undef; foreach[] nextnode (node["@*"].nodes) lastitem = set_tree(item, nextnode, lastitem); foreach[] nextnode (node["*"].nodes) lastitem = set_tree(item, nextnode, lastitem); return item; } var list = qt_child(win, "tree", "QListView", 1); list.setSortColumn(-1); set_tree(list, xd["/*"].node, undef); function clickonitem(item) { if (defined item and declared item_to_node[item.ptr]) { var textarea = qt_child(win, "edit", "QTextEdit", 1); var text = item_to_node[item.ptr]["."].xml; while (text !~ /\n[^ ]/ and text =~ s/\n /\n/g) {} textarea.setText(text); } } qt_signal_callback(list, "clicked(QListViewItem*)", clickonitem); qapp.setMainWidget(win); win.show(); qapp.exec();