• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kjots

  • sources
  • kde-4.14
  • kdepim
  • kjots
kjotsbrowser.cpp
Go to the documentation of this file.
1 //
2 // kjots
3 //
4 // Copyright (C) 1997 Christoph Neerfeld <Christoph.Neerfeld@home.ivm.de>
5 // Copyright (C) 2002, 2003 Aaron J. Seigo <aseigo@kde.org>
6 // Copyright (C) 2003 Stanislav Kljuhhin <crz@hot.ee>
7 // Copyright (C) 2005-2006 Jaison Lee <lee.jaison@gmail.com>
8 //
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 
24 //Own Header
25 #include "kjotsbrowser.h"
26 
27 #include <QItemSelectionModel>
28 
29 #include <krun.h>
30 #include <kdebug.h>
31 #include <Akonadi/EntityTreeModel>
32 
33 KJotsBrowser::KJotsBrowser ( QItemSelectionModel *selectionModel, QWidget *parent )
34  : QTextBrowser(parent), m_itemSelectionModel( selectionModel )
35 {
36  setWordWrapMode(QTextOption::WordWrap);
37 }
38 
39 KJotsBrowser::~KJotsBrowser()
40 {
41 }
42 
43 void KJotsBrowser::delayedInitialization ()
44 {
45  connect(this, SIGNAL(anchorClicked(QUrl)), SLOT(linkClicked(QUrl)));
46 }
47 
51 void KJotsBrowser::linkClicked(const QUrl& link)
52 {
53  //Stop QTextBrowser from being stupid by giving it an invalid url.
54  QUrl url;
55  setSource(url);
56 
57  QString anchor = link.fragment();
58 
59  if ( link.toString().startsWith(QLatin1String("#")) && (anchor.startsWith( QLatin1String( "book_" ) )
60  || anchor.startsWith( QLatin1String( "page_" ) ) ) ) {
61  scrollToAnchor(anchor);
62  return;
63  }
64 
65  if ( link.scheme() == QLatin1String("kjots") ) {
66  const quint64 targetId = link.path().mid(1).toULongLong();
67  if (link.host().endsWith(QLatin1String("book"))) {
68  const QModelIndex colIndex = Akonadi::EntityTreeModel::modelIndexForCollection(m_itemSelectionModel->model(), Akonadi::Collection(targetId));
69  if (!colIndex.isValid())
70  return;
71  m_itemSelectionModel->select(colIndex, QItemSelectionModel::ClearAndSelect);
72  } else {
73  Q_ASSERT(link.host().endsWith(QLatin1String("page")));
74  const QModelIndexList itemIndexes = Akonadi::EntityTreeModel::modelIndexesForItem(m_itemSelectionModel->model(), Akonadi::Item(targetId));
75  if (itemIndexes.size() != 1)
76  return;
77  m_itemSelectionModel->select(itemIndexes.first(), QItemSelectionModel::ClearAndSelect);
78  }
79  } else {
80  new KRun ( link, this );
81  }
82 }
83 
84 /* ex: set tabstop=4 softtabstop=4 shiftwidth=4 expandtab: */
85 /* kate: tab-indents off; replace-tabs on; tab-width 4; remove-trailing-space on; encoding utf-8;*/
KJotsBrowser::linkClicked
void linkClicked(const QUrl &)
Handle link clicks.
Definition: kjotsbrowser.cpp:51
QModelIndex
QWidget
QUrl::host
QString host() const
KJotsBrowser::~KJotsBrowser
virtual ~KJotsBrowser()
Definition: kjotsbrowser.cpp:39
QUrl::toString
QString toString(QFlags< QUrl::FormattingOption > options) const
QTextEdit::scrollToAnchor
void scrollToAnchor(const QString &name)
QModelIndex::isValid
bool isValid() const
QTextEdit::setWordWrapMode
void setWordWrapMode(QTextOption::WrapMode policy)
QItemSelectionModel::select
virtual void select(const QModelIndex &index, QFlags< QItemSelectionModel::SelectionFlag > command)
QUrl::fragment
QString fragment() const
KJotsBrowser::KJotsBrowser
KJotsBrowser(QItemSelectionModel *selectionModel, QWidget *)
Definition: kjotsbrowser.cpp:33
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
QUrl::path
QString path() const
QString::endsWith
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
QString
QString::toULongLong
qulonglong toULongLong(bool *ok, int base) const
QUrl::scheme
QString scheme() const
kjotsbrowser.h
QUrl
QTextBrowser::anchorClicked
void anchorClicked(const QUrl &link)
QTextBrowser::setSource
virtual void setSource(const QUrl &name)
QString::mid
QString mid(int position, int n) const
QLatin1String
KJotsBrowser::delayedInitialization
void delayedInitialization()
Definition: kjotsbrowser.cpp:43
QTextBrowser
QItemSelectionModel
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QItemSelectionModel::model
const QAbstractItemModel * model() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:12 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kjots

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal