// language:nemerle

using System;
using Qyoto;
using Kimono;

public class Main : PlasmaScripting.Applet {
	m_svg : Plasma.Svg;
	m_icon : KIcon;
	
	public this(script : Plasma.AppletScript) {
		base(script);
		m_svg = Plasma.Svg(this);
		m_icon = KIcon("konsole");
		
		// we can't cast directly to uint because that would generate an opcode that's not
		// supported by mono :(
		SetBackgroundHints((Plasma.Applet.BackgroundHint.NoBackground :> int) :> uint);
		m_svg.ImagePath = "widget/background";
		PlasmaApplet.Resize(200, 200);
	}

	public override Init() : void {
	}
	
	public override PaintInterface(p : QPainter, option : QStyleOptionGraphicsItem, contentsRect : QRect) : void {
		p.SetRenderHint(QPainter.RenderHint.SmoothPixmapTransform);
		p.SetRenderHint(QPainter.RenderHint.Antialiasing);

		// Now we draw the applet, starting with our svg
		m_svg.Resize(contentsRect.Width(), contentsRect.Height());
		m_svg.Paint(p, contentsRect.Left(), contentsRect.Top());

		// We place the icon and text
		p.DrawPixmap(7, 0, m_icon.Pixmap(contentsRect.Width(), contentsRect.Width() - 14));
		p.Save();
		p.SetPen(Qt.GlobalColor.white);
		p.DrawText(contentsRect,
			(Qt.AlignmentFlag.AlignBottom | Qt.AlignmentFlag.AlignHCenter) :> int,
			"Hello ScriptEngine from Nemerle!");
		p.Restore();
	}
}
