~ubuntu-branches/ubuntu/trusty/kvirc/trusty

« back to all changes in this revision

Viewing changes to src/modules/objects/class_treewidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//=============================================================================
2
 
//
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)
6
 
//
7
 
//   This file is part of the KVirc irc client distribution
8
 
//   Copyright (C) 2005-2008 Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor)
9
 
//
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.
14
 
//
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.
19
 
//
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.
23
 
//
24
 
//=============================================================================
25
 
 
26
 
#include "class_treewidget.h"
27
 
 
28
 
#include "kvi_error.h"
29
 
#include "kvi_debug.h"
30
 
#include "kvi_locale.h"
31
 
#include "kvi_iconmanager.h"
32
 
#include <QTreeWidget>
33
 
 
34
 
 #include <QSqlDatabase>
35
 
 
36
 
#include <QEvent>
37
 
#include <QDragEnterEvent>
38
 
#include <QDropEvent>
39
 
#include <QHeaderView>
40
 
#include <QUrl>
41
 
 
42
 
/*
43
 
        @doc: listview
44
 
        @keyterms:
45
 
                listview widget class
46
 
        @title:
47
 
                listview class
48
 
        @type:
49
 
                class
50
 
        @short:
51
 
                A listview widget class
52
 
        @inherits:
53
 
                [class]widget[/class]
54
 
        @description:
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.
67
 
        @functions:
68
 
                !fn: $addColumn(<text_label:string>,[<width:integer>])
69
 
                Adds a width pixels wide column with the column header label to the list view.
70
 
 
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.
78
 
 
79
 
                !fn: $showListViewHeader()
80
 
                Show the listview column header.
81
 
 
82
 
                !fn: <boolean> $isListViewHeaderVisible()
83
 
                Returns '1' if the listview header is currently visible. Otherwise this function returns '0'.
84
 
 
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.
89
 
 
90
 
                !fn: $setSelectionMode(<mode:string>)
91
 
                Sets the selection mode for this listview. <mode> can be one of "Single","NoSelection","Multi" or "Extended".
92
 
 
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.
96
 
 
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.
99
 
 
100
 
                !fn: <listviewitem> $currentItem()
101
 
                Returns the current [class]listviewitem[/class] or $null if no item is current at the moment.
102
 
 
103
 
                !fn: <listviewitem> $firstChild()
104
 
                Returns the first child [class]listviewitem[/class] of this listview or $null if there are no items at all.
105
 
 
106
 
                !fn: <listviewitem> $topLevelItem(<index:int>)
107
 
                Returns the <index> child [class]listviewitem[/class] of this listview or $null if it does not exists.
108
 
 
109
 
                !fn: <int> $topLevelItemCount()
110
 
                Returns the number of top level items of this listview.
111
 
 
112
 
                !fn: setAcceptDrops(<benabled:boolean>)
113
 
                If <bEnabled> is true, user can drop files for this listview. The default value is true.
114
 
 
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.
119
 
 
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.
125
 
 
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.
130
 
 
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.
135
 
 
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.
140
 
 
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.
144
 
 
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.
148
 
 
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.
152
 
 
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.
156
 
 
157
 
 
158
 
        @signals:
159
 
                !sg: $clicked()
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]().
167
 
                !sg: $spacePressed()
168
 
                This signal is emitted by the default implementation of [classfnc]$spacePredssedEvent[/classfnc]().
169
 
                !sg: $onItem()
170
 
                This signal is emitted by the default implementation of [classfnc]$onItemEvent[/classfnc]().
171
 
                !sg: $itemExpanded()
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]().
175
 
                !sg: $itemChanged()
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]().
179
 
 
180
 
 
181
 
*/
182
 
 
183
 
 
184
 
 
185
 
//---------------------------------------------------------------------------------
186
 
 
187
 
KVSO_BEGIN_REGISTERCLASS(KviKvsObject_treewidget,"listview","widget")
188
 
 
189
 
        KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,setHeaderLabels)
190
 
        KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,addColumn)
191
 
 
192
 
        KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,setColumnText)
193
 
        KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_treewidget,setColumnCount)
194
 
 
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)
205
 
 
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)
211
 
 
212
 
 
213
 
 
214
 
 
215
 
        //events
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")
226
 
 
227
 
KVSO_END_REGISTERCLASS(KviKvsObject_treewidget)
228
 
 
229
 
KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_treewidget,KviKvsObject_widget)
230
 
 
231
 
KVSO_END_CONSTRUCTOR(KviKvsObject_treewidget)
232
 
 
233
 
 
234
 
KVSO_BEGIN_DESTRUCTOR(KviKvsObject_treewidget)
235
 
 
236
 
KVSO_END_CONSTRUCTOR(KviKvsObject_treewidget)
237
 
 
238
 
bool KviKvsObject_treewidget::init(KviKvsRunTimeContext *,KviKvsVariantList *)
239
 
{
240
 
        setObject(new KviKvsTreeWidget(parentScriptWidget(),getName().toUtf8().data(),this),true);
241
 
        // hack for compatibility with "old" addColumn method;
242
 
        ((QTreeWidget*) widget())->setColumnCount(0);
243
 
 
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)));
252
 
        return true;
253
 
}
254
 
 
255
 
KVSO_CLASS_FUNCTION(treewidget,setHeaderLabels)
256
 
{
257
 
        QStringList columns;
258
 
        KVSO_PARAMETERS_BEGIN(c)
259
 
                KVSO_PARAMETER("labels",KVS_PT_STRINGLIST,KVS_PF_OPTIONAL,columns)
260
 
        KVSO_PARAMETERS_END(c)
261
 
        if (widget()){
262
 
                ((QTreeWidget *)object())->setHeaderLabels(columns);
263
 
        }
264
 
    return true;
265
 
}
266
 
 
267
 
KVSO_CLASS_FUNCTION(treewidget,setColumnText)
268
 
{
269
 
        if (!widget()) return true;
270
 
        QString szLabel;
271
 
        kvs_int_t iCol;
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);
278
 
        return true;
279
 
}
280
 
 
281
 
KVSO_CLASS_FUNCTION(treewidget,topLevelItem)
282
 
{
283
 
        if (!widget()) return true;
284
 
        kvs_int_t iIdx;
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));
291
 
        return true;
292
 
}
293
 
KVSO_CLASS_FUNCTION(treewidget,itemAt)
294
 
{
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));
305
 
        return true;
306
 
}
307
 
KVSO_CLASS_FUNCTION(treewidget,topLevelItemCount)
308
 
{
309
 
        if (!widget()) return true;
310
 
        c->returnValue()->setInteger(((QTreeWidget *)widget())->topLevelItemCount());
311
 
        return true;
312
 
}
313
 
 
314
 
KVSO_CLASS_FUNCTION(treewidget,addColumn)
315
 
{
316
 
        if (!widget()) return true;
317
 
        QString szLabel;
318
 
        kvs_int_t iW;
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);
327
 
        col++;
328
 
        ((QTreeWidget *)widget())->setColumnCount(col);
329
 
        //col++;
330
 
        return true;
331
 
}
332
 
 
333
 
KVSO_CLASS_FUNCTION(treewidget,setAcceptDrops)
334
 
{
335
 
        bool bEnable;
336
 
        KVSO_PARAMETERS_BEGIN(c)
337
 
                KVSO_PARAMETER("bEnable",KVS_PT_BOOLEAN,0,bEnable)
338
 
        KVSO_PARAMETERS_END(c)
339
 
        if (widget())
340
 
                ((QTreeWidget *)object())->setAcceptDrops(bEnable);
341
 
        return true;
342
 
}
343
 
 
344
 
KVSO_CLASS_FUNCTION(treewidget,clear)
345
 
{
346
 
        Q_UNUSED(c);
347
 
        if (widget())
348
 
                ((QTreeWidget *)object())->clear();
349
 
        return true;
350
 
}
351
 
 
352
 
KVSO_CLASS_FUNCTION(treewidget,selectedItems)
353
 
{
354
 
        if(widget())
355
 
        {
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))));
361
 
        }
362
 
        else
363
 
                c->returnValue()->setHObject((kvs_hobject_t)0);
364
 
        return true;
365
 
}
366
 
 
367
 
KVSO_CLASS_FUNCTION(treewidget,firstChild)
368
 
{
369
 
        if(widget())
370
 
                c->returnValue()->setHObject(KviKvsObject_treewidgetitem::itemToHandle((QTreeWidgetItem*)((QTreeWidget *)widget())->topLevelItem(0)));
371
 
        else
372
 
                c->returnValue()->setHObject((kvs_hobject_t)0);
373
 
        return true;
374
 
}
375
 
 
376
 
KVSO_CLASS_FUNCTION(treewidget,currentItem)
377
 
{
378
 
        if(widget())
379
 
                c->returnValue()->setHObject(KviKvsObject_treewidgetitem::itemToHandle((QTreeWidgetItem*)((QTreeWidget *)widget())->currentItem()));
380
 
        else
381
 
                c->returnValue()->setHObject((kvs_hobject_t)0);
382
 
        return true;
383
 
}
384
 
/*
385
 
KVSO_CLASS_FUNCTION(treewidget,setColumnText)
386
 
{
387
 
        kvs_int_t uCol;
388
 
        QString szText;
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);
394
 
    return true;
395
 
}
396
 
*/
397
 
KVSO_CLASS_FUNCTION(treewidget,setColumnCount)
398
 
{
399
 
        kvs_uint_t uCol;
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);
404
 
        return true;
405
 
}
406
 
 
407
 
KVSO_CLASS_FUNCTION(treewidget,setSelectionMode)
408
 
{
409
 
        QString szMode;
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);
423
 
        return true;
424
 
}
425
 
 
426
 
KVSO_CLASS_FUNCTION(treewidget,setSorting)
427
 
{
428
 
        kvs_int_t iCol;
429
 
        QString szOrder;
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);
438
 
        return true;
439
 
}
440
 
KVSO_CLASS_FUNCTION(treewidget,setSortingEnabled)
441
 
{
442
 
        bool bEnables;
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);
448
 
        return true;
449
 
}
450
 
 
451
 
KVSO_CLASS_FUNCTION(treewidget,setRootIsDecorated)
452
 
{
453
 
        bool bEnabled;
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);
458
 
        return true;
459
 
}
460
 
 
461
 
KVSO_CLASS_FUNCTION(treewidget,setAllColumnsShowFocus)
462
 
{
463
 
        bool bEnabled;
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);
468
 
        return true;
469
 
}
470
 
 
471
 
KVSO_CLASS_FUNCTION(treewidget,hideListViewHeader)
472
 
{
473
 
        Q_UNUSED(c);
474
 
        ((QTreeWidget *)widget())->header()->hide();
475
 
        return true;
476
 
}
477
 
 
478
 
KVSO_CLASS_FUNCTION(treewidget,showListViewHeader)
479
 
{
480
 
        Q_UNUSED(c);
481
 
        ((QTreeWidget *)widget())->header()->show();
482
 
        return true;
483
 
}
484
 
 
485
 
KVSO_CLASS_FUNCTION(treewidget,listViewHeaderIsVisible)
486
 
{
487
 
        c->returnValue()->setBoolean(((QTreeWidget *)widget())->header()->isVisible());
488
 
        return true;
489
 
}
490
 
 
491
 
KVSO_CLASS_FUNCTION(treewidget,itemClickedEvent)
492
 
{
493
 
        emitSignal("itemClicked",c,c->params());
494
 
        return true;
495
 
}
496
 
 
497
 
void KviKvsObject_treewidget::slotClicked(QTreeWidgetItem * i,int col)
498
 
{
499
 
        KviKvsVariant *column=new KviKvsVariant((kvs_int_t)col);
500
 
 
501
 
        KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(i)),column);
502
 
        callFunction(this,"itemClickedEvent",0,&params);
503
 
}
504
 
 
505
 
KVSO_CLASS_FUNCTION(treewidget,selectionChangedEvent)
506
 
{
507
 
        emitSignal("selectionChanged",c,c->params());
508
 
        return true;
509
 
}
510
 
 
511
 
void KviKvsObject_treewidget::slotSelectionChanged()
512
 
{
513
 
        if (((QTreeWidget *)widget())->selectionMode()==QTreeWidget::SingleSelection)
514
 
        {
515
 
                QTreeWidgetItem *it=(QTreeWidgetItem *) ((QTreeWidget *)widget())->currentItem();
516
 
                KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(it)));
517
 
                callFunction(this,"selectionChangedEvent",0,&params);
518
 
        }
519
 
        else{
520
 
                KviKvsVariantList params(new KviKvsVariant((kvs_hobject_t)0));
521
 
                callFunction(this,"selectionChangedEvent",0,&params);
522
 
        }
523
 
}
524
 
 
525
 
KVSO_CLASS_FUNCTION(treewidget,currentChangedEvent)
526
 
{
527
 
        emitSignal("currentChanged",c,c->params());
528
 
        return true;
529
 
}
530
 
 
531
 
void KviKvsObject_treewidget::slotCurrentChanged(QTreeWidgetItem * i,QTreeWidgetItem *prev)
532
 
{
533
 
        KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(i)),new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(prev)));
534
 
        callFunction(this,"currentChangedEvent",0,&params);
535
 
}
536
 
 
537
 
KVSO_CLASS_FUNCTION(treewidget,itemActivatedEvent)
538
 
{
539
 
        emitSignal("itemActivated",c,c->params());
540
 
        return true;
541
 
}
542
 
 
543
 
void KviKvsObject_treewidget::slotItemActivated(QTreeWidgetItem * i,int col)
544
 
