VirtualBox

Changeset 86806 in vbox


Ignore:
Timestamp:
Nov 4, 2020 11:04:53 AM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9831. Adding a context menu to content widget

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  
    105105    void retranslateUi();
    106106    const QHelpEngine* m_pHelpEngine;
    107     QString m_strOpenInNewTab;
    108107};
    109108
     
    183182    /* Url of the current tab. */
    184183    QUrl currentSource() const;
    185     void setCurrentSource(const QUrl &url);
     184    void setSource(const QUrl &url, bool fNewTab = false);
    186185    /* Return the list of urls of all open tabs as QStringList. */
    187186    QStringList tabUrlList();
    188     void addNewTab(const QUrl &initialUrl);
    189187
    190188private slots:
     
    199197    void prepare();
    200198    void clearAndDeleteTabs();
     199    void addNewTab(const QUrl &initialUrl);
    201200    const QHelpEngine* m_pHelpEngine;
    202201    QUrl m_homeUrl;
     
    376375    for (int i = -1 * m_pContentViewer->backwardHistoryCount(); i <= m_pContentViewer->forwardHistoryCount(); ++i)
    377376    {
     377        int iIndex = m_pAddressBar->count();
    378378        m_pAddressBar->addItem(m_pContentViewer->historyUrl(i).toString(), i);
     379        m_pAddressBar->setItemData(iIndex, m_pContentViewer->historyTitle(i), Qt::ToolTipRole);
    379380        if (i == 0)
    380381            iCurrentIndex = m_pAddressBar->count();
     
    461462        QString strLink = source().resolved(anchorAt(event->pos())).toString();
    462463
    463         QAction *pOpenInNewTabAction = new QAction(m_strOpenInNewTab);
     464        QAction *pOpenInNewTabAction = new QAction(UIHelpBrowserWidget::tr("Open Link in New Tab"));
    464465        pOpenInNewTabAction->setData(strLink);
    465466        connect(pOpenInNewTabAction, &QAction::triggered,
     
    473474void UIHelpBrowserViewer::retranslateUi()
    474475{
    475     m_strOpenInNewTab = UIHelpBrowserWidget::tr("Open Link in New Tab");
    476476}
    477477
     
    535535}
    536536
    537 void UIHelpBrowserTabManager::setCurrentSource(const QUrl &url)
    538 {
    539     UIHelpBrowserTab *pTab = qobject_cast<UIHelpBrowserTab*>(currentWidget());
    540     if (!pTab)
    541         return;
    542     pTab->setSource(url);
     537void 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);
    543548}
    544549
     
    718723    AssertReturnVoid(m_pContentWidget && m_pIndexWidget && m_pContentModel);
    719724    m_pSplitter->addWidget(m_pTabWidget);
     725    m_pContentWidget->setContextMenuPolicy(Qt::CustomContextMenu);
    720726
    721727    m_pTabWidget->insertTab(HelpBrowserTabs_TOC, m_pContentWidget, QString());
     
    733739    connect(m_pHelpEngine, &QHelpEngine::setupFinished,
    734740            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);
    738746    connect(m_pContentModel, &QHelpContentModel::contentsCreated,
    739747            this, &UIHelpBrowserWidget::sltHandleContentsCreated);
    740 
     748    connect(m_pContentWidget, &QHelpContentWidget::customContextMenuRequested,
     749            this, &UIHelpBrowserWidget::sltOpenLinksContextMenu);
    741750
    742751    if (QFile(m_strHelpFilePath).exists() && m_pHelpEngine)
     
    888897}
    889898
     899QUrl 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
    890911void UIHelpBrowserWidget::cleanup()
    891912{
     
    963984{
    964985    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);
    974990
    975991    m_pContentWidget->scrollTo(index, QAbstractItemView::EnsureVisible);
     
    10361052}
    10371053
     1054void 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
     1081void UIHelpBrowserWidget::sltOpenLinkInNewTab()
     1082{
     1083    openLinkSlotHandler(sender(), true);
     1084}
     1085
     1086void UIHelpBrowserWidget::sltOpenLink()
     1087{
     1088    openLinkSlotHandler(sender(), false);
     1089}
     1090
     1091void 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}
    10381100
    10391101#include "UIHelpBrowserWidget.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserWidget.h

    r86799 r86806  
    9595    void sltHandleSearchStart();
    9696    void sltHandleHelpBrowserViewerSourceChange(const QUrl &source);
     97    void sltOpenLinksContextMenu(const QPoint &pos);
     98    void sltOpenLinkInNewTab();
     99    void sltOpenLink();
    97100
    98101private:
     
    109112    void cleanup();
    110113    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);
    112117
    113118    /** @name Event handling stuff.
Note: See TracChangeset for help on using the changeset viewer.

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