VirtualBox

Ignore:
Timestamp:
Nov 9, 2020 4:56:38 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9831. Making the bookmark stuff a bit more useful.

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  
    3131#endif
    3232#include <QLabel>
     33#include <QListWidget>
    3334#include <QMenu>
    3435#include <QMouseEvent>
    3536#include <QPixmap>
     37#include <QPushButton>
    3638#include <QScrollBar>
    3739#include <QSpacerItem>
     
    7375Q_DECLARE_METATYPE(HelpBrowserTabs);
    7476
     77const int iBookmarkUrlDataType = 6;
     78
     79
     80/*********************************************************************************************************************************
     81*   UIBookmarksListContainer definition.                                                                                         *
     82*********************************************************************************************************************************/
     83class UIBookmarksListWidget : public QListWidget
     84{
     85
     86    Q_OBJECT;
     87
     88signals:
     89
     90    void sigBookmarkDoubleClick(const QUrl &url);
     91
     92public:
     93
     94    UIBookmarksListWidget(QWidget *pParent = 0);
     95
     96protected:
     97
     98    void mouseDoubleClickEvent(QMouseEvent *event) /* override */;
     99
     100};
     101
     102
     103/*********************************************************************************************************************************
     104*   UIBookmarksListContainer definition.                                                                                         *
     105*********************************************************************************************************************************/
     106class UIBookmarksListContainer : public QIWithRetranslateUI<QWidget>
     107{
     108
     109    Q_OBJECT;
     110
     111signals:
     112
     113    void sigBookmarkDoubleClick(const QUrl &url);
     114    void sigListWidgetContextMenuRequest(const QPoint &listWidgetLocalPos);
     115
     116public:
     117
     118    UIBookmarksListContainer(QWidget *pParent = 0);
     119    void addBookmark(const QUrl &url, const QString &strTitle);
     120    QUrl currentBookmarkUrl();
     121
     122protected:
     123
     124    void retranslateUi() /* override */;
     125
     126private:
     127
     128    void prepare();
     129    int itemIndex(const QUrl &url);
     130
     131    QVBoxLayout  *m_pMainLayout;
     132    UIBookmarksListWidget  *m_pListWidget;
     133};
    75134
    76135/*********************************************************************************************************************************
     
    182241    void sigTitleUpdate(const QString &strTitle);
    183242    void sigOpenLinkInNewTab(const QUrl &url);
     243    void sigAddBookmark(const QUrl &url, const QString &strTitle);
    184244
    185245public:
     
    240300
    241301    void sigSourceChanged(const QUrl &url);
     302    void sigAddBookmark(const QUrl &url, const QString &strTitle);
    242303
    243304public:
     
    271332    bool m_fSwitchToNewTab;
    272333};
     334
     335
     336/*********************************************************************************************************************************
     337*   UIBookmarksListContainer implementation.                                                                                     *
     338*********************************************************************************************************************************/
     339UIBookmarksListWidget::UIBookmarksListWidget(QWidget *pParent /* = 0 */)
     340    :QListWidget(pParent)
     341{
     342}
     343
     344void 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
     358UIBookmarksListContainer::UIBookmarksListContainer(QWidget *pParent /* = 0 */)
     359    :QIWithRetranslateUI<QWidget>(pParent)
     360    , m_pMainLayout(0)
     361    , m_pListWidget(0)
     362{
     363    prepare();
     364}
     365
     366void 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
     377QUrl UIBookmarksListContainer::currentBookmarkUrl()
     378{
     379    if (!m_pListWidget || !m_pListWidget->currentItem())
     380        return QUrl();
     381    return m_pListWidget->currentItem()->data(iBookmarkUrlDataType).toUrl();
     382}
     383
     384void UIBookmarksListContainer::retranslateUi()
     385{
     386}
     387
     388void 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
     402int 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}
    273413
    274414
     
    495635
    496636    connect(m_pHomeAction, &QAction::triggered, this, &UIHelpBrowserTab::sltHandleHomeAction);
    497     connect(m_pBackwardAction, &QAction::triggered, this, &UIHelpBrowserTab::sltHandleAddBookmarkAction);
     637    connect(m_pAddBookmarkAction, &QAction::triggered, this, &UIHelpBrowserTab::sltHandleAddBookmarkAction);
    498638    connect(m_pForwardAction, &QAction::triggered, this, &UIHelpBrowserTab::sltHandleForwardAction);
    499639    connect(m_pBackwardAction, &QAction::triggered, this, &UIHelpBrowserTab::sltHandleBackwardAction);
     
    614754void UIHelpBrowserTab::sltHandleAddBookmarkAction()
    615755{
     756    emit sigAddBookmark(source(), documentTitle());
    616757}
    617758
     
    9001041   connect(pTabWidget, &UIHelpBrowserTab::sigOpenLinkInNewTab,
    9011042           this, &UIHelpBrowserTabManager::sltHandleOpenLinkInNewTab);
     1043   connect(pTabWidget, &UIHelpBrowserTab::sigAddBookmark,
     1044           this, &UIHelpBrowserTabManager::sigAddBookmark);
    9021045   if (m_fSwitchToNewTab)
    9031046       setCurrentIndex(index);
     
    11071250    m_pMainLayout->addWidget(m_pSplitter);
    11081251    m_pHelpEngine = new QHelpEngine(m_strHelpFilePath, this);
    1109     m_pBookmarksWidget = new QWidget(this);
     1252    m_pBookmarksWidget = new UIBookmarksListContainer(this);
    11101253    m_pTabWidget = new QITabWidget;
    11111254    m_pTabManager = new UIHelpBrowserTabManager(m_pHelpEngine, findIndexHtml(), loadSavedUrlList());
     
    11251268
    11261269    m_pTabWidget->insertTab(HelpBrowserTabs_TOC, m_pContentWidget, QString());
     1270    m_pTabWidget->insertTab(HelpBrowserTabs_Bookmarks, m_pBookmarksWidget, QString());
    11271271    m_pTabWidget->insertTab(HelpBrowserTabs_Index, m_pIndexWidget, QString());
    1128     m_pTabWidget->insertTab(HelpBrowserTabs_Bookmarks, m_pBookmarksWidget, QString());
    11291272
    11301273    m_pSplitter->addWidget(m_pTabManager);
     
    11361279    connect(m_pTabManager, &UIHelpBrowserTabManager::sigSourceChanged,
    11371280            this, &UIHelpBrowserWidget::sltHandleHelpBrowserViewerSourceChange);
     1281    connect(m_pTabManager, &UIHelpBrowserTabManager::sigAddBookmark,
     1282           this, &UIHelpBrowserWidget::sltAddNewBookmark);
    11381283    connect(m_pHelpEngine, &QHelpEngine::setupFinished,
    11391284            this, &UIHelpBrowserWidget::sltHandleHelpEngineSetupFinished);
     
    11431288            this, &UIHelpBrowserWidget::sltHandleContentsCreated);
    11441289    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,
    11451294            this, &UIHelpBrowserWidget::sltShowLinksContextMenu);
    11461295
     
    14591608        if (!browser)
    14601609            return;
    1461         if (!browser->rect().contains(pos, true))
    1462             return;
     1610        // if (!browser->rect().contains(pos, true))
     1611        //     return;
    14631612        QPoint browserPos = browser->mapFromGlobal(m_pSearchResultWidget->mapToGlobal(pos));
    14641613        url = browser->anchorAt(browserPos);
    14651614    }
     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;
    14661625
    14671626    if (!url.isValid())
     
    14911650}
    14921651
     1652void UIHelpBrowserWidget::sltAddNewBookmark(const QUrl &url, const QString &strTitle)
     1653{
     1654    if (m_pBookmarksWidget)
     1655        m_pBookmarksWidget->addBookmark(url, strTitle);
     1656}
     1657
    14931658void UIHelpBrowserWidget::openLinkSlotHandler(QObject *pSenderObject, bool fOpenInNewTab)
    14941659{
  • trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserWidget.h

    r86812 r86835  
    5252class QIToolBar;
    5353class UIActionPool;
     54class UIBookmarksListContainer;
    5455class UIDialogPanel;
    5556class UIHelpBrowserTabManager;
     
    9899    void sltOpenLinkInNewTab();
    99100    void sltOpenLink();
     101    void sltAddNewBookmark(const QUrl &url, const QString &strTitle);
    100102
    101103private:
     
    157159    QHelpSearchEngine   *m_pSearchEngine;
    158160    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;
    162164    QWidget             *m_pSearchContainerWidget;
    163165    QAction             *m_pShowHideSideBarAction;
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