{
545
 
        KviKvsVariant *column=new KviKvsVariant((kvs_int_t)col);
546
 
        KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(i)),column);
547
 
        callFunction(this,"itemActivatedEvent",0,&params);
548
 
}
549
 
 
550
 
KVSO_CLASS_FUNCTION(treewidget,onItemEvent)
551
 
{
552
 
 
553
 
        emitSignal("onItem",c,c->params());
554
 
        return true;
555
 
}
556
 
 
557
 
void KviKvsObject_treewidget::slotOnItemEntered(QTreeWidgetItem * i,int col)
558
 
{
559
 
        KviKvsVariant *column=new KviKvsVariant((kvs_int_t)col);
560
 
 
561
 
        KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(i)),column);
562
 
        callFunction(this,"onItemEvent",0,&params);
563
 
}
564
 
 
565
 
KVSO_CLASS_FUNCTION(treewidget,itemExpandedEvent)
566
 
{
567
 
        emitSignal("itemExpanded",c,c->params());
568
 
        return true;
569
 
}
570
 
 
571
 
void KviKvsObject_treewidget::slotItemExpanded(QTreeWidgetItem * i)
572
 
{
573
 
        KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(i)));
574
 
        callFunction(this,"itemExpandedEvent",0,&params);
575
 
}
576
 
 
577
 
KVSO_CLASS_FUNCTION(treewidget,itemCollapsedEvent)
578
 
{
579
 
        emitSignal("itemCollapsed",c,c->params());
580
 
        return true;
581
 
}
582
 
 
583
 
void KviKvsObject_treewidget::slotItemCollapsed(QTreeWidgetItem * i)
584
 
{
585
 
        KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(i)));
586
 
        callFunction(this,"itemCollapsedEvent",0,&params);
587
 
}
588
 
 
589
 
 
590
 
 
591
 
KVSO_CLASS_FUNCTION(treewidget,itemChangedEvent)
592
 
{
593
 
        emitSignal("itemChanged",c,c->params());
594
 
        return true;
595
 
}
596
 
 
597
 
void KviKvsObject_treewidget::slotItemChanged(QTreeWidgetItem *item,int col)
598
 
{
599
 
        KviKvsVariant *column=new KviKvsVariant((kvs_int_t)col);
600
 
        KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(item)),column);
601
 
        callFunction(this,"itemChangedEvent",0,&params);
602
 
}
603
 
 
604
 
void KviKvsObject_treewidget::fileDropped(QString &szFile,QTreeWidgetItem *item)
605
 
{
606
 
        KviKvsVariant *file=new KviKvsVariant(szFile);
607
 
        KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(item)),file);
608
 
        callFunction(this,"fileDroppedEvent",0,&params);
609
 
}
610
 
 
611
 
KviKvsTreeWidget::KviKvsTreeWidget(QWidget * par,const char *,KviKvsObject_treewidget *parent)
612
 
:QTreeWidget(par)
613
 
{
614
 
        m_pParentScript=parent;
615
 
        setAcceptDrops(true);
616
 
        setDragEnabled(true);
617
 
        setDropIndicatorShown(true);
618
 
        setDragDropMode(QAbstractItemView::DragDrop);
619
 
        viewport()->setAcceptDrops(true);
620
 
}
621
 
 
622
 
KviKvsTreeWidget::~KviKvsTreeWidget()
623
 
{
624
 
}
625
 
 
626
 
void KviKvsTreeWidget::dragEnterEvent( QDragEnterEvent * e )
627
 
{
628
 
        if(!e->mimeData()->hasUrls())
629
 
        {
630
 
            e->ignore();
631
 
                return;
632
 
        }
633
 
        e->acceptProposedAction();
634
 
}
635
 
 
636
 
void KviKvsTreeWidget::dragMoveEvent( QDragMoveEvent * )
637
 
{
638
 
        // ?#!
639
 
}
640
 
 
641
 
void KviKvsTreeWidget::dropEvent(QDropEvent * e)
642
 
{
643
 
        debug("Drop event");
644
 
        QList<QUrl> list;
645
 
        if(e->mimeData()->hasUrls())
646
 
        {
647
 
                list = e->mimeData()->urls();
648
 
 
649
 
                if(!list.isEmpty())
650
 
                {
651
 
                        QList<QUrl>::Iterator it = list.begin();
652
 
                        for( ; it != list.end(); ++it )
653
 
                        {
654
 
                                QUrl url = *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);
659
 
                        }
660
 
                }
661
 
        }
662
 
}
663
 
 
664
 
#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES
665
 
#include "m_class_treewidget.moc"
666
 
#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES