summaryrefslogtreecommitdiffstats
path: root/kviewshell/tableOfContents.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit47d455dd55be855e4cc691c32f687f723d9247ee (patch)
tree52e236aaa2576bdb3840ebede26619692fed6d7d /kviewshell/tableOfContents.cpp
downloadtdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.tar.gz
tdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.zip
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
Diffstat (limited to 'kviewshell/tableOfContents.cpp')
-rw-r--r--kviewshell/tableOfContents.cpp119
1 files changed, 119 insertions, 0 deletions
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 <config.h>
+
+#include <klocale.h>
+#include <kdebug.h>
+
+#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<Bookmark>& bookmarks)
+{
+ clear();
+ addItems(bookmarks);
+}
+
+void TableOfContents::addItems(const QPtrList<Bookmark>& _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<Bookmark> 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<TocItem*>(_item);
+
+ Anchor destination = item->getAnchor();
+
+ emit gotoPage(destination);
+}
+
+#include "tableOfContents.moc"