/*
 *  SPL - The SPL Programming Language
 *  Copyright (C) 2004, 2005  Clifford Wolf <clifford@clifford.at>
 *
 *  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
 *
 *  qtdemo002.spl: A more advanced example for the Qt bindings
 */

load "qt";

var output_lines = <:>
	: 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  US
</> =~ /[^\n]*\n?/Ag;;

var a = new qt.QApplication();

var d = qt_ui("qtdemo002.ui");

var b = qt_child(d, "pushButton1", "QPushButton", 1);
var q = qt_child(d, "pushButton2", "QPushButton", 1);
var t = qt_child(d, "textEdit1", "QTextEdit", 1);

qt_event_callback(b, function(e)
{
	if (e.type() == e.MouseButtonPress() ||
	    e.type() == e.MouseButtonDblClick()) {
		if (elementsof output_lines > 0)
			t.append(shift output_lines);
		b.setText("Thanks for clicking the button!");
		return 1;
	}
	if (e.type() == e.MouseButtonRelease()) {
		b.setText("Click Me Again!");
		return 1;
	}
	return 0;
});

qt_connect(q, "clicked()", a, "quit()");

a.setMainWidget(d);
d.show();

a.exec();

write(t.text());

