VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserWidget.cpp@ 104158

Last change on this file since 104158 was 103803, checked in by vboxsync, 9 months ago

FE/Qt. bugref:10618. Splitting COMEnums.h file into individual enum header files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 75.1 KB
Line 
1/* $Id: UIHelpBrowserWidget.cpp 103803 2024-03-12 11:15:18Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIHelpBrowserWidget class implementation.
4 */
5
6/*
7 * Copyright (C) 2010-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28/* Qt includes: */
29#include <QClipboard>
30#include <QComboBox>
31#include <QtGlobal>
32#include <QtHelp/QHelpEngine>
33#include <QtHelp/QHelpContentWidget>
34#include <QtHelp/QHelpIndexWidget>
35#include <QtHelp/QHelpSearchEngine>
36#include <QtHelp/QHelpSearchQueryWidget>
37#include <QtHelp/QHelpSearchResultWidget>
38#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
39# include <QtHelp/QHelpLink>
40#endif
41
42#include <QLabel>
43#include <QListWidget>
44#include <QMenu>
45#include <QMouseEvent>
46#include <QtPrintSupport/QPrintDialog>
47#include <QtPrintSupport/QPrinter>
48#include <QSplitter>
49#include <QVBoxLayout>
50#ifdef RT_OS_SOLARIS
51# include <QFontDatabase>
52#endif
53#include <QWidgetAction>
54
55/* GUI includes: */
56#include "QIAdvancedSlider.h"
57#include "QITabWidget.h"
58#include "QIToolBar.h"
59#include "QIToolButton.h"
60#include "UIActionPool.h"
61#include "UIExtraDataManager.h"
62#include "UIHelpViewer.h"
63#include "UIHelpBrowserWidget.h"
64#include "UIIconPool.h"
65
66
67/* COM includes: */
68#include "CSystemProperties.h"
69
70
71enum HelpBrowserTabs
72{
73 HelpBrowserTabs_TOC = 0,
74 HelpBrowserTabs_Search,
75 HelpBrowserTabs_Bookmarks,
76 HelpBrowserTabs_Index,
77 HelpBrowserTabs_Max
78};
79Q_DECLARE_METATYPE(HelpBrowserTabs);
80
81static const int iBookmarkUrlDataType = 6;
82
83static int iZoomPercentageStep = 20;
84const QPair<int, int> zoomPercentageMinMax = QPair<int, int>(20, 300);
85
86
87/*********************************************************************************************************************************
88* UIZoomMenuAction definition. *
89*********************************************************************************************************************************/
90class UIZoomMenuAction : public QIWithRetranslateUI<QWidgetAction>
91{
92
93 Q_OBJECT;
94
95signals:
96
97 void sigZoomChanged(int iOperation);
98
99public:
100
101 UIZoomMenuAction(QWidget *pParent = 0);
102 void setZoomPercentage(int iZoomPercentage);
103
104protected:
105
106 void retranslateUi() RT_OVERRIDE;
107
108private slots:
109
110 void sltZoomOperation();
111
112private:
113
114 void prepare();
115
116 QIToolButton *m_pMinusButton;
117 QIToolButton *m_pResetButton;
118 QIToolButton *m_pPlusButton;
119 QLabel *m_pValueLabel;
120 QLabel *m_pLabel;
121};
122
123
124/*********************************************************************************************************************************
125* UIBookmarksListWidget definition. *
126*********************************************************************************************************************************/
127class UIBookmarksListWidget : public QListWidget
128{
129
130 Q_OBJECT;
131
132signals:
133
134 void sigBookmarkDoubleClick(const QUrl &url);
135
136public:
137
138 UIBookmarksListWidget(QWidget *pParent = 0);
139
140protected:
141
142 void mouseDoubleClickEvent(QMouseEvent *event) RT_OVERRIDE;
143 void mousePressEvent(QMouseEvent *pEvent) RT_OVERRIDE;
144};
145
146
147/*********************************************************************************************************************************
148* UIBookmarksListContainer definition. *
149*********************************************************************************************************************************/
150class UIBookmarksListContainer : public QIWithRetranslateUI<QWidget>
151{
152
153 Q_OBJECT;
154
155signals:
156
157 void sigBookmarkDoubleClick(const QUrl &url);
158 void sigListWidgetContextMenuRequest(const QPoint &listWidgetLocalPos);
159
160public:
161
162 UIBookmarksListContainer(QWidget *pParent = 0);
163 void addBookmark(const QUrl &url, const QString &strTitle);
164 /** Return all bookmarks a url, title pair list. */
165 QStringList bookmarks() const;
166 QUrl currentBookmarkUrl();
167
168public:
169
170 void sltDeleteSelectedBookmark();
171 void sltDeleteAllBookmarks();
172
173protected:
174
175 void retranslateUi() RT_OVERRIDE;
176
177private slots:
178
179private:
180
181 void prepare();
182 int itemIndex(const QUrl &url);
183
184 QVBoxLayout *m_pMainLayout;
185 UIBookmarksListWidget *m_pListWidget;
186};
187
188/*********************************************************************************************************************************
189* UIHelpBrowserTab definition. *
190*********************************************************************************************************************************/
191
192class UIHelpBrowserTab : public QIWithRetranslateUI<QWidget>
193{
194 Q_OBJECT;
195
196signals:
197
198 void sigSourceChanged(const QUrl &url);
199 void sigCopyAvailableChanged(bool fAvailable);
200 void sigTitleUpdate(const QString &strTitle);
201 void sigOpenLinkInNewTab(const QUrl &url, bool fBackground);
202 void sigAddBookmark(const QUrl &url, const QString &strTitle);
203 void sigLinkHighlighted(const QUrl &url);
204 void sigFindInPageWidgetVisibilityChanged(bool fVisible);
205 void sigHistoryChanged(bool fBackwardAvailable, bool fForwardAvailable);
206 void sigMouseOverImage(const QString &strImageName);
207 void sigZoomRequest(UIHelpViewer::ZoomOperation enmZoomOperation);
208
209public:
210
211 UIHelpBrowserTab(const QHelpEngine *pHelpEngine, const QUrl &homeUrl,
212 const QUrl &initialUrl, QWidget *pParent = 0);
213
214 QUrl source() const;
215 void setSource(const QUrl &url);
216 QString documentTitle() const;
217 void setToolBarVisible(bool fVisible);
218 void print(QPrinter &printer);
219 void setZoomPercentage(int iZoomPercentage);
220 void setHelpFileList(const QList<QUrl> &helpFileList);
221 void copySelectedText() const;
222 bool hasSelectedText() const;
223 bool isFindInPageWidgetVisible() const;
224 void findNext();
225 void findPrevious();
226
227public slots:
228
229 void sltFindInPageAction(bool fToggled);
230 void sltHomeAction();
231 void sltForwardAction();
232 void sltBackwardAction();
233 void sltAddBookmarkAction();
234 void sltReloadPageAction();
235
236private slots:
237
238 void sltHistoryChanged();
239 void sltAddressBarIndexChanged(int index);
240 void sltAnchorClicked(const QUrl &link);
241 void sltFindInPageWidgetVisibilityChanged(bool fVisible);
242
243private:
244
245 void prepare(const QUrl &initialUrl);
246 void prepareWidgets(const QUrl &initialUrl);
247 void prepareToolBarAndAddressBar();
248 virtual void retranslateUi() RT_OVERRIDE;
249 void setActionTextAndToolTip(QAction *pAction, const QString &strText, const QString &strToolTip);
250
251 QAction *m_pHomeAction;
252 QAction *m_pForwardAction;
253 QAction *m_pBackwardAction;
254 QAction *m_pAddBookmarkAction;
255 QAction *m_pFindInPageAction;
256 QAction *m_pReloadPageAction;
257
258 QVBoxLayout *m_pMainLayout;
259 QIToolBar *m_pToolBar;
260 QComboBox *m_pAddressBar;
261 UIHelpViewer *m_pContentViewer;
262 const QHelpEngine* m_pHelpEngine;
263 QUrl m_homeUrl;
264};
265
266
267/*********************************************************************************************************************************
268* UIHelpBrowserTabManager definition. *
269*********************************************************************************************************************************/
270
271class UIHelpBrowserTabManager : public QITabWidget
272{
273 Q_OBJECT;
274
275signals:
276
277 void sigSourceChanged(const QUrl &url);
278 void sigAddBookmark(const QUrl &url, const QString &strTitle);
279 /** list.first is tab title and list.second is tab's index. */
280 void sigTabsListChanged(const QStringList &titleList);
281 void sigLinkHighlighted(const QUrl &url);
282 void sigZoomPercentageChanged(int iPercentage);
283 void sigCopyAvailableChanged(bool fAvailable);
284 void sigFindInPageWidgetVisibilityChanged(bool fVisible);
285 void sigHistoryChanged(bool fBackwardAvailable, bool fForwardAvailable);
286 void sigMouseOverImage(const QString &strImageName);
287
288public:
289
290 UIHelpBrowserTabManager(const QHelpEngine *pHelpEngine, const QUrl &homeUrl,
291 const QStringList &urlList, QWidget *pParent = 0);
292 /* Returns the list of urls of all open tabs as QStringList. */
293 QStringList tabUrlList() const;
294 QStringList tabTitleList() const;
295
296 /** Either start with a single tab showin the home url or saved tab(s). Depending on the params. passed to ctor. */
297 void initializeTabs();
298 /* Url of the current tab. */
299 QUrl currentSource() const;
300 void setSource(const QUrl &url, bool fNewTab = false);
301 void setToolBarVisible(bool fVisible);
302 void printCurrent(QPrinter &printer);
303 void switchToTab(int iIndex);
304 int zoomPercentage() const;
305 void setZoomPercentage(int iZoomPercentage);
306 void setHelpFileList(const QList<QUrl> &helpFileList);
307 void copySelectedText() const;
308 bool hasCurrentTabSelectedText() const;
309 bool isFindInPageWidgetVisible() const;
310 void toggleFindInPage(bool fTrigger);
311 void findNext();
312 void findPrevious();
313
314public slots:
315
316 void sltCloseCurrentTab();
317 void sltCloseOtherTabs();
318 void sltHomeAction();
319 void sltAddBookmarkAction();
320 void sltForwardAction();
321 void sltBackwardAction();
322 void sltReloadPageAction();
323 void sltHandleZoomRequest(UIHelpViewer::ZoomOperation enmOperation);
324
325private slots:
326
327 void sltTabTitleChange(const QString &strTitle);
328 void sltOpenLinkInNewTab(const QUrl &url, bool fBackground);
329 void sltTabClose(int iTabIndex);
330 void sltContextMenuTabClose();
331 void sltCurrentChanged(int iTabIndex);
332 void sltShowTabBarContextMenu(const QPoint &pos);
333 void sltCloseOtherTabsContextMenuAction();
334 void sltCopyAvailableChanged(bool fAvailable);
335
336private:
337
338 void prepare();
339 void clearAndDeleteTabs();
340 void addNewTab(const QUrl &initialUrl, bool fBackground);
341 /** Check if lists of tab url/title has changed. if so emit a signal. */
342 void updateTabUrlTitleList();
343 /** Closes all tabs other than the one with index @param iTabIndex. */
344 void closeAllTabsBut(int iTabIndex);
345 /* Returns the tab index with @Url if there is one. Returns -1 otherwise. */
346 int findTab(const QUrl &Url) const;
347
348 const QHelpEngine* m_pHelpEngine;
349 QUrl m_homeUrl;
350 QStringList m_savedUrlList;
351 /** Immediately switch the newly created tab. Otherwise open the tab in background. */
352 bool m_fSwitchToNewTab;
353 bool m_fToolBarVisible;
354 QStringList m_tabTitleList;
355 QList<QUrl> m_helpFileList;
356 /** As percentage. */
357 int m_iZoomPercentage;
358};
359
360
361/*********************************************************************************************************************************
362* UIZoomMenuAction implementation. *
363*********************************************************************************************************************************/
364UIZoomMenuAction::UIZoomMenuAction(QWidget *pParent /* = 0 */)
365 :QIWithRetranslateUI<QWidgetAction>(pParent)
366 , m_pMinusButton(0)
367 , m_pResetButton(0)
368 , m_pPlusButton(0)
369 , m_pValueLabel(0)
370 , m_pLabel(0)
371{
372 prepare();
373 retranslateUi();
374}
375
376void UIZoomMenuAction::setZoomPercentage(int iZoomPercentage)
377{
378 if (m_pValueLabel)
379 m_pValueLabel->setText(QString("%1%2").arg(QString::number(iZoomPercentage)).arg("%"));
380}
381
382void UIZoomMenuAction::retranslateUi()
383{
384 if (m_pLabel)
385 m_pLabel->setText(UIHelpBrowserWidget::tr("Zoom"));
386}
387
388void UIZoomMenuAction::prepare()
389{
390 QWidget *pWidget = new QWidget;
391 setDefaultWidget(pWidget);
392
393 QHBoxLayout *pMainLayout = new QHBoxLayout(pWidget);
394 pMainLayout->setSpacing(0);
395 AssertReturnVoid(pMainLayout);
396
397 m_pLabel = new QLabel;
398 m_pMinusButton = new QIToolButton;
399 m_pResetButton = new QIToolButton;
400 m_pPlusButton = new QIToolButton;
401 m_pValueLabel = new QLabel;
402 m_pValueLabel->setAlignment(Qt::AlignCenter);
403 m_pValueLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
404 AssertReturnVoid(m_pMinusButton &&
405 m_pResetButton &&
406 m_pPlusButton &&
407 m_pValueLabel);
408
409 m_pMinusButton->setIcon(UIIconPool::iconSet(":/help_browser_minus_16px.png", ":/help_browser_minus_disabled_16px.png"));
410 m_pResetButton->setIcon(UIIconPool::iconSet(":/help_browser_reset_16px.png", ":/help_browser_reset_disabled_16px.png"));
411 m_pPlusButton->setIcon(UIIconPool::iconSet(":/help_browser_plus_16px.png", ":/help_browser_plus_disabled_16px.png"));
412
413 connect(m_pPlusButton, &QIToolButton::pressed, this, &UIZoomMenuAction::sltZoomOperation);
414 connect(m_pMinusButton, &QIToolButton::pressed, this, &UIZoomMenuAction::sltZoomOperation);
415 connect(m_pResetButton, &QIToolButton::pressed, this, &UIZoomMenuAction::sltZoomOperation);
416
417 pMainLayout->addWidget(m_pLabel);
418 pMainLayout->addWidget(m_pResetButton);
419 pMainLayout->addWidget(m_pMinusButton);
420 pMainLayout->addWidget(m_pValueLabel, Qt::AlignCenter);
421 pMainLayout->addWidget(m_pPlusButton);
422 setZoomPercentage(100);
423}
424
425void UIZoomMenuAction::sltZoomOperation()
426{
427 if (!sender())
428 return;
429 UIHelpViewer::ZoomOperation enmOperation = UIHelpViewer::ZoomOperation_In;
430 if (sender() == m_pMinusButton)
431 enmOperation = UIHelpViewer::ZoomOperation_Out;
432 else if (sender() == m_pPlusButton)
433 enmOperation = UIHelpViewer::ZoomOperation_In;
434 else if (sender() == m_pResetButton)
435 enmOperation = UIHelpViewer::ZoomOperation_Reset;
436 emit sigZoomChanged((int)enmOperation);
437}
438
439
440/*********************************************************************************************************************************
441* UIBookmarksListWidget implementation. *
442*********************************************************************************************************************************/
443UIBookmarksListWidget::UIBookmarksListWidget(QWidget *pParent /* = 0 */)
444 :QListWidget(pParent)
445{
446 setSelectionMode(QAbstractItemView::SingleSelection);
447}
448
449void UIBookmarksListWidget::mouseDoubleClickEvent(QMouseEvent *event)
450{
451 QListWidgetItem *pItem = currentItem();
452 if (!pItem)
453 return;
454 emit sigBookmarkDoubleClick(pItem->data(iBookmarkUrlDataType).toUrl());
455 QListWidget::mouseDoubleClickEvent(event);
456}
457
458void UIBookmarksListWidget::mousePressEvent(QMouseEvent *pEvent)
459{
460 if (!indexAt(pEvent->position().toPoint()).isValid())
461 {
462 clearSelection();
463 setCurrentItem(0);
464 }
465 QListWidget::mousePressEvent(pEvent);
466}
467
468
469/*********************************************************************************************************************************
470* UIBookmarksListContainer implementation. *
471*********************************************************************************************************************************/
472
473UIBookmarksListContainer::UIBookmarksListContainer(QWidget *pParent /* = 0 */)
474 :QIWithRetranslateUI<QWidget>(pParent)
475 , m_pMainLayout(0)
476 , m_pListWidget(0)
477{
478 prepare();
479}
480
481void UIBookmarksListContainer::addBookmark(const QUrl &url, const QString &strTitle)
482{
483 if (!m_pListWidget)
484 return;
485 if (itemIndex(url) != -1)
486 return;
487 QListWidgetItem *pNewItem = new QListWidgetItem(strTitle, m_pListWidget);
488 pNewItem->setData(iBookmarkUrlDataType, url);
489 pNewItem->setToolTip(url.toString());
490}
491
492QStringList UIBookmarksListContainer::bookmarks() const
493{
494 if (!m_pListWidget)
495 return QStringList();
496 QStringList bookmarks;
497 for (int i = 0; i < m_pListWidget->count(); ++i)
498 {
499 QListWidgetItem *pItem = m_pListWidget->item(i);
500 if (!pItem)
501 continue;
502 bookmarks << pItem->data(iBookmarkUrlDataType).toUrl().toString() << pItem->text();
503 }
504 return bookmarks;
505}
506
507QUrl UIBookmarksListContainer::currentBookmarkUrl()
508{
509 if (!m_pListWidget || !m_pListWidget->currentItem())
510 return QUrl();
511 return m_pListWidget->currentItem()->data(iBookmarkUrlDataType).toUrl();
512}
513
514void UIBookmarksListContainer::sltDeleteSelectedBookmark()
515{
516 if (!m_pListWidget || !m_pListWidget->currentItem())
517 return;
518 QListWidgetItem *pCurrentItem = m_pListWidget->takeItem(m_pListWidget->currentRow());
519 delete pCurrentItem;
520}
521
522void UIBookmarksListContainer::sltDeleteAllBookmarks()
523{
524 if (m_pListWidget)
525 m_pListWidget->clear();
526}
527
528void UIBookmarksListContainer::retranslateUi()
529{
530}
531
532void UIBookmarksListContainer::prepare()
533{
534 m_pMainLayout = new QVBoxLayout(this);
535 AssertReturnVoid(m_pMainLayout);
536 m_pMainLayout->setContentsMargins(0, 0, 0, 0);
537
538 m_pListWidget = new UIBookmarksListWidget;
539 AssertReturnVoid(m_pListWidget);
540 m_pMainLayout->addWidget(m_pListWidget);
541 m_pListWidget->setContextMenuPolicy(Qt::CustomContextMenu);
542 connect(m_pListWidget, &UIBookmarksListWidget::sigBookmarkDoubleClick,
543 this, &UIBookmarksListContainer::sigBookmarkDoubleClick);
544 connect(m_pListWidget, &UIBookmarksListWidget::customContextMenuRequested,
545 this, &UIBookmarksListContainer::sigListWidgetContextMenuRequest);
546}
547
548int UIBookmarksListContainer::itemIndex(const QUrl &url)
549{
550 if (!m_pListWidget || !url.isValid())
551 return -1;
552 for (int i = 0; i < m_pListWidget->count(); ++i)
553 {
554 if (m_pListWidget->item(i)->data(iBookmarkUrlDataType).toUrl() == url)
555 return i;
556 }
557 return -1;
558}
559
560/*********************************************************************************************************************************
561* UIHelpBrowserTab implementation. *
562*********************************************************************************************************************************/
563
564UIHelpBrowserTab::UIHelpBrowserTab(const QHelpEngine *pHelpEngine, const QUrl &homeUrl,
565 const QUrl &initialUrl, QWidget *pParent /* = 0 */)
566 : QIWithRetranslateUI<QWidget>(pParent)
567 , m_pHomeAction(0)
568 , m_pForwardAction(0)
569 , m_pBackwardAction(0)
570 , m_pAddBookmarkAction(0)
571 , m_pFindInPageAction(0)
572 , m_pReloadPageAction(0)
573 , m_pMainLayout(0)
574 , m_pToolBar(0)
575 , m_pAddressBar(0)
576 , m_pContentViewer(0)
577 , m_pHelpEngine(pHelpEngine)
578 , m_homeUrl(homeUrl)
579{
580 if (initialUrl.isValid())
581 prepare(initialUrl);
582 else
583 prepare(m_homeUrl);
584}
585
586QUrl UIHelpBrowserTab::source() const
587{
588 if (!m_pContentViewer)
589 return QUrl();
590 return m_pContentViewer->source();
591}
592
593void UIHelpBrowserTab::setSource(const QUrl &url)
594{
595 if (m_pContentViewer)
596 {
597 m_pContentViewer->blockSignals(true);
598 m_pContentViewer->setSource(url);
599 m_pContentViewer->blockSignals(false);
600 /* emit historyChanged signal explicitly since we have blocked the signals: */
601 m_pContentViewer->emitHistoryChangedSignal();
602 }
603}
604
605QString UIHelpBrowserTab::documentTitle() const
606{
607 if (!m_pContentViewer)
608 return QString();
609 return m_pContentViewer->documentTitle();
610}
611
612void UIHelpBrowserTab::setToolBarVisible(bool fVisible)
613{
614 if (m_pToolBar)
615 m_pToolBar->setVisible(fVisible);
616 if (m_pAddressBar)
617 m_pAddressBar->setVisible(fVisible);
618}
619
620void UIHelpBrowserTab::print(QPrinter &printer)
621{
622 if (m_pContentViewer)
623 m_pContentViewer->print(&printer);
624}
625
626void UIHelpBrowserTab::setZoomPercentage(int iZoomPercentage)
627{
628 if (m_pContentViewer)
629 m_pContentViewer->setZoomPercentage(iZoomPercentage);
630}
631
632void UIHelpBrowserTab::setHelpFileList(const QList<QUrl> &helpFileList)
633{
634 if (m_pContentViewer)
635 m_pContentViewer->setHelpFileList(helpFileList);
636}
637
638void UIHelpBrowserTab::copySelectedText() const
639{
640 if (m_pContentViewer && m_pContentViewer->hasSelectedText())
641 m_pContentViewer->copy();
642}
643
644bool UIHelpBrowserTab::hasSelectedText() const
645{
646 if (m_pContentViewer)
647 return m_pContentViewer->textCursor().hasSelection();
648 return false;
649}
650
651bool UIHelpBrowserTab::isFindInPageWidgetVisible() const
652{
653 if (m_pContentViewer)
654 return m_pContentViewer->isFindInPageWidgetVisible();
655 return false;
656}
657
658void UIHelpBrowserTab::findNext()
659{
660 if (m_pContentViewer)
661 return m_pContentViewer->sltSelectNextMatch();
662}
663
664void UIHelpBrowserTab::findPrevious()
665{
666 if (m_pContentViewer)
667 return m_pContentViewer->sltSelectPreviousMatch();
668}
669
670void UIHelpBrowserTab::prepare(const QUrl &initialUrl)
671{
672 m_pMainLayout = new QVBoxLayout(this);
673 AssertReturnVoid(m_pMainLayout);
674 prepareToolBarAndAddressBar();
675 prepareWidgets(initialUrl);
676 retranslateUi();
677}
678
679void UIHelpBrowserTab::prepareWidgets(const QUrl &initialUrl)
680{
681 m_pContentViewer = new UIHelpViewer(m_pHelpEngine);
682 AssertReturnVoid(m_pContentViewer);
683 setFocusProxy(m_pContentViewer);
684 m_pMainLayout->setContentsMargins(0, 0, 0, 0);
685 m_pMainLayout->setSpacing(0);
686
687 m_pMainLayout->addWidget(m_pContentViewer);
688 m_pContentViewer->setOpenExternalLinks(false);
689 connect(m_pContentViewer, &UIHelpViewer::sourceChanged,
690 this, &UIHelpBrowserTab::sigSourceChanged);
691 connect(m_pContentViewer, &UIHelpViewer::historyChanged,
692 this, &UIHelpBrowserTab::sltHistoryChanged);
693 connect(m_pContentViewer, &UIHelpViewer::anchorClicked,
694 this, &UIHelpBrowserTab::sltAnchorClicked);
695 connect(m_pContentViewer, &UIHelpViewer::sigOpenLinkInNewTab,
696 this, &UIHelpBrowserTab::sigOpenLinkInNewTab);
697 connect(m_pContentViewer, &UIHelpViewer::sigGoBackward,
698 this, &UIHelpBrowserTab::sltBackwardAction);
699 connect(m_pContentViewer, &UIHelpViewer::sigGoForward,
700 this, &UIHelpBrowserTab::sltForwardAction);
701 connect(m_pContentViewer, &UIHelpViewer::sigGoHome,
702 this, &UIHelpBrowserTab::sltHomeAction);
703 connect(m_pContentViewer, &UIHelpViewer::sigAddBookmark,
704 this, &UIHelpBrowserTab::sltAddBookmarkAction);
705 connect(m_pContentViewer, &UIHelpViewer::highlighted,
706 this, &UIHelpBrowserTab::sigLinkHighlighted);
707 connect(m_pContentViewer, &UIHelpViewer::copyAvailable,
708 this, &UIHelpBrowserTab::sigCopyAvailableChanged);
709 connect(m_pContentViewer, &UIHelpViewer::sigFindInPageWidgetToogle,
710 this, &UIHelpBrowserTab::sltFindInPageWidgetVisibilityChanged);
711 connect(m_pContentViewer, &UIHelpViewer::sigMouseOverImage,
712 this, &UIHelpBrowserTab::sigMouseOverImage);
713 connect(m_pContentViewer, &UIHelpViewer::sigZoomRequest,
714 this, &UIHelpBrowserTab::sigZoomRequest);
715
716 m_pContentViewer->setSource(initialUrl);
717}
718
719void UIHelpBrowserTab::prepareToolBarAndAddressBar()
720{
721 m_pHomeAction =
722 new QAction(UIIconPool::iconSetFull(":/help_browser_home_32px.png", ":/help_browser_home_16px.png",
723 ":/help_browser_home_disabled_32px.png", ":/help_browser_home_disabled_16px.png"), QString(), this);
724 m_pForwardAction =
725 new QAction(UIIconPool::iconSetFull(":/help_browser_forward_32px.png", ":/help_browser_forward_16px.png",
726 ":/help_browser_forward_disabled_32px.png", ":/help_browser_forward_disabled_16px.png"), QString(), this);
727 m_pBackwardAction =
728 new QAction(UIIconPool::iconSetFull(":/help_browser_backward_32px.png", ":/help_browser_backward_16px.png",
729 ":/help_browser_backward_disabled_32px.png", ":/help_browser_backward_disabled_16px.png"), QString(), this);
730 m_pAddBookmarkAction =
731 new QAction(UIIconPool::iconSetFull(":/help_browser_add_bookmark_32px.png", ":/help_browser_add_bookmark_16px.png",
732 ":/help_browser_add_bookmark_disabled_32px.png", ":/help_browser_add_bookmark_disabled_16px.png"), QString(), this);
733 m_pFindInPageAction =
734 new QAction(UIIconPool::iconSetFull(":/help_browser_search_32px.png", ":/help_browser_search_16px.png",
735 ":/help_browser_search_disabled_32px.png", ":/help_browser_search_disabled_16px.png"), QString(), this);
736 m_pReloadPageAction =
737 new QAction(UIIconPool::iconSetFull(":/help_browser_reload_32px.png", ":/help_browser_reload_16px.png",
738 ":/help_browser_reload_disabled_32px.png", ":/help_browser_reload_disabled_16px.png"), QString(), this);
739
740 AssertReturnVoid(m_pHomeAction && m_pForwardAction &&
741 m_pBackwardAction && m_pAddBookmarkAction &&
742 m_pFindInPageAction);
743 m_pFindInPageAction->setCheckable(true);
744
745 connect(m_pHomeAction, &QAction::triggered, this, &UIHelpBrowserTab::sltHomeAction);
746 connect(m_pAddBookmarkAction, &QAction::triggered, this, &UIHelpBrowserTab::sltAddBookmarkAction);
747 connect(m_pForwardAction, &QAction::triggered, this, &UIHelpBrowserTab::sltForwardAction);
748 connect(m_pBackwardAction, &QAction::triggered, this, &UIHelpBrowserTab::sltBackwardAction);
749 connect(m_pFindInPageAction, &QAction::toggled, this, &UIHelpBrowserTab::sltFindInPageAction);
750 connect(m_pReloadPageAction, &QAction::triggered, this, &UIHelpBrowserTab::sltReloadPageAction);
751
752 m_pForwardAction->setEnabled(false);
753 m_pBackwardAction->setEnabled(false);
754
755 m_pToolBar = new QIToolBar;
756 AssertReturnVoid(m_pToolBar);
757 m_pToolBar->addAction(m_pBackwardAction);
758 m_pToolBar->addAction(m_pForwardAction);
759 m_pToolBar->addAction(m_pHomeAction);
760 m_pToolBar->addAction(m_pReloadPageAction);
761 m_pToolBar->addAction(m_pAddBookmarkAction);
762 m_pToolBar->addAction(m_pFindInPageAction);
763
764 m_pAddressBar = new QComboBox();
765 m_pAddressBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
766 connect(m_pAddressBar, &QComboBox::currentIndexChanged,
767 this, &UIHelpBrowserTab::sltAddressBarIndexChanged);
768
769 QHBoxLayout *pTopLayout = new QHBoxLayout;
770 pTopLayout->addWidget(m_pToolBar);
771 pTopLayout->addWidget(m_pAddressBar);
772 m_pMainLayout->addLayout(pTopLayout);
773}
774
775void UIHelpBrowserTab::setActionTextAndToolTip(QAction *pAction, const QString &strText, const QString &strToolTip)
776{
777 if (!pAction)
778 return;
779 pAction->setText(strText);
780 pAction->setToolTip(strToolTip);
781}
782
783void UIHelpBrowserTab::retranslateUi()
784{
785 setActionTextAndToolTip(m_pHomeAction, UIHelpBrowserWidget::tr("Home"), UIHelpBrowserWidget::tr("Return to Start Page"));
786 setActionTextAndToolTip(m_pBackwardAction, UIHelpBrowserWidget::tr("Backward"), UIHelpBrowserWidget::tr("Go Back to Previous Page"));
787 setActionTextAndToolTip(m_pForwardAction, UIHelpBrowserWidget::tr("Forward"), UIHelpBrowserWidget::tr("Go Forward to Next Page"));
788 setActionTextAndToolTip(m_pAddBookmarkAction, UIHelpBrowserWidget::tr("Add Bookmark"), UIHelpBrowserWidget::tr("Add a New Bookmark"));
789 setActionTextAndToolTip(m_pReloadPageAction, UIHelpBrowserWidget::tr("Reload"), UIHelpBrowserWidget::tr("Reload the Current Page"));
790 setActionTextAndToolTip(m_pFindInPageAction, UIHelpBrowserWidget::tr("Find in Page"), UIHelpBrowserWidget::tr("Find a String in the Current Page"));
791}
792
793void UIHelpBrowserTab::sltHomeAction()
794{
795 if (!m_pContentViewer)
796 return;
797 m_pContentViewer->setSource(m_homeUrl);
798}
799
800void UIHelpBrowserTab::sltForwardAction()
801{
802 if (m_pContentViewer)
803 {
804 m_pContentViewer->forward();
805 /* when we dont reload our overload imag hack does not work and images look ugly: */
806 m_pContentViewer->reload();
807 }
808}
809
810void UIHelpBrowserTab::sltBackwardAction()
811{
812 if (m_pContentViewer)
813 {
814 m_pContentViewer->backward();
815 /* when we dont reload our overload imag hack does not work and images look ugly: */
816 m_pContentViewer->reload();
817 }
818}
819
820void UIHelpBrowserTab::sltFindInPageAction(bool fToggled)
821{
822 if (m_pContentViewer)
823 m_pContentViewer->toggleFindInPageWidget(fToggled);
824}
825
826void UIHelpBrowserTab::sltReloadPageAction()
827{
828 if (m_pContentViewer)
829 m_pContentViewer->reload();
830}
831
832void UIHelpBrowserTab::sltHistoryChanged()
833{
834 if (!m_pContentViewer)
835 return;
836 int iCurrentIndex = 0;
837 /* QTextBrower history has negative and positive indices for bacward and forward items, respectively.
838 * 0 is the current item: */
839 m_pAddressBar->blockSignals(true);
840 m_pAddressBar->clear();
841 for (int i = -1 * m_pContentViewer->backwardHistoryCount(); i <= m_pContentViewer->forwardHistoryCount(); ++i)
842 {
843 int iIndex = m_pAddressBar->count();
844 m_pAddressBar->addItem(m_pContentViewer->historyUrl(i).toString(), i);
845 m_pAddressBar->setItemData(iIndex, m_pContentViewer->historyTitle(i), Qt::ToolTipRole);
846 if (i == 0)
847 iCurrentIndex = m_pAddressBar->count();
848 }
849 /* Make sure address bar show the current item: */
850 m_pAddressBar->setCurrentIndex(iCurrentIndex - 1);
851 m_pAddressBar->blockSignals(false);
852
853 if (m_pBackwardAction)
854 m_pBackwardAction->setEnabled(m_pContentViewer->isBackwardAvailable());
855 if (m_pForwardAction)
856 m_pForwardAction->setEnabled(m_pContentViewer->isForwardAvailable());
857
858 emit sigTitleUpdate(m_pContentViewer->historyTitle(0));
859 emit sigHistoryChanged(m_pContentViewer->isBackwardAvailable(), m_pContentViewer->isForwardAvailable());
860}
861
862void UIHelpBrowserTab::sltAddressBarIndexChanged(int iIndex)
863{
864 if (!m_pAddressBar || iIndex >= m_pAddressBar->count())
865 return;
866 int iHistoryIndex = m_pAddressBar->itemData(iIndex).toInt();
867 /* There seems to be no way to one-step-jump to a history item: */
868 if (iHistoryIndex == 0)
869 return;
870 if (iHistoryIndex > 0)
871 for (int i = 0; i < iHistoryIndex; ++i)
872 m_pContentViewer->forward();
873 else
874 for (int i = 0; i > iHistoryIndex ; --i)
875 m_pContentViewer->backward();
876}
877
878void UIHelpBrowserTab::sltAddBookmarkAction()
879{
880 emit sigAddBookmark(source(), documentTitle());
881}
882
883void UIHelpBrowserTab::sltAnchorClicked(const QUrl &link)
884{
885 Q_UNUSED(link);
886}
887
888void UIHelpBrowserTab::sltFindInPageWidgetVisibilityChanged(bool fVisible)
889{
890 if (m_pFindInPageAction)
891 {
892 m_pFindInPageAction->blockSignals(true);
893 m_pFindInPageAction->setChecked(fVisible);
894 m_pFindInPageAction->blockSignals(false);
895 }
896 emit sigFindInPageWidgetVisibilityChanged(fVisible);
897}
898
899
900/*********************************************************************************************************************************
901* UIHelpBrowserTabManager definition. *
902*********************************************************************************************************************************/
903
904UIHelpBrowserTabManager::UIHelpBrowserTabManager(const QHelpEngine *pHelpEngine, const QUrl &homeUrl,
905 const QStringList &urlList, QWidget *pParent /* = 0 */)
906 : QITabWidget(pParent)
907 , m_pHelpEngine(pHelpEngine)
908 , m_homeUrl(homeUrl)
909 , m_savedUrlList(urlList)
910 , m_fSwitchToNewTab(true)
911 , m_fToolBarVisible(true)
912 , m_iZoomPercentage(100)
913{
914 Q_UNUSED(m_fSwitchToNewTab);
915 prepare();
916}
917
918void UIHelpBrowserTabManager::addNewTab(const QUrl &initialUrl, bool fBackground)
919{
920 /* If there is already a tab with a source which is equal to @initialUrl then make it current: */
921 int iExistIndex = findTab(initialUrl);
922 if (iExistIndex != -1)
923 {
924 setCurrentIndex(iExistIndex);
925 return;
926 }
927
928 UIHelpBrowserTab *pTabWidget = new UIHelpBrowserTab(m_pHelpEngine, m_homeUrl, initialUrl);
929 AssertReturnVoid(pTabWidget);
930 pTabWidget->setToolBarVisible(m_fToolBarVisible);
931 int index = addTab(pTabWidget, pTabWidget->documentTitle());
932 connect(pTabWidget, &UIHelpBrowserTab::sigSourceChanged,
933 this, &UIHelpBrowserTabManager::sigSourceChanged);
934 connect(pTabWidget, &UIHelpBrowserTab::sigTitleUpdate,
935 this, &UIHelpBrowserTabManager::sltTabTitleChange);
936 connect(pTabWidget, &UIHelpBrowserTab::sigOpenLinkInNewTab,
937 this, &UIHelpBrowserTabManager::sltOpenLinkInNewTab);
938 connect(pTabWidget, &UIHelpBrowserTab::sigAddBookmark,
939 this, &UIHelpBrowserTabManager::sigAddBookmark);
940 connect(pTabWidget, &UIHelpBrowserTab::sigLinkHighlighted,
941 this, &UIHelpBrowserTabManager::sigLinkHighlighted);
942 connect(pTabWidget, &UIHelpBrowserTab::sigCopyAvailableChanged,
943 this, &UIHelpBrowserTabManager::sltCopyAvailableChanged);
944 connect(pTabWidget, &UIHelpBrowserTab::sigFindInPageWidgetVisibilityChanged,
945 this, &UIHelpBrowserTabManager::sigFindInPageWidgetVisibilityChanged);
946 connect(pTabWidget, &UIHelpBrowserTab::sigHistoryChanged,
947 this, &UIHelpBrowserTabManager::sigHistoryChanged);
948 connect(pTabWidget, &UIHelpBrowserTab::sigMouseOverImage,
949 this, &UIHelpBrowserTabManager::sigMouseOverImage);
950 connect(pTabWidget, &UIHelpBrowserTab::sigZoomRequest,
951 this, &UIHelpBrowserTabManager::sltHandleZoomRequest);
952
953 pTabWidget->setZoomPercentage(zoomPercentage());
954 pTabWidget->setHelpFileList(m_helpFileList);
955 setFocusProxy(pTabWidget);
956 if (!fBackground)
957 setCurrentIndex(index);
958}
959
960void UIHelpBrowserTabManager::updateTabUrlTitleList()
961{
962 QList<QPair<QString, int> > newList;
963
964 QStringList titles = tabTitleList();
965
966 if (titles == m_tabTitleList)
967 return;
968
969 m_tabTitleList = titles;
970 emit sigTabsListChanged(m_tabTitleList);
971}
972
973void UIHelpBrowserTabManager::closeAllTabsBut(int iTabIndex)
974{
975 QString strTitle = tabText(iTabIndex);
976 QList<QWidget*> widgetList;
977 for (int i = 0; i < count(); ++i)
978 widgetList.append(widget(i));
979 clear();
980 for (int i = 0; i < widgetList.size(); ++i)
981 {
982 if (i != iTabIndex)
983 delete widgetList[i];
984 }
985 addTab(widgetList[iTabIndex], strTitle);
986 updateTabUrlTitleList();
987}
988
989int UIHelpBrowserTabManager::findTab(const QUrl &Url) const
990{
991 for (int i = 0; i < count(); ++i)
992 {
993 UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(widget(i));
994 if (!pTab || !pTab->source().isValid())
995 continue;
996 if (pTab->source() == Url)
997 return i;
998 }
999 return -1;
1000}
1001
1002void UIHelpBrowserTabManager::initializeTabs()
1003{
1004 clearAndDeleteTabs();
1005 /* Start with a single tab showing the home URL: */
1006 if (m_savedUrlList.isEmpty())
1007 addNewTab(QUrl(), false);
1008 /* Start with saved tab(s): */
1009 else
1010 for (int i = 0; i < m_savedUrlList.size(); ++i)
1011 addNewTab(m_savedUrlList[i], false);
1012 updateTabUrlTitleList();
1013}
1014
1015QUrl UIHelpBrowserTabManager::currentSource() const
1016{
1017 UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(currentWidget());
1018 if (!pTab)
1019 return QUrl();
1020 return pTab->source();
1021}
1022
1023void UIHelpBrowserTabManager::setSource(const QUrl &url, bool fNewTab /* = false */)
1024{
1025 if (!fNewTab)
1026 {
1027 UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(currentWidget());
1028 if (!pTab)
1029 return;
1030 pTab->setSource(url);
1031 }
1032 else
1033 addNewTab(url, false);
1034 updateTabUrlTitleList();
1035}
1036
1037QStringList UIHelpBrowserTabManager::tabUrlList() const
1038{
1039 QStringList list;
1040 for (int i = 0; i < count(); ++i)
1041 {
1042 UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(widget(i));
1043 if (!pTab || !pTab->source().isValid())
1044 continue;
1045 list << pTab->source().toString();
1046 }
1047 return list;
1048}
1049
1050QStringList UIHelpBrowserTabManager::tabTitleList() const
1051{
1052 QStringList list;
1053 for (int i = 0; i < count(); ++i)
1054 {
1055 UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(widget(i));
1056 if (!pTab || !pTab->source().isValid())
1057 continue;
1058 list << pTab->documentTitle();
1059 }
1060 return list;
1061}
1062
1063void UIHelpBrowserTabManager::setToolBarVisible(bool fVisible)
1064{
1065 /* Make sure existing tabs are configured: */
1066 for (int i = 0; i < count(); ++i)
1067 {
1068 UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(widget(i));
1069 if (!pTab)
1070 continue;
1071 pTab->setToolBarVisible(fVisible);
1072 }
1073 /* This is for the tabs that will be created later: */
1074 m_fToolBarVisible = fVisible;
1075}
1076
1077void UIHelpBrowserTabManager::printCurrent(QPrinter &printer)
1078{
1079 UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(currentWidget());
1080 if (!pTab)
1081 return;
1082 return pTab->print(printer);
1083}
1084
1085void UIHelpBrowserTabManager::switchToTab(int iIndex)
1086{
1087 if (iIndex == currentIndex())
1088 return;
1089 setCurrentIndex(iIndex);
1090}
1091
1092int UIHelpBrowserTabManager::zoomPercentage() const
1093{
1094 return m_iZoomPercentage;
1095}
1096
1097void UIHelpBrowserTabManager::setHelpFileList(const QList<QUrl> &helpFileList)
1098{
1099 m_helpFileList = helpFileList;
1100}
1101
1102void UIHelpBrowserTabManager::copySelectedText() const
1103{
1104 UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(currentWidget());
1105 if (!pTab)
1106 return;
1107 return pTab->copySelectedText();
1108}
1109
1110bool UIHelpBrowserTabManager::hasCurrentTabSelectedText() const
1111{
1112 UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(currentWidget());
1113 if (!pTab)
1114 return false;
1115 return pTab->hasSelectedText();
1116}
1117
1118bool UIHelpBrowserTabManager::isFindInPageWidgetVisible() const
1119{
1120 UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(currentWidget());
1121 if (!pTab)
1122 return false;
1123 return pTab->isFindInPageWidgetVisible();
1124}
1125
1126void UIHelpBrowserTabManager::toggleFindInPage(bool fTrigger)
1127{
1128 UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(currentWidget());
1129 if (pTab)
1130 pTab->sltFindInPageAction(fTrigger);
1131}
1132
1133void UIHelpBrowserTabManager::findNext()
1134{
1135 UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(currentWidget());
1136 if (pTab)
1137 pTab->findNext();
1138}
1139
1140void UIHelpBrowserTabManager::findPrevious()
1141{
1142 UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(currentWidget());
1143 if (pTab)
1144 pTab->findPrevious();
1145}
1146
1147void UIHelpBrowserTabManager::sltTabTitleChange(const QString &strTitle)
1148{
1149 for (int i = 0; i < count(); ++i)
1150 {
1151 if (sender() == widget(i))
1152 {
1153 setTabText(i, strTitle);
1154 setTabToolTip(i, strTitle);
1155 continue;
1156 }
1157 }
1158 updateTabUrlTitleList();
1159}
1160
1161void UIHelpBrowserTabManager::sltOpenLinkInNewTab(const QUrl &url, bool fBackground)
1162{
1163 if (url.isValid())
1164 addNewTab(url, fBackground);
1165 updateTabUrlTitleList();
1166}
1167
1168void UIHelpBrowserTabManager::sltCopyAvailableChanged(bool fAvailable)
1169{
1170 UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(currentWidget());
1171 /* Emit coresponding signal only if sender is the current tab: */
1172 if (pTab && sender() == pTab)
1173 emit sigCopyAvailableChanged(fAvailable);
1174}
1175
1176void UIHelpBrowserTabManager::sltTabClose(int iTabIndex)
1177{
1178 if (count() <= 1)
1179 return;
1180 QWidget *pWidget = widget(iTabIndex);
1181 if (!pWidget)
1182 return;
1183 removeTab(iTabIndex);
1184 delete pWidget;
1185 updateTabUrlTitleList();
1186}
1187
1188void UIHelpBrowserTabManager::sltContextMenuTabClose()
1189{
1190 QAction *pAction = qobject_cast<QAction*>(sender());
1191 if (!pAction)
1192 return;
1193 int iTabIndex = pAction->data().toInt();
1194 if (iTabIndex < 0 || iTabIndex >= count())
1195 return;
1196 sltTabClose(iTabIndex);
1197}
1198
1199void UIHelpBrowserTabManager::sltCloseOtherTabsContextMenuAction()
1200{
1201 /* Find the index of the sender tab. we will close all tabs but sender tab: */
1202 QAction *pAction = qobject_cast<QAction*>(sender());
1203 if (!pAction)
1204 return;
1205 int iTabIndex = pAction->data().toInt();
1206 if (iTabIndex < 0 || iTabIndex >= count())
1207 return;
1208 closeAllTabsBut(iTabIndex);
1209}
1210
1211void UIHelpBrowserTabManager::sltCloseCurrentTab()
1212{
1213 sltTabClose(currentIndex());
1214}
1215
1216void UIHelpBrowserTabManager::sltCloseOtherTabs()
1217{
1218 closeAllTabsBut(currentIndex());
1219}
1220
1221void UIHelpBrowserTabManager::sltCurrentChanged(int iTabIndex)
1222{
1223 Q_UNUSED(iTabIndex);
1224 emit sigSourceChanged(currentSource());
1225}
1226
1227void UIHelpBrowserTabManager::sltShowTabBarContextMenu(const QPoint &pos)
1228{
1229 if (!tabBar())
1230 return;
1231 QMenu menu;
1232 QAction *pCloseAll = menu.addAction(UIHelpBrowserWidget::tr("Close Other Tabs"));
1233 connect(pCloseAll, &QAction::triggered, this, &UIHelpBrowserTabManager::sltCloseOtherTabsContextMenuAction);
1234 pCloseAll->setData(tabBar()->tabAt(pos));
1235
1236 QAction *pClose = menu.addAction(UIHelpBrowserWidget::tr("Close Tab"));
1237 connect(pClose, &QAction::triggered, this, &UIHelpBrowserTabManager::sltContextMenuTabClose);
1238 pClose->setData(tabBar()->tabAt(pos));
1239
1240 menu.exec(tabBar()->mapToGlobal(pos));
1241}
1242
1243void UIHelpBrowserTabManager::sltHomeAction()
1244{
1245 UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(currentWidget());
1246 if (pTab)
1247 pTab->sltHomeAction();
1248}
1249
1250void UIHelpBrowserTabManager::sltAddBookmarkAction()
1251{
1252 UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(currentWidget());
1253 if (pTab)
1254 pTab->sltAddBookmarkAction();
1255}
1256
1257void UIHelpBrowserTabManager::sltForwardAction()
1258{
1259 UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(currentWidget());
1260 if (pTab)
1261 pTab->sltForwardAction();
1262}
1263
1264void UIHelpBrowserTabManager::sltBackwardAction()
1265{
1266 UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(currentWidget());
1267 if (pTab)
1268 pTab->sltBackwardAction();
1269}
1270
1271void UIHelpBrowserTabManager::sltHandleZoomRequest(UIHelpViewer::ZoomOperation enmOperation)
1272{
1273 int iZoomPercentage = m_iZoomPercentage;
1274 switch (enmOperation)
1275 {
1276 case UIHelpViewer::ZoomOperation_In:
1277 iZoomPercentage += iZoomPercentageStep;
1278 break;
1279 case UIHelpViewer::ZoomOperation_Out:
1280 iZoomPercentage -= iZoomPercentageStep;
1281 break;
1282 case UIHelpViewer::ZoomOperation_Reset:
1283 default:
1284 iZoomPercentage = 100;
1285 break;
1286 }
1287 setZoomPercentage(iZoomPercentage);
1288}
1289
1290void UIHelpBrowserTabManager::setZoomPercentage(int iZoomPercentage)
1291{
1292
1293 if (iZoomPercentage > zoomPercentageMinMax.second ||
1294 iZoomPercentage < zoomPercentageMinMax.first)
1295 return;
1296
1297 m_iZoomPercentage = iZoomPercentage;
1298
1299 for (int i = 0; i < count(); ++i)
1300 {
1301 UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(widget(i));
1302 if (pTab)
1303 pTab->setZoomPercentage(m_iZoomPercentage);
1304 }
1305 emit sigZoomPercentageChanged(m_iZoomPercentage);
1306}
1307
1308void UIHelpBrowserTabManager::sltReloadPageAction()
1309{
1310 UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(currentWidget());
1311 if (pTab)
1312 pTab->sltReloadPageAction();
1313}
1314
1315void UIHelpBrowserTabManager::prepare()
1316{
1317 setTabsClosable(true);
1318 setTabBarAutoHide(true);
1319 connect(this, &UIHelpBrowserTabManager::tabCloseRequested, this, &UIHelpBrowserTabManager::sltTabClose);
1320 connect(this, &UIHelpBrowserTabManager::currentChanged, this, &UIHelpBrowserTabManager::sltCurrentChanged);
1321 if (tabBar())
1322 {
1323 tabBar()->setContextMenuPolicy(Qt::CustomContextMenu);
1324 connect(tabBar(), &QTabBar::customContextMenuRequested, this, &UIHelpBrowserTabManager::sltShowTabBarContextMenu);
1325 }
1326}
1327
1328void UIHelpBrowserTabManager::clearAndDeleteTabs()
1329{
1330 QList<QWidget*> tabList;
1331 for (int i = 0; i < count(); ++i)
1332 tabList << widget(i);
1333 /* QTabWidget::clear() does not delete tab widgets: */
1334 clear();
1335 foreach (QWidget *pWidget, tabList)
1336 delete pWidget;
1337}
1338
1339
1340/*********************************************************************************************************************************
1341* UIHelpBrowserWidget implementation. *
1342*********************************************************************************************************************************/
1343
1344UIHelpBrowserWidget::UIHelpBrowserWidget(EmbedTo enmEmbedding, const QString &strHelpFilePath, QWidget *pParent /* = 0 */)
1345 : QIWithRetranslateUI<QWidget>(pParent)
1346 , m_enmEmbedding(enmEmbedding)
1347 , m_fIsPolished(false)
1348 , m_pMainLayout(0)
1349 , m_pTopLayout(0)
1350 , m_pTabWidget(0)
1351 , m_pToolBar(0)
1352 , m_strHelpFilePath(strHelpFilePath)
1353 , m_pHelpEngine(0)
1354 , m_pSplitter(0)
1355 , m_pFileMenu(0)
1356 , m_pEditMenu(0)
1357 , m_pViewMenu(0)
1358 , m_pTabsMenu(0)
1359 , m_pNavigationMenu(0)
1360 , m_pContentWidget(0)
1361 , m_pIndexWidget(0)
1362 , m_pContentModel(0)
1363 , m_pSearchEngine(0)
1364 , m_pSearchQueryWidget(0)
1365 , m_pSearchResultWidget(0)
1366 , m_pTabManager(0)
1367 , m_pBookmarksWidget(0)
1368 , m_pSearchContainerWidget(0)
1369 , m_pPrintAction(0)
1370 , m_pShowHideSideBarAction(0)
1371 , m_pShowHideToolBarAction(0)
1372 , m_pShowHideStatusBarAction(0)
1373 , m_pCopySelectedTextAction(0)
1374 , m_pFindInPageAction(0)
1375 , m_pFindNextInPageAction(0)
1376 , m_pFindPreviousInPageAction(0)
1377 , m_pBackwardAction(0)
1378 , m_pForwardAction(0)
1379 , m_pHomeAction(0)
1380 , m_pReloadPageAction(0)
1381 , m_pAddBookmarkAction(0)
1382 , m_pZoomMenuAction(0)
1383 , m_fModelContentCreated(false)
1384 , m_fIndexingFinished(false)
1385{
1386 qRegisterMetaType<HelpBrowserTabs>("HelpBrowserTabs");
1387 prepare();
1388 loadOptions();
1389}
1390
1391UIHelpBrowserWidget::~UIHelpBrowserWidget()
1392{
1393 cleanup();
1394}
1395
1396QList<QMenu*> UIHelpBrowserWidget::menus() const
1397{
1398 QList<QMenu*> menuList;
1399 menuList
1400 << m_pFileMenu
1401 << m_pEditMenu
1402 << m_pNavigationMenu
1403 << m_pViewMenu
1404 << m_pTabsMenu;
1405 return menuList;
1406}
1407
1408void UIHelpBrowserWidget::showHelpForKeyword(const QString &strKeyword)
1409{
1410 if (m_fIndexingFinished)
1411 findAndShowUrlForKeyword(strKeyword);
1412 else
1413 m_keywordList.append(strKeyword);
1414}
1415
1416int UIHelpBrowserWidget::zoomPercentage() const
1417{
1418 if (m_pTabManager)
1419 return m_pTabManager->zoomPercentage();
1420 return 0;
1421}
1422
1423bool UIHelpBrowserWidget::shouldBeMaximized() const
1424{
1425 return gEDataManager->logWindowShouldBeMaximized();
1426}
1427
1428void UIHelpBrowserWidget::prepare()
1429{
1430 m_pMainLayout = new QVBoxLayout(this);
1431 m_pMainLayout->setContentsMargins(0.2 * qApp->style()->pixelMetric(QStyle::PM_LayoutLeftMargin),
1432 qApp->style()->pixelMetric(QStyle::PM_LayoutTopMargin),
1433 0.2 * qApp->style()->pixelMetric(QStyle::PM_LayoutRightMargin),
1434 0.2 * qApp->style()->pixelMetric(QStyle::PM_LayoutBottomMargin));
1435
1436 AssertReturnVoid(m_pMainLayout);
1437
1438 prepareActions();
1439 prepareMenu();
1440 prepareWidgets();
1441 prepareConnections();
1442 prepareSearchWidgets();
1443 loadBookmarks();
1444 retranslateUi();
1445}
1446
1447void UIHelpBrowserWidget::prepareActions()
1448{
1449 m_pShowHideSideBarAction = new QAction(this);
1450 m_pShowHideSideBarAction->setCheckable(true);
1451 m_pShowHideSideBarAction->setChecked(true);
1452 connect(m_pShowHideSideBarAction, &QAction::toggled,
1453 this, &UIHelpBrowserWidget::sltWidgetVisibilityToggle);
1454
1455 m_pShowHideToolBarAction = new QAction(this);
1456 m_pShowHideToolBarAction->setCheckable(true);
1457 m_pShowHideToolBarAction->setChecked(true);
1458 connect(m_pShowHideToolBarAction, &QAction::toggled,
1459 this, &UIHelpBrowserWidget::sltWidgetVisibilityToggle);
1460
1461 m_pShowHideStatusBarAction = new QAction(this);
1462 m_pShowHideStatusBarAction->setCheckable(true);
1463 m_pShowHideStatusBarAction->setChecked(true);
1464 connect(m_pShowHideStatusBarAction, &QAction::toggled,
1465 this, &UIHelpBrowserWidget::sltWidgetVisibilityToggle);
1466
1467 m_pCopySelectedTextAction = new QAction(this);
1468 connect(m_pCopySelectedTextAction, &QAction::triggered,
1469 this, &UIHelpBrowserWidget::sltCopySelectedText);
1470 m_pCopySelectedTextAction->setShortcut(QString("Ctrl+C"));
1471
1472 m_pFindInPageAction = new QAction(this);
1473 m_pFindInPageAction->setCheckable(true);
1474 m_pFindInPageAction->setChecked(false);
1475 connect(m_pFindInPageAction, &QAction::triggered,
1476 this, &UIHelpBrowserWidget::sltFindInPage);
1477 m_pFindInPageAction->setShortcut(QKeySequence::Find);
1478
1479 m_pFindNextInPageAction = new QAction(this);
1480 m_pFindNextInPageAction->setEnabled(false);
1481 connect(m_pFindNextInPageAction, &QAction::triggered,
1482 this, &UIHelpBrowserWidget::sltFindNextInPage);
1483 m_pFindNextInPageAction->setShortcut(QKeySequence::FindNext);
1484
1485 m_pFindPreviousInPageAction = new QAction(this);
1486 m_pFindPreviousInPageAction->setEnabled(false);
1487 connect(m_pFindPreviousInPageAction, &QAction::triggered,
1488 this, &UIHelpBrowserWidget::sltFindPreviousInPage);
1489 m_pFindPreviousInPageAction->setShortcut(QKeySequence::FindPrevious);
1490
1491 m_pPrintAction = new QAction(this);
1492 connect(m_pPrintAction, &QAction::triggered,
1493 this, &UIHelpBrowserWidget::sltShowPrintDialog);
1494 m_pPrintAction->setShortcut(QString("Ctrl+P"));
1495
1496 m_pQuitAction = new QAction(this);
1497 connect(m_pQuitAction, &QAction::triggered,
1498 this, &UIHelpBrowserWidget::sigCloseDialog);
1499 m_pQuitAction->setShortcut(QString("Ctrl+Q"));
1500
1501 m_pBackwardAction = new QAction(this);
1502 m_pBackwardAction->setShortcut(QKeySequence::Back);
1503 connect(m_pBackwardAction, &QAction::triggered,
1504 this, &UIHelpBrowserWidget::sigGoBackward);
1505 m_pBackwardAction->setEnabled(false);
1506
1507 m_pForwardAction = new QAction(this);
1508 m_pForwardAction->setShortcut(QKeySequence::Forward);
1509 connect(m_pForwardAction, &QAction::triggered,
1510 this, &UIHelpBrowserWidget::sigGoForward);
1511 m_pForwardAction->setEnabled(false);
1512
1513 m_pHomeAction = new QAction(this);
1514 connect(m_pHomeAction, &QAction::triggered,
1515 this, &UIHelpBrowserWidget::sigGoHome);
1516
1517 m_pReloadPageAction = new QAction(this);
1518 m_pReloadPageAction->setShortcut(QKeySequence::Refresh);
1519 connect(m_pReloadPageAction, &QAction::triggered,
1520 this, &UIHelpBrowserWidget::sigReloadPage);
1521
1522 m_pAddBookmarkAction = new QAction(this);
1523 m_pAddBookmarkAction->setShortcut(QKeySequence("Ctrl+D"));
1524 connect(m_pAddBookmarkAction, &QAction::triggered,
1525 this, &UIHelpBrowserWidget::sigAddBookmark);
1526
1527 m_pZoomMenuAction = new UIZoomMenuAction(this);
1528 connect(m_pZoomMenuAction, &UIZoomMenuAction::sigZoomChanged,
1529 this, &UIHelpBrowserWidget::sltZoomActions);
1530}
1531
1532void UIHelpBrowserWidget::prepareConnections()
1533{
1534 if (m_pTabManager)
1535 {
1536 connect(m_pHomeAction, &QAction::triggered, m_pTabManager, &UIHelpBrowserTabManager::sltHomeAction);
1537 connect(m_pAddBookmarkAction, &QAction::triggered, m_pTabManager, &UIHelpBrowserTabManager::sltAddBookmarkAction);
1538 connect(m_pForwardAction, &QAction::triggered, m_pTabManager, &UIHelpBrowserTabManager::sltForwardAction);
1539 connect(m_pBackwardAction, &QAction::triggered, m_pTabManager, &UIHelpBrowserTabManager::sltBackwardAction);
1540 connect(m_pReloadPageAction, &QAction::triggered, m_pTabManager, &UIHelpBrowserTabManager::sltReloadPageAction);
1541 }
1542}
1543
1544void UIHelpBrowserWidget::prepareWidgets()
1545{
1546 m_pSplitter = new QSplitter;
1547 AssertReturnVoid(m_pSplitter);
1548
1549 m_pMainLayout->addWidget(m_pSplitter);
1550 m_pHelpEngine = new QHelpEngine(m_strHelpFilePath, this);
1551 m_pBookmarksWidget = new UIBookmarksListContainer(this);
1552 m_pTabWidget = new QITabWidget;
1553 m_pTabManager = new UIHelpBrowserTabManager(m_pHelpEngine, findIndexHtml(), loadSavedUrlList());
1554 m_pTabManager->setHelpFileList(m_pHelpEngine->files(m_pHelpEngine->namespaceName(m_strHelpFilePath), QStringList()));
1555
1556 AssertReturnVoid(m_pTabWidget &&
1557 m_pHelpEngine &&
1558 m_pBookmarksWidget &&
1559 m_pTabManager);
1560
1561 m_pContentWidget = m_pHelpEngine->contentWidget();
1562 m_pIndexWidget = m_pHelpEngine->indexWidget();
1563 m_pContentModel = m_pHelpEngine->contentModel();
1564
1565 AssertReturnVoid(m_pContentWidget && m_pIndexWidget && m_pContentModel);
1566 m_pSplitter->addWidget(m_pTabWidget);
1567 m_pContentWidget->setContextMenuPolicy(Qt::CustomContextMenu);
1568
1569 m_pTabWidget->insertTab(HelpBrowserTabs_TOC, m_pContentWidget, QString());
1570 m_pTabWidget->insertTab(HelpBrowserTabs_Bookmarks, m_pBookmarksWidget, QString());
1571 /* Dont insert the index widget since we only have automatically generated indexes: */
1572#if 0
1573 m_pTabWidget->insertTab(HelpBrowserTabs_Index, m_pIndexWidget, QString());
1574#endif
1575
1576 m_pSplitter->addWidget(m_pTabManager);
1577 m_pSplitter->setStretchFactor(0,0);
1578 m_pSplitter->setStretchFactor(1,1);
1579
1580 m_pSplitter->setChildrenCollapsible(false);
1581
1582 connect(m_pTabManager, &UIHelpBrowserTabManager::sigSourceChanged,
1583 this, &UIHelpBrowserWidget::sltViewerSourceChange);
1584 connect(m_pTabManager, &UIHelpBrowserTabManager::sigAddBookmark,
1585 this, &UIHelpBrowserWidget::sltAddNewBookmark);
1586 connect(m_pTabManager, &UIHelpBrowserTabManager::sigTabsListChanged,
1587 this, &UIHelpBrowserWidget::sltTabListChanged);
1588 connect(m_pTabManager, &UIHelpBrowserTabManager::currentChanged,
1589 this, &UIHelpBrowserWidget::sltCurrentTabChanged);
1590 connect(m_pTabManager, &UIHelpBrowserTabManager::sigLinkHighlighted,
1591 this, &UIHelpBrowserWidget::sltLinkHighlighted);
1592 connect(m_pTabManager, &UIHelpBrowserTabManager::sigZoomPercentageChanged,
1593 this, &UIHelpBrowserWidget::sltZoomPercentageChanged);
1594 connect(m_pTabManager, &UIHelpBrowserTabManager::sigCopyAvailableChanged,
1595 this, &UIHelpBrowserWidget::sltCopyAvailableChanged);
1596 connect(m_pTabManager, &UIHelpBrowserTabManager::sigFindInPageWidgetVisibilityChanged,
1597 this, &UIHelpBrowserWidget::sltFindInPageWidgetVisibilityChanged);
1598 connect(m_pTabManager, &UIHelpBrowserTabManager::sigHistoryChanged,
1599 this, &UIHelpBrowserWidget::sltHistoryChanged);
1600 connect(m_pTabManager, &UIHelpBrowserTabManager::sigMouseOverImage,
1601 this, &UIHelpBrowserWidget::sltMouseOverImage);
1602
1603 connect(m_pHelpEngine, &QHelpEngine::setupFinished,
1604 this, &UIHelpBrowserWidget::sltHelpEngineSetupFinished);
1605 connect(m_pContentWidget, &QHelpContentWidget::clicked,
1606 this, &UIHelpBrowserWidget::sltContentWidgetItemClicked);
1607 connect(m_pContentModel, &QHelpContentModel::contentsCreated,
1608 this, &UIHelpBrowserWidget::sltContentsCreated);
1609 connect(m_pContentWidget, &QHelpContentWidget::customContextMenuRequested,
1610 this, &UIHelpBrowserWidget::sltShowLinksContextMenu);
1611 connect(m_pBookmarksWidget, &UIBookmarksListContainer::sigBookmarkDoubleClick,
1612 this, &UIHelpBrowserWidget::sltOpenLinkWithUrl);
1613 connect(m_pBookmarksWidget, &UIBookmarksListContainer::sigListWidgetContextMenuRequest,
1614 this, &UIHelpBrowserWidget::sltShowLinksContextMenu);
1615
1616 if (QFile(m_strHelpFilePath).exists() && m_pHelpEngine)
1617 m_pHelpEngine->setupData();
1618}
1619
1620void UIHelpBrowserWidget::prepareSearchWidgets()
1621{
1622 AssertReturnVoid(m_pTabWidget && m_pHelpEngine);
1623
1624 m_pSearchContainerWidget = new QWidget;
1625 m_pTabWidget->insertTab(HelpBrowserTabs_Search, m_pSearchContainerWidget, QString());
1626 m_pTabWidget->setTabPosition(QTabWidget::South);
1627
1628 m_pSearchEngine = m_pHelpEngine->searchEngine();
1629 AssertReturnVoid(m_pSearchEngine);
1630
1631 m_pSearchQueryWidget = m_pSearchEngine->queryWidget();
1632 m_pSearchResultWidget = m_pSearchEngine->resultWidget();
1633 AssertReturnVoid(m_pSearchQueryWidget && m_pSearchResultWidget);
1634 m_pSearchResultWidget->setContextMenuPolicy(Qt::CustomContextMenu);
1635 m_pSearchQueryWidget->setCompactMode(false);
1636
1637 QVBoxLayout *pSearchLayout = new QVBoxLayout(m_pSearchContainerWidget);
1638 pSearchLayout->addWidget(m_pSearchQueryWidget);
1639 pSearchLayout->addWidget(m_pSearchResultWidget);
1640 m_pSearchQueryWidget->expandExtendedSearch();
1641
1642 connect(m_pSearchQueryWidget, &QHelpSearchQueryWidget::search,
1643 this, &UIHelpBrowserWidget::sltSearchStart);
1644 connect(m_pSearchResultWidget, &QHelpSearchResultWidget::requestShowLink,
1645 this, &UIHelpBrowserWidget::sltOpenLinkWithUrl);
1646 connect(m_pSearchResultWidget, &QHelpContentWidget::customContextMenuRequested,
1647 this, &UIHelpBrowserWidget::sltShowLinksContextMenu);
1648 connect(m_pSearchEngine, &QHelpSearchEngine::indexingStarted,
1649 this, &UIHelpBrowserWidget::sltIndexingStarted);
1650 connect(m_pSearchEngine, &QHelpSearchEngine::indexingFinished,
1651 this, &UIHelpBrowserWidget::sltIndexingFinished);
1652 connect(m_pSearchEngine, &QHelpSearchEngine::searchingStarted,
1653 this, &UIHelpBrowserWidget::sltSearchingStarted);
1654
1655 m_pSearchEngine->reindexDocumentation();
1656}
1657
1658void UIHelpBrowserWidget::prepareToolBar()
1659{
1660 m_pTopLayout = new QHBoxLayout;
1661 m_pToolBar = new QIToolBar(parentWidget());
1662 if (m_pToolBar)
1663 {
1664 m_pToolBar->setToolButtonStyle(Qt::ToolButtonIconOnly);
1665 const int iIconMetric = (int)(QApplication::style()->pixelMetric(QStyle::PM_LargeIconSize));
1666 m_pToolBar->setIconSize(QSize(iIconMetric, iIconMetric));
1667
1668#ifdef VBOX_WS_MAC
1669 /* Check whether we are embedded into a stack: */
1670 if (m_enmEmbedding == EmbedTo_Stack)
1671 {
1672 /* Add into layout: */
1673 m_pTopLayout->addWidget(m_pToolBar);
1674 m_pMainLayout->addLayout(m_pTopLayout);
1675 }
1676#else
1677 /* Add into layout: */
1678 m_pTopLayout->addWidget(m_pToolBar);
1679 m_pMainLayout->addLayout(m_pTopLayout);
1680#endif
1681 }
1682}
1683
1684void UIHelpBrowserWidget::prepareMenu()
1685{
1686 m_pFileMenu = new QMenu(tr("&File"), this);
1687 m_pEditMenu = new QMenu(tr("&Edit"), this);
1688 m_pNavigationMenu = new QMenu(tr("&Navigation"), this);
1689 m_pViewMenu = new QMenu(tr("&View"), this);
1690 m_pTabsMenu = new QMenu(tr("&Tabs"), this);
1691
1692 AssertReturnVoid(m_pFileMenu && m_pViewMenu &&
1693 m_pTabsMenu && m_pNavigationMenu);
1694
1695 addActionToMenu(m_pFileMenu, m_pPrintAction);
1696 addActionToMenu(m_pFileMenu, m_pQuitAction);
1697
1698 addActionToMenu(m_pEditMenu, m_pCopySelectedTextAction);
1699 addActionToMenu(m_pEditMenu, m_pFindInPageAction);
1700 addActionToMenu(m_pEditMenu, m_pFindNextInPageAction);
1701 addActionToMenu(m_pEditMenu, m_pFindPreviousInPageAction);
1702
1703 addActionToMenu(m_pViewMenu, m_pZoomMenuAction);
1704 addActionToMenu(m_pViewMenu, m_pShowHideSideBarAction);
1705 addActionToMenu(m_pViewMenu, m_pShowHideToolBarAction);
1706 addActionToMenu(m_pViewMenu, m_pShowHideStatusBarAction);
1707
1708 addActionToMenu(m_pNavigationMenu, m_pBackwardAction);
1709 addActionToMenu(m_pNavigationMenu, m_pForwardAction);
1710 addActionToMenu(m_pNavigationMenu, m_pHomeAction);
1711 addActionToMenu(m_pNavigationMenu, m_pReloadPageAction);
1712 addActionToMenu(m_pNavigationMenu, m_pAddBookmarkAction);
1713}
1714
1715void UIHelpBrowserWidget::loadOptions()
1716{
1717 if (m_pTabManager)
1718 m_pTabManager->setZoomPercentage(gEDataManager->helpBrowserZoomPercentage());
1719}
1720
1721QStringList UIHelpBrowserWidget::loadSavedUrlList()
1722{
1723 return gEDataManager->helpBrowserLastUrlList();
1724}
1725
1726void UIHelpBrowserWidget::loadBookmarks()
1727{
1728 if (!m_pBookmarksWidget)
1729 return;
1730
1731 QStringList bookmarks = gEDataManager->helpBrowserBookmarks();
1732 /* bookmarks list is supposed to have url title pair: */
1733 for (int i = 0; i < bookmarks.size(); ++i)
1734 {
1735 const QString &url = bookmarks[i];
1736 if (i+1 >= bookmarks.size())
1737 break;
1738 ++i;
1739 const QString &strTitle = bookmarks[i];
1740 m_pBookmarksWidget->addBookmark(url, strTitle);
1741 }
1742}
1743
1744void UIHelpBrowserWidget::saveBookmarks()
1745{
1746 if (!m_pBookmarksWidget)
1747 return;
1748 gEDataManager->setHelpBrowserBookmarks(m_pBookmarksWidget->bookmarks());
1749}
1750
1751void UIHelpBrowserWidget::saveOptions()
1752{
1753 if (m_pTabManager)
1754 {
1755 gEDataManager->setHelpBrowserLastUrlList(m_pTabManager->tabUrlList());
1756 gEDataManager->setHelpBrowserZoomPercentage(m_pTabManager->zoomPercentage());
1757 }
1758}
1759
1760QUrl UIHelpBrowserWidget::findIndexHtml() const
1761{
1762 QList<QUrl> files = m_pHelpEngine->files(m_pHelpEngine->namespaceName(m_strHelpFilePath), QStringList());
1763 int iIndex = -1;
1764 for (int i = 0; i < files.size(); ++i)
1765 {
1766 if (files[i].toString().contains("index.html", Qt::CaseInsensitive))
1767 {
1768 iIndex = i;
1769 break;
1770 }
1771 }
1772 if (iIndex == -1)
1773 {
1774 /* If index html/htm could not be found try to find a html file at least: */
1775 for (int i = 0; i < files.size(); ++i)
1776 {
1777 if (files[i].toString().contains(".html", Qt::CaseInsensitive) ||
1778 files[i].toString().contains(".htm", Qt::CaseInsensitive))
1779 {
1780 iIndex = i;
1781 break;
1782 }
1783 }
1784 }
1785 if (iIndex != -1 && files.size() > iIndex)
1786 return files[iIndex];
1787 else
1788 return QUrl();
1789}
1790
1791QUrl UIHelpBrowserWidget::contentWidgetUrl(const QModelIndex &itemIndex)
1792{
1793 QHelpContentModel *pContentModel =
1794 qobject_cast<QHelpContentModel*>(m_pContentWidget->model());
1795 if (!pContentModel)
1796 return QUrl();
1797 QHelpContentItem *pItem = pContentModel->contentItemAt(itemIndex);
1798 if (!pItem)
1799 return QUrl();
1800 return pItem->url();
1801}
1802
1803void UIHelpBrowserWidget::cleanup()
1804{
1805 saveOptions();
1806 saveBookmarks();
1807}
1808
1809void UIHelpBrowserWidget::retranslateUi()
1810{
1811 if (m_pTabWidget)
1812 {
1813 m_pTabWidget->setTabText(HelpBrowserTabs_TOC, tr("Contents"));
1814 m_pTabWidget->setTabText(HelpBrowserTabs_Index, tr("Index"));
1815 m_pTabWidget->setTabText(HelpBrowserTabs_Search, tr("Search"));
1816 m_pTabWidget->setTabText(HelpBrowserTabs_Bookmarks, tr("Bookmarks"));
1817 }
1818
1819 if (m_pShowHideSideBarAction)
1820 m_pShowHideSideBarAction->setText(tr("Show &Side Bar"));
1821 if (m_pShowHideToolBarAction)
1822 m_pShowHideToolBarAction->setText(tr("Show &Tool Bar"));
1823 if (m_pShowHideStatusBarAction)
1824 m_pShowHideStatusBarAction->setText(tr("Show St&atus Bar"));
1825
1826 if (m_pPrintAction)
1827 m_pPrintAction->setText(tr("&Print..."));
1828 if (m_pQuitAction)
1829 m_pQuitAction->setText(tr("&Quit"));
1830
1831 if (m_pCopySelectedTextAction)
1832 m_pCopySelectedTextAction->setText(tr("&Copy Selected Text"));
1833 if (m_pFindInPageAction)
1834 m_pFindInPageAction->setText(tr("&Find in Page"));
1835 if (m_pFindNextInPageAction)
1836 m_pFindNextInPageAction->setText(tr("Find Ne&xt"));
1837 if (m_pFindPreviousInPageAction)
1838 m_pFindPreviousInPageAction->setText(tr("Find &Previous"));
1839
1840 if (m_pBackwardAction)
1841 m_pBackwardAction->setText(tr("Go Backward"));
1842 if (m_pForwardAction)
1843 m_pForwardAction->setText(tr("Go Forward"));
1844 if (m_pHomeAction)
1845 m_pHomeAction->setText(tr("Go to Start Page"));
1846 if (m_pReloadPageAction)
1847 m_pReloadPageAction->setText(tr("Reload Page"));
1848 if (m_pAddBookmarkAction)
1849 m_pAddBookmarkAction->setText(tr("Add Bookmark"));
1850}
1851
1852
1853void UIHelpBrowserWidget::showEvent(QShowEvent *pEvent)
1854{
1855 QWidget::showEvent(pEvent);
1856 if (m_fIsPolished)
1857 return;
1858 m_fIsPolished = true;
1859 if (m_pTabManager)
1860 m_pTabManager->setFocus();
1861}
1862
1863void UIHelpBrowserWidget::keyPressEvent(QKeyEvent *pEvent)
1864{
1865 QWidget::keyPressEvent(pEvent);
1866}
1867
1868void UIHelpBrowserWidget::findAndShowUrlForKeyword(const QString &strKeyword)
1869{
1870#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
1871 QList<QHelpLink> links = m_pHelpEngine->documentsForIdentifier(strKeyword);
1872 if (!links.isEmpty())
1873 {
1874 /* We have to a have a single url per keyword in this case: */
1875 m_pTabManager->setSource(links.first().url, true /* new tab */);
1876 }
1877#else
1878 QMap<QString, QUrl> map = m_pHelpEngine->linksForIdentifier(strKeyword);
1879 if (!map.isEmpty())
1880 {
1881 /* We have to a have a single url per keyword in this case: */
1882 QUrl keywordUrl = map.first();
1883 m_pTabManager->setSource(keywordUrl, true /* new tab */);
1884 }
1885#endif
1886}
1887
1888void UIHelpBrowserWidget::sltWidgetVisibilityToggle(bool fToggled)
1889{
1890 if (sender() == m_pShowHideSideBarAction)
1891 {
1892 if (m_pTabWidget)
1893 m_pTabWidget->setVisible(fToggled);
1894 }
1895 else if (sender() == m_pShowHideToolBarAction)
1896 {
1897 if (m_pTabManager)
1898 m_pTabManager->setToolBarVisible(fToggled);
1899 }
1900 else if (sender() == m_pShowHideStatusBarAction)
1901 emit sigStatusBarVisible(fToggled);
1902}
1903
1904void UIHelpBrowserWidget::sltCopySelectedText()
1905{
1906 if (m_pTabManager)
1907 m_pTabManager->copySelectedText();
1908}
1909
1910void UIHelpBrowserWidget::sltFindInPage(bool fChecked)
1911{
1912 if (m_pTabManager)
1913 m_pTabManager->toggleFindInPage(fChecked);
1914}
1915
1916void UIHelpBrowserWidget::sltFindNextInPage()
1917{
1918 if (m_pTabManager)
1919 m_pTabManager->findNext();
1920}
1921
1922void UIHelpBrowserWidget::sltFindPreviousInPage()
1923{
1924 if (m_pTabManager)
1925 m_pTabManager->findPrevious();
1926}
1927
1928void UIHelpBrowserWidget::sltHistoryChanged(bool fBackwardAvailable, bool fForwardAvailable)
1929{
1930 if (m_pBackwardAction)
1931 m_pBackwardAction->setEnabled(fBackwardAvailable);
1932 if (m_pForwardAction)
1933 m_pForwardAction->setEnabled(fForwardAvailable);
1934}
1935
1936void UIHelpBrowserWidget::sltLinkHighlighted(const QUrl &url)
1937{
1938 QString strMessage = url.url();
1939 if (url.scheme() != "qthelp")
1940 strMessage = QString("%1: %2").arg(tr("Click to open this link in an external browser")).arg(strMessage);
1941
1942 emit sigStatusBarMessage(strMessage, 0);
1943}
1944
1945void UIHelpBrowserWidget::sltMouseOverImage(const QString &strImageName)
1946{
1947 emit sigStatusBarMessage(QString("%1: %2").arg(tr("Click to enlarge the image")).arg(strImageName), 3000);
1948}
1949
1950void UIHelpBrowserWidget::sltCopyAvailableChanged(bool fAvailable)
1951{
1952 if (m_pCopySelectedTextAction)
1953 m_pCopySelectedTextAction->setEnabled(fAvailable);
1954}
1955
1956void UIHelpBrowserWidget::sltFindInPageWidgetVisibilityChanged(bool fVisible)
1957{
1958 if (m_pFindInPageAction)
1959 {
1960 m_pFindInPageAction->blockSignals(true);
1961 m_pFindInPageAction->setChecked(fVisible);
1962 m_pFindInPageAction->blockSignals(false);
1963 }
1964 if (m_pFindNextInPageAction)
1965 m_pFindNextInPageAction->setEnabled(fVisible);
1966
1967 if (m_pFindPreviousInPageAction)
1968 m_pFindPreviousInPageAction->setEnabled(fVisible);
1969}
1970
1971void UIHelpBrowserWidget::sltShowPrintDialog()
1972{
1973#ifdef VBOX_WS_NIX
1974 if (!m_pTabManager)
1975 return;
1976 QPrinter printer;
1977 QPrintDialog printDialog(&printer, this);
1978 if (printDialog.exec() == QDialog::Accepted)
1979 m_pTabManager->printCurrent(printer);
1980#endif
1981}
1982
1983void UIHelpBrowserWidget::sltHelpEngineSetupFinished()
1984{
1985 AssertReturnVoid(m_pTabManager);
1986 m_fIndexingFinished = true;
1987 m_pTabManager->initializeTabs();
1988}
1989
1990void UIHelpBrowserWidget::sltContentWidgetItemClicked(const QModelIndex & index)
1991{
1992 AssertReturnVoid(m_pTabManager && m_pHelpEngine && m_pContentWidget);
1993 QUrl url = contentWidgetUrl(index);
1994 if (!url.isValid())
1995 return;
1996 m_pTabManager->setSource(url);
1997
1998 m_pContentWidget->scrollTo(index, QAbstractItemView::EnsureVisible);
1999 m_pContentWidget->expand(index);
2000}
2001
2002void UIHelpBrowserWidget::sltViewerSourceChange(const QUrl &source)
2003{
2004 if (m_fModelContentCreated && m_pContentWidget && source.isValid() && m_pContentModel)
2005 {
2006 QModelIndex index = m_pContentWidget->indexOf(source);
2007 QItemSelectionModel *pSelectionModel = m_pContentWidget->selectionModel();
2008 if (pSelectionModel && index.isValid())
2009 {
2010 m_pContentWidget->blockSignals(true);
2011 pSelectionModel->select(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
2012 m_pContentWidget->scrollTo(index, QAbstractItemView::EnsureVisible);
2013 m_pContentWidget->expand(index);
2014 m_pContentWidget->blockSignals(false);
2015 }
2016 }
2017}
2018
2019void UIHelpBrowserWidget::sltContentsCreated()
2020{
2021 m_fModelContentCreated = true;
2022 if (m_pTabManager)
2023 sltViewerSourceChange(m_pTabManager->currentSource());
2024}
2025
2026void UIHelpBrowserWidget::sltIndexingStarted()
2027{
2028 if (m_pSearchContainerWidget)
2029 m_pSearchContainerWidget->setEnabled(false);
2030}
2031
2032void UIHelpBrowserWidget::sltIndexingFinished()
2033{
2034 AssertReturnVoid(m_pTabManager &&
2035 m_pHelpEngine &&
2036 m_pSearchContainerWidget);
2037
2038 m_pSearchContainerWidget->setEnabled(true);
2039 m_fIndexingFinished = true;
2040 /* Process the keyword queue. */
2041 foreach (const QString strKeyword, m_keywordList)
2042 findAndShowUrlForKeyword(strKeyword);
2043 m_keywordList.clear();
2044
2045}
2046
2047void UIHelpBrowserWidget::sltSearchingStarted()
2048{
2049}
2050
2051void UIHelpBrowserWidget::sltSearchStart()
2052{
2053 AssertReturnVoid(m_pSearchEngine && m_pSearchQueryWidget);
2054 m_pSearchEngine->search(m_pSearchQueryWidget->searchInput());
2055}
2056
2057void UIHelpBrowserWidget::sltShowLinksContextMenu(const QPoint &pos)
2058{
2059 QWidget *pSender = qobject_cast<QWidget*>(sender());
2060 if (!pSender)
2061 return;
2062
2063 QUrl url;
2064 if (pSender == m_pContentWidget)
2065 url = contentWidgetUrl(m_pContentWidget->currentIndex());
2066 else if (pSender == m_pSearchResultWidget)
2067 {
2068 QTextBrowser* browser = m_pSearchResultWidget->findChild<QTextBrowser*>();
2069 if (!browser)
2070 return;
2071 QPoint browserPos = browser->mapFromGlobal(m_pSearchResultWidget->mapToGlobal(pos));
2072 url = browser->anchorAt(browserPos);
2073 }
2074 else if (pSender == m_pBookmarksWidget)
2075 {
2076 /* Assuming that only the UIBookmarksListWidget under the m_pBookmarksWidget sends the context menu request: */
2077 UIBookmarksListWidget *pListWidget = m_pBookmarksWidget->findChild<UIBookmarksListWidget*>();
2078 if (!pListWidget)
2079 return;
2080 url = m_pBookmarksWidget->currentBookmarkUrl();
2081 }
2082 else
2083 return;
2084
2085 bool fURLValid = url.isValid();
2086
2087 QMenu menu;
2088 QAction *pOpen = menu.addAction(tr("Open Link"));
2089 QAction *pOpenInNewTab = menu.addAction(tr("Open Link in New Tab"));
2090 QAction *pCopyLink = menu.addAction(tr("Copy Link"));
2091
2092 pOpen->setData(url);
2093 pOpenInNewTab->setData(url);
2094 pCopyLink->setData(url);
2095
2096 pOpen->setEnabled(fURLValid);
2097 pOpenInNewTab->setEnabled(fURLValid);
2098 pCopyLink->setEnabled(fURLValid);
2099
2100 connect(pOpenInNewTab, &QAction::triggered, this, &UIHelpBrowserWidget::sltOpenLinkInNewTab);
2101 connect(pOpen, &QAction::triggered, this, &UIHelpBrowserWidget::sltOpenLink);
2102 connect(pCopyLink, &QAction::triggered, this, &UIHelpBrowserWidget::sltCopyLink);
2103
2104 if (pSender == m_pBookmarksWidget)
2105 {
2106 menu.addSeparator();
2107 QAction *pDeleteBookmark = menu.addAction(tr("Delete Bookmark"));
2108 QAction *pDeleteAllBookmarks = menu.addAction(tr("Delete All Bookmarks"));
2109 pDeleteBookmark->setEnabled(fURLValid);
2110
2111 connect(pDeleteBookmark, &QAction::triggered, m_pBookmarksWidget, &UIBookmarksListContainer::sltDeleteSelectedBookmark);
2112 connect(pDeleteAllBookmarks, &QAction::triggered, m_pBookmarksWidget, &UIBookmarksListContainer::sltDeleteAllBookmarks);
2113 }
2114
2115 menu.exec(pSender->mapToGlobal(pos));
2116}
2117
2118void UIHelpBrowserWidget::sltOpenLinkInNewTab()
2119{
2120 openLinkSlotHandler(sender(), true);
2121}
2122
2123void UIHelpBrowserWidget::sltOpenLink()
2124{
2125 openLinkSlotHandler(sender(), false);
2126}
2127
2128void UIHelpBrowserWidget::sltCopyLink()
2129{
2130 QAction *pAction = qobject_cast<QAction*>(sender());
2131 if (!pAction)
2132 return;
2133 QUrl url = pAction->data().toUrl();
2134 if (url.isValid())
2135 {
2136 QClipboard *pClipboard = QApplication::clipboard();
2137 if (pClipboard)
2138 pClipboard->setText(url.toString());
2139 }
2140}
2141
2142void UIHelpBrowserWidget::sltAddNewBookmark(const QUrl &url, const QString &strTitle)
2143{
2144 if (m_pBookmarksWidget)
2145 m_pBookmarksWidget->addBookmark(url, strTitle);
2146 Q_UNUSED(url);
2147 emit sigStatusBarMessage(QString("%1 %2").arg(tr("Bookmark added:")).arg(strTitle), 3000);
2148}
2149
2150void UIHelpBrowserWidget::openLinkSlotHandler(QObject *pSenderObject, bool fOpenInNewTab)
2151{
2152 QAction *pAction = qobject_cast<QAction*>(pSenderObject);
2153 if (!pAction)
2154 return;
2155 QUrl url = pAction->data().toUrl();
2156 if (m_pTabManager && url.isValid())
2157 m_pTabManager->setSource(url, fOpenInNewTab);
2158}
2159
2160void UIHelpBrowserWidget::updateTabsMenu(const QStringList &titles)
2161{
2162 if (!m_pTabsMenu)
2163 return;
2164 m_pTabsMenu->clear();
2165
2166 QAction *pCloseTabAction = m_pTabsMenu->addAction(tr("Close T&ab"));
2167 QAction *pCloseOtherTabsAction = m_pTabsMenu->addAction(tr("Close &Other Tabs"));
2168
2169 pCloseTabAction->setShortcut(QString("Ctrl+W"));
2170 pCloseOtherTabsAction->setShortcut(QString("Ctrl+Shift+W"));
2171
2172 pCloseTabAction->setEnabled(titles.size() > 1);
2173 pCloseOtherTabsAction->setEnabled(titles.size() > 1);
2174
2175 connect(pCloseTabAction, &QAction::triggered, m_pTabManager, &UIHelpBrowserTabManager::sltCloseCurrentTab);
2176 connect(pCloseOtherTabsAction, &QAction::triggered, m_pTabManager, &UIHelpBrowserTabManager::sltCloseOtherTabs);
2177
2178 m_pTabsMenu->addSeparator();
2179
2180 for (int i = 0; i < titles.size(); ++i)
2181 {
2182 QAction *pAction = m_pTabsMenu->addAction(titles[i]);
2183 pAction->setData(i);
2184 connect(pAction, &QAction::triggered, this, &UIHelpBrowserWidget::sltTabChoose);
2185 }
2186 if (m_pTabManager)
2187 sltCurrentTabChanged(m_pTabManager->currentIndex());
2188}
2189
2190void UIHelpBrowserWidget::sltOpenLinkWithUrl(const QUrl &url)
2191{
2192 if (m_pTabManager && url.isValid())
2193 m_pTabManager->setSource(url, false);
2194}
2195
2196void UIHelpBrowserWidget::sltZoomActions(int iZoomOperation)
2197{
2198 if (iZoomOperation >= (int) UIHelpViewer::ZoomOperation_Max)
2199 return;
2200 UIHelpViewer::ZoomOperation enmOperation = (UIHelpViewer::ZoomOperation)(iZoomOperation);
2201 m_pTabManager->sltHandleZoomRequest(enmOperation);
2202}
2203
2204void UIHelpBrowserWidget::sltTabListChanged(const QStringList &titleList)
2205{
2206 updateTabsMenu(titleList);
2207}
2208
2209void UIHelpBrowserWidget::sltTabChoose()
2210{
2211 QAction *pAction = qobject_cast<QAction*>(sender());
2212 if (!pAction)
2213 return;
2214 int iIndex = pAction->data().toInt();
2215 if (m_pTabManager)
2216 m_pTabManager->switchToTab(iIndex);
2217}
2218
2219void UIHelpBrowserWidget::sltCurrentTabChanged(int iIndex)
2220{
2221 Q_UNUSED(iIndex);
2222 if (!m_pTabsMenu)
2223 return;
2224
2225 /** Mark the action with iIndex+3 by assigning an icon to it. it is iIndex+3 and not iIndex since we have
2226 * two additional (close tab, close other tabs and a separator) action on top of the tab selection actions: */
2227 QList<QAction*> list = m_pTabsMenu->actions();
2228 for (int i = 0; i < list.size(); ++i)
2229 list[i]->setIcon(QIcon());
2230 if (iIndex+3 >= list.size())
2231 return;
2232 list[iIndex+3]->setIcon(UIIconPool::iconSet(":/help_browser_star_16px.png"));
2233
2234 if (m_pTabManager)
2235 {
2236 if (m_pCopySelectedTextAction)
2237 m_pCopySelectedTextAction->setEnabled(m_pTabManager->hasCurrentTabSelectedText());
2238 if (m_pFindInPageAction)
2239 m_pFindInPageAction->setChecked(m_pTabManager->isFindInPageWidgetVisible());
2240 if (m_pFindNextInPageAction)
2241 m_pFindNextInPageAction->setEnabled(m_pTabManager->isFindInPageWidgetVisible());
2242 if (m_pFindPreviousInPageAction)
2243 m_pFindPreviousInPageAction->setEnabled(m_pTabManager->isFindInPageWidgetVisible());
2244 }
2245}
2246
2247void UIHelpBrowserWidget::sltZoomPercentageChanged(int iPercentage)
2248{
2249 if (m_pZoomMenuAction)
2250 m_pZoomMenuAction->setZoomPercentage(iPercentage);
2251 emit sigZoomPercentageChanged(iPercentage);
2252}
2253
2254void UIHelpBrowserWidget::addActionToMenu(QMenu *pMenu, QAction *pAction)
2255{
2256 if (!pMenu || !pAction)
2257 return;
2258 pMenu->addAction(pAction);
2259}
2260
2261#include "UIHelpBrowserWidget.moc"
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette