VirtualBox

Changeset 86906 in vbox


Ignore:
Timestamp:
Nov 18, 2020 7:06:07 AM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
141386
Message:

FE/Qt: bugref:9831. Enabling context sensitive help

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp

    r86846 r86906  
    1717
    1818/* Qt includes: */
     19#include <QAbstractButton>
    1920#include <QDir>
    2021#include <QFileInfo>
     
    612613    error(pParent, MessageType_Error,
    613614          tr("Failed to acquire machine parameter."), UIErrorString::formatErrorInfo(comMachine));
     615}
     616
     617void UIMessageCenter::cannotFindHelpFile(const QString &strFileLocation, QWidget *pParent /* = 0 */) const
     618{
     619    /* Show the error: */
     620    error(pParent, MessageType_Error,
     621          tr("Failed to find help file."),
     622          QString("%1:<!--EOM-->%2").arg(tr("The following file could not found")).arg(strFileLocation));
    614623}
    615624
     
    32253234#elif defined (VBOX_WS_X11)
    32263235# if defined(VBOX_WITH_DOCS_QHELP) && (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
    3227     showHelpBrowser(strLocation);
    3228 # endif /* #if defined(VBOX_WITH_DOCS_QHELP) && (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))&& (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)) */
    3229 # ifndef VBOX_OSE
     3236    showHelpBrowser(strLocation, QString());
     3237# elif !defined(VBOX_OSE)
    32303238    char szViewerPath[RTPATH_MAX];
    32313239    int rc;
     
    34253433}
    34263434
    3427 void UIMessageCenter::showHelpBrowser(const QString strHelpFilePath, QWidget *pParent /* = 0 */)
     3435void UIMessageCenter::showHelpBrowser(const QString &strHelpFilePath, const QString &strKeyword, QWidget *pParent /* = 0 */)
    34283436{
    34293437    Q_UNUSED(pParent);
     3438    if (!QFileInfo(strHelpFilePath).exists())
     3439    {
     3440        cannotFindHelpFile(strHelpFilePath, pParent);
     3441        return;
     3442    }
    34303443    if (!m_pHelpBrowserDialog)
    34313444    {
    3432 
    3433         UIHelpBrowserDialogFactory dialogFactory(strHelpFilePath);
     3445        UIHelpBrowserDialogFactory dialogFactory(strHelpFilePath, strKeyword);
    34343446        dialogFactory.prepare(m_pHelpBrowserDialog);
    34353447        AssertReturnVoid(m_pHelpBrowserDialog);
     
    34523464    UIHelpBrowserDialogFactory().cleanup(pDialog);
    34533465}
     3466
     3467void UIMessageCenter::sltHandleDialogHelpButtonPress()
     3468{
     3469# if defined(VBOX_WITH_DOCS_QHELP) && (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
     3470
     3471    QAbstractButton *pSender = qobject_cast<QAbstractButton*>(sender());
     3472    if (!pSender)
     3473        return;
     3474    QVariant keyWordProp = pSender->property("helptag");
     3475    if (!keyWordProp.isValid() || !keyWordProp.canConvert(QMetaType::QString))
     3476        return;
     3477    QString strKeyword = keyWordProp.toString();
     3478    showHelpBrowser(uiCommon().helpFile(), strKeyword);
     3479# endif /* #if defined(VBOX_WITH_DOCS_QHELP) && (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))&& (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)) */
     3480}
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h

    r86846 r86906  
    266266    void cannotAcquireVirtualBoxParameter(const CVirtualBox &comVBox, QWidget *pParent = 0) const;
    267267    void cannotAcquireMachineParameter(const CMachine &comMachine, QWidget *pParent = 0) const;
     268    void cannotFindHelpFile(const QString &strFileLocation, QWidget *pParent = 0) const;
    268269
    269270    /* API: Selector warnings: */
     
    552553    void sltShowUserManual(const QString &strLocation);
    553554    void sltCloseHelpBrowser();
     555    void sltHandleDialogHelpButtonPress();
    554556
    555557private slots:
     
    602604                       const QString &strButtonText1, const QString &strButtonText2, const QString &strButtonText3,
    603605                       const QString &strAutoConfirmId) const;
    604 
    605     void showHelpBrowser(const QString strHelpFilePath, QWidget *pParent = 0);
     606    /** @param strKeyword is passed possbily from a hrlp button and used by QHelpEngine infrastructure to find a
     607      * corresponding Url. */
     608    void showHelpBrowser(const QString &strHelpFilePath, const QString &strKeyword, QWidget *pParent = 0);
    606609
    607610    /** Holds the list of shown warnings. */
  • trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserDialog.cpp

    r86844 r86906  
    4444*********************************************************************************************************************************/
    4545
    46 UIHelpBrowserDialogFactory::UIHelpBrowserDialogFactory(const QString &strHelpFilePath /*  = QString() */)
    47     :m_strHelpFilePath(strHelpFilePath)
     46UIHelpBrowserDialogFactory::UIHelpBrowserDialogFactory(const QString &strHelpFilePath,
     47                                                       const QString &strKeyword /* = QString() */)
     48    : m_strHelpFilePath(strHelpFilePath)
     49    , m_strKeyword(strKeyword)
     50{
     51}
     52
     53UIHelpBrowserDialogFactory::UIHelpBrowserDialogFactory()
     54    : m_strHelpFilePath(QString())
     55    , m_strKeyword(QString())
    4856{
    4957}
     
    5159void UIHelpBrowserDialogFactory::create(QIManagerDialog *&pDialog, QWidget *pCenterWidget)
    5260{
    53     pDialog = new UIHelpBrowserDialog(pCenterWidget, m_strHelpFilePath);
     61    pDialog = new UIHelpBrowserDialog(pCenterWidget, m_strHelpFilePath, m_strKeyword);
    5462}
    5563
     
    5967*********************************************************************************************************************************/
    6068
    61 UIHelpBrowserDialog::UIHelpBrowserDialog(QWidget *pCenterWidget, const QString &strHelpFilePath)
     69UIHelpBrowserDialog::UIHelpBrowserDialog(QWidget *pCenterWidget, const QString &strHelpFilePath,
     70                                         const QString &strKeyword /* = QString() */)
    6271    : QIWithRetranslateUI<QIManagerDialog>(pCenterWidget)
    6372    , m_strHelpFilePath(strHelpFilePath)
     73    , m_strKeyword(strKeyword)
    6474{
    6575}
     
    8292{
    8393#if defined(RT_OS_LINUX) && defined(VBOX_WITH_DOCS_QHELP) && (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
    84     UIHelpBrowserWidget *pWidget = new UIHelpBrowserWidget(EmbedTo_Dialog, m_strHelpFilePath, true /* show toolbar */, this);
     94    UIHelpBrowserWidget *pWidget = new UIHelpBrowserWidget(EmbedTo_Dialog, m_strHelpFilePath, m_strKeyword);
    8595    if (pWidget)
    8696    {
  • trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserDialog.h

    r86581 r86906  
    4343class SHARED_LIBRARY_STUFF UIHelpBrowserDialogFactory : public QIManagerDialogFactory
    4444{
     45
    4546public:
    4647
    47     UIHelpBrowserDialogFactory(const QString &strHelpFilePath = QString());
     48    /** @param strHelpFilePath: the full path of the qHelp archive file.
     49      * @param strKeyword: optional keyword string. Used in context sensitive help. */
     50    UIHelpBrowserDialogFactory(const QString &strHelpFilePath, const QString &strKeyword = QString());
     51    UIHelpBrowserDialogFactory();
    4852
    4953protected:
     
    5660
    5761    QString m_strHelpFilePath;
     62    QString    m_strKeyword;
    5863};
    59 
    60 
    6164
    6265class SHARED_LIBRARY_STUFF UIHelpBrowserDialog : public QIWithRetranslateUI<QIManagerDialog>
     
    6669public:
    6770
    68     UIHelpBrowserDialog(QWidget *pCenterWidget, const QString &strHelpFilePath);
     71    UIHelpBrowserDialog(QWidget *pCenterWidget, const QString &strHelpFilePath,
     72                        const QString &strKeyword = QString());
    6973
    7074protected:
     
    105109
    106110    QString m_strHelpFilePath;
     111    QString m_strKeyword;
    107112};
    108113
  • trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserWidget.cpp

    r86884 r86906  
    277277    virtual QVariant loadResource(int type, const QUrl &name) /* override */;
    278278    void emitHistoryChangedSignal();
    279     void setSource(const QUrl &url, const QString &strError);
     279    void setSource(const QUrl &url) /* override */;
    280280    void toggleFindInPageWidget(bool fVisible);
    281281    int initialFontPointSize() const;
     
    381381    UIHelpBrowserViewer *m_pContentViewer;
    382382    const QHelpEngine* m_pHelpEngine;
    383     QString              m_strPageNotFoundText;
    384383    QUrl m_homeUrl;
    385384};
     
    404403                            const QStringList &urlList, QWidget *pParent = 0);
    405404    QStringList tabUrlList() const;
    406     void initilizeTabs();
     405    /** Either start with a single tab showin the home url or saved tab(s). Depending on the params. passed to ctor. */
     406    void initializeTabs();
     407    /** Initialize with a single url. Effectively disables multitab. Possibly used in context sensitive help mode. */
     408    void initializeSingleTab(const QUrl &url);
    407409    /* Url of the current tab. */
    408410    QUrl currentSource() const;
     
    416418    int fontPointSize() const;
    417419    void setFontScaleWidgetVisible(bool fToggled);
     420    void setMultiTabEnabled(bool fFlag);
    418421
    419422protected:
     
    438441    QUrl m_homeUrl;
    439442    QStringList m_savedUrlList;
     443    /** Immediately switch the newly created tab. Otherwise open the tab in background. */
    440444    bool m_fSwitchToNewTab;
     445    bool m_fMultiTabEnabled;
     446    bool m_fToolBarVisible;
    441447};
    442448
     
    832838    {
    833839        m_pContentViewer->blockSignals(true);
    834         m_pContentViewer->setSource(url, m_strPageNotFoundText);
     840        m_pContentViewer->setSource(url);
    835841        m_pContentViewer->blockSignals(false);
    836842        /* emit historyChanged signal explicitly since we have blocked the signals: */
     
    925931            this, &UIHelpBrowserTab::sltHandleAddBookmarkAction);
    926932
    927     m_pContentViewer->setSource(initialUrl, m_strPageNotFoundText);
     933    m_pContentViewer->setSource(initialUrl);
    928934}
    929935
     
    985991void UIHelpBrowserTab::retranslateUi()
    986992{
    987     m_strPageNotFoundText = tr("<div><p><h3>404. Not found.</h3>The page <b>%1</b> could not be found.</p></div>");
    988 
    989993    setActionTextAndToolTip(m_pHomeAction, tr("Home"), tr("Return to start page"));
    990994    setActionTextAndToolTip(m_pBackwardAction, tr("Backward"), tr("Navigate to previous page"));
     
    9981002    if (!m_pContentViewer)
    9991003        return;
    1000     m_pContentViewer->setSource(m_homeUrl, m_strPageNotFoundText);
     1004    m_pContentViewer->setSource(m_homeUrl);
    10011005}
    10021006
     
    11261130}
    11271131
    1128 void UIHelpBrowserViewer::setSource(const QUrl &url, const QString &strError)
    1129 {
    1130     if (!url.isValid())
    1131         setText(strError.arg(url.toString()));
    1132     else
    1133         QTextBrowser::setSource(url);
     1132void UIHelpBrowserViewer::setSource(const QUrl &url)
     1133{
     1134    QTextBrowser::setSource(url);
     1135    QTextDocument *pDocument = document();
     1136    if (!pDocument || pDocument->isEmpty())
     1137    {
     1138        setText(tr("<div><p><h3>404. Not found.</h3>The page <b>%1</b> could not be found.</p></div>").arg(url.toString()));
     1139    }
    11341140}
    11351141
     
    14121418    , m_savedUrlList(urlList)
    14131419    , m_fSwitchToNewTab(true)
     1420    , m_fMultiTabEnabled(true)
     1421    , m_fToolBarVisible(true)
    14141422{
    14151423    prepare();
     
    14181426void UIHelpBrowserTabManager::addNewTab(const QUrl &initialUrl)
    14191427{
     1428    if (!m_fMultiTabEnabled && count() >= 1)
     1429        return;
    14201430   UIHelpBrowserTab *pTabWidget = new  UIHelpBrowserTab(m_pHelpEngine, m_homeUrl, initialUrl);
    14211431   AssertReturnVoid(pTabWidget);
     1432   pTabWidget->setToolBarVisible(m_fToolBarVisible);
    14221433   int index = addTab(pTabWidget, pTabWidget->documentTitle());
    14231434   connect(pTabWidget, &UIHelpBrowserTab::sigSourceChanged,
     
    14431454}
    14441455
    1445 void UIHelpBrowserTabManager::initilizeTabs()
     1456void UIHelpBrowserTabManager::initializeTabs()
    14461457{
    14471458    clearAndDeleteTabs();
     1459    /* Start with a single tab showing the home URL: */
    14481460    if (m_savedUrlList.isEmpty())
    14491461        addNewTab(QUrl());
     1462    /* Start with saved tab(s): */
    14501463    else
    14511464        for (int i = 0; i < m_savedUrlList.size(); ++i)
    14521465            addNewTab(m_savedUrlList[i]);
     1466}
     1467
     1468void UIHelpBrowserTabManager::initializeSingleTab(const QUrl &url)
     1469{
     1470    m_fMultiTabEnabled = false;
     1471    clearAndDeleteTabs();
     1472    addNewTab(url);
    14531473}
    14541474
     
    14891509void UIHelpBrowserTabManager::setToolBarVisible(bool fVisible)
    14901510{
     1511    /* Make sure existing tabs are configured: */
    14911512    for (int i = 0; i < count(); ++i)
    14921513    {
     
    14961517        pTab->setToolBarVisible(fVisible);
    14971518    }
     1519    /* This is for the tabs that will be created later: */
     1520    m_fToolBarVisible = fVisible;
    14981521}
    14991522
     
    16171640*********************************************************************************************************************************/
    16181641
    1619 UIHelpBrowserWidget::UIHelpBrowserWidget(EmbedTo enmEmbedding,
    1620                                          const QString &strHelpFilePath,
    1621                                          bool fShowToolbar /* = true */,
    1622                                          QWidget *pParent /* = 0 */)
     1642UIHelpBrowserWidget::UIHelpBrowserWidget(EmbedTo enmEmbedding, const QString &strHelpFilePath,
     1643                                         const QString &strKeyword /* = QString() */, QWidget *pParent /* = 0 */)
    16231644    : QIWithRetranslateUI<QWidget>(pParent)
    16241645    , m_enmEmbedding(enmEmbedding)
    1625     , m_fShowToolbar(fShowToolbar)
    16261646    , m_fIsPolished(false)
    16271647    , m_pMainLayout(0)
     
    16301650    , m_pToolBar(0)
    16311651    , m_strHelpFilePath(strHelpFilePath)
     1652    , m_strKeyword(strKeyword)
     1653    , m_fContextSensitiveMode(strKeyword.isEmpty() ? false : true)
    16321654    , m_pHelpEngine(0)
    16331655    , m_pSplitter(0)
     
    17631785
    17641786    m_pSplitter->addWidget(m_pTabManager);
    1765 
    1766     m_pSplitter->setStretchFactor(0, 1);
    1767     m_pSplitter->setStretchFactor(1, 4);
     1787    m_pSplitter->setStretchFactor(0,0);
     1788    m_pSplitter->setStretchFactor(1,1);
     1789
    17681790    m_pSplitter->setChildrenCollapsible(false);
    17691791
     
    17961818    m_pTabWidget->insertTab(HelpBrowserTabs_Search, m_pSearchContainerWidget, QString());
    17971819    m_pTabWidget->setTabPosition(QTabWidget::South);
     1820
     1821
    17981822    m_pSearchEngine = m_pHelpEngine->searchEngine();
    17991823    AssertReturnVoid(m_pSearchEngine);
     
    18871911void UIHelpBrowserWidget::saveOptions()
    18881912{
    1889     if (m_pTabManager)
     1913    /* dont save the url list if context sensitive mode; */
     1914    if (m_pTabManager && !m_fContextSensitiveMode)
    18901915        gEDataManager->setHelpBrowserLastUrlList(m_pTabManager->tabUrlList());
    18911916}
     
    20222047void UIHelpBrowserWidget::sltHandleHelpEngineSetupFinished()
    20232048{
    2024     AssertReturnVoid(m_pTabManager && m_pHelpEngine);
    2025     m_pTabManager->initilizeTabs();
    20262049}
    20272050
     
    20702093void UIHelpBrowserWidget::sltHandleIndexingFinished()
    20712094{
    2072     if (m_pSearchContainerWidget)
    2073         m_pSearchContainerWidget->setEnabled(true);
     2095    AssertReturnVoid(m_pTabManager &&
     2096                     m_pHelpEngine &&
     2097                     m_pSearchContainerWidget);
     2098
     2099    m_pSearchContainerWidget->setEnabled(true);
     2100    if (!m_fContextSensitiveMode)
     2101        m_pTabManager->initializeTabs();
     2102    else
     2103    {
     2104        QMap<QString, QUrl> map = m_pHelpEngine->linksForIdentifier(m_strKeyword);
     2105        if (!map.isEmpty())
     2106        {
     2107            /* We have to a have a single url per keyword in this case: */
     2108            QUrl keywordUrl = map.first();
     2109            m_pTabManager->initializeSingleTab(keywordUrl);
     2110        }
     2111    }
    20742112}
    20752113
  • trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserWidget.h

    r86884 r86906  
    6868
    6969    UIHelpBrowserWidget(EmbedTo enmEmbedding, const QString &strHelpFilePath,
    70                         bool fShowToolbar = true, QWidget *pParent = 0);
     70                        const QString &strKeyword = QString(), QWidget *pParent = 0);
    7171    ~UIHelpBrowserWidget();
    7272
     
    135135    /** Hold sthe action-pool reference. */
    136136    UIActionPool *m_pActionPool;
    137     /** Holds whether we should create/show toolbar. */
    138     const bool    m_fShowToolbar;
    139137
    140138    /** Holds whether the dialog is polished. */
     
    152150
    153151    QString       m_strHelpFilePath;
     152    /** Start the browser with this keyword. When not empty widget is shown `only` with html viewer and single tab.*/
     153    QString m_strKeyword;
     154    bool    m_fContextSensitiveMode;
    154155    QHelpEngine  *m_pHelpEngine;
    155156    QSplitter           *m_pSplitter;
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/UIWizard.cpp

    r86356 r86906  
    2626#include "UIWizardPage.h"
    2727#include "UICommon.h"
     28#include "UIMessageCenter.h"
    2829#include "QIRichTextLabel.h"
    2930#include "UIExtraDataManager.h"
     
    5051    /* Make sure custom buttons shown even if final page is first to show: */
    5152    sltCurrentIdChanged(startId());
     53
     54    /* If help button is enabled by the subclass, connect it to proper slot: */
     55    if (button(QWizard::HelpButton))
     56        connect(button(QWizard::HelpButton), &QAbstractButton::pressed,
     57                &(msgCenter()), &UIMessageCenter::sltHandleDialogHelpButtonPress);
    5258}
    5359
     
    533539}
    534540#endif /* !VBOX_WS_MAC */
    535 
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVM.cpp

    r85150 r86906  
    1616 */
    1717
     18/* Qt includes: */
     19#include <QAbstractButton>
     20
    1821/* GUI includes: */
    1922#include "UICommon.h"
     
    5457    , m_iUSBCount(0)
    5558{
     59    setOptions(options() | QWizard::HaveHelpButton);
     60    if (button(QWizard::HelpButton))
     61        button(QWizard::HelpButton)->setProperty("helptag", "gui-createvm");
    5662#ifndef VBOX_WS_MAC
    5763    /* Assign watermark: */
Note: See TracChangeset for help on using the changeset viewer.

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