Changeset View
Changeset View
Standalone View
Standalone View
documentation/qthelp/qthelpdocumentation.cpp
Show First 20 Lines • Show All 109 Lines • ▼ Show 20 Line(s) | |||||
110 | 110 | | |||
111 | QtHelpDocumentation::~QtHelpDocumentation() | 111 | QtHelpDocumentation::~QtHelpDocumentation() | ||
112 | { | 112 | { | ||
113 | } | 113 | } | ||
114 | 114 | | |||
115 | QString QtHelpDocumentation::description() const | 115 | QString QtHelpDocumentation::description() const | ||
116 | { | 116 | { | ||
117 | QUrl url(m_current.value()); | 117 | QUrl url(m_current.value()); | ||
118 | QByteArray data = m_provider->engine()->fileData(url); | 118 | QByteArray data = m_provider->engine()->fileData(url); | ||
kfunk: Please remove | |||||
119 | 119 | | |||
120 | //Extract a short description from the html data | 120 | //Extract a short description from the html data | ||
121 | const QString dataString = QString::fromLatin1(data); ///@todo encoding | 121 | const QString dataString = QString::fromLatin1(data); ///@todo encoding | ||
122 | 122 | | |||
123 | const QString fragment = url.fragment(); | 123 | const QString fragment = url.fragment(); | ||
124 | const QString p = QStringLiteral("((\\\")|(\\\'))"); | 124 | const QString p = QStringLiteral("((\\\")|(\\\'))"); | ||
125 | const QString optionalSpace = QStringLiteral("( )*"); | 125 | const QString optionalSpace = QStringLiteral("( )*"); | ||
126 | const QString exp = QString("< a name = " + p + fragment + p + " > < / a >").replace(' ', optionalSpace); | 126 | const QString exp = QString("< a name = " + p + fragment + p + " > < / a >").replace(' ', optionalSpace); | ||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Line(s) | 149 | if(pos != -1) { | |||
219 | } | 219 | } | ||
220 | 220 | | |||
221 | return thisFragment; | 221 | return thisFragment; | ||
222 | } | 222 | } | ||
223 | 223 | | |||
224 | return QStringList(m_info.keys()).join(", "); | 224 | return QStringList(m_info.keys()).join(", "); | ||
225 | } | 225 | } | ||
226 | 226 | | |||
227 | void QtHelpDocumentation::setUserStyleSheet(QWebView* view, const QUrl& url) | 227 | void QtHelpDocumentation::setUserStyleSheet(StandardDocumentationView* view, const QUrl& url) | ||
228 | { | 228 | { | ||
229 | 229 | | |||
230 | QTemporaryFile* file = new QTemporaryFile(view); | 230 | QTemporaryFile* file = new QTemporaryFile(view); | ||
231 | file->open(); | 231 | file->open(); | ||
232 | 232 | | |||
233 | QTextStream ts(file); | 233 | QTextStream ts(file); | ||
234 | ts << "html { background: white !important; }\n"; | 234 | ts << "html { background: white !important; }\n"; | ||
235 | if (url.scheme() == "qthelp" && url.host().startsWith("com.trolltech.qt.")) { | 235 | if (url.scheme() == "qthelp" && url.host().startsWith("com.trolltech.qt.")) { | ||
236 | ts << ".content .toc + .title + p { clear:left; }\n" | 236 | ts << ".content .toc + .title + p { clear:left; }\n" | ||
237 | << "#qtdocheader .qtref { position: absolute !important; top: 5px !important; right: 0 !important; }\n"; | 237 | << "#qtdocheader .qtref { position: absolute !important; top: 5px !important; right: 0 !important; }\n"; | ||
238 | } | 238 | } | ||
239 | file->close(); | 239 | file->close(); | ||
240 | view->settings()->setUserStyleSheetUrl(QUrl::fromLocalFile(file->fileName())); | 240 | view->setOverrideCss(QUrl::fromLocalFile(file->fileName())); | ||
kfunk: Dito | |||||
241 | 241 | | |||
242 | delete m_lastStyleSheet.data(); | 242 | delete m_lastStyleSheet.data(); | ||
243 | m_lastStyleSheet = file; | 243 | m_lastStyleSheet = file; | ||
244 | } | 244 | } | ||
245 | 245 | | |||
246 | QWidget* QtHelpDocumentation::documentationWidget(DocumentationFindWidget* findWidget, QWidget* parent) | 246 | QWidget* QtHelpDocumentation::documentationWidget(DocumentationFindWidget* findWidget, QWidget* parent) | ||
247 | { | 247 | { | ||
248 | if(m_info.isEmpty()) { //QtHelp sometimes has empty info maps. e.g. availableaudioeffects i 4.5.2 | 248 | if(m_info.isEmpty()) { //QtHelp sometimes has empty info maps. e.g. availableaudioeffects i 4.5.2 | ||
249 | return new QLabel(i18n("Could not find any documentation for '%1'", m_name), parent); | 249 | return new QLabel(i18n("Could not find any documentation for '%1'", m_name), parent); | ||
250 | } else { | 250 | } else { | ||
251 | StandardDocumentationView* view = new StandardDocumentationView(findWidget, parent); | 251 | StandardDocumentationView* view = new StandardDocumentationView(findWidget, parent); | ||
252 | // QCH files created by doxygen can come with JavaScript | 252 | // QCH files created by doxygen can come with JavaScript | ||
253 | view->settings()->setAttribute(QWebSettings::JavascriptEnabled, true); | | |||
254 | if (!m_sharedQNAM) { | 253 | if (!m_sharedQNAM) { | ||
255 | m_sharedQNAM.reset(new HelpNetworkAccessManager(m_provider->engine())); | 254 | m_sharedQNAM.reset(new HelpNetworkAccessManager(m_provider->engine())); | ||
256 | } | 255 | } | ||
257 | view->page()->setNetworkAccessManager(m_sharedQNAM.data()); | 256 | view->setNetworkAccessManager(m_sharedQNAM.data()); | ||
258 | view->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); | | |||
259 | view->setContextMenuPolicy(Qt::CustomContextMenu); | 257 | view->setContextMenuPolicy(Qt::CustomContextMenu); | ||
260 | connect(view, &StandardDocumentationView::customContextMenuRequested, this, &QtHelpDocumentation::viewContextMenuRequested); | 258 | connect(view, &StandardDocumentationView::customContextMenuRequested, this, &QtHelpDocumentation::viewContextMenuRequested); | ||
261 | 259 | | |||
262 | QObject::connect(view, &StandardDocumentationView::linkClicked, this, &QtHelpDocumentation::jumpedTo); | | |||
263 | | ||||
264 | setUserStyleSheet(view, m_current.value()); | 260 | setUserStyleSheet(view, m_current.value()); | ||
265 | view->setHtml(m_provider->engine()->fileData(m_current.value())); | 261 | view->load(m_current.value()); | ||
266 | view->setUrl(m_current.value()); | | |||
267 | lastView = view; | 262 | lastView = view; | ||
268 | return view; | 263 | return view; | ||
269 | } | 264 | } | ||
270 | } | 265 | } | ||
271 | 266 | | |||
272 | void QtHelpDocumentation::viewContextMenuRequested(const QPoint& pos) | 267 | void QtHelpDocumentation::viewContextMenuRequested(const QPoint& pos) | ||
273 | { | 268 | { | ||
274 | StandardDocumentationView* view = qobject_cast<StandardDocumentationView*>(sender()); | 269 | StandardDocumentationView* view = qobject_cast<StandardDocumentationView*>(sender()); | ||
275 | if (!view) | 270 | if (!view) | ||
276 | return; | 271 | return; | ||
277 | 272 | | |||
278 | QMenu menu; | 273 | QMenu menu; | ||
279 | QAction* copyAction = view->pageAction(QWebPage::Copy); | 274 | QAction* copyAction = view->copyAction(); | ||
280 | copyAction->setIcon(QIcon::fromTheme("edit-copy")); | 275 | copyAction->setIcon(QIcon::fromTheme("edit-copy")); | ||
281 | menu.addAction(copyAction); | 276 | menu.addAction(copyAction); | ||
282 | 277 | | |||
283 | if (m_info.count() > 1) { | 278 | if (m_info.count() > 1) { | ||
284 | menu.addSeparator(); | 279 | menu.addSeparator(); | ||
285 | 280 | | |||
286 | QActionGroup* actionGroup = new QActionGroup(&menu); | 281 | QActionGroup* actionGroup = new QActionGroup(&menu); | ||
287 | foreach(const QString& name, m_info.keys()) { | 282 | foreach(const QString& name, m_info.keys()) { | ||
▲ Show 20 Lines • Show All 70 Lines • Show Last 20 Lines |
Please remove