blob: 0d590cc26a2134bda18686702cf80a76591b1880 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/*
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.
*/
/*
ServerListView is derived from TDEListView and implements custom
drag'n'drop behavior needed in ServerListDialog.
Copyright (C) 2006 Eike Hein <hein@kde.org>
*/
#include "serverlistview.h"
#include <tqdragobject.h>
#include <kdebug.h>
ServerListView::ServerListView(TQWidget *parent)
: TDEListView(parent)
{
}
ServerListView::~ServerListView()
{
}
TQPtrList<TQListViewItem> ServerListView::selectedServerListItems()
{
TQPtrList<TQListViewItem> selectedItems = TDEListView::selectedItems();
TQPtrList<TQListViewItem> selectedServerListItems;
TQListViewItem* item = selectedItems.first();
while (item)
{
if (item->parent())
{
if (!item->parent()->isSelected())
selectedServerListItems.append(item);
}
else
{
selectedServerListItems.append(item);
}
item = selectedItems.next();
}
return selectedServerListItems;
}
void ServerListView::findDrop(const TQPoint &pos, TQListViewItem *&parent, TQListViewItem *&after)
{
TQPoint p (contentsToViewport(pos));
// Get the position to put it in
TQListViewItem *atpos = itemAt(p);
TQListViewItem *above;
if (!atpos) // put it at the end
above = lastItem();
else
{
// Get the closest item before us ('atpos' or the one above, if any)
if (p.y() - itemRect(atpos).topLeft().y() < (atpos->height()/2))
above = atpos->itemAbove();
else
above = atpos;
}
if (above)
{
if (above->firstChild())
{
after = above;
parent = after->parent();
return;
}
else
{
after = above->parent();
parent = after ? after->parent() : 0L;
return;
}
}
// set as sibling
after = above;
parent = after ? after->parent() : 0L;
}
TQDragObject* ServerListView::dragObject()
{
if (!currentItem())
return 0;
TQPtrList<TQListViewItem> selected = selectedItems();
TQListViewItem* item = selected.first();
while (item)
{
if (!item->dragEnabled())
return 0;
item = selected.next();
}
return new TQStoredDrag("application/x-qlistviewitem", viewport());
}
#include "serverlistview.moc"
|