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
|
/***************************************************************************
* Copyright (C) 2007 Nicolas Hadacek <hadacek@kde.org> *
* *
* 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. *
***************************************************************************/
#include "list_container.h"
//----------------------------------------------------------------------------
PopupContainer::PopupContainer(const TQString &title, TQWidget *parent, const char *name)
: KPopupMenu(parent, name)
{
if ( !title.isEmpty() ) insertTitle(title);
}
ListContainer *PopupContainer::appendBranch(const TQString &title)
{
PopupContainer *branch = new PopupContainer(title, this);
insertItem(title, branch);
return branch;
}
ListContainer *PopupContainer::appendBranch(const TQPixmap &pixmap, const TQString &title)
{
PopupContainer *branch = new PopupContainer(title, this);
insertItem(pixmap, title, branch);
return branch;
}
void PopupContainer::appendItem(const TQPixmap &icon, const TQString &label, uint id, ItemState state)
{
insertItem(icon, label, id);
switch (state) {
case Normal: break;
case Checked: setItemChecked(id, true); break;
case UnChecked: setItemChecked(id, false); break;
case Disabled: setItemEnabled(id, false); break;
}
}
//----------------------------------------------------------------------------
ListViewItemContainer::ListViewItemContainer(const TQString &title, KListView *parent)
: KListViewItem(parent, title), _parent(0), _column(0)
{
_ids = new TQMap<const TQListViewItem *, uint>;
}
ListViewItemContainer::ListViewItemContainer(const TQString &title, ListViewItemContainer *parent)
: KListViewItem(parent, title), _parent(parent), _column(0)
{
_ids = parent->_ids;
}
ListViewItemContainer::~ListViewItemContainer()
{
if ( _parent==0 ) delete _ids;
}
ListContainer *ListViewItemContainer::appendBranch(const TQString &title)
{
ListViewItemContainer *branch = new ListViewItemContainer(title, this);
branch->setColumn(_column);
branch->setSelectable(false);
// append instead of prepend
TQListViewItem *litem=firstChild();
while ( litem && litem->nextSibling() ) litem = litem->nextSibling();
if (litem) branch->moveItem(litem);
return branch;
}
void ListViewItemContainer::appendItem(const TQPixmap &icon, const TQString &title, uint id, ItemState state)
{
TQListViewItem *item = 0;
if ( state==Normal || state==Disabled ) {
item = new KListViewItem(this);
item->setText(_column, title);
} else {
item = new TQCheckListItem(this, title, TQCheckListItem::CheckBox);
static_cast<TQCheckListItem *>(item)->setState(state==Checked ? TQCheckListItem::On : TQCheckListItem::Off);
}
item->setPixmap(_column, icon);
item->setSelectable(state==Normal);
// append instead of prepend
TQListViewItem *litem=firstChild();
while ( litem && litem->nextSibling() ) litem = litem->nextSibling();
if (litem) item->moveItem(litem);
(*_ids)[item] = id;
}
int ListViewItemContainer::id(const TQListViewItem *item) const
{
return (_ids->contains(item) ? int((*_ids)[item]) : -1);
}
|