//============================================================================= // // File : KvsObject_painter.cpp // Creation date : Fri Mar 18 14:30:48 CEST 2005 // by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) // Lucia Papini (^ashura^) English Translation. // // This file is part of the KVIrc irc client distribution // Copyright (C) 2005-2008 Alessandro Carbone (elfonol at gmail dot com) // // 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 opinion) 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // //============================================================================= #include "KvsObject_painter.h" #include "KvsObject_pixmap.h" #include "KvsObject_widget.h" #include "kvi_debug.h" #include "KviLocale.h" #include "KviError.h" #include "KviIconManager.h" #include "KviMemory.h" #include #include #include #define PAINTER_ROTATE(__angle,__axis)\ QTransform transform;\ transform.rotate(__angle,__axis);\ m_pPainter->setTransform(transform,true); #define PAINTER_TRANSLATE(__x,__y)\ QTransform transform;\ transform.translate(__x,__y);\ m_pPainter->setTransform(transform,true); #define PAINTER_SHEAR(__sH,__sV)\ QTransform transform;\ transform.shear(__sH,__sV);\ m_pPainter->setTransform(transform,true); #define PAINTER_SCALE(__sX,__sY)\ QTransform transform;\ transform.scale(__sX,__sY);\ m_pPainter->setTransform(transform,true); const Qt::PenStyle penstyles_cod[] = { Qt::NoPen, Qt::SolidLine, Qt::DashLine, Qt::DotLine, Qt::DashDotLine, Qt::DashDotDotLine }; const char * const penstyles_tbl[] = { "noPen", "solidLine", "dashLine", "dotLine", "dashDotLine", "dashDotDotLine" }; const int align_cod[] = { Qt::AlignLeft, Qt::AlignRight, Qt::AlignHCenter, Qt::AlignTop, Qt::AlignBottom, Qt::AlignVCenter, Qt::AlignCenter, Qt::TextSingleLine, Qt::TextExpandTabs, Qt::TextShowMnemonic, Qt::TextWordWrap, Qt::TextIncludeTrailingSpaces }; const char * const align_tbl[] = { "Left", "Right", "HCenter", "Top", "Bottom", "VCenter", "Center", "TextSingleLine", "TextExpandTabs", "TextShowMnemonic", "TextWordWrap", "TextIncludeTrailingSpaces" }; #define align_num (sizeof(align_tbl) / sizeof(align_tbl[0])) const QPainter::CompositionMode composition_cod[] = { QPainter::CompositionMode_SourceOver, QPainter::CompositionMode_DestinationOver, QPainter::CompositionMode_Clear, QPainter::CompositionMode_Source, QPainter::CompositionMode_Destination, QPainter::CompositionMode_SourceIn, QPainter::CompositionMode_DestinationIn, QPainter::CompositionMode_SourceOut, QPainter::CompositionMode_DestinationOut, QPainter::CompositionMode_SourceAtop, QPainter::CompositionMode_DestinationAtop, QPainter::CompositionMode_Xor, QPainter::CompositionMode_Plus, QPainter::CompositionMode_Multiply, QPainter::CompositionMode_Screen, QPainter::CompositionMode_Overlay, QPainter::CompositionMode_Darken, QPainter::CompositionMode_Lighten, QPainter::CompositionMode_ColorDodge, QPainter::CompositionMode_ColorBurn, QPainter::CompositionMode_HardLight, QPainter::CompositionMode_SoftLight, QPainter::CompositionMode_Difference, QPainter::CompositionMode_Exclusion, }; const char * const composition_tbl[] = { "SourceOver", "DestinationOver", "Clear", "Source", "Destination", "SourceIn", "DestinationIn", "SourceOut", "DestinationOut", "SourceAtop", "DestinationAtop", "Xor", "Plus", "Multiply", "Screen", "Overlay", "Darken", "Lighten", "ColorDodge", "ColorBurn", "HardLight", "SoftLight", "Difference", "Exclusion" }; #define penstyles_num (sizeof(penstyles_tbl) / sizeof(penstyles_tbl[0])) #define composition_num (sizeof(composition_tbl) / sizeof(composition_tbl[0])) const Qt::BrushStyle brushstyles_cod[] = { Qt::NoBrush, Qt::SolidPattern, Qt::Dense1Pattern, Qt::Dense2Pattern, Qt::Dense3Pattern, Qt::Dense4Pattern, Qt::Dense5Pattern, Qt::Dense6Pattern, Qt::Dense7Pattern, Qt::HorPattern, Qt::VerPattern, Qt::CrossPattern, Qt::BDiagPattern, Qt::FDiagPattern, Qt::DiagCrossPattern }; const char * const brushstyles_tbl[] = { "NoBrush", "SolidPattern", "Dense1Pattern", "Dense2Pattern", "Dense3Pattern", "Dense4Pattern", "Dense5Pattern", "Dense6Pattern", "Dense7Pattern", "HorPattern", "VerPattern", "CrossPattern", "BDiagPattern", "FDiagPattern", "DiagCrossPattern" }; #define brushstyles_num (sizeof(brushstyles_tbl) / sizeof(brushstyles_tbl[0])) /* @doc: painter @keyterms: painter object class, line editor, input @title: painter class @type: class @short: This class provide a painter to paint line and shapes. @inherits: [class]object[/class] [class]widget[/class] @description: With this class you can draw many graphics objects from simple lines to complex shapes like pies and chords.[br] It can also draw aligned text and pixmaps. Normally, it draws in a "natural" coordinate system, but it can also do view and world transformation.[br] The class need to be implemented into a [classfnc]$paintEvent[/classfnc](); @functions: !fn: $drawLine(,,,) Draws a line from (x1, y1) to (x2, y2) and sets the current pen position to (x2, y2). !fn: $begin() Begins painting the paint device : the parameter MUST be a widget or a pixmap.[br] Warning: A paint device can only be painted by one painter at a time. !fn: $beginPdf() Begins painting on a file using the pdf format. At present the pdf support is in experimental state. !fn: $end() Ends painting. Any resources used while painting are released. !fn: $setPen(,,][,,],[system color:RGB or HSV) The pen defines the lines or text, color. You can set it with Red,Green,Blue, or H,S,V value[br] All parameters are in integer form. !fn: $setPen(,,][,,],[opacity],[system color:RGB or HSV]) The pen defines the lines or text, color. You can set it with Red,Green,Blue, or H,S,V value[br] All parameters are in integer form. The HSV system, like RGB, has three components:[br] * H, for hue, is either 0-359 if the color is chromatic (not gray), or meaningless if it is gray.[br] It represents degrees on the color wheel familiar to most people. Red is 0 (degrees), green is 120 and blue is 240.[br] * S, for saturation, is 0-255, and the bigger it is, the stronger the color is. Grayish colors have saturation near 0; very strong colors have saturation near 255.[br] * V, for value, is 0-255 and represents lightness or brightness of the color. 0 is black; 255 is as far from black as possible.[br] Examples: RED is H=0, S=255, V=255.[br] Light RED could have H about 0, S about 50-100, and S=255. ES: $setPen(00,00,00) for black;[br] Default color mode is RGB; !fn: $setBrush(,,][,,],[system color:RGB or HSV) Sets the painter's brush to have the specified color.[br] Example:[br] class (wdg,widget)[br] {[br] paintevent()[br] {[br] %b=$new(painter)[br] %b->$setBackgroundMode(Opaque)[br] %b->$setBrush(0,250,250)[br] %b->$begin($$)[br] %b->$drawEllipse(50,50,100,50)[br] }[br] }[br] %aa=$new(wdg)[br] %aa->$show()[br] !fn: $drawRect(,,,) Draws a rectangle with upper left corner at (x, y) and with width w and height h. !fn: $drawRoundRect(,,,,,) Draws a rectangle with rounded corners at (x, y), with width w and height h.[rb] The xCor and yCor arguments specify how rounded the corners should be (range is 0->99). !fn: $drawPie(,,,,,) Draws a pie defined by the rectangle (x, y, w, h), the start angle a and the arc length alen.[br] The angles and are 1/16th of a degree, i.e. a full circle equals 5760 (16*360). !fn: $drawArc(,,,,,) Draws an arc defined by the rectangle (x, y, w, h), the start angle a and the arc length alen.[br] The angles and are 1/16th of a degree, i.e. a full circle equals 5760 (16*360). !fn: $drawPoint(,) Draws a point at x and y coordinates. !fn: $drawEllipse(,,,) Draws an ellipse with center at (x + w/2, y + h/2) and size (w, h). !fn: $drawChord(,,,,,) Draws a chord defined by the rectangle (x, y, w, h), the start angle a and the arc length alen.[br] The angles and are 1/16th of a degree, i.e. a full circle equals 5760 (16*360). !fn: $drawText(,,,[,]) Draws the given at position , .[br] If is -1 (the default) all the text is drawn, otherwise the first characters are drawn. The text's direction is given by , valid flag are:[br] [pre] Auto [br] RTL (right to left) [br] LTR (left to right) [br] [/pre] !fn: $drawPixmap(,,,,,,) Draws a pixmap at x,y coordinates[br] !fn: $setFont(,[,,,..])[br] Set the font's family, size and style, valid flag for style are:[br] [pre] italic [br] bold [br] underline [br] overline [br] strikeout [br] fixedpitch [br] [/pre] !fn: $setFontSize()[br] Set the current painter font's size.[br] !fn: $fontAscent() Return the distance from the baseline to the highest position characters extend to. !fn: $fontDescent() Return the distance from the baseline to the lowest point characters extend to. !fn: $fontMetricsWidth() Returns the font metrics width for the painter's current font. !fn: $fontMetricsHeight() Returns the font metrics height for the painter's current font. !fn: $rotate(,[]) Rotates the coordinate system a degrees counterclockwise by the given angle about the optional parameter . Valid values for axis are: ZAxis, XAxis, YAxis. Optional parameter !fn: $translate(,) Translates the coordinate system by , . !fn: $shear(,) Shears the coordinate system by , . !fn: $scale(,) Scales the coordinate system by , . !fn: $setBackgroundMode() Sets the background mode of the painter to : valid values are:[br] - Transparent (that is the default value);[br] - Opaque.[br] !fn: $setOpacity() Sets the painter opacity that affects all painter operations (drawpixmap, drawtext...). Valid values range are from 0 (total transparency) to 1 (total opacity)[br] You must invoke the [classfnc]$begin[/classfnc] before using it. !fn: $setTextAntialiasing() Enable/disable antialias in text if possible. You must call the [classfnc]$begin[/classfnc] before using it. !fn: $setAntialiasing() Enable/disable antialias in edges of primitives if possible. You must call the [classfnc]$begin[/classfnc] before using it. !fn: $setSmoothPixmapTransform() Enable/disable smooth bilinear pixmap transformation algorithm (such as bilinear). You must call the [classfnc]$begin[/classfnc] before using it. Example:[br] [br] class (hello,widget)[br] {[br] constructor()[br] {[br] $$->%sintbl[]= $array( 0, 38, 71, 92, 100, 92, 71, 38,0, -38, -71, -92, -100, -92, -71, -38);[br] $$->%index=0[br] $$->$starttimer( 30 );[br] $$->$resize(800,600 );[br] $$->%string=$0[br] $$->%waitfor=1;[br] $$->%nextanim=0[br] [br] #zoom and rotation anim[br] $$->%Zoomindex=11[br] $$->%degree=0[br] $$->%Noanim=0[br] $$->%scrollright=-450[br] [br] #anim effect init[br] $$->%xoffset=4[br] $$->%yoffset=3[br] $$->%xstart=270[br] $$->%ystart=200[br] $$->%b=0[br] $$->%yoffs=400[br] [br] #parallax parameter[br] $$->%Off=400[br] $$->%roll=1[br] }[br] timerevent()[br] {[br] $$->%b = $(($$->%b + 1) & 15);[br] if ($$->%nextanim == 1) $$->$repaint(1);[br] $$->$repaint(0);[br] }[br] drawAnim()[br] {[br] %P->$setFont(32,"times",bold);[br] %w=$(%P->$fontMetricsWidth($$->%string[$$->%index]) + 20);[br] %h=$(%P->$fontMetricsHeight * 2);[br] %pmx = $(($$->$width/2) -%w/2);[br] %pmy = $(($$->$height()/2) - %h/2);[br] %x = 10;[br] %y= $((%h/2) + $$->$fontDescent());[br] %i=0[br] while ( $str.mid("Grifisx/Noldor",%i,1) != "") [br] {[br] %i16 = $(($$->%b+%i) & 15);[br] %char=$str.mid("Grifisx/Noldor",%i,1)[br] %P->$setPen($((15-%i16)*16),$((15-%i16)*16),$((15-%i16)*16) );[br] %P->$drawText( $(%x+$$->%xstart),$($$->%ystart+%y-$$->%sintbl[%i16]*%h/800),%char,1,Auto);[br] %x += %P->$fontMetricsWidth(%char);[br] %i++;[br] }[br] }[br] matrixeffect()[br] {[br] if (($$->%Zoomindex == 99) && ($$->%degree==360)) return %P->$drawPixmap($(400-32),$(300-32),"kvirc.png",0,0,-1,-1)[br] %P->$scale(0.$$->%Zoomindex,0.$$->%Zoomindex)[br] if ($$->%Zoomindex != 99) $$->%Zoomindex++;[br] %P->$rotate($$->%degree)[br] %P->$translate(400,300)[br] %P->$drawPixmap(-32,-32,"kvirc.png",0,0,-1,-1)[br] %P->$setFont(28,"times",bold);[br] %P->$reset()[br] if ($$->%scrollright >= 550) return[br] %P->$scale(0.$$->%Zoomindex,0.$$->%Zoomindex)[br] %P->$translate(400,350)[br] %P->$drawText($$->%scrollright,10,"Another cool class brought to you by...",-1,Auto) [br] $$->%scrollright += 3;[br] %P->$reset()[br] }[br] nextanim()[br] {[br] %p=$new(painter)[br] %p->$setBackgroundMode(Opaque)[br] %p->$setBrush($rand(255),$rand(255),$rand(255))[br] %p->$begin($$)[br] %rand=$rand(5)[br] %p->$drawrect($rand(800),$rand(400),120,200)[br] %p->$drawArc($rand(800),$rand(400),120,200,20,$(16*20))[br] %p->$drawPie($rand(800),$rand(400),120,200,20,$(16*20))[br] %p->$drawChord($rand(800),$rand(400),120,200,20,$(16*20))[br] %p->$drawEllipse($rand(800),$rand(400),100,30)[br] %p->$end()[br] delete %p[br] }[br] paintEvent()[br] {[br] if ($$->%nextanim ==1) return $$->$nextanim()[br] # pixmap creation: every effect will be painted on it then copied on widget[br] %pixmap=$new(pixmap)[br] %pixmap->$resize($$->$width(),$$->$height())[br] [br] # painter creation [br] %P=$new(painter);[br] %P->$begin(%pixmap);[br] $$->$drawanim[br] $$->$matrixeffect[br] %i=0[br] while (%i != 100)[br] {[br] %i16 = $(($$->%b+%i) & 15);[br] %P->$setPen($((15-%i16)*16),$((15-%i16)*16),$((15-%i16)*16) );[br] %P->$drawpoint($rand(800),$rand(600))[br] %i++[br] }[br] [br] # sets the animations order to manage the parallax effect[br] %P->$end[br] objects.bitBlt $$ 0 0 %pixmap[br] delete %pixmap[br] delete %P[br] if (%Pauseflag == 1) return[br] [br] # manage the animations parameters[br] if (($$->%Off<=60) && ($$->%roll<182)) $$->%roll += 2;[br] if ($$->%roll>182) $$->%waitfor=0[br] if ($$->%Noanim != 1) $$->%degree += 16;[br] if ($$->%degree >= 360)[br] {[br] $$->%degree=0;[br] if ($$->%Zoomindex == 99) $$->%Noanim=1[br] } [br] if ($$->%Noanim != 1) return[br] [br] #sinusoid animation[br] if (($$->%xstart <1) && ($$->%xoffset == -4)) $$->%xoffset=4;[br] if (($$->%xstart >$($$->$width()-%P->$fontMetricsWidth("Grifisx/Noldor"))) && ($$->%xoffset == 4)) $$->%xoffset=-4;[br] if (($$->%ystart <1) && ($$->%yoffset == -3)) $$->%yoffset=3;[br] if (($$->%ystart >$($$->$height()-60)) && ($$->%yoffset == 3)) $$->%yoffset=-3;[br] $$->%xstart += $$->%xoffset;[br] $$->%ystart += $$->%yoffset;[br] }[br] }[br] [br] %Hello=$new(hello)[br] %Hello->$setWindowTitle("Painter effects" );[br] %Hello->$setFont(28,"times",bold);[br] %Btn=$new(button,%Hello)[br] %Btn->$setmaximumwidth(80)[br] %Btn->$setmaximumheight(30)[br] %Btn->$setFont(8,"times",bold);[br] %Btn->$settext(Next)[br] [br] privateimpl(%Btn,mousepressevent)[br] {[br] if ($$->$parent->%nextanim==0) [br] {[br] $$->$parent->%nextanim=1[br] $$->$settext(Prev)[br] } [br] else[br] {[br] $$->$parent->%nextanim=0[br] $$->$settext(Next)[br] }[br] }[br] [br] %lay=$new(layout,%Hello)[br] %lay->$addwidget(%Btn,4,0)[br] %Hello->$setBackgroundColor("000000");[br] %Hello->$setmaximumwidth(800)[br] %Hello->$setminimumwidth(780)[br] %Hello->$setmaximumheight(600)[br] %Hello->$setminimumheight(600)[br] %Hello->$move(10,10)[br] %Hello->$show();[br] [br] */ // ======================================================================== KVSO_BEGIN_REGISTERCLASS(KvsObject_painter,"painter","object") // Fonts KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,setFont) KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,setFontSize) KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,fontAscent) KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,fontDescent) KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,fontMetricsHeight) KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,fontMetricsWidth) // Draws KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,drawRect) KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,drawLine) KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,drawRoundRect) KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,drawPoint) KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,drawArc) KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,drawEllipse) KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,drawPie) KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,drawChord) KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,fillRect) // Text & Pixmap & Icons KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_painter,drawText) KVSO_REGISTER_HANDLER_BY_NAME(
//=============================================================================
//
//   File : KvsObject_treeWidgeteItem.cpp
//   Creation date : Fri Jan 28 14:21:48 CEST 2005
//   by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor)
//
//   This file is part of the KVIrc irc client distribution
//   Copyright (C) 2005-2008 Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor)
//
//   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 opinion) 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
//=============================================================================

#include "KvsObject_treeWidgeteItem.h"
#include "KvsObject_pixmap.h"

#include "KviError.h"
#include "kvi_debug.h"
#include "KviLocale.h"
#include "KviIconManager.h"
#include <QIcon>

const int item_flags[] = {
        Qt::NoItemFlags,
	Qt::ItemIsSelectable,
	Qt::ItemIsEditable,
	Qt::ItemIsDragEnabled,
	Qt::ItemIsDropEnabled,
	Qt::ItemIsUserCheckable,
	Qt::ItemIsEnabled,
	Qt::ItemIsTristate
};

const char * const itemflags_tbl[] = {
	"noitemflag",
        "selectable",
	"editable",
	"dragEnabled",
	"dropEnabled",
	"userCheckable",
	"enabled",
	"tristate"
};

#define itemflags_num	(sizeof(itemflags_tbl) / sizeof(itemflags_tbl[0]))



/*
        @doc: listviewitem
	@keyterms:
                listview tlistviewitem class
	@title:
                listviewtitem class
	@type:
		class
	@short:
                A listviewitem class
	@inherits:
                [class]listviewitem[/class]
	@description:
                The listviewitem class implements a list view item.
                A list view item is a multi-column object capable of displaying itself in a [class]listview[/class].
                To use this class you must instantiate it with another listviewitem or a [class]listview[/class]
		as parent. The item will be automatically displayed.
		You can set the text and a pixmap in each column and you can make it checkable
                with [classfnc:listviewitem]$setCheckable[/classfnc]().
                A checkable listviewitem will display a small check mark in the first column.
	@functions:
		!fn: $setText(<column:integer>,<text:string>)
		Sets the text in column column to text, if column is a valid column number and text is different from the existing text.

		!fn: <string> $text(<column:integer>)
		Returs the text of the specified column.

		!fn: $setPixmap(<column:integer>,<pixmap:hobject or imageID>)
		Sets the pixmap in column column to pm, if pm is non-null and different from the current pixmap, and if column is non-negative.
		Pixmap can be a Kvirc imageid, an image file or a [class]pixmap[/class] object.

                !fn: $setItemEditable(<bEnabled:boolean>)
                If bEnabled is TRUE (1), this item can be in-place editable by the user; otherwise it cannot be editable in-place.

                !fn: $isItemEditable()
                Returns $true if this item is editable and $false otherwise.

		!fn: $setEnabled(<bEnabled:boolean>)
                Enables or disables the item.

		!fn: $isEnabled()
                Returns $true if this item is enabled and $false otherwise.

		!fn: $setOpen(<bOpen:boolean>)
                Opens or closes the item to show its children items.

		!fn: $isOpen()
		Returns the open state of this item

		!fn: $setCheckable(<bCheckable:boolean>)
		Makes this item checkable or not. This function should be called immediately
		after the item creation: changing this property later at runtime may have
		strange results (like the item being moved inside the list, text disappearing,
		hidden children etc... don't do it :D ).

		!fn: $isCheckable()
		Returns $true if this item is checkable and $false otherwise

		!fn: $setChecked(<bChecked:boolean>)
                Sets this item to be checked or not. [classfnc:listviewitem]$setCheckable[/classfnc]() must
		have been previously called.

		!fn: $isChecked()
                Returns the check status of this item. [classfnc:listviewitem]$setCheckable[/classfnc]() must
		have been previously called.

		!fn: $setFlags(<flag1:string>, <flag2:string>, ...)
                Sets the flags for the item to the given flags. These determine whether the item can be selected or modified. This is often used to disable an item.
                Supported flags are:
                - noitemflag : no flag sets;
                - selectable : item is selecatble;
                - editable : item is editable;
                - dragEnabled : item can dragged;
                - dropEnabled : item can used as drop target;
                - userCheckable : item is checkable;
                - enabled :item is enabled;
                - tristate : item is checkable with three separate states.


*/


//===========================================================================================

KVSO_BEGIN_REGISTERCLASS(KvsObject_treeWidgetItem,"listviewitem","object")
	KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,setText)
	KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,text)
	KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,setPixmap);
        KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,setItemEditable);
        KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,isItemEditable);
        KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,setEnabled);
        KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,isEnabled);
	KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,setOpen);
	KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,isOpen);
        KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,setCheckable);
        KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,isCheckable);
	KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,setChecked);
	KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,isChecked);
        KVSO_REGISTER_HANDLER_BY_NAME(KvsObject_treeWidgetItem,setFlags);

KVSO_END_REGISTERCLASS(KvsObject_treeWidgetItem)


KVSO_BEGIN_CONSTRUCTOR(KvsObject_treeWidgetItem,KviKvsObject)

	m_pTreeWidgetItem = 0;

KVSO_END_CONSTRUCTOR(KvsObject_treeWidgetItem)


KVSO_BEGIN_DESTRUCTOR(KvsObject_treeWidgetItem)

	if(m_pTreeWidgetItem)delete m_pTreeWidgetItem;

KVSO_END_CONSTRUCTOR(KvsObject_treeWidgetItem)

bool KvsObject_treeWidgetItem::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *)
{
	if (!parentObject())
	{
		pContext->error(__tr2qs_ctx("The listviewitem cannot be parentless","objects"));
		return false;
	}
	if(parentObject()->inheritsClass("listviewitem"))
	{
		 m_pTreeWidgetItem = new KviKvsStandardTreeWidgetItem(this,((KvsObject_treeWidgetItem *)parentObject())->m_pTreeWidgetItem);
	} else {
		if(parentObject()->inheritsClass("listview"))
			m_pTreeWidgetItem = new KviKvsStandardTreeWidgetItem(this,((QTreeWidget *)parentScriptWidget()));
		else {
                        pContext->error(__tr2qs_ctx("The parent of the listviewitem must be either another listviewitem or a listview","objects"));
			return false;
		}
	}
	return true;
}

void KvsObject_treeWidgetItem::childDestroyed()
{
	if(m_pTreeWidgetItem == 0)return;
	m_pTreeWidgetItem = 0;
	die();
}

KviKvsStandardTreeWidgetItem::KviKvsStandardTreeWidgetItem(KvsObject_treeWidgetItem * ob,QTreeWidget * par)
:QTreeWidgetItem(par), m_pMasterObject(ob)
{
}

KviKvsStandardTreeWidgetItem::KviKvsStandardTreeWidgetItem(KvsObject_treeWidgetItem * ob,QTreeWidgetItem * par)
:QTreeWidgetItem(par), m_pMasterObject(ob)
{
}

KviKvsStandardTreeWidgetItem::~KviKvsStandardTreeWidgetItem()
{
	if(m_pMasterObject)m_pMasterObject->childDestroyed();
}

kvs_hobject_t KvsObject_treeWidgetItem::itemToHandle(QTreeWidgetItem * it)
{
	if(!it)return (kvs_hobject_t)0;
	KvsObject_treeWidgetItem * pObject;
	pObject = ((KviKvsStandardTreeWidgetItem *)it)->masterObject();
	if(!pObject)return (kvs_hobject_t)0;
	return pObject->handle();
}

KVSO_CLASS_FUNCTION(treeWidgetItem,setText)
{
	kvs_uint_t uCol;
	QString szText;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uCol)
		KVSO_PARAMETER("text",KVS_PT_STRING,0,szText)
		KVSO_PARAMETERS_END(c)
	if(m_pTreeWidgetItem)
		m_pTreeWidgetItem->setText(uCol,szText);
	return true;
}


KVSO_CLASS_FUNCTION(treeWidgetItem,setItemEditable)
{
        bool bEnabled;
	KVSO_PARAMETERS_BEGIN(c)
                KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled)
        KVSO_PARAMETERS_END(c)
	if(m_pTreeWidgetItem)
            m_pTreeWidgetItem->setFlags(bEnabled?m_pTreeWidgetItem->flags()|Qt::ItemIsEditable:m_pTreeWidgetItem->flags()&~Qt::ItemIsEditable);
	return true;
}
KVSO_CLASS_FUNCTION(treeWidgetItem,isItemEditable)
{
        if(!m_pTreeWidgetItem)
        {
                c->returnValue()->setBoolean(false);
                return true;
        }
        c->returnValue()->setBoolean(m_pTreeWidgetItem->flags()&Qt::ItemIsEditable);
        return true;
}
KVSO_CLASS_FUNCTION(treeWidgetItem,setFlags)
{
	QStringList itemflags;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("flags",KVS_PT_STRINGLIST,KVS_PF_OPTIONAL,itemflags)
	KVSO_PARAMETERS_END(c)
	int flag,sum=0;
	for ( int i=0;i<itemflags.count();i++)
	{
		flag = 0;
		for(unsigned int j = 0; j < itemflags_num; j++)
		{
			if(KviQString::equalCI(itemflags.at(i), itemflags_tbl[j]))
			{
				flag=item_flags[j];
				break;
			}
		}
		if(flag){
			if (flag==Qt::ItemIsUserCheckable)
					m_pTreeWidgetItem->setCheckState(0,Qt::Unchecked);
			sum = sum | flag;
		}
		else
                        c->warning(__tr2qs_ctx("Unknown item flag '%Q'","objects"),&itemflags.at(i));
	}
	if(m_pTreeWidgetItem)
		m_pTreeWidgetItem->setFlags((Qt::ItemFlags)sum);

	return true;
}

KVSO_CLASS_FUNCTION(treeWidgetItem,setEnabled)
{
	bool bEnabled;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled)
		KVSO_PARAMETERS_END(c)
	if(m_pTreeWidgetItem)
                m_pTreeWidgetItem->setFlags(bEnabled?m_pTreeWidgetItem->flags()|Qt::ItemIsEnabled:m_pTreeWidgetItem->flags()&~Qt::ItemIsEnabled);
	return true;
}

KVSO_CLASS_FUNCTION(treeWidgetItem,isEnabled)
{
	if(!m_pTreeWidgetItem)
	{
		c->returnValue()->setBoolean(false);
		return true;
	}
        c->returnValue()->setBoolean(m_pTreeWidgetItem->flags()&Qt::ItemIsEnabled);
	return true;
}

KVSO_CLASS_FUNCTION(treeWidgetItem,setOpen)
{
	bool bEnabled;
	KVSO_PARAMETERS_BEGIN(c)
		KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled)
	KVSO_PARAMETERS_END(c)
	if(m_pTreeWidgetItem)