Changeset 86800 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Nov 3, 2020 6:50:12 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserWidget.cpp
r86799 r86800 75 75 *********************************************************************************************************************************/ 76 76 77 class UIHelpBrowserViewer : public Q TextBrowser77 class UIHelpBrowserViewer : public QIWithRetranslateUI<QTextBrowser> 78 78 { 79 79 Q_OBJECT; 80 81 signals: 82 83 void sigOpenLinkInNewTab(const QUrl &url); 80 84 81 85 public: … … 88 92 public slots: 89 93 90 //virtual void setSource(const QUrl &name) /* override */; 94 95 protected: 96 97 void contextMenuEvent(QContextMenuEvent *event) /* override */; 98 99 private slots: 100 101 void sltHandleOpenInNewTab(); 91 102 92 103 private: 93 104 105 void retranslateUi(); 94 106 const QHelpEngine* m_pHelpEngine; 107 QString m_strOpenInNewTab; 95 108 }; 96 109 … … 106 119 107 120 void sigSourceChanged(const QUrl &url); 121 void sigTitleUpdate(const QString &strTitle); 122 void sigOpenLinkInNewTab(const QUrl &url); 108 123 109 124 public: … … 114 129 QUrl source() const; 115 130 void setSource(const QUrl &url); 131 QString documentTitle() const; 116 132 117 133 private slots: … … 170 186 /* Return the list of urls of all open tabs as QStringList. */ 171 187 QStringList tabUrlList(); 188 void addNewTab(const QUrl &initialUrl); 189 190 private slots: 191 192 void sltHandletabTitleChange(const QString &strTitle); 193 void sltHandleOpenLinkInNewTab(const QUrl &url); 172 194 173 195 private: … … 178 200 QUrl m_homeUrl; 179 201 QStringList m_savedUrlList; 202 bool m_fSwitchToNewTab; 180 203 }; 181 204 … … 223 246 } 224 247 248 QString UIHelpBrowserTab::documentTitle() const 249 { 250 if (!m_pContentViewer) 251 return QString(); 252 return m_pContentViewer->documentTitle(); 253 } 254 225 255 void UIHelpBrowserTab::prepare(const QUrl &initialUrl) 226 256 { … … 247 277 connect(m_pContentViewer, &UIHelpBrowserViewer::anchorClicked, 248 278 this, &UIHelpBrowserTab::sltAnchorClicked); 249 279 connect(m_pContentViewer, &UIHelpBrowserViewer::sigOpenLinkInNewTab, 280 this, &UIHelpBrowserTab::sigOpenLinkInNewTab); 250 281 m_pContentViewer->setSource(initialUrl, m_strPageNotFoundText); 251 282 } … … 357 388 m_pForwardAction->setEnabled(m_pContentViewer->isForwardAvailable()); 358 389 390 emit sigTitleUpdate(m_pContentViewer->historyTitle(0)); 359 391 } 360 392 … … 391 423 392 424 UIHelpBrowserViewer::UIHelpBrowserViewer(const QHelpEngine *pHelpEngine, QWidget *pParent /* = 0 */) 393 :Q TextBrowser(pParent)425 :QIWithRetranslateUI<QTextBrowser>(pParent) 394 426 , m_pHelpEngine(pHelpEngine) 395 427 { 396 428 Q_UNUSED(pHelpEngine); 429 retranslateUi(); 397 430 } 398 431 … … 419 452 } 420 453 454 void UIHelpBrowserViewer::contextMenuEvent(QContextMenuEvent *event) 455 { 456 QMenu *pMenu = createStandardContextMenu(); 457 QString strAnchor = anchorAt(event->pos()); 458 if (!strAnchor.isEmpty()) 459 { 460 QString strLink = source().resolved(anchorAt(event->pos())).toString(); 461 462 QAction *pOpenInNewTabAction = new QAction(m_strOpenInNewTab); 463 pOpenInNewTabAction->setData(strLink); 464 connect(pOpenInNewTabAction, &QAction::triggered, 465 this, &UIHelpBrowserViewer::sltHandleOpenInNewTab); 466 pMenu->addAction(pOpenInNewTabAction); 467 } 468 pMenu->exec(event->globalPos()); 469 delete pMenu; 470 } 471 472 void UIHelpBrowserViewer::retranslateUi() 473 { 474 m_strOpenInNewTab = UIHelpBrowserWidget::tr("Open Link in New Tab"); 475 } 476 477 void UIHelpBrowserViewer::sltHandleOpenInNewTab() 478 { 479 QAction *pSender = qobject_cast<QAction*>(sender()); 480 if (!pSender) 481 return; 482 QUrl url = pSender->data().toUrl(); 483 if (url.isValid()) 484 emit sigOpenLinkInNewTab(url); 485 } 421 486 422 487 /********************************************************************************************************************************* … … 430 495 , m_homeUrl(homeUrl) 431 496 , m_savedUrlList(urlList) 497 , m_fSwitchToNewTab(true) 432 498 { 433 499 prepare(); 500 } 501 502 void UIHelpBrowserTabManager::addNewTab(const QUrl &initialUrl) 503 { 504 UIHelpBrowserTab *pTabWidget = new UIHelpBrowserTab(m_pHelpEngine, m_homeUrl, initialUrl); 505 AssertReturnVoid(pTabWidget); 506 int index = addTab(pTabWidget, pTabWidget->documentTitle()); 507 connect(pTabWidget, &UIHelpBrowserTab::sigSourceChanged, 508 this, &UIHelpBrowserTabManager::sigSourceChanged); 509 connect(pTabWidget, &UIHelpBrowserTab::sigTitleUpdate, 510 this, &UIHelpBrowserTabManager::sltHandletabTitleChange); 511 connect(pTabWidget, &UIHelpBrowserTab::sigOpenLinkInNewTab, 512 this, &UIHelpBrowserTabManager::sltHandleOpenLinkInNewTab); 513 if (m_fSwitchToNewTab) 514 setCurrentIndex(index); 434 515 } 435 516 … … 441 522 if (!m_savedUrlList.isEmpty()) 442 523 initialUrl = m_savedUrlList[0]; 443 UIHelpBrowserTab *pTabWidget = new UIHelpBrowserTab(m_pHelpEngine, m_homeUrl, initialUrl); 444 addTab(pTabWidget, QString()); 445 connect(pTabWidget, &UIHelpBrowserTab::sigSourceChanged, 446 this, &UIHelpBrowserTabManager::sigSourceChanged); 524 addNewTab(initialUrl); 447 525 } 448 526 … … 474 552 } 475 553 return list; 554 } 555 556 void UIHelpBrowserTabManager::sltHandletabTitleChange(const QString &strTitle) 557 { 558 for (int i = 0; i < count(); ++i) 559 { 560 if (sender() == widget(i)) 561 { 562 setTabText(i, strTitle); 563 continue; 564 } 565 } 566 } 567 568 void UIHelpBrowserTabManager::sltHandleOpenLinkInNewTab(const QUrl &url) 569 { 570 if (url.isValid()) 571 addNewTab(url); 476 572 } 477 573 … … 858 954 m_pContentWidget->scrollTo(index, QAbstractItemView::EnsureVisible); 859 955 m_pContentWidget->expand(index); 860 861 956 } 862 957
Note:
See TracChangeset
for help on using the changeset viewer.