Changeset 86806 in vbox
- Timestamp:
- Nov 4, 2020 11:04:53 AM (4 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserWidget.cpp
r86805 r86806 105 105 void retranslateUi(); 106 106 const QHelpEngine* m_pHelpEngine; 107 QString m_strOpenInNewTab;108 107 }; 109 108 … … 183 182 /* Url of the current tab. */ 184 183 QUrl currentSource() const; 185 void set CurrentSource(const QUrl &url);184 void setSource(const QUrl &url, bool fNewTab = false); 186 185 /* Return the list of urls of all open tabs as QStringList. */ 187 186 QStringList tabUrlList(); 188 void addNewTab(const QUrl &initialUrl);189 187 190 188 private slots: … … 199 197 void prepare(); 200 198 void clearAndDeleteTabs(); 199 void addNewTab(const QUrl &initialUrl); 201 200 const QHelpEngine* m_pHelpEngine; 202 201 QUrl m_homeUrl; … … 376 375 for (int i = -1 * m_pContentViewer->backwardHistoryCount(); i <= m_pContentViewer->forwardHistoryCount(); ++i) 377 376 { 377 int iIndex = m_pAddressBar->count(); 378 378 m_pAddressBar->addItem(m_pContentViewer->historyUrl(i).toString(), i); 379 m_pAddressBar->setItemData(iIndex, m_pContentViewer->historyTitle(i), Qt::ToolTipRole); 379 380 if (i == 0) 380 381 iCurrentIndex = m_pAddressBar->count(); … … 461 462 QString strLink = source().resolved(anchorAt(event->pos())).toString(); 462 463 463 QAction *pOpenInNewTabAction = new QAction( m_strOpenInNewTab);464 QAction *pOpenInNewTabAction = new QAction(UIHelpBrowserWidget::tr("Open Link in New Tab")); 464 465 pOpenInNewTabAction->setData(strLink); 465 466 connect(pOpenInNewTabAction, &QAction::triggered, … … 473 474 void UIHelpBrowserViewer::retranslateUi() 474 475 { 475 m_strOpenInNewTab = UIHelpBrowserWidget::tr("Open Link in New Tab");476 476 } 477 477 … … 535 535 } 536 536 537 void UIHelpBrowserTabManager::setCurrentSource(const QUrl &url) 538 { 539 UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(currentWidget()); 540 if (!pTab) 541 return; 542 pTab->setSource(url); 537 void UIHelpBrowserTabManager::setSource(const QUrl &url, bool fNewTab /* = false */) 538 { 539 if (!fNewTab) 540 { 541 UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(currentWidget()); 542 if (!pTab) 543 return; 544 pTab->setSource(url); 545 } 546 else 547 addNewTab(url); 543 548 } 544 549 … … 718 723 AssertReturnVoid(m_pContentWidget && m_pIndexWidget && m_pContentModel); 719 724 m_pSplitter->addWidget(m_pTabWidget); 725 m_pContentWidget->setContextMenuPolicy(Qt::CustomContextMenu); 720 726 721 727 m_pTabWidget->insertTab(HelpBrowserTabs_TOC, m_pContentWidget, QString()); … … 733 739 connect(m_pHelpEngine, &QHelpEngine::setupFinished, 734 740 this, &UIHelpBrowserWidget::sltHandleHelpEngineSetupFinished); 735 if (m_pContentWidget->selectionModel()) 736 connect(m_pContentWidget->selectionModel(), &QItemSelectionModel::selectionChanged, 737 this, &UIHelpBrowserWidget::sltHandleContentWidgetSelectionChanged); 741 // if (m_pContentWidget->selectionModel()) 742 // connect(m_pContentWidget->selectionModel(), &QItemSelectionModel::selectionChanged, 743 // this, &UIHelpBrowserWidget::sltHandleContentWidgetSelectionChanged); 744 connect(m_pContentWidget, &QHelpContentWidget::clicked, 745 this, &UIHelpBrowserWidget::sltHandleContentWidgetItemClicked); 738 746 connect(m_pContentModel, &QHelpContentModel::contentsCreated, 739 747 this, &UIHelpBrowserWidget::sltHandleContentsCreated); 740 748 connect(m_pContentWidget, &QHelpContentWidget::customContextMenuRequested, 749 this, &UIHelpBrowserWidget::sltOpenLinksContextMenu); 741 750 742 751 if (QFile(m_strHelpFilePath).exists() && m_pHelpEngine) … … 888 897 } 889 898 899 QUrl UIHelpBrowserWidget::contentWidgetUrl(const QModelIndex &itemIndex) 900 { 901 QHelpContentModel *pContentModel = 902 qobject_cast<QHelpContentModel*>(m_pContentWidget->model()); 903 if (!pContentModel) 904 return QUrl(); 905 QHelpContentItem *pItem = pContentModel->contentItemAt(itemIndex); 906 if (!pItem) 907 return QUrl(); 908 return pItem->url(); 909 } 910 890 911 void UIHelpBrowserWidget::cleanup() 891 912 { … … 963 984 { 964 985 AssertReturnVoid(m_pTabManager && m_pHelpEngine && m_pContentWidget); 965 QHelpContentModel *pContentModel = 966 qobject_cast<QHelpContentModel*>(m_pContentWidget->model()); 967 if (!pContentModel) 968 return; 969 QHelpContentItem *pItem = pContentModel->contentItemAt(index); 970 if (!pItem) 971 return; 972 const QUrl &url = pItem->url(); 973 m_pTabManager->setCurrentSource(url); 986 QUrl url = contentWidgetUrl(index); 987 if (!url.isValid()) 988 return; 989 m_pTabManager->setSource(url); 974 990 975 991 m_pContentWidget->scrollTo(index, QAbstractItemView::EnsureVisible); … … 1036 1052 } 1037 1053 1054 void UIHelpBrowserWidget::sltOpenLinksContextMenu(const QPoint &pos) 1055 { 1056 QWidget *pSender = qobject_cast<QWidget*>(sender()); 1057 if (!pSender) 1058 return; 1059 1060 QUrl url; 1061 1062 if (pSender == m_pContentWidget) 1063 url = contentWidgetUrl(m_pContentWidget->currentIndex()); 1064 1065 if (!url.isValid()) 1066 return; 1067 1068 QMenu menu; 1069 QAction *pOpen = menu.addAction(tr("Open in Link")); 1070 QAction *pOpenInNewTab = menu.addAction(tr("Open in Link New Tab")); 1071 pOpen->setData(url); 1072 pOpenInNewTab->setData(url); 1073 connect(pOpenInNewTab, &QAction::triggered, 1074 this, &UIHelpBrowserWidget::sltOpenLinkInNewTab); 1075 connect(pOpen, &QAction::triggered, 1076 this, &UIHelpBrowserWidget::sltOpenLink); 1077 1078 menu.exec(pSender->mapToGlobal(pos)); 1079 } 1080 1081 void UIHelpBrowserWidget::sltOpenLinkInNewTab() 1082 { 1083 openLinkSlotHandler(sender(), true); 1084 } 1085 1086 void UIHelpBrowserWidget::sltOpenLink() 1087 { 1088 openLinkSlotHandler(sender(), false); 1089 } 1090 1091 void UIHelpBrowserWidget::openLinkSlotHandler(QObject *pSenderObject, bool fOpenInNewTab) 1092 { 1093 QAction *pAction = qobject_cast<QAction*>(pSenderObject); 1094 if (!pAction) 1095 return; 1096 QUrl url = pAction->data().toUrl(); 1097 if (m_pTabManager && url.isValid()) 1098 m_pTabManager->setSource(url, fOpenInNewTab); 1099 } 1038 1100 1039 1101 #include "UIHelpBrowserWidget.moc" -
trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserWidget.h
r86799 r86806 95 95 void sltHandleSearchStart(); 96 96 void sltHandleHelpBrowserViewerSourceChange(const QUrl &source); 97 void sltOpenLinksContextMenu(const QPoint &pos); 98 void sltOpenLinkInNewTab(); 99 void sltOpenLink(); 97 100 98 101 private: … … 109 112 void cleanup(); 110 113 QUrl findIndexHtml() const; 111 //bool eventFilter(QObject *pWatched, QEvent *pEvent); 114 /* Returns the url of the item with @p itemIndex. */ 115 QUrl contentWidgetUrl(const QModelIndex &itemIndex); 116 void openLinkSlotHandler(QObject *pSenderObject, bool fOpenInNewTab); 112 117 113 118 /** @name Event handling stuff.
Note:
See TracChangeset
for help on using the changeset viewer.