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
115
116
117
118
119
|
/***************************************************************************
* Copyright (C) 2005 by Wilfried Huss *
* [email protected] *
* *
* 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. *
* *
* 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 <config.h>
#include <klocale.h>
#include <kdebug.h>
#include "tableOfContents.h"
#include "bookmark.h"
#include "kvsprefs.h"
TocItem::TocItem(TocItem* tqparent)
: KListViewItem(tqparent)
{
}
TocItem::TocItem(TQListView* tqparent)
: KListViewItem(tqparent)
{
}
TableOfContents::TableOfContents(TQWidget* tqparent)
: KListView(tqparent)
{
addColumn(i18n("Topic"));
addColumn(i18n("Page"));
setSorting(-1);
setRootIsDecorated(true);
setSelectionMode(TQListView::NoSelection);
setResizeMode(AllColumns);
setColumnWidthMode(0, Manual);
setColumnWidthMode(1, Manual);
setFullWidth(true);
readSettings();
connect(this, TQT_SIGNAL(executed(TQListViewItem*)), this, TQT_SLOT(itemClicked(TQListViewItem*)));
}
TableOfContents::~TableOfContents()
{
writeSettings();
}
void TableOfContents::writeSettings()
{
saveLayout(KVSPrefs::self()->config(), "tocLayout");
}
void TableOfContents::readSettings()
{
restoreLayout(KVSPrefs::self()->config(), "tocLayout");
}
void TableOfContents::setContents(const TQPtrList<Bookmark>& bookmarks)
{
clear();
addItems(bookmarks);
}
void TableOfContents::addItems(const TQPtrList<Bookmark>& _bookmarks, TocItem* tqparent)
{
kdDebug(1223) << "TableOfContents::setContents()" << endl;
if (_bookmarks.isEmpty())
return;
kdDebug(1223) << "Bookmarks are not empty" << endl;
// Why isn't TQPtrList const-correct?
TQPtrList<Bookmark> bookmarks = _bookmarks;
for (Bookmark* current = bookmarks.last(); current; current = bookmarks.prev() ) {
TocItem* item;
if (!tqparent)
item = new TocItem(this);
else
item = new TocItem(tqparent);
item->setText(0, current->bookmarkText);
if (current->position.page != 0)
item->setText(1, TQString().setNum(current->position.page));
else
item->setText(1, "--");
item->setAnchor(current->position);
if (!current->subordinateBookmarks.isEmpty())
addItems(current->subordinateBookmarks, item);
}
}
void TableOfContents::itemClicked(TQListViewItem* _item)
{
TocItem* item = static_cast<TocItem*>(_item);
Anchor destination = item->getAnchor();
emit gotoPage(destination);
}
#include "tableOfContents.moc"
|