From 47d455dd55be855e4cc691c32f687f723d9247ee Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegraphics@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kviewshell/tableOfContents.cpp | 119 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 kviewshell/tableOfContents.cpp (limited to 'kviewshell/tableOfContents.cpp') diff --git a/kviewshell/tableOfContents.cpp b/kviewshell/tableOfContents.cpp new file mode 100644 index 00000000..e7c5db28 --- /dev/null +++ b/kviewshell/tableOfContents.cpp @@ -0,0 +1,119 @@ +/*************************************************************************** + * Copyright (C) 2005 by Wilfried Huss * + * Wilfried.Huss@gmx.at * + * * + * 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 + +#include +#include + +#include "tableOfContents.h" +#include "bookmark.h" +#include "kvsprefs.h" + + +TocItem::TocItem(TocItem* parent) + : KListViewItem(parent) +{ +} + +TocItem::TocItem(QListView* parent) + : KListViewItem(parent) +{ +} + + +TableOfContents::TableOfContents(QWidget* parent) + : KListView(parent) +{ + addColumn(i18n("Topic")); + addColumn(i18n("Page")); + + setSorting(-1); + setRootIsDecorated(true); + setSelectionMode(QListView::NoSelection); + setResizeMode(AllColumns); + setColumnWidthMode(0, Manual); + setColumnWidthMode(1, Manual); + setFullWidth(true); + + readSettings(); + + connect(this, SIGNAL(executed(QListViewItem*)), this, SLOT(itemClicked(QListViewItem*))); +} + +TableOfContents::~TableOfContents() +{ + writeSettings(); +} + +void TableOfContents::writeSettings() +{ + saveLayout(KVSPrefs::self()->config(), "tocLayout"); +} + +void TableOfContents::readSettings() +{ + restoreLayout(KVSPrefs::self()->config(), "tocLayout"); +} + +void TableOfContents::setContents(const QPtrList& bookmarks) +{ + clear(); + addItems(bookmarks); +} + +void TableOfContents::addItems(const QPtrList& _bookmarks, TocItem* parent) +{ + kdDebug(1223) << "TableOfContents::setContents()" << endl; + if (_bookmarks.isEmpty()) + return; + kdDebug(1223) << "Bookmarks are not empty" << endl; + + // Why isn't QPtrList const-correct? + QPtrList bookmarks = _bookmarks; + for (Bookmark* current = bookmarks.last(); current; current = bookmarks.prev() ) { + TocItem* item; + if (!parent) + item = new TocItem(this); + else + item = new TocItem(parent); + + item->setText(0, current->bookmarkText); + if (current->position.page != 0) + item->setText(1, QString().setNum(current->position.page)); + else + item->setText(1, "--"); + item->setAnchor(current->position); + + if (!current->subordinateBookmarks.isEmpty()) + addItems(current->subordinateBookmarks, item); + } + } + +void TableOfContents::itemClicked(QListViewItem* _item) +{ + TocItem* item = static_cast(_item); + + Anchor destination = item->getAnchor(); + + emit gotoPage(destination); +} + +#include "tableOfContents.moc" -- cgit v1.2.1