• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kviewshell

tableOfContents.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Wilfried Huss                                   *
00003  *   Wilfried.Huss@gmx.at                                                  *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
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   // Why isn't QPtrList const-correct?
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"

kviewshell

Skip menu "kviewshell"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • kviewshell
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal