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

rocs/App

  • sources
  • kde-4.14
  • kdeedu
  • rocs
  • App
  • InterfacePlugins
  • ApiDoc
ApiDocWidget.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Rocs.
3  Copyright 2012 Andreas Cord-Landwehr <cola@uni-paderborn.de>
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License as
7  published by the Free Software Foundation; either version 2 of
8  the License, or (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 
20 #include "ApiDocWidget.h"
21 #include "ApiDocManager.h"
22 #include "ApiDocModel.h"
23 
24 #include <QWebView>
25 #include <KDebug>
26 #include <KStandardDirs>
27 
28 ApiDocWidget::ApiDocWidget(QWidget* parent)
29  : QWidget(parent)
30  , _manager(new ApiDocManager(this))
31  , _historyPointer(-1)
32 {
33  _baseUrl = KUrl::fromPath(KGlobal::dirs()->findResourceDir("appdata", QString("plugin/apidoc/objectApi.html")));
34  _baseUrl.addPath("plugin/apidoc/");
35 
36  ui = new Ui::ApiDocWidget;
37  ui->setupUi(this);
38  ui->buttonTree->setIcon(KIcon("view-sidetree"));
39  ui->buttonHome->setIcon(KIcon("go-home"));
40  ui->buttonPrev->setIcon(KIcon("go-previous-view"));
41  ui->buttonNext->setIcon(KIcon("go-next-view"));
42 
43  ui->buttonPrev->setEnabled(false);
44  ui->buttonNext->setEnabled(false);
45 
46  _manager->loadLocalData();
47  _model = new ApiDocModel(_manager->objectApiList(), this);
48 
49  connect(ui->buttonTree, SIGNAL(clicked(bool)), this, SLOT(showTreeOutline()));
50  connect(ui->buttonHome, SIGNAL(clicked(bool)), this, SLOT(showHtmlOutline()));
51  connect(ui->docTree, SIGNAL(clicked(QModelIndex)), this, SLOT(showDetails(QModelIndex)));
52  connect(ui->buttonNext, SIGNAL(clicked(bool)), this, SLOT(historyGoForward()));
53  connect(ui->buttonPrev, SIGNAL(clicked(bool)), this, SLOT(historyGoBack()));
54 
55  // listen to all links for ids
56  connect(ui->docDetails, SIGNAL(linkClicked(QUrl)), this, SLOT(showObjectApi(QUrl)));
57  // this option has the following idea:
58  // * handle relative anchor calls directly in the web engine
59  // * use for switching between object pages the path "http://virtual/<object-id>"
60  // such that that path is handles as external and progapages to this widget
61  // drawback: history only works for object pages, not for anchors
62  ui->docDetails->page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks);
63 
64  ui->docTree->setModel(_model);
65 }
66 
67 void ApiDocWidget::showTreeOutline()
68 {
69  ui->pageStack->setCurrentIndex(0);
70 }
71 
72 void ApiDocWidget::showHtmlOutline()
73 {
74  showHtmlOutline(true);
75 }
76 
77 void ApiDocWidget::showHtmlOutline(bool logHistory)
78 {
79  ui->docDetails->setHtml(_manager->apiOverviewDocument(), _baseUrl);
80  ui->pageStack->setCurrentIndex(1);
81 
82  if (!logHistory) {
83  return;
84  }
85 
86  // clear forward history
87  if (_historyPointer < _history.count() - 1) {
88  while (_historyPointer < _history.count() - 1) {
89  _history.removeAt(_history.count() - 1);
90  }
91  ui->buttonNext->setEnabled(false);
92  }
93 
94  ++_historyPointer;
95  _history.append("_outline"); // use this identifier for the script api html outline
96  if (_historyPointer > 0) {
97  ui->buttonPrev->setEnabled(true);
98  }
99 }
100 
101 void ApiDocWidget::showDetails(const QModelIndex &index)
102 {
103  showObjectApi(_model->data(index, ApiDocModel::DocumentRole).toString(), true);
104  ui->pageStack->setCurrentIndex(1);
105 
106  // TODO jump to anchor
107  // _model->data(index, ApiDocModel::AnchorRole).toString();
108 }
109 
110 void ApiDocWidget::showObjectApi(const QString &id, bool logHistory=true)
111 {
112  QString htmlDocument = _manager->objectApiDocument(id);
113  ui->docDetails->setHtml(htmlDocument, _baseUrl);
114  ui->pageStack->setCurrentIndex(1);
115 
116  if (logHistory) {
117  // update history
118  if (_historyPointer < _history.count() - 1) {
119  while (_historyPointer < _history.count() -1) {
120  _history.removeAt(_history.count() - 1);
121  }
122  ui->buttonNext->setEnabled(false);
123  }
124  _history.append(id);
125  ++_historyPointer;
126  if (_historyPointer > 0) {
127  ui->buttonPrev->setEnabled(true);
128  }
129  }
130 }
131 
132 void ApiDocWidget::showObjectApi(const QUrl &aliasPage)
133 {
134  if (aliasPage.toString().isEmpty()) {
135  kError() << "No path given, aborting.";
136  return;
137  }
138 
139  QString path = aliasPage.toString();
140  int len = path.length() - 1;
141  while (path.at(len) != '/' && len >= 0) {
142  --len;
143  }
144 
145  if (len <= 0) {
146  showObjectApi(path);
147  } else {
148  QString id = path.mid(len + 1);
149  showObjectApi(id);
150  }
151 }
152 
153 void ApiDocWidget::historyGoBack()
154 {
155  if (_historyPointer <= 0) {
156  kError() << "Cannot go back in history, none exist";
157  return;
158  }
159  --_historyPointer;
160  if (_history.at(_historyPointer) == "_outline") {
161  showHtmlOutline(false);
162  } else {
163  showObjectApi(_history.at(_historyPointer), false);
164  }
165 
166  // set buttons
167  ui->buttonNext->setEnabled(true);
168  if (_historyPointer <= 0) {
169  ui->buttonPrev->setEnabled(false);
170  }
171 }
172 
173 void ApiDocWidget::historyGoForward()
174 {
175  if (_historyPointer >= _history.length() - 1) {
176  kError() << "Cannot go forward in history, none exist";
177  return;
178  }
179  ++_historyPointer;
180  if (_history.at(_historyPointer) == "_outline") {
181  showHtmlOutline(false);
182  } else {
183  showObjectApi(_history.at(_historyPointer), false);
184  }
185  // set buttons
186  ui->buttonPrev->setEnabled(true);
187  if (_historyPointer >= _history.count() - 1) {
188  ui->buttonNext->setEnabled(false);
189  }
190 }
QModelIndex
ApiDocWidget::showDetails
void showDetails(const QModelIndex &index)
Definition: ApiDocWidget.cpp:101
QWidget
ApiDocModel::DocumentRole
Definition: ApiDocModel.h:31
ApiDocWidget::showHtmlOutline
void showHtmlOutline()
Definition: ApiDocWidget.cpp:72
ApiDocModel.h
ApiDocManager::objectApiDocument
QString objectApiDocument(const QString &identifier)
Generates HTML document with the API documentation for the specified object.
Definition: ApiDocManager.cpp:64
QList::length
int length() const
ApiDocWidget::historyGoBack
void historyGoBack()
Definition: ApiDocWidget.cpp:153
QList::at
const T & at(int i) const
QList::removeAt
void removeAt(int i)
QUrl::toString
QString toString(QFlags< QUrl::FormattingOption > options) const
ApiDocWidget::historyGoForward
void historyGoForward()
Definition: ApiDocWidget.cpp:173
QList::count
int count(const T &value) const
QList::append
void append(const T &value)
ApiDocWidget::showObjectApi
void showObjectApi(const QString &id, bool logHistory)
Definition: ApiDocWidget.cpp:110
ApiDocModel
Definition: ApiDocModel.h:24
QString::isEmpty
bool isEmpty() const
ApiDocWidget::ApiDocWidget
ApiDocWidget(QWidget *parent)
Default constructor.
Definition: ApiDocWidget.cpp:28
ApiDocManager::objectApiList
QList< ObjectDocumentation * > objectApiList() const
Definition: ApiDocManager.cpp:53
QString
ApiDocManager.h
QUrl
QString::mid
QString mid(int position, int n) const
ApiDocManager
Load and provide api documentation objects.
Definition: ApiDocManager.h:37
ApiDocModel::data
QVariant data(const QModelIndex &index, int role) const
Definition: ApiDocModel.cpp:200
QString::at
const QChar at(int position) const
ApiDocWidget::showTreeOutline
void showTreeOutline()
Definition: ApiDocWidget.cpp:67
QString::length
int length() const
ApiDocManager::apiOverviewDocument
QString apiOverviewDocument() const
Generates HTML document with the an overview over all available API objects.
Definition: ApiDocManager.cpp:265
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
ApiDocManager::loadLocalData
void loadLocalData()
This method loads all api documentation files.
Definition: ApiDocManager.cpp:45
ApiDocWidget.h
QVariant::toString
QString toString() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:16:13 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

rocs/App

Skip menu "rocs/App"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

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