kjots
kjotsbrowser.cpp
Go to the documentation of this file.00001 // 00002 // kjots 00003 // 00004 // Copyright (C) 1997 Christoph Neerfeld <Christoph.Neerfeld@home.ivm.de> 00005 // Copyright (C) 2002, 2003 Aaron J. Seigo <aseigo@kde.org> 00006 // Copyright (C) 2003 Stanislav Kljuhhin <crz@hot.ee> 00007 // Copyright (C) 2005-2006 Jaison Lee <lee.jaison@gmail.com> 00008 // 00009 // This program is free software; you can redistribute it and/or modify 00010 // it under the terms of the GNU General Public License as published by 00011 // the Free Software Foundation; either version 2 of the License, or 00012 // (at your option) any later version. 00013 // 00014 // This program is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 // GNU General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU General Public License 00020 // along with this program; if not, write to the Free Software 00021 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00022 // 00023 00024 //Own Header 00025 #include "kjotsbrowser.h" 00026 00027 #include <QTextBrowser> 00028 #include <QTextDocument> 00029 #include <QStackedWidget> 00030 #include <QDebug> 00031 00032 #include <krun.h> 00033 00034 #include "kjotsentry.h" 00035 #include "bookshelf.h" 00036 00037 KJotsBrowser::KJotsBrowser ( QWidget *parent ) : QTextBrowser(parent) 00038 { 00039 setWordWrapMode(QTextOption::WordWrap); 00040 } 00041 00042 KJotsBrowser::~KJotsBrowser() 00043 { 00044 } 00045 00046 void KJotsBrowser::DelayedInitialization ( Bookshelf *shelf ) 00047 { 00048 bookshelf = shelf; 00049 connect(bookshelf, SIGNAL(itemSelectionChanged()), SLOT(onSelectionChange())); 00050 connect(this, SIGNAL(anchorClicked(const QUrl&)), SLOT(linkClicked(const QUrl&))); 00051 } 00052 00053 void KJotsBrowser::onSelectionChange ( void ) 00054 { 00055 QList<KJotsEntry*> selection = bookshelf->selected(); 00056 int selectionSize = selection.size(); 00057 00058 QStackedWidget *stack = static_cast<QStackedWidget*>(parent()); 00059 00060 if ( selectionSize == 0 ) { 00061 clear(); 00062 setEnabled(false); 00063 stack->setCurrentWidget(this); 00064 setFocus(); 00065 } else if (selectionSize == 1 && selection[0]->isPage() ) { 00066 setEnabled(false); 00067 } else { 00068 setEnabled(true); 00069 QTextDocument document; 00070 QTextCursor bookCursor ( &document ); 00071 00072 foreach ( KJotsEntry *entry, selection ) { 00073 entry->generateHtml(entry, false, &bookCursor); 00074 } 00075 00076 setHtml(document.toHtml()); 00077 00078 stack->setCurrentWidget(this); 00079 setFocus(); 00080 } 00081 } 00082 00086 void KJotsBrowser::linkClicked(const QUrl& link) 00087 { 00088 qDebug() << "Link clicked: " << link; 00089 00090 //Stop QTextBrowser from being stupid by giving it an invalid url. 00091 QUrl url; 00092 setSource(url); 00093 00094 QString anchor = link.fragment(); 00095 if ( anchor.size() ) { 00096 scrollToAnchor(anchor); 00097 return; 00098 } 00099 00100 if ( link.scheme() == "kjots" ) { 00101 quint64 target = link.path().mid(1).toULongLong(); 00102 bookshelf->jumpToId(target); 00103 } else { 00104 new KRun ( link, this ); 00105 } 00106 00107 return; 00108 } 00109 00110 #include "kjotsbrowser.moc" 00111 /* ex: set tabstop=4 softtabstop=4 shiftwidth=4 expandtab: */ 00112 /* kate: tab-indents off; replace-tabs on; tab-width 4; remove-trailing-space on; encoding utf-8;*/
KDE 4.0 API Reference