1
//=============================================================================
3
// File : class_treewidget.cpp
4
// Creation date : Fri Jan 28 14:21:48 CEST 2005
5
// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor)
7
// This file is part of the KVirc irc client distribution
8
// Copyright (C) 2005-2008 Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor)
10
// This program is FREE software. You can redistribute it and/or
11
// modify it under the terms of the GNU General Public License
12
// as published by the Free Software Foundation; either version 2
13
// of the License, or (at your opinion) any later version.
15
// This program is distributed in the HOPE that it will be USEFUL,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
// See the GNU General Public License for more details.
20
// You should have received a copy of the GNU General Public License
21
// along with this program. If not, write to the Free Software Foundation,
22
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24
//=============================================================================
26
#include "class_treewidget.h"
28
#include "kvi_error.h"
29
#include "kvi_debug.h"
30
#include "kvi_locale.h"
31
#include "kvi_iconmanager.h"
32
#include <QTreeWidget>
34
#include <QSqlDatabase>
37
#include <QDragEnterEvent>
39
#include <QHeaderView>
51
A listview widget class
55
It can display and control a hierarchy of multi-column items, and provides the ability to add new items at any time.
56
The items are added by creating children [class]listviewitem[/class] objects: simply allocating them with $new
57
will add the items to the listview and simply deleting them will remove them.
58
Allocating a [class]listviewtitem[/class] item2 as a child of item1 will insert it to the same listview creating
59
a subtree of items spannig from item1. The subtree can be opened or closed by a simple click either
60
on the parent item or on the little plus sign on the side of it (when [classfnc:listview]$setRootIsDecorated[/classfnc]
61
is set to $true. The listview can be in Single, Multi, Extended or NoSelection selection mode.
62
In single selection mode there can be only one selected item at a time and the selected item is also
63
the current item (this mode is the default). In Multi and Extended selection mode there can be multiple selected items
64
and the current item is one of them. The difference between Multi and Extended is in the way
65
that items can be selected by the mouse actions: experiment with the two modes :).
66
The NoSelection mode has obviously no selection at all.
68
!fn: $addColumn(<text_label:string>,[<width:integer>])
69
Adds a width pixels wide column with the column header label to the list view.
71
!fn: $setSorting(<column:integer>,<sort_order:string>)
72
Sets the list view to be sorted by column in ascending order if sort_order is "ascending" or descending order if it is "descending".
73
!fn: $setSortingEnabled(<bEnabled:boolean>)
74
If <bEnabled> is true, user sorting is enabled for the tree. The default value is false.
75
In order to avoid performance issues, it is recommended that sorting is enabled after inserting the items into the tree.
76
!fn: $hideListViewHeader()
77
Hide the listview column header.
79
!fn: $showListViewHeader()
80
Show the listview column header.
82
!fn: <boolean> $isListViewHeaderVisible()
83
Returns '1' if the listview header is currently visible. Otherwise this function returns '0'.
85
!fn: $setAllColumnsShowFocus(<bAllColumnsShowFocus:boolean>)
86
When the argument is $true, causes the listview to display the focus and selection
87
by highlighting all the columns of the item. When the argument is $false then
88
only the first column is selected/highlighted.
90
!fn: $setSelectionMode(<mode:string>)
91
Sets the selection mode for this listview. <mode> can be one of "Single","NoSelection","Multi" or "Extended".
93
!fn: <listviewitem> $selectedItems()
94
Returns the currently selected [class]listviewitem[/class] or $null if no items are selected.
95
This function works only if the list view is in single selection mode.
97
!fn: <listviewitem:hobject> $itemAt(<x_global_pos:integer>,<y_global_pos:integer>)
98
Returns the listviewitem object at the x,y globals coordinates or $null if no item at.
100
!fn: <listviewitem> $currentItem()
101
Returns the current [class]listviewitem[/class] or $null if no item is current at the moment.
103
!fn: <listviewitem> $firstChild()
104
Returns the first child [class]listviewitem[/class] of this listview or $null if there are no items at all.
106
!fn: <listviewitem> $topLevelItem(<index:int>)
107
Returns the <index> child [class]listviewitem[/class] of this listview or $null if it does not exists.
109
!fn: <int> $topLevelItemCount()
110
Returns the number of top level items of this listview.
112
!fn: setAcceptDrops(<benabled:boolean>)
113
If <bEnabled> is true, user can drop files for this listview. The default value is true.
115
!fn: $clickEvent(<item:object>)
116
This function is called when the user clicks in the list view.
117
In its argument the [class]listviewitem[/class] object clicked or 0 if the user didn't click on an item.[br]
118
The default implementation emits the [classfnc]$clicked[/classfnc]() signal.
120
!fn: $selectionChangedEvent(<item:object>)
121
This event handle whenever the set of selected items has changed.
122
The argument is the newly selected item if the listview is in single selection mode.[br]
123
When the listview is in Multi or Extended selection mode then item is always $null.[br]
124
The default implementation emits the [classfnc]$selectionChanged[/classfnc]() signal.
126
!fn: $currentChangedEvent(<item:object>)
127
This event are called whenever the current item has changed.
128
In its argument is the newly selected item or 0 if the change made no item current.[br]
129
The default implementation emits the [classfnc]$currentChanged[/classfnc]() signal.
131
!fn: $itemActivatedEvent(<item:object>)
132
This s signal is emitted when the user activates an item by single- or double-clicking or pressing 'Enter'.[br]
133
In its argument the currrent item.[br]
134
The default implementation emits the [classfnc]$itemActivated[/classfnc]() signal.
136
!fn: $spacePressedEvent(<item:object>)
137
This function is called by the framework when the space key is pressed.[br]
138
In its arument the currrent item.[br]
139
The default implementation emits the [classfnc]$spacePressed[/classfnc]() signal.
141
!fn: $onItemEvent(<item:object)
142
This event is called by framwork when the user moves the mouse cursor onto item.
143
The default implementation emits the [classfnc]$onItem[/classfnc]() signal.
145
!fn: $itemExpandedEvent(<item:object>)
146
This event is called when an item has been expanded, i.e. when the children of item are shown.
147
The default implementation emits the [classfnc]$expanded[/classfnc]() signal.
149
!fn: $itemCollapsedEvent(<item:object>)
150
This event is called when an item has been collapsed, i.e. when the children of item are hidden.
151
The default implementation emits the [classfnc]$collapsed[/classfnc]() signal.
153
!fn: $itemChangedEvent(<item:object>,<col:integer>,<text:string>)
154
This event is called when the item has been renamed in text, e.g. by in in-place renaming, in column col.[br]
155
The default implementation emits the [classfnc]$itemChanged[/classfnc]() signal.
160
This signal is emitted by the default implementation of [classfnc]$clickEvent[/classfnc]().
161
!sg: $selectionChanged()
162
This signal is emitted by the default implementation of [classfnc]$selectionChangedEvent[/classfnc]().
163
!sg: $currentChanged()
164
This signal is emitted by the default implementation of [classfnc]$currentChangedEvent[/classfnc]().
165
!sg: $itemActivated()
166
This signal is emitted by the default implementation of [classfnc]$itemActivatedEvent[/classfnc]().
168
This signal is emitted by the default implementation of [classfnc]$spacePredssedEvent[/classfnc]().
170
This signal is emitted by the default implementation of [classfnc]$onItemEvent[/classfnc]().
172
This signal is emitted by the default implementation of [classfnc]$itemExpandedEvent[/classfnc]().
173
!sg: $itemCollapsed()
174
This signal is emitted by the default implementation of [classfnc]$itemCollapsedEvent[/classfnc]().
176
This signal is emitted by the default implementation of [classfnc]$itemChangedEvent[/classfnc]().
177
!sg: $rightButtonClicked()
178
This signal is emitted by the default implementation of [classfnc]$rightButtonClickedEvent[/classfnc]().
185
//---------------------------------------------------------------------------------
187
KVSO_BEGIN_REGISTERCLASS(KviKvsObject_treewidget,"listview","widget")
189
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,setHeaderLabels)
190
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,addColumn)
192
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,setColumnText)
193
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,setColumnCount)
195
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,setSorting)
196
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,setSortingEnabled)
197
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,setRootIsDecorated)
198
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,setAllColumnsShowFocus)
199
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,clear)
200
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,selectedItems)
201
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,currentItem)
202
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,setSelectionMode)
203
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,listViewHeaderIsVisible)
204
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,itemAt)
206
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,hideListViewHeader)
207
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,showListViewHeader)
208
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,firstChild)
209
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,topLevelItem)
210
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,topLevelItemCount)
216
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,selectionChangedEvent);
217
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,currentChangedEvent);
218
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,itemActivatedEvent);
219
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,onItemEvent);
220
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,itemClickedEvent);
221
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,itemExpandedEvent);
222
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,itemCollapsedEvent);
223
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,itemChangedEvent);
224
KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,setAcceptDrops);
225
KVSO_REGISTER_STANDARD_NOTHINGRETURN_HANDLER(KviKvsObject_treewidget,"fileDroppedEvent")
227
KVSO_END_REGISTERCLASS(KviKvsObject_treewidget)
229
KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_treewidget,KviKvsObject_widget)
231
KVSO_END_CONSTRUCTOR(KviKvsObject_treewidget)
234
KVSO_BEGIN_DESTRUCTOR(KviKvsObject_treewidget)
236
KVSO_END_CONSTRUCTOR(KviKvsObject_treewidget)
238
bool KviKvsObject_treewidget::init(KviKvsRunTimeContext *,KviKvsVariantList *)
240
setObject(new KviKvsTreeWidget(parentScriptWidget(),getName().toUtf8().data(),this),true);
241
// hack for compatibility with "old" addColumn method;
242
((QTreeWidget*) widget())->setColumnCount(0);
244
connect(widget(),SIGNAL(itemClicked(QTreeWidgetItem *,int)),this,SLOT(slotClicked(QTreeWidgetItem *,int)));
245
connect(widget(),SIGNAL(itemSelectionChanged()),this,SLOT(slotSelectionChanged()));
246
connect(widget(),SIGNAL(currentItemChanged(QTreeWidgetItem *,QTreeWidgetItem *)),this,SLOT(slotCurrentChanged(QTreeWidgetItem *,QTreeWidgetItem *)));
247
connect(widget(),SIGNAL(itemActivated(QTreeWidgetItem *,int)),this,SLOT(slotItemActivated(QTreeWidgetItem *,int)));
248
connect(widget(),SIGNAL(itemEntered(QTreeWidgetItem *,int)),this,SLOT(slotOnItemEntered(QTreeWidgetItem *,int)));
249
connect(widget(),SIGNAL(itemExpanded(QTreeWidgetItem *)),this,SLOT(slotItemExpanded(QTreeWidgetItem *)));
250
connect(widget(),SIGNAL(itemCollapsed(QTreeWidgetItem *)),this,SLOT(slotItemCollapsed(QTreeWidgetItem *)));
251
connect(widget(),SIGNAL(itemChanged(QTreeWidgetItem *,int)),this,SLOT(slotItemChanged(QTreeWidgetItem *,int)));
255
KVSO_CLASS_FUNCTION(treewidget,setHeaderLabels)
258
KVSO_PARAMETERS_BEGIN(c)
259
KVSO_PARAMETER("labels",KVS_PT_STRINGLIST,KVS_PF_OPTIONAL,columns)
260
KVSO_PARAMETERS_END(c)
262
((QTreeWidget *)object())->setHeaderLabels(columns);
267
KVSO_CLASS_FUNCTION(treewidget,setColumnText)
269
if (!widget()) return true;
272
KVSO_PARAMETERS_BEGIN(c)
273
KVSO_PARAMETER("column",KVS_PT_INT,0,iCol)
274
KVSO_PARAMETER("label",KVS_PT_STRING,0,szLabel)
275
KVSO_PARAMETERS_END(c)
276
QTreeWidgetItem *header=((QTreeWidget *)widget())->headerItem();
277
header->setText(iCol,szLabel);
281
KVSO_CLASS_FUNCTION(treewidget,topLevelItem)
283
if (!widget()) return true;
285
KVSO_PARAMETERS_BEGIN(c)
286
KVSO_PARAMETER("index",KVS_PT_INT,0,iIdx)
287
KVSO_PARAMETERS_END(c)
288
QTreeWidgetItem *pItem=((QTreeWidget *)widget())->topLevelItem(iIdx);
289
if (!pItem) c->returnValue()->setHObject((kvs_hobject_t)0);
290
else c->returnValue()->setHObject(KviKvsObject_treewidgetitem::itemToHandle(pItem));
293
KVSO_CLASS_FUNCTION(treewidget,itemAt)
295
if (!widget()) return true;
296
kvs_int_t iXpos,iYpos;
297
KVSO_PARAMETERS_BEGIN(c)
298
KVSO_PARAMETER("x_pos",KVS_PT_INT,0,iXpos)
299
KVSO_PARAMETER("y_pos",KVS_PT_INT,0,iYpos)
300
KVSO_PARAMETERS_END(c)
301
QPoint pPoint=((QTreeWidget *)widget())->viewport()->mapFromGlobal(QPoint(iXpos,iYpos));
302
QTreeWidgetItem *pItem=((QTreeWidget *)widget())->itemAt(pPoint);
303
if (!pItem) c->returnValue()->setHObject((kvs_hobject_t)0);
304
else c->returnValue()->setHObject(KviKvsObject_treewidgetitem::itemToHandle(pItem));
307
KVSO_CLASS_FUNCTION(treewidget,topLevelItemCount)
309
if (!widget()) return true;
310
c->returnValue()->setInteger(((QTreeWidget *)widget())->topLevelItemCount());
314
KVSO_CLASS_FUNCTION(treewidget,addColumn)
316
if (!widget()) return true;
319
KVSO_PARAMETERS_BEGIN(c)
320
KVSO_PARAMETER("label",KVS_PT_STRING,0,szLabel)
321
KVSO_PARAMETER("width",KVS_PT_INT,KVS_PF_OPTIONAL,iW)
322
KVSO_PARAMETERS_END(c)
323
int col=((QTreeWidget *)widget())->columnCount();
324
QTreeWidgetItem *header=((QTreeWidget *)widget())->headerItem();
325
header->setText(col,szLabel);
326
if(iW) ((QTreeWidget *)widget())->setColumnWidth(col,iW);
328
((QTreeWidget *)widget())->setColumnCount(col);
333
KVSO_CLASS_FUNCTION(treewidget,setAcceptDrops)
336
KVSO_PARAMETERS_BEGIN(c)
337
KVSO_PARAMETER("bEnable",KVS_PT_BOOLEAN,0,bEnable)
338
KVSO_PARAMETERS_END(c)
340
((QTreeWidget *)object())->setAcceptDrops(bEnable);
344
KVSO_CLASS_FUNCTION(treewidget,clear)
348
((QTreeWidget *)object())->clear();
352
KVSO_CLASS_FUNCTION(treewidget,selectedItems)
356
QList<QTreeWidgetItem *> list=((QTreeWidget *)widget())->selectedItems();
357
KviKvsArray * pArray = new KviKvsArray();
358
c->returnValue()->setArray(pArray);
359
for (int i=0;i<list.count();i++)
360
pArray->set(i,new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle((QTreeWidgetItem*)list.at(i))));
363
c->returnValue()->setHObject((kvs_hobject_t)0);
367
KVSO_CLASS_FUNCTION(treewidget,firstChild)
370
c->returnValue()->setHObject(KviKvsObject_treewidgetitem::itemToHandle((QTreeWidgetItem*)((QTreeWidget *)widget())->topLevelItem(0)));
372
c->returnValue()->setHObject((kvs_hobject_t)0);
376
KVSO_CLASS_FUNCTION(treewidget,currentItem)
379
c->returnValue()->setHObject(KviKvsObject_treewidgetitem::itemToHandle((QTreeWidgetItem*)((QTreeWidget *)widget())->currentItem()));
381
c->returnValue()->setHObject((kvs_hobject_t)0);
385
KVSO_CLASS_FUNCTION(treewidget,setColumnText)
389
KVSO_PARAMETERS_BEGIN(c)
390
KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uCol)
391
KVSO_PARAMETER("text",KVS_PT_STRING,0,szText)
392
KVSO_PARAMETERS_END(c)
393
if (widget())((QTreeWidget *)widget())->setColumnText(uCol,szText);
397
KVSO_CLASS_FUNCTION(treewidget,setColumnCount)
400
KVSO_PARAMETERS_BEGIN(c)
401
KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uCol)
402
KVSO_PARAMETERS_END(c)
403
if (widget())((QTreeWidget *)widget())->setColumnCount(uCol);
407
KVSO_CLASS_FUNCTION(treewidget,setSelectionMode)
410
KVSO_PARAMETERS_BEGIN(c)
411
KVSO_PARAMETER("mode",KVS_PT_NONEMPTYSTRING,0,szMode)
412
KVSO_PARAMETERS_END(c)
413
if(!widget())return true;
414
if(KviQString::equalCI(szMode,"NoSelection"))
415
((QTreeWidget *)widget())->setSelectionMode(QAbstractItemView::NoSelection);
416
else if(KviQString::equalCI(szMode,"Multi"))
417
((QTreeWidget *)widget())->setSelectionMode(QTreeWidget::MultiSelection);
418
else if(KviQString::equalCI(szMode,"Extended"))
419
((QTreeWidget *)widget())->setSelectionMode(QTreeWidget::ExtendedSelection);
420
else if(KviQString::equalCI(szMode,"Single"))
421
((QTreeWidget *)widget())->setSelectionMode(QTreeWidget::SingleSelection);
422
else c->warning(__tr2qs_ctx("Invalid selection mode '%Q'","objects"),&szMode);
426
KVSO_CLASS_FUNCTION(treewidget,setSorting)
430
KVSO_PARAMETERS_BEGIN(c)
431
KVSO_PARAMETER("column",KVS_PT_INT,0,iCol)
432
KVSO_PARAMETER("sort_order",KVS_PT_STRING,0,szOrder)
433
KVSO_PARAMETERS_END(c)
434
if (!widget())return true;
435
if (KviQString::equalCI(szOrder,"ascending")) ((QTreeWidget *)widget())->sortItems(iCol,Qt::AscendingOrder);
436
else if (KviQString::equalCI(szOrder,"descending")) ((QTreeWidget *)widget())->sortItems(iCol,Qt::DescendingOrder);
437
else c->warning(__tr2qs_ctx("Unknown '%Q' sort order: switching to ascending order","objects"),&szOrder);
440
KVSO_CLASS_FUNCTION(treewidget,setSortingEnabled)
443
KVSO_PARAMETERS_BEGIN(c)
444
KVSO_PARAMETER("bEnables",KVS_PT_BOOLEAN,0,bEnables)
445
KVSO_PARAMETERS_END(c)
446
if (!widget())return true;
447
((QTreeWidget *)widget())->setSortingEnabled(bEnables);
451
KVSO_CLASS_FUNCTION(treewidget,setRootIsDecorated)
454
KVSO_PARAMETERS_BEGIN(c)
455
KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled)
456
KVSO_PARAMETERS_END(c)
457
if (widget()) ((QTreeWidget *)widget())->setRootIsDecorated(bEnabled);
461
KVSO_CLASS_FUNCTION(treewidget,setAllColumnsShowFocus)
464
KVSO_PARAMETERS_BEGIN(c)
465
KVSO_PARAMETER("bAllColumnsShowFocus",KVS_PT_BOOL,0,bEnabled)
466
KVSO_PARAMETERS_END(c)
467
if (widget())((QTreeWidget *)widget())->setAllColumnsShowFocus(bEnabled);
471
KVSO_CLASS_FUNCTION(treewidget,hideListViewHeader)
474
((QTreeWidget *)widget())->header()->hide();
478
KVSO_CLASS_FUNCTION(treewidget,showListViewHeader)
481
((QTreeWidget *)widget())->header()->show();
485
KVSO_CLASS_FUNCTION(treewidget,listViewHeaderIsVisible)
487
c->returnValue()->setBoolean(((QTreeWidget *)widget())->header()->isVisible());
491
KVSO_CLASS_FUNCTION(treewidget,itemClickedEvent)
493
emitSignal("itemClicked",c,c->params());
497
void KviKvsObject_treewidget::slotClicked(QTreeWidgetItem * i,int col)
499
KviKvsVariant *column=new KviKvsVariant((kvs_int_t)col);
501
KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(i)),column);
502
callFunction(this,"itemClickedEvent",0,¶ms);
505
KVSO_CLASS_FUNCTION(treewidget,selectionChangedEvent)
507
emitSignal("selectionChanged",c,c->params());
511
void KviKvsObject_treewidget::slotSelectionChanged()
513
if (((QTreeWidget *)widget())->selectionMode()==QTreeWidget::SingleSelection)
515
QTreeWidgetItem *it=(QTreeWidgetItem *) ((QTreeWidget *)widget())->currentItem();
516
KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(it)));
517
callFunction(this,"selectionChangedEvent",0,¶ms);
520
KviKvsVariantList params(new KviKvsVariant((kvs_hobject_t)0));
521
callFunction(this,"selectionChangedEvent",0,¶ms);
525
KVSO_CLASS_FUNCTION(treewidget,currentChangedEvent)
527
emitSignal("currentChanged",c,c->params());
531
void KviKvsObject_treewidget::slotCurrentChanged(QTreeWidgetItem * i,QTreeWidgetItem *prev)
533
KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(i)),new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(prev)));
534
callFunction(this,"currentChangedEvent",0,¶ms);
537
KVSO_CLASS_FUNCTION(treewidget,itemActivatedEvent)
539
emitSignal("itemActivated",c,c->params());
543
void KviKvsObject_treewidget::slotItemActivated(QTreeWidgetItem * i,int col)
545
KviKvsVariant *column=new KviKvsVariant((kvs_int_t)col);
546
KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(i)),column);
547
callFunction(this,"itemActivatedEvent",0,¶ms);
550
KVSO_CLASS_FUNCTION(treewidget,onItemEvent)
553
emitSignal("onItem",c,c->params());
557
void KviKvsObject_treewidget::slotOnItemEntered(QTreeWidgetItem * i,int col)
559
KviKvsVariant *column=new KviKvsVariant((kvs_int_t)col);
561
KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(i)),column);
562
callFunction(this,"onItemEvent",0,¶ms);
565
KVSO_CLASS_FUNCTION(treewidget,itemExpandedEvent)
567
emitSignal("itemExpanded",c,c->params());
571
void KviKvsObject_treewidget::slotItemExpanded(QTreeWidgetItem * i)
573
KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(i)));
574
callFunction(this,"itemExpandedEvent",0,¶ms);
577
KVSO_CLASS_FUNCTION(treewidget,itemCollapsedEvent)
579
emitSignal("itemCollapsed",c,c->params());
583
void KviKvsObject_treewidget::slotItemCollapsed(QTreeWidgetItem * i)
585
KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(i)));
586
callFunction(this,"itemCollapsedEvent",0,¶ms);
591
KVSO_CLASS_FUNCTION(treewidget,itemChangedEvent)
593
emitSignal("itemChanged",c,c->params());
597
void KviKvsObject_treewidget::slotItemChanged(QTreeWidgetItem *item,int col)
599
KviKvsVariant *column=new KviKvsVariant((kvs_int_t)col);
600
KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(item)),column);
601
callFunction(this,"itemChangedEvent",0,¶ms);
604
void KviKvsObject_treewidget::fileDropped(QString &szFile,QTreeWidgetItem *item)
606
KviKvsVariant *file=new KviKvsVariant(szFile);
607
KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(item)),file);
608
callFunction(this,"fileDroppedEvent",0,¶ms);
611
KviKvsTreeWidget::KviKvsTreeWidget(QWidget * par,const char *,KviKvsObject_treewidget *parent)
614
m_pParentScript=parent;
615
setAcceptDrops(true);
616
setDragEnabled(true);
617
setDropIndicatorShown(true);
618
setDragDropMode(QAbstractItemView::DragDrop);
619
viewport()->setAcceptDrops(true);
622
KviKvsTreeWidget::~KviKvsTreeWidget()
626
void KviKvsTreeWidget::dragEnterEvent( QDragEnterEvent * e )
628
if(!e->mimeData()->hasUrls())
633
e->acceptProposedAction();
636
void KviKvsTreeWidget::dragMoveEvent( QDragMoveEvent * )
641
void KviKvsTreeWidget::dropEvent(QDropEvent * e)
645
if(e->mimeData()->hasUrls())
647
list = e->mimeData()->urls();
651
QList<QUrl>::Iterator it = list.begin();
652
for( ; it != list.end(); ++it )
655
QString path = url.toLocalFile();
656
debug("path %s",path.toUtf8().data());
657
QTreeWidgetItem *i = itemAt( e->pos() );
658
m_pParentScript->fileDropped(path,i);
664
#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES
665
#include "m_class_treewidget.moc"
666
#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES