Changeset 86835 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Nov 9, 2020 4:56:38 PM (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
r86832 r86835 31 31 #endif 32 32 #include <QLabel> 33 #include <QListWidget> 33 34 #include <QMenu> 34 35 #include <QMouseEvent> 35 36 #include <QPixmap> 37 #include <QPushButton> 36 38 #include <QScrollBar> 37 39 #include <QSpacerItem> … … 73 75 Q_DECLARE_METATYPE(HelpBrowserTabs); 74 76 77 const int iBookmarkUrlDataType = 6; 78 79 80 /********************************************************************************************************************************* 81 * UIBookmarksListContainer definition. * 82 *********************************************************************************************************************************/ 83 class UIBookmarksListWidget : public QListWidget 84 { 85 86 Q_OBJECT; 87 88 signals: 89 90 void sigBookmarkDoubleClick(const QUrl &url); 91 92 public: 93 94 UIBookmarksListWidget(QWidget *pParent = 0); 95 96 protected: 97 98 void mouseDoubleClickEvent(QMouseEvent *event) /* override */; 99 100 }; 101 102 103 /********************************************************************************************************************************* 104 * UIBookmarksListContainer definition. * 105 *********************************************************************************************************************************/ 106 class UIBookmarksListContainer : public QIWithRetranslateUI<QWidget> 107 { 108 109 Q_OBJECT; 110 111 signals: 112 113 void sigBookmarkDoubleClick(const QUrl &url); 114 void sigListWidgetContextMenuRequest(const QPoint &listWidgetLocalPos); 115 116 public: 117 118 UIBookmarksListContainer(QWidget *pParent = 0); 119 void addBookmark(const QUrl &url, const QString &strTitle); 120 QUrl currentBookmarkUrl(); 121 122 protected: 123 124 void retranslateUi() /* override */; 125 126 private: 127 128 void prepare(); 129 int itemIndex(const QUrl &url); 130 131 QVBoxLayout *m_pMainLayout; 132 UIBookmarksListWidget *m_pListWidget; 133 }; 75 134 76 135 /********************************************************************************************************************************* … … 182 241 void sigTitleUpdate(const QString &strTitle); 183 242 void sigOpenLinkInNewTab(const QUrl &url); 243 void sigAddBookmark(const QUrl &url, const QString &strTitle); 184 244 185 245 public: … … 240 300 241 301 void sigSourceChanged(const QUrl &url); 302 void sigAddBookmark(const QUrl &url, const QString &strTitle); 242 303 243 304 public: … … 271 332 bool m_fSwitchToNewTab; 272 333 }; 334 335 336 /********************************************************************************************************************************* 337 * UIBookmarksListContainer implementation. * 338 *********************************************************************************************************************************/ 339 UIBookmarksListWidget::UIBookmarksListWidget(QWidget *pParent /* = 0 */) 340 :QListWidget(pParent) 341 { 342 } 343 344 void UIBookmarksListWidget::mouseDoubleClickEvent(QMouseEvent *event) 345 { 346 QListWidgetItem *pItem = currentItem(); 347 if (!pItem) 348 return; 349 emit sigBookmarkDoubleClick(pItem->data(iBookmarkUrlDataType).toUrl()); 350 QListWidget::mouseDoubleClickEvent(event); 351 } 352 353 354 /********************************************************************************************************************************* 355 * UIBookmarksListContainer implementation. * 356 *********************************************************************************************************************************/ 357 358 UIBookmarksListContainer::UIBookmarksListContainer(QWidget *pParent /* = 0 */) 359 :QIWithRetranslateUI<QWidget>(pParent) 360 , m_pMainLayout(0) 361 , m_pListWidget(0) 362 { 363 prepare(); 364 } 365 366 void UIBookmarksListContainer::addBookmark(const QUrl &url, const QString &strTitle) 367 { 368 if (!m_pListWidget) 369 return; 370 if (itemIndex(url) != -1) 371 return; 372 QListWidgetItem *pNewItem = new QListWidgetItem(strTitle, m_pListWidget); 373 pNewItem->setData(iBookmarkUrlDataType, url); 374 pNewItem->setToolTip(url.toString()); 375 } 376 377 QUrl UIBookmarksListContainer::currentBookmarkUrl() 378 { 379 if (!m_pListWidget || !m_pListWidget->currentItem()) 380 return QUrl(); 381 return m_pListWidget->currentItem()->data(iBookmarkUrlDataType).toUrl(); 382 } 383 384 void UIBookmarksListContainer::retranslateUi() 385 { 386 } 387 388 void UIBookmarksListContainer::prepare() 389 { 390 m_pMainLayout = new QVBoxLayout(this); 391 AssertReturnVoid(m_pMainLayout); 392 m_pListWidget = new UIBookmarksListWidget; 393 AssertReturnVoid(m_pListWidget); 394 m_pMainLayout->addWidget(m_pListWidget); 395 m_pListWidget->setContextMenuPolicy(Qt::CustomContextMenu); 396 connect(m_pListWidget, &UIBookmarksListWidget::sigBookmarkDoubleClick, 397 this, &UIBookmarksListContainer::sigBookmarkDoubleClick); 398 connect(m_pListWidget, &UIBookmarksListWidget::customContextMenuRequested, 399 this, &UIBookmarksListContainer::sigListWidgetContextMenuRequest); 400 } 401 402 int UIBookmarksListContainer::itemIndex(const QUrl &url) 403 { 404 if (!m_pListWidget || !url.isValid()) 405 return -1; 406 for (int i = 0; i < m_pListWidget->count(); ++i) 407 { 408 if (m_pListWidget->item(i)->data(iBookmarkUrlDataType).toUrl() == url) 409 return i; 410 } 411 return -1; 412 } 273 413 274 414 … … 495 635 496 636 connect(m_pHomeAction, &QAction::triggered, this, &UIHelpBrowserTab::sltHandleHomeAction); 497 connect(m_p BackwardAction, &QAction::triggered, this, &UIHelpBrowserTab::sltHandleAddBookmarkAction);637 connect(m_pAddBookmarkAction, &QAction::triggered, this, &UIHelpBrowserTab::sltHandleAddBookmarkAction); 498 638 connect(m_pForwardAction, &QAction::triggered, this, &UIHelpBrowserTab::sltHandleForwardAction); 499 639 connect(m_pBackwardAction, &QAction::triggered, this, &UIHelpBrowserTab::sltHandleBackwardAction); … … 614 754 void UIHelpBrowserTab::sltHandleAddBookmarkAction() 615 755 { 756 emit sigAddBookmark(source(), documentTitle()); 616 757 } 617 758 … … 900 1041 connect(pTabWidget, &UIHelpBrowserTab::sigOpenLinkInNewTab, 901 1042 this, &UIHelpBrowserTabManager::sltHandleOpenLinkInNewTab); 1043 connect(pTabWidget, &UIHelpBrowserTab::sigAddBookmark, 1044 this, &UIHelpBrowserTabManager::sigAddBookmark); 902 1045 if (m_fSwitchToNewTab) 903 1046 setCurrentIndex(index); … … 1107 1250 m_pMainLayout->addWidget(m_pSplitter); 1108 1251 m_pHelpEngine = new QHelpEngine(m_strHelpFilePath, this); 1109 m_pBookmarksWidget = new QWidget(this);1252 m_pBookmarksWidget = new UIBookmarksListContainer(this); 1110 1253 m_pTabWidget = new QITabWidget; 1111 1254 m_pTabManager = new UIHelpBrowserTabManager(m_pHelpEngine, findIndexHtml(), loadSavedUrlList()); … … 1125 1268 1126 1269 m_pTabWidget->insertTab(HelpBrowserTabs_TOC, m_pContentWidget, QString()); 1270 m_pTabWidget->insertTab(HelpBrowserTabs_Bookmarks, m_pBookmarksWidget, QString()); 1127 1271 m_pTabWidget->insertTab(HelpBrowserTabs_Index, m_pIndexWidget, QString()); 1128 m_pTabWidget->insertTab(HelpBrowserTabs_Bookmarks, m_pBookmarksWidget, QString());1129 1272 1130 1273 m_pSplitter->addWidget(m_pTabManager); … … 1136 1279 connect(m_pTabManager, &UIHelpBrowserTabManager::sigSourceChanged, 1137 1280 this, &UIHelpBrowserWidget::sltHandleHelpBrowserViewerSourceChange); 1281 connect(m_pTabManager, &UIHelpBrowserTabManager::sigAddBookmark, 1282 this, &UIHelpBrowserWidget::sltAddNewBookmark); 1138 1283 connect(m_pHelpEngine, &QHelpEngine::setupFinished, 1139 1284 this, &UIHelpBrowserWidget::sltHandleHelpEngineSetupFinished); … … 1143 1288 this, &UIHelpBrowserWidget::sltHandleContentsCreated); 1144 1289 connect(m_pContentWidget, &QHelpContentWidget::customContextMenuRequested, 1290 this, &UIHelpBrowserWidget::sltShowLinksContextMenu); 1291 connect(m_pBookmarksWidget, &UIBookmarksListContainer::sigBookmarkDoubleClick, 1292 this, &UIHelpBrowserWidget::sltOpenLinkWithUrl); 1293 connect(m_pBookmarksWidget, &UIBookmarksListContainer::sigListWidgetContextMenuRequest, 1145 1294 this, &UIHelpBrowserWidget::sltShowLinksContextMenu); 1146 1295 … … 1459 1608 if (!browser) 1460 1609 return; 1461 if (!browser->rect().contains(pos, true))1462 return;1610 // if (!browser->rect().contains(pos, true)) 1611 // return; 1463 1612 QPoint browserPos = browser->mapFromGlobal(m_pSearchResultWidget->mapToGlobal(pos)); 1464 1613 url = browser->anchorAt(browserPos); 1465 1614 } 1615 else if (pSender == m_pBookmarksWidget) 1616 { 1617 /* Assuming that only the UIBookmarksListWidget under the m_pBookmarksWidget sends the context menu request: */ 1618 UIBookmarksListWidget *pListWidget = m_pBookmarksWidget->findChild<UIBookmarksListWidget*>(); 1619 if (!pListWidget) 1620 return; 1621 url = m_pBookmarksWidget->currentBookmarkUrl(); 1622 } 1623 else 1624 return; 1466 1625 1467 1626 if (!url.isValid()) … … 1491 1650 } 1492 1651 1652 void UIHelpBrowserWidget::sltAddNewBookmark(const QUrl &url, const QString &strTitle) 1653 { 1654 if (m_pBookmarksWidget) 1655 m_pBookmarksWidget->addBookmark(url, strTitle); 1656 } 1657 1493 1658 void UIHelpBrowserWidget::openLinkSlotHandler(QObject *pSenderObject, bool fOpenInNewTab) 1494 1659 { -
trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserWidget.h
r86812 r86835 52 52 class QIToolBar; 53 53 class UIActionPool; 54 class UIBookmarksListContainer; 54 55 class UIDialogPanel; 55 56 class UIHelpBrowserTabManager; … … 98 99 void sltOpenLinkInNewTab(); 99 100 void sltOpenLink(); 101 void sltAddNewBookmark(const QUrl &url, const QString &strTitle); 100 102 101 103 private: … … 157 159 QHelpSearchEngine *m_pSearchEngine; 158 160 QHelpSearchQueryWidget *m_pSearchQueryWidget; 159 QHelpSearchResultWidget *m_pSearchResultWidget;160 UIHelpBrowserTabManager *m_pTabManager;161 QWidget*m_pBookmarksWidget;161 QHelpSearchResultWidget *m_pSearchResultWidget; 162 UIHelpBrowserTabManager *m_pTabManager; 163 UIBookmarksListContainer *m_pBookmarksWidget; 162 164 QWidget *m_pSearchContainerWidget; 163 165 QAction *m_pShowHideSideBarAction;
Note:
See TracChangeset
for help on using the changeset viewer.