kviewshell
tableOfContents.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #include <klocale.h>
00024 #include <kdebug.h>
00025
00026 #include "tableOfContents.h"
00027 #include "bookmark.h"
00028 #include "kvsprefs.h"
00029
00030
00031 TocItem::TocItem(TocItem* parent)
00032 : KListViewItem(parent)
00033 {
00034 }
00035
00036 TocItem::TocItem(QListView* parent)
00037 : KListViewItem(parent)
00038 {
00039 }
00040
00041
00042 TableOfContents::TableOfContents(QWidget* parent)
00043 : KListView(parent)
00044 {
00045 addColumn(i18n("Topic"));
00046 addColumn(i18n("Page"));
00047
00048 setSorting(-1);
00049 setRootIsDecorated(true);
00050 setSelectionMode(QListView::NoSelection);
00051 setResizeMode(AllColumns);
00052 setColumnWidthMode(0, Manual);
00053 setColumnWidthMode(1, Manual);
00054 setFullWidth(true);
00055
00056 readSettings();
00057
00058 connect(this, SIGNAL(executed(QListViewItem*)), this, SLOT(itemClicked(QListViewItem*)));
00059 }
00060
00061 TableOfContents::~TableOfContents()
00062 {
00063 writeSettings();
00064 }
00065
00066 void TableOfContents::writeSettings()
00067 {
00068 saveLayout(KVSPrefs::self()->config(), "tocLayout");
00069 }
00070
00071 void TableOfContents::readSettings()
00072 {
00073 restoreLayout(KVSPrefs::self()->config(), "tocLayout");
00074 }
00075
00076 void TableOfContents::setContents(const QPtrList<Bookmark>& bookmarks)
00077 {
00078 clear();
00079 addItems(bookmarks);
00080 }
00081
00082 void TableOfContents::addItems(const QPtrList<Bookmark>& _bookmarks, TocItem* parent)
00083 {
00084 kdDebug(1223) << "TableOfContents::setContents()" << endl;
00085 if (_bookmarks.isEmpty())
00086 return;
00087 kdDebug(1223) << "Bookmarks are not empty" << endl;
00088
00089
00090 QPtrList<Bookmark> bookmarks = _bookmarks;
00091 for (Bookmark* current = bookmarks.last(); current; current = bookmarks.prev() ) {
00092 TocItem* item;
00093 if (!parent)
00094 item = new TocItem(this);
00095 else
00096 item = new TocItem(parent);
00097
00098 item->setText(0, current->bookmarkText);
00099 if (current->position.page != 0)
00100 item->setText(1, QString().setNum(current->position.page));
00101 else
00102 item->setText(1, "--");
00103 item->setAnchor(current->position);
00104
00105 if (!current->subordinateBookmarks.isEmpty())
00106 addItems(current->subordinateBookmarks, item);
00107 }
00108 }
00109
00110 void TableOfContents::itemClicked(QListViewItem* _item)
00111 {
00112 TocItem* item = static_cast<TocItem*>(_item);
00113
00114 Anchor destination = item->getAnchor();
00115
00116 emit gotoPage(destination);
00117 }
00118
00119 #include "tableOfContents.moc